confirm-order.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <template>
  2. <view class="confirm-order">
  3. <custom-nav ref="ltm" :title="title" />
  4. <view v-if="!confirmed" class="pay">
  5. <view class="num">共{{ totalNum }}件</view>
  6. <view class="total">
  7. 总计:<text>¥{{ totalPrice + '.00' }}</text>
  8. </view>
  9. <view class="buy" @tap="confirm">结算({{ ' ' + totalNum + ' ' }})</view>
  10. </view>
  11. <view v-if="!confirmed" class="content">
  12. <navigator url="../address-manage/address-manage?choose=1" class="address">
  13. <view class="left">
  14. <view class="name-tel">
  15. <text class="name">收货人:{{ address ? address.con_name : '未选择' }}</text>
  16. <text class="tel">{{ address ? address.con_mobile : '' }}</text>
  17. </view>
  18. <view class="text">{{ address | getAddressString }}</view>
  19. </view>
  20. <text class="cuIcon-right"></text>
  21. </navigator>
  22. <view class="list">
  23. <view class="comfirm-item" v-for="(item, index) in list" :key="index">
  24. <view class="info item">
  25. <image :src="item.img" mode=""></image>
  26. <view class="name ellipsis">{{ item.name }}</view>
  27. </view>
  28. <view class="type" v-for="(tyepItem, typeIndex) in item.typeList" :key="typeIndex">
  29. <view class="item type-size-counter" v-for="(value, key) in tyepItem.size" :key="key">
  30. <view class="type-size">
  31. <text>款式:{{ tyepItem.name }} 尺码: {{ key }}</text>
  32. <text class="cost">¥{{ item.price * value }}.00</text>
  33. </view>
  34. <view class="num">×{{ ' ' + value + ' ' }}</view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="remark">
  40. <textarea :auto-height="true" class="textarea" v-model="remark" placeholder="请输入备注" />
  41. </view>
  42. </view>
  43. <view v-else class="success">
  44. <image class="ok" src="../../static/icon/ok.png"></image>
  45. <view class="title">下单成功,请等待上级审核发货...</view>
  46. <view class="big-btn bg" @tap="upload">查看订单</view>
  47. <view class="big-btn know" @tap="know">我知道了</view>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. import { confirmOrder } from '../../common/util/index.js'
  53. import { _API_PlaceOrder } from '@/apis/order.js'
  54. export default {
  55. data() {
  56. return {
  57. title: '确认订单',
  58. list: [],
  59. from: '',
  60. remark: '',
  61. confirmed: false,
  62. order_num: '',
  63. requesting: false
  64. }
  65. },
  66. computed: {
  67. address() { return this.$store.state.address.list[this.$store.getters['address/usingAddressIndex']] }, // 用户选择的地址
  68. totalNum() {
  69. return this.list.reduce((t, e) => {
  70. return e.typeList.reduce((tt, ee) => {
  71. return Object.keys(ee.size).reduce((ttt, eee) => {
  72. return ttt + ee.size[eee]
  73. }, tt)
  74. }, t)
  75. }, 0)
  76. },
  77. totalPrice() {
  78. return this.list.reduce((t, e) => {
  79. return e.typeList.reduce((tt, ee) => {
  80. return Object.keys(ee.size).reduce((ttt, eee) => {
  81. return ttt + ee.size[eee] * e.price
  82. }, tt)
  83. }, t)
  84. }, 0)
  85. }
  86. },
  87. onLoad(opt) {
  88. this.from = opt.from // 记录用户是用那个页面进来的
  89. this.list = JSON.parse(opt.order)
  90. },
  91. beforeDestroy() {
  92. this.$store.commit('address/CLEARCHOOSED') // 清除已选地址
  93. },
  94. methods: {
  95. upload() { // 点击查看订单
  96. uni.redirectTo({ url: `../order-detail/order-detail?order_num=${this.order_num}` })
  97. },
  98. know() { // 点击我知道了
  99. uni.navigateBack()
  100. },
  101. confirm() { // 点击提交订单
  102. if (this.address) {
  103. if (!this.requesting) {
  104. this.requesting = true
  105. this.$refs.ltm.loading()
  106. _API_PlaceOrder({ // 发送网络请求
  107. remark: this.remark, // 备注
  108. total: this.totalPrice, // 订单总金额
  109. list: confirmOrder(this.list), // 将数据转换为后端需要的数据格式
  110. address_id: this.address.id // 地址
  111. }).then(res => {
  112. if (res.code === 200) {
  113. this.requesting = false
  114. this.confirmed = true // 显示下单成功样式
  115. this.order_num = res.data.order_num // 获取订单号
  116. this.$store.commit('address/CLEARCHOOSED') // 清除已选地址
  117. if (this.from === 'gooddetail') { // 如果用户是从商品详情页点进来的,清除已选择状态
  118. this.$store.commit('choosed/CLEAR')
  119. } else if (this.from === 'shopcar') { // 如果用户是从购车车页点进来的,清除购车车中已经提交的商品
  120. this.$store.commit('shopcar/CLEARCONFIRM', this.list)
  121. }
  122. } else {
  123. this.requesting = false
  124. this.$refs.ltm.toast('下单失败,请稍后重试')
  125. }
  126. })
  127. }
  128. } else {
  129. this.$refs.ltm.toast('请选择地址')
  130. }
  131. }
  132. }
  133. }
  134. </script>
  135. <style lang="scss">
  136. .confirm-order {
  137. @include page();
  138. .pay {
  139. @include flex();
  140. left: 0;
  141. right: 0;
  142. bottom: 0;
  143. z-index: 1;
  144. height: 98rpx;
  145. position: fixed;
  146. font-size: 32rpx;
  147. background: #FFFFFF;
  148. box-shadow: 0rpx -1rpx 0rpx 0rpx rgba(178,178,178,1);
  149. .num {
  150. @include flex();
  151. height: 100%;
  152. padding: 0 30rpx;
  153. box-sizing: border-box;
  154. }
  155. .total {
  156. @include flex();
  157. flex: 1;
  158. height: 100%;
  159. padding: 0 30rpx;
  160. box-sizing: border-box;
  161. text {
  162. color: $app-base-color;
  163. }
  164. }
  165. .buy {
  166. @include flex();
  167. height: 100%;
  168. width: 220rpx;
  169. color: #FFFFFF;
  170. background: $app-base-color;
  171. }
  172. }
  173. .success {
  174. @include flex(column);
  175. height: 100%;
  176. background: #FFFFFF;
  177. box-sizing: border-box;
  178. padding: 98rpx 111rpx 0;
  179. justify-content: flex-start;
  180. .ok {
  181. width: 228rpx;
  182. height: 228rpx;
  183. }
  184. .title {
  185. font-size: 36rpx;
  186. margin-top: 100rpx;
  187. }
  188. .big-btn {
  189. width: 100%;
  190. margin-top: 121rpx;
  191. &.know {
  192. margin-top: 30rpx;
  193. }
  194. }
  195. }
  196. .content {
  197. overflow: auto;
  198. border-bottom: 98rpx solid #FFFFFF;
  199. .address {
  200. @include flex();
  201. min-height: 128rpx;
  202. background: #FFFFFF;
  203. padding: 20rpx 30rpx;
  204. margin-bottom: 10rpx;
  205. box-sizing: border-box;
  206. .left {
  207. @include flex(column);
  208. flex: 1;
  209. height: 100%;
  210. .name-tel {
  211. @include flex();
  212. width: 100%;
  213. font-size: 26rpx;
  214. justify-content: space-between;
  215. margin-bottom: 16rpx;
  216. .name {
  217. font-size: 32rpx;
  218. }
  219. }
  220. .text {
  221. width: 100%;
  222. font-size: 26rpx;
  223. line-height: 36rpx;
  224. color: $app-sec-text-color;
  225. }
  226. }
  227. >text {
  228. margin-left: 20rpx;
  229. }
  230. }
  231. .list {
  232. .comfirm-item {
  233. margin-bottom: 10rpx;
  234. .item {
  235. @include flex();
  236. height: 100rpx;
  237. font-size: 26rpx;
  238. padding: 0 30rpx;
  239. margin-bottom: 2rpx;
  240. background: #FFFFFF;
  241. box-sizing: border-box;
  242. justify-content: flex-start;
  243. &.info {
  244. height: 180rpx;
  245. image {
  246. width: 140rpx;
  247. height: 140rpx;
  248. margin-right: 30rpx;
  249. }
  250. .name {
  251. flex: 1;
  252. }
  253. }
  254. &.type-size-counter {
  255. .type-size {
  256. @include flex(column);
  257. flex: 1;
  258. height: 100%;
  259. margin-right: 30rpx;
  260. text {
  261. @include flex();
  262. flex: 1;
  263. width: 100%;
  264. justify-content: space-between;
  265. &.cost {
  266. color: $app-base-color;
  267. }
  268. }
  269. }
  270. }
  271. }
  272. }
  273. }
  274. .remark {
  275. font-size: 26rpx;
  276. margin-top: 10rpx;
  277. min-height: 120rpx;
  278. line-height: 36rpx;
  279. position: relative;
  280. background: #FFFFFF;
  281. padding: 20rpx 30rpx;
  282. box-sizing: border-box;
  283. .textarea {
  284. width: 100%;
  285. height: 80rpx;
  286. }
  287. }
  288. }
  289. }
  290. </style>