order.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <view class="order">
  3. <!-- 默认地址 -->
  4. <van-cell icon="contact-o" is-link>
  5. <template #title class="tips">
  6. <view class="top">姓名:{{defaultArr === '' ? '' : addressList[0].receiver + " " + addressList[0].mobile}}
  7. </view>
  8. <view class="bottom van-ellipsis">地址:{{defaultArr === "" ? "展示默认地址" : defaultArr}}</view>
  9. </template>
  10. </van-cell>
  11. <!-- 商品信息 -->
  12. <view class="main">
  13. <view v-for="(item,index) in shopCart.shopCartOrders" :key="index">
  14. <view v-for="(item1,index1) in item.shopCartItemDiscounts[0].shopCartItems" :key="index1">
  15. <view class="shopName">
  16. {{item.shopName}}
  17. </view>
  18. <van-card :num="item1.prodCount" :price="item1.price" :desc="item1.skuName" :title="item1.prodName"
  19. :thumb="item1.pic">
  20. <template #footer>
  21. <view>
  22. <van-stepper :value="item1.prodCount" disabled integer />
  23. <view class="free">
  24. 邮费:<text>{{item.transfee}}元</text>
  25. </view>
  26. </view>
  27. </template>
  28. </van-card>
  29. </view>
  30. </view>
  31. <!-- 订单备注 -->
  32. <van-cell title="订单备注" value="请输入订单信息" :label="item.remarks" :border="false" />
  33. <!-- 优惠劵 -->
  34. <van-cell title="优惠劵" is-link value="暂无可用" :border="false" />
  35. </view>
  36. <!-- 分割线 -->
  37. <van-divider custom-style="border:7px solid #eee"/>
  38. <!-- 订单信息 -->
  39. <van-cell title="总金额" value="">
  40. <template #default>
  41. <view>¥{{shopCart.total}}</view>
  42. </template>
  43. </van-cell>
  44. <van-cell title="优惠金额" :value="shopCart.orderReduce" />
  45. <van-cell title="商品总数" :value="shopCart.totalCount" />
  46. <van-cell title="支付金额" value="">
  47. <template #default>
  48. <view class="payCount">
  49. 合计:¥{{shopCart.actualTotal}}
  50. </view>
  51. </template>
  52. </van-cell>
  53. <!-- 按钮 -->
  54. <van-submit-bar
  55. :price="shopCart.actualTotal * 100"
  56. button-text="提交订单"
  57. @submit="onSubmit"
  58. />
  59. </view>
  60. </template>
  61. <script>
  62. import {
  63. prodInfo
  64. } from '@/api/address.js'
  65. import {
  66. confirm,
  67. submit,
  68. pay
  69. } from '@/api/order.js'
  70. export default {
  71. data() {
  72. return {
  73. addressList: [],
  74. defaultArr: "",
  75. shopCart: [],
  76. shopMain:{
  77. orderShopParam: [
  78. {
  79. shopId: 0,
  80. remarks: ""
  81. }
  82. ],
  83. }
  84. }
  85. },
  86. onShow() {
  87. this.confirm = JSON.parse(uni.getStorageSync("confirm"));
  88. this.getAddress();
  89. this.getCard();
  90. },
  91. methods: {
  92. async getAddress() {
  93. this.addressList = await prodInfo();
  94. for (const key in this.addressList) {
  95. // console.log(key)
  96. if (Object.hasOwnProperty.call(this.addressList, key)) {
  97. if (this.addressList[key].commonAddr === 1) {
  98. console.log(this.addressList[key])
  99. const result = this.addressList[key];
  100. this.defaultArr = result.province + "" + result.city + "" + result.area + "" + result.addr;
  101. }
  102. }
  103. }
  104. },
  105. async getCard() {
  106. let result = await confirm(this.confirm);
  107. result.shopCartOrders.map(item => item.remarks = "");
  108. this.shopCart = result;
  109. console.log(this.shopCart, 'shopCart');
  110. },
  111. async onSubmit() {
  112. console.log("点击")
  113. let cardInfo = this.shopCart.shopCartOrders;
  114. for(var i=0;i<cardInfo.length;i++) {
  115. this.shopMain.orderShopParam.push({
  116. shopId: cardInfo[i].shopId,
  117. remarks: cardInfo[i].remarks
  118. })
  119. }
  120. let result = await submit(this.shopMain);
  121. console.log(result,'结果')
  122. let shopList = await pay({
  123. orderNumbers: result.orderNumbers,
  124. payType: 1
  125. })
  126. uni.showModal({
  127. title:"支付成功",
  128. content:"恭喜您完成支付!",
  129. success: function(res) {
  130. uni.switchTab({
  131. url:"/pages/my/my"
  132. })
  133. }
  134. })
  135. }
  136. }
  137. }
  138. </script>
  139. <style lang="scss">
  140. .van-ellipsis {
  141. width: 500rpx;
  142. }
  143. .main {
  144. padding: 20rpx;
  145. .shopName {
  146. font-size: 35rpx;
  147. }
  148. }
  149. .payCount {
  150. color: #f00;
  151. }
  152. </style>