confirm-order1.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <view class="confirm-order1">
  3. <navigator url="../address-manage/address-manage?choose=1" class="address">
  4. <view v-if="address" class="address-info">
  5. <view class="top">
  6. <text class="name">收货人:{{ address.con_name }}</text>
  7. <text class="phone">{{ address.con_mobile }}</text>
  8. </view>
  9. <view class="detail ellipsis">{{ address | getAddressString }}</view>
  10. </view>
  11. <view v-else class="choose">
  12. <text class="add">+</text>
  13. <text class="text">添加收货人</text>
  14. </view>
  15. <text class="cuIcon-right"></text>
  16. </navigator>
  17. <view class="border">
  18. <text style="margin-left: 0;"></text>
  19. <text v-for="item in 21" :key="item" :class="{ red: item % 2 === 1 }"></text>
  20. </view>
  21. <view class="list">
  22. <view class="list-item" v-for="(item, index) in list" :key="index" v-if="item.cart.reduce((t, e, i) => t + (item.sizeChoosed[i] ? e : 0), 0)">
  23. <view class="info">
  24. <view class="name">{{ item.name }}</view>
  25. <view class="num">
  26. <text>尺码:{{ item.sizeChoosed.reduce((t, e, i) => t + (item.cart[i] ? 1 : 0), 0) }}</text>
  27. <text>数量:{{ item.cart.reduce((t, e, i) => t + (item.sizeChoosed[i] ? e : 0), 0) }}</text>
  28. </view>
  29. </view>
  30. <view class="size-item" v-for="(sizeItem, sizeIndex) in item.size" :key="sizeIndex" v-if="item.sizeChoosed[sizeIndex] && item.cart[sizeIndex]">
  31. <image :src="item.main_img"></image>
  32. <view class="info">
  33. <text class="size">尺码:{{ sizeItem }}</text>
  34. <text class="basecolor">¥{{ item.money }}.00/{{ item.unit }}</text>
  35. </view>
  36. <view class="num">数量:{{ item.cart[sizeIndex] }}</view>
  37. </view>
  38. </view>
  39. </view>
  40. <view class="total app-item">
  41. <text>订单金额</text>
  42. <text class="basecolor">共计:¥{{ choosedPrice }}.00</text>
  43. </view>
  44. <view class="remark app-item">
  45. <text>备注信息</text>
  46. <input type="text" v-model="remark" placeholder="请输入备注信息" />
  47. </view>
  48. <view class="submit">
  49. <view class="left">合计:<text class="basecolor">¥{{ choosedPrice }}.00</text></view>
  50. <view class="right" @tap="sumbit">提交订单</view>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. import { deepClone } from '@/common/util/index.js'
  56. import { _API_PlaceOrder } from '@/apis/order.js'
  57. export default {
  58. data() {
  59. return {
  60. remark: ''
  61. }
  62. },
  63. computed: {
  64. address() { return this.$store.state.address.list[this.$store.getters['address/usingAddressIndex']] }, // 用户选择的地址
  65. list() { return this.$store.state.cart.list }, // 用户选择的地址
  66. choosedNum() { return this.$store.getters['cart/choosedNum'] },
  67. choosedPrice() { return this.$store.getters['cart/choosedPrice'] }
  68. },
  69. beforeDestroy() {
  70. this.$store.commit('address/CLEARCHOOSED') // 清除已选地址
  71. },
  72. methods: {
  73. sumbit() {
  74. if (this.address) {
  75. if (!this.requesting) {
  76. this.requesting = true
  77. uni.showLoading({ mask: true })
  78. let type = 0
  79. let total = 0
  80. let num = []
  81. let size_id = []
  82. deepClone(this.list).forEach((goodItem, goodIndex) => {
  83. goodItem.cart.forEach((n, i) => {
  84. if (n && goodItem.sizeChoosed[i]) {
  85. type ++
  86. total += n
  87. num.push(n)
  88. size_id.push(goodItem.size_id[i])
  89. }
  90. })
  91. })
  92. _API_PlaceOrder({ // 发送网络请求
  93. remark: this.remark, // 备注
  94. total,
  95. type,
  96. num,
  97. size_id,
  98. money: this.choosedPrice, // 订单总金额
  99. address_id: this.address.id // 地址
  100. }).then(res => {
  101. if (res.code === 200) {
  102. this.requesting = false
  103. this.$store.commit('address/CLEARCHOOSED') // 清除已选地址
  104. const money = this.choosedPrice
  105. deepClone(this.list).forEach((goodItem, goodIndex) => { // 清除购物车已选中项
  106. goodItem.cart.forEach((num, i) => {
  107. if (num && goodItem.sizeChoosed[i]) {
  108. this.$store.commit('cart/COUNTCHANGE', { value: 0, index: goodIndex, sizeIndex: i })
  109. }
  110. })
  111. })
  112. this.$store.commit('cart/CLEAREMPTYITEM')
  113. uni.redirectTo({ url: `../comfirm-order-success/comfirm-order-success?order_num=${res.data.order_num}&money=${money}` })
  114. } else {
  115. this.requesting = false
  116. uni.toast('下单失败,请稍后重试')
  117. }
  118. }).catch(() => his.requesting = false)
  119. }
  120. } else {
  121. uni.showToast({ title: '请选择地址', icon: 'none' })
  122. }
  123. }
  124. }
  125. }
  126. </script>
  127. <style lang="scss">
  128. .confirm-order1 {
  129. height: 100vh;
  130. overflow: auto;
  131. background: $app-base-bg;
  132. border-bottom: 100rpx solid transparent;
  133. .address {
  134. height: 120rpx;
  135. background: #FFFFFF;
  136. padding: 0 30rpx;
  137. box-sizing: border-box;
  138. @include flex();
  139. justify-content: space-between;
  140. .address-info {
  141. flex: 1;
  142. color: #181818;
  143. font-size: 28rpx;
  144. @include flex(column);
  145. align-items: flex-start;
  146. .name {
  147. font-size: 32rpx;
  148. font-weight: bold;
  149. }
  150. .phone {
  151. margin-left: 30rpx;
  152. }
  153. .detail {
  154. width: 654rpx;
  155. color: #666666;
  156. }
  157. }
  158. .choose {
  159. @include flex();
  160. justify-content: flex-start;
  161. .add {
  162. @include flex();
  163. background: $app-base-color;
  164. font-size: 40rpx;
  165. color: #FFFFFF;
  166. width: 60rpx;
  167. height: 60rpx;
  168. }
  169. .text {
  170. margin-left: 17rpx;
  171. color: 32rpx;
  172. }
  173. }
  174. .cuIcon-right {
  175. font-size: 38rpx;
  176. }
  177. }
  178. .border {
  179. @include flex();
  180. height: 6rpx;
  181. background: #FFFFFF;
  182. text {
  183. flex: 1;
  184. height: 100%;
  185. background: #3283FA;
  186. margin-left: 8rpx;
  187. &.red {
  188. background: #F56C6C;
  189. }
  190. }
  191. }
  192. .list {
  193. margin-top: 30rpx;
  194. .list-item {
  195. margin-bottom: 20rpx;
  196. > .info {
  197. height: 90rpx;
  198. @include flex();
  199. padding: 30rpx;
  200. background: #FFFFFF;
  201. margin-bottom: 1rpx;
  202. box-sizing: border-box;
  203. justify-content: space-between;
  204. .name {
  205. font-size: 32rpx;
  206. font-weight: bold;
  207. }
  208. .num {
  209. font-size: 28rpx;
  210. text {
  211. margin-left: 24rpx;
  212. }
  213. }
  214. }
  215. .size-item {
  216. @include flex();
  217. height: 200rpx;
  218. background: #FFFFFF;
  219. border-bottom: 2rpx;
  220. background: #FFFFFF;
  221. box-sizing: border-box;
  222. align-items: flex-end;
  223. justify-content: space-between;
  224. padding: 30rpx 81rpx 30rpx 30rpx;
  225. image {
  226. width: 140rpx;
  227. height: 140rpx;
  228. border-radius: 6rpx;
  229. margin-right: 30rpx;
  230. }
  231. > .info {
  232. @include flex(column);
  233. justify-content: space-between;
  234. align-items: flex-start;
  235. height: 100%;
  236. flex: 1;
  237. line-height: 2;
  238. .size {
  239. font-size: 32rpx;
  240. font-weight: bold;
  241. }
  242. .basecolor {
  243. font-weight: bold;
  244. }
  245. }
  246. .num {
  247. line-height: 2;
  248. font-size: 28rpx;
  249. }
  250. }
  251. }
  252. }
  253. .total {
  254. font-size: 32rpx;
  255. .basecolor {
  256. font-weight: bold;
  257. }
  258. }
  259. .remark {
  260. font-size: 32rpx;
  261. margin-bottom: 10rpx;
  262. input {
  263. text-align: right;
  264. }
  265. }
  266. .submit {
  267. @include flex();
  268. position: fixed;
  269. height: 100rpx;
  270. bottom: 0;
  271. width: 100vw;
  272. background: #FFFFFF;
  273. border-top: 1rpx solid #999999;
  274. .right {
  275. width: 280rpx;
  276. height: 100%;
  277. background: $app-base-color;
  278. color: #FFFFFF;
  279. @include flex();
  280. font-size: 36rpx;
  281. }
  282. .left {
  283. height: 100%;
  284. flex: 1;
  285. font-size: 28rpx;
  286. box-sizing: border-box;
  287. padding: 0 31rpx;
  288. line-height: 100rpx;
  289. }
  290. }
  291. }
  292. </style>