index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <template>
  2. <view class="cart-pages">
  3. <view v-if="!userInfo.receiveAddress" @click="editAddress" class="noAddress">
  4. <view>请输入收货地址</view>
  5. <u-icon name="arrow-right" size="36"></u-icon>
  6. </view>
  7. <view v-else class="cart-bar">
  8. <view>
  9. <u-image height="40rpx" width="40rpx" src="/static/position.png"></u-image>
  10. </view>
  11. <view class="position">
  12. <view class="address">{{userInfo.receiveAddress}}</view>
  13. <view>{{userInfo.receiverName +'&nbsp;&nbsp;&nbsp;' + userInfo.receiverPhone}}</view>
  14. </view>
  15. <view @click="editAddress">
  16. <u-image height="50rpx" width="50rpx" src="/static/edit.png"></u-image>
  17. </view>
  18. </view>
  19. <view class="goods-list">
  20. <!-- 商品列表 -->
  21. <view class="goods-item" v-for="(item,index) in goodsList" :key="item.id">
  22. <view class="goods-imgs">
  23. <u-image border-radius="12" width="158rpx" height="140rpx" :src="item.goods.homeImage"></u-image>
  24. </view>
  25. <view class="goods-info">
  26. <view class="good-name">{{item.goods.name}}</view>
  27. <view class="goods-price">
  28. <view>
  29. <text>{{item.goods.sellGold}}</text>
  30. <u-image mode="scaleToFill" width="30rpx" height="30rpx" src="/static/ledou.png"></u-image>
  31. </view>
  32. <view>×{{item.buyQty}}</view>
  33. </view>
  34. </view>
  35. </view>
  36. <!-- 总计 -->
  37. <view class="goods-heji">
  38. <view>
  39. <view>商品合计:</view>
  40. <view class="heji">
  41. <text>{{totalPrice}}</text>
  42. <u-image mode="scaleToFill" width="35rpx" height="35rpx" src="/static/ledou.png"></u-image>
  43. </view>
  44. </view>
  45. <view>
  46. <view>运费:</view>
  47. <view>免运费</view>
  48. </view>
  49. </view>
  50. </view>
  51. <view class="cart-submit">
  52. <view>
  53. <view>总计:<text>{{totalPrice}}</text></view>
  54. <u-image mode="scaleToFill" width="40rpx" height="40rpx" src="/static/ledou.png"></u-image>
  55. </view>
  56. <view>
  57. <u-button size="mini" :loading="btnLoading" :custom-style="toOrderButton" type="error" @click="toSave">确认支付</u-button>
  58. </view>
  59. </view>
  60. <!-- 提示用户设置支付密码 -->
  61. <u-modal v-model="showSetPswModal"
  62. content="请先设置支付密码,才能使用乐豆"
  63. show-cancel-button
  64. confirm-text="去设置"
  65. cancel-text="暂时放弃"
  66. @confirm="toSetPwd"
  67. @cancel="showSetPswModal=false"
  68. ></u-modal>
  69. <!-- 确认取消弹窗 -->
  70. <u-modal v-model="showLeavePsw"
  71. title="确认放弃支付吗?"
  72. content="您的订单在30分钟内未支付将被取消"
  73. show-cancel-button
  74. confirm-text="确认放弃"
  75. cancel-text="继续支付"
  76. @confirm="canclePay"
  77. @cancel="payAgain"
  78. ></u-modal>
  79. <!-- 确认支付弹窗 -->
  80. <u-popup mode="center" closeable @close="showLeavePsw=true" v-model="showInputPsw" width="500rpx" >
  81. <view class="slot-content">
  82. <view>确认支付</view>
  83. <view class="text-cont">
  84. <text class="num-big">{{totalPrice}}</text>乐豆
  85. </view>
  86. <view class="footer">
  87. <u-input v-model="password"
  88. maxlength="30"
  89. input-align="center"
  90. type="password"
  91. @confirm="toSaveOrder"
  92. placeholder="请输入支付密码" />
  93. </view>
  94. <view class="fot-btn">
  95. <u-button @click="toSaveOrder" type="error" >确认支付</u-button>
  96. </view>
  97. </view>
  98. </u-popup>
  99. </view>
  100. </template>
  101. <script>
  102. import { saveOrder, signPay, existPayPwd} from '@/api/order.js'
  103. import {
  104. findAddressBycustomerNo
  105. } from '@/api/receiveAddress.js'
  106. export default {
  107. data() {
  108. return {
  109. toOrderButton: {
  110. borderRadius:'100rpx',
  111. fontSize:'30rpx',
  112. width: '180rpx',
  113. height: '60rpx'
  114. },
  115. goodsList: [], // 商品列表
  116. // 用户信息
  117. userInfo: {},
  118. btnLoading: false, // 提交按钮加载圈
  119. orderId: '', // 订单id
  120. password: '', // 支付密码
  121. showSetPswModal: false, // 设置支付密码弹窗
  122. showInputPsw: false, // 打开输入密码弹窗
  123. showLeavePsw: false, // 打开确定放弃弹窗
  124. };
  125. },
  126. onShow() {
  127. this.getLocation()
  128. },
  129. onLoad() {
  130. this.goodsList = this.$store.state.vuex_toOrderList
  131. // 监听设置密码是否成功
  132. uni.$once('setPswSuccess', this.setPsw)
  133. },
  134. computed: {
  135. totalPrice() {
  136. let total = 0
  137. this.goodsList.map(item => {
  138. total = total + item.buyQty * item.goods.sellGold
  139. })
  140. return total
  141. }
  142. },
  143. methods: {
  144. // 获取用户位置
  145. getLocation() {
  146. findAddressBycustomerNo({}).then(res => {
  147. console.log(res)
  148. if (res.status == 200) {
  149. this.userInfo = res.data[0] || {}
  150. } else {
  151. this.userInfo = {}
  152. uni.showToast({
  153. title: res.message,
  154. icon: 'none'
  155. })
  156. }
  157. })
  158. },
  159. //新增/修改收货地址信息
  160. editAddress(){
  161. this.$u.vuex("vuex_OrderAddress",this.userInfo)
  162. uni.navigateTo({
  163. url:"/pages/toOrder/editAddress?"
  164. })
  165. },
  166. // 跳转到设置支付密码页
  167. toSetPwd () {
  168. uni.navigateTo({
  169. url:"/pages/userCenter/userInfo/paymentPwd"
  170. })
  171. },
  172. // 设置密码成功, 打开输入密码弹窗
  173. setPsw (e) {
  174. if (e.success) {
  175. this.showInputPsw = true
  176. }
  177. },
  178. //确认放弃
  179. canclePay() {
  180. this.showLeavePsw = false
  181. this.showInputPsw = false
  182. },
  183. // 继续支付
  184. payAgain () {
  185. this.showLeavePsw = false
  186. this.showInputPsw = true
  187. },
  188. // 支付 校验用户是否设置过支付密码
  189. toSave(){
  190. // 判断用户是否设置过支付密码
  191. existPayPwd().then(res=>{
  192. console.log(res,'rrrrrr')
  193. if(res.status == 200) {
  194. // 设置过支付密码,输入密码
  195. if(res.data) {
  196. this.showInputPsw = true
  197. } else {
  198. // 没设置过支付密码,提示设置密码
  199. this.showSetPswModal = true
  200. }
  201. } else {
  202. uni.showToast({
  203. title: res.message,
  204. icon: 'none'
  205. })
  206. }
  207. })
  208. },
  209. // 支付 保存订单
  210. toSaveOrder () {
  211. let orderGoodsList = []
  212. this.goodsList.map((item,index)=>{
  213. orderGoodsList[index] = {
  214. goodsNo: item.goodsNo,
  215. buyQty: item.buyQty
  216. }
  217. })
  218. this.btnLoading = true
  219. let params = {
  220. receiveAddress: this.userInfo.receiveAddress,
  221. receiverName: this.userInfo.receiverName,
  222. receiverPhone: this.userInfo.receiverPhone,
  223. orderGoodsList: orderGoodsList,
  224. password: this.password
  225. }
  226. saveOrder(params).then(res=>{
  227. console.log(res,'rrrrrrr')
  228. if(res.status==200) {
  229. this.orderId = res.data.id
  230. this.toPay(this.orderId)
  231. } else {
  232. this.btnLoading = false
  233. uni.showToast({
  234. title: res.message,
  235. icon: 'none'
  236. })
  237. }
  238. })
  239. },
  240. // 支付
  241. toPay(id) {
  242. signPay({id:id}).then(res=>{
  243. this.btnLoading = false
  244. if(res.status == 200) {
  245. // 跳转到支付完成界面
  246. uni.navigateTo({
  247. url:"/pages/toOrder/payFinish?id=" + this.orderId
  248. })
  249. } else{
  250. uni.showToast({
  251. title: res.message,
  252. icon: 'none'
  253. })
  254. }
  255. })
  256. }
  257. },
  258. }
  259. </script>
  260. <style lang="scss">
  261. page{
  262. height: 100%;
  263. }
  264. .cart-pages{
  265. width: 100%;
  266. height: 100%;
  267. display: flex;
  268. flex-direction: column;
  269. .cart-bar{
  270. background: #FFFFFF;
  271. border-bottom: 1px solid #F8F8F8;
  272. border-top: 10upx solid #F8F8F8;
  273. display: flex;
  274. align-items: center;
  275. padding:15upx 20upx;
  276. .position{
  277. flex-grow: 1;
  278. }
  279. > view{
  280. padding: 10upx;
  281. .address{
  282. padding: 5upx 0;
  283. }
  284. &:last-child{
  285. padding: 0 20upx;
  286. }
  287. }
  288. }
  289. .noAddress{
  290. background: #FFFFFF;
  291. border-bottom: 1px solid #F8F8F8;
  292. border-top: 10upx solid #F8F8F8;
  293. display: flex;
  294. align-items: center;
  295. justify-content: space-between;
  296. padding:30upx 20upx;
  297. font-size: 30upx;
  298. }
  299. .goods-list{
  300. padding: 20upx 0;
  301. flex-grow: 1;
  302. overflow: auto;
  303. .goods-class-box{
  304. background: #FFFFFF;
  305. box-shadow: 1px 1px 3px #eee;
  306. margin-bottom: 20upx;
  307. }
  308. .goods-item{
  309. padding: 20upx 40upx;
  310. display: flex;
  311. align-items: center;
  312. border-bottom: 1px solid #F8F8F8;
  313. background: #fff;
  314. &:last-child{
  315. border: 0;
  316. }
  317. .goods-imgs{
  318. position: relative;
  319. }
  320. .goods-info{
  321. flex-grow: 1;
  322. padding-left: 20upx;
  323. .good-name{
  324. font-weight: bold;
  325. word-break: break-all;
  326. }
  327. }
  328. .goods-price{
  329. display: flex;
  330. align-items: center;
  331. justify-content: space-between;
  332. padding-top: 20upx;
  333. >view{
  334. &:first-child{
  335. display: flex;
  336. align-items: center;
  337. text{
  338. color: red;
  339. font-size: 35upx;
  340. margin-right: 6upx;
  341. font-weight: bold;
  342. }
  343. }
  344. }
  345. }
  346. }
  347. }
  348. .goods-heji{
  349. padding: 20upx 40upx;
  350. background: #FFFFFF;
  351. box-shadow: 1px 1px 3px #eee;
  352. margin-top: 20upx;
  353. >view{
  354. display: flex;
  355. align-items: center;
  356. justify-content: space-between;
  357. padding: 10upx 0;
  358. .heji{
  359. display: flex;
  360. align-items: center;
  361. text{
  362. color: red;
  363. margin-right: 6upx;
  364. font-size: 35upx;
  365. font-weight: bold;
  366. }
  367. }
  368. }
  369. }
  370. .cart-submit{
  371. padding: 20upx 30upx;
  372. background: #FFFFFF;
  373. box-shadow: 1px 1px 3px #eee;
  374. border-top: 1px solid #eee;
  375. display: flex;
  376. align-items: center;
  377. justify-content: space-between;
  378. > view{
  379. &:first-child{
  380. display: flex;
  381. align-items: center;
  382. text{
  383. color: red;
  384. font-size: 40upx;
  385. margin-right: 6upx;
  386. font-weight: bold;
  387. }
  388. }
  389. }
  390. }
  391. // 支付密码弹窗
  392. .slot-content{
  393. padding: 30upx 0;
  394. display: flex;
  395. flex-direction: column;
  396. align-items: center;
  397. justify-content: space-between;
  398. .text-cont{
  399. width: 100%;
  400. padding: 60upx 0;
  401. text-align: center;
  402. .num-big{
  403. font-size: 40upx;
  404. color: red;
  405. }
  406. }
  407. .footer{
  408. width: 80%;
  409. border-bottom: 1px solid #b1b1b1;
  410. }
  411. }
  412. }
  413. </style>