confirm.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <template>
  2. <s-layout title="确认订单">
  3. <!-- 头部地址选择【配送地址】【自提地址】 -->
  4. <AddressSelection v-model="addressState"></AddressSelection>
  5. <!-- 商品信息 -->
  6. <view class="order-card-box ss-m-b-14">
  7. <s-goods-item
  8. v-for="item in state.orderInfo.items"
  9. :key="item.skuId"
  10. :img="item.picUrl"
  11. :title="item.spuName"
  12. :skuText="item.properties.map((property) => property.valueName).join(' ')"
  13. :price="item.price"
  14. :num="item.count"
  15. marginBottom="10"
  16. />
  17. <view class="order-item ss-flex ss-col-center ss-row-between ss-p-x-20 bg-white ss-r-10">
  18. <view class="item-title">订单备注</view>
  19. <view class="ss-flex ss-col-center">
  20. <uni-easyinput
  21. maxlength="20"
  22. placeholder="建议留言前先与商家沟通"
  23. v-model="state.orderPayload.remark"
  24. :inputBorder="false"
  25. :clearable="false"
  26. />
  27. </view>
  28. </view>
  29. </view>
  30. <!-- 价格信息 -->
  31. <view class="bg-white total-card-box ss-p-20 ss-m-b-14 ss-r-10">
  32. <view class="total-box-content border-bottom">
  33. <view class="order-item ss-flex ss-col-center ss-row-between">
  34. <view class="item-title">商品金额</view>
  35. <view class="ss-flex ss-col-center">
  36. <text class="item-value ss-m-r-24">
  37. ¥{{ fen2yuan(state.orderInfo.price.totalPrice) }}
  38. </text>
  39. </view>
  40. </view>
  41. <!-- TODO 芋艿:接入积分 -->
  42. <view
  43. class="order-item ss-flex ss-col-center ss-row-between"
  44. v-if="state.orderPayload.order_type === 'score'"
  45. >
  46. <view class="item-title">扣除积分</view>
  47. <view class="ss-flex ss-col-center">
  48. <image
  49. :src="sheep.$url.static('/static/img/shop/goods/score1.svg')"
  50. class="score-img"
  51. />
  52. <text class="item-value ss-m-r-24">{{ state.orderInfo.score_amount }}</text>
  53. </view>
  54. </view>
  55. <view class="order-item ss-flex ss-col-center ss-row-between" v-if='addressState.deliveryType === 1'>
  56. <view class="item-title">运费</view>
  57. <view class="ss-flex ss-col-center">
  58. <text class="item-value ss-m-r-24" v-if="state.orderInfo.price.deliveryPrice > 0">
  59. +¥{{ fen2yuan(state.orderInfo.price.deliveryPrice) }}
  60. </text>
  61. <view class='item-value ss-m-r-24' v-else>免运费</view>
  62. </view>
  63. </view>
  64. <view class="order-item ss-flex ss-col-center ss-row-between" v-if='addressState.deliveryType === 2'>
  65. <view class="item-title">联系人</view>
  66. <view class="ss-flex ss-col-center">
  67. <uni-easyinput
  68. maxlength="20"
  69. placeholder="请填写您的联系姓名"
  70. v-model="addressState.receiverName"
  71. :inputBorder="false"
  72. :clearable="false"
  73. />
  74. </view>
  75. </view>
  76. <view class="order-item ss-flex ss-col-center ss-row-between" v-if='addressState.deliveryType === 2'>
  77. <view class="item-title">联系电话</view>
  78. <view class="ss-flex ss-col-center">
  79. <uni-easyinput
  80. maxlength="20"
  81. placeholder="请填写您的联系电话"
  82. v-model="addressState.receiverMobile"
  83. :inputBorder="false"
  84. :clearable="false"
  85. />
  86. </view>
  87. </view>
  88. <!-- 优惠劵:只有 type = 0 普通订单(非拼团、秒杀、砍价),才可以使用优惠劵 -->
  89. <view
  90. class="order-item ss-flex ss-col-center ss-row-between"
  91. v-if="state.orderInfo.type === 0"
  92. >
  93. <view class="item-title">优惠券</view>
  94. <view class="ss-flex ss-col-center" @tap="state.showCoupon = true">
  95. <text class="item-value text-red" v-if="state.orderPayload.couponId > 0">
  96. -¥{{ fen2yuan(state.orderInfo.price.couponPrice) }}
  97. </text>
  98. <text
  99. class="item-value"
  100. :class="state.couponInfo.length > 0 ? 'text-red' : 'text-disabled'"
  101. v-else
  102. >
  103. {{
  104. state.couponInfo.length > 0 ? state.couponInfo.length + ' 张可用' : '暂无可用优惠券'
  105. }}
  106. </text>
  107. <text class="_icon-forward item-icon" />
  108. </view>
  109. </view>
  110. <view
  111. class="order-item ss-flex ss-col-center ss-row-between"
  112. v-if="state.orderInfo.price.discountPrice > 0"
  113. >
  114. <view class="item-title">活动优惠</view>
  115. <view class="ss-flex ss-col-center">
  116. <!-- @tap="state.showDiscount = true" TODO 芋艿:后续要把优惠信息打进去 -->
  117. <text class="item-value text-red">
  118. -¥{{ fen2yuan(state.orderInfo.price.discountPrice) }}
  119. </text>
  120. <text class="_icon-forward item-icon" />
  121. </view>
  122. </view>
  123. <view
  124. class="order-item ss-flex ss-col-center ss-row-between"
  125. v-if="state.orderInfo.price.vipPrice > 0"
  126. >
  127. <view class="item-title">会员优惠</view>
  128. <view class="ss-flex ss-col-center">
  129. <text class="item-value text-red">
  130. -¥{{ fen2yuan(state.orderInfo.price.vipPrice) }}
  131. </text>
  132. </view>
  133. </view>
  134. </view>
  135. <view class="total-box-footer ss-font-28 ss-flex ss-row-right ss-col-center ss-m-r-28">
  136. <view class="total-num ss-m-r-20">
  137. 共{{ state.orderInfo.items.reduce((acc, item) => acc + item.count, 0) }}件
  138. </view>
  139. <view>合计:</view>
  140. <view class="total-num text-red"> ¥{{ fen2yuan(state.orderInfo.price.payPrice) }}</view>
  141. </view>
  142. </view>
  143. <!-- 选择优惠券弹框 -->
  144. <s-coupon-select
  145. v-model="state.couponInfo"
  146. :show="state.showCoupon"
  147. @confirm="onSelectCoupon"
  148. @close="state.showCoupon = false"
  149. />
  150. <!-- 满额折扣弹框 TODO 芋艿:后续要把优惠信息打进去 -->
  151. <s-discount-list
  152. v-model="state.orderInfo"
  153. :show="state.showDiscount"
  154. @close="state.showDiscount = false"
  155. />
  156. <!-- 底部 -->
  157. <su-fixed bottom :opacity="false" bg="bg-white" placeholder :noFixed="false" :index="200">
  158. <view class="footer-box border-top ss-flex ss-row-between ss-p-x-20 ss-col-center">
  159. <view class="total-box-footer ss-flex ss-col-center">
  160. <view class="total-num ss-font-30 text-red">
  161. ¥{{ fen2yuan(state.orderInfo.price.payPrice) }}
  162. </view>
  163. </view>
  164. <button
  165. class="ss-reset-button ui-BG-Main-Gradient ss-r-40 submit-btn ui-Shadow-Main"
  166. @tap="onConfirm"
  167. >
  168. 提交订单
  169. </button>
  170. </view>
  171. </su-fixed>
  172. </s-layout>
  173. </template>
  174. <script setup>
  175. import { reactive, ref } from 'vue';
  176. import { onLoad } from '@dcloudio/uni-app';
  177. import AddressSelection from '@/pages/order/addressSelection.vue';
  178. import sheep from '@/sheep';
  179. import OrderApi from '@/sheep/api/trade/order';
  180. import CouponApi from '@/sheep/api/promotion/coupon';
  181. import { fen2yuan } from '@/sheep/hooks/useGoods';
  182. const state = reactive({
  183. orderPayload: {},
  184. orderInfo: {
  185. items: [], // 商品项列表
  186. price: {}, // 价格信息
  187. },
  188. showCoupon: false, // 是否展示优惠劵
  189. couponInfo: [], // 优惠劵列表
  190. showDiscount: false, // 是否展示营销活动
  191. });
  192. const addressState = ref({
  193. addressInfo: {}, // 选择的收货地址
  194. deliveryType: 1, // 收货方式 1 - 快递配送;2 - 门店自提
  195. isPickUp: true, // 门店自提是否开启 TODO puhui999: 默认开启,看看后端有开关的话接入
  196. pickUpInfo: {}, // 选择的自提门店信息
  197. receiverName: '', // 收件人名称
  198. receiverMobile: '', // 收件人手机
  199. });
  200. // 选择优惠券
  201. async function onSelectCoupon(couponId) {
  202. state.orderPayload.couponId = couponId || 0;
  203. await getOrderInfo();
  204. state.showCoupon = false;
  205. }
  206. // 提交订单
  207. function onConfirm() {
  208. if (addressState.value.deliveryType === 1 && !addressState.value.addressInfo.id) {
  209. sheep.$helper.toast('请选择收货地址');
  210. return;
  211. }
  212. if (addressState.value.deliveryType === 2) {
  213. if (!addressState.value.pickUpInfo.id) {
  214. sheep.$helper.toast('请选择自提门店地址');
  215. return;
  216. }
  217. if (addressState.value.receiverName === '' || addressState.value.receiverMobile === '') {
  218. sheep.$helper.toast('请填写联系人或联系人电话');
  219. return;
  220. }
  221. if (!/^[\u4e00-\u9fa5\w]{2,16}$/.test(addressState.value.receiverName)) {
  222. sheep.$helper.toast('请填写您的真实姓名');
  223. return;
  224. }
  225. if (!/^1(3|4|5|7|8|9|6)\d{9}$/.test(addressState.value.receiverMobile)) {
  226. sheep.$helper.toast('请填写正确的手机号');
  227. return;
  228. }
  229. }
  230. submitOrder();
  231. }
  232. // 创建订单&跳转
  233. async function submitOrder() {
  234. const { code, data } = await OrderApi.createOrder({
  235. items: state.orderPayload.items,
  236. couponId: state.orderPayload.couponId,
  237. remark: state.orderPayload.remark,
  238. deliveryType: addressState.value.deliveryType,
  239. addressId: addressState.value.addressInfo.id, // 收件地址编号
  240. pickUpStoreId: addressState.value.pickUpInfo.id,//自提门店编号
  241. receiverName: addressState.value.receiverName,// 选择门店自提时,该字段为联系人名
  242. receiverMobile: addressState.value.receiverMobile,// 选择门店自提时,该字段为联系人手机
  243. pointStatus: false, // TODO 芋艿:需要支持【积分选择】
  244. combinationActivityId: state.orderPayload.combinationActivityId,
  245. combinationHeadId: state.orderPayload.combinationHeadId,
  246. seckillActivityId: state.orderPayload.seckillActivityId,
  247. });
  248. if (code !== 0) {
  249. return;
  250. }
  251. // 更新购物车列表,如果来自购物车
  252. if (state.orderPayload.items[0].cartId > 0) {
  253. sheep.$store('cart').getList();
  254. }
  255. // 跳转到支付页面
  256. sheep.$router.redirect('/pages/pay/index', {
  257. id: data.payOrderId,
  258. });
  259. }
  260. // 检查库存 & 计算订单价格
  261. async function getOrderInfo() {
  262. // 计算价格
  263. const { data, code } = await OrderApi.settlementOrder({
  264. items: state.orderPayload.items,
  265. couponId: state.orderPayload.couponId,
  266. deliveryType: addressState.value.deliveryType,
  267. addressId: addressState.value.addressInfo.id, // 收件地址编号
  268. pickUpStoreId: addressState.value.pickUpInfo.id,//自提门店编号
  269. receiverName: addressState.value.receiverName,// 选择门店自提时,该字段为联系人名
  270. receiverMobile: addressState.value.receiverMobile,// 选择门店自提时,该字段为联系人手机
  271. pointStatus: false, // TODO 芋艿:需要支持【积分选择】
  272. combinationActivityId: state.orderPayload.combinationActivityId,
  273. combinationHeadId: state.orderPayload.combinationHeadId,
  274. seckillActivityId: state.orderPayload.seckillActivityId
  275. });
  276. if (code !== 0) {
  277. return;
  278. }
  279. state.orderInfo = data;
  280. // 设置收货地址
  281. if (state.orderInfo.address) {
  282. addressState.value.addressInfo = state.orderInfo.address;
  283. }
  284. }
  285. // 获取可用优惠券
  286. async function getCoupons() {
  287. const { code, data } = await CouponApi.getMatchCouponList(
  288. state.orderInfo.price.payPrice,
  289. state.orderInfo.items.map((item) => item.spuId),
  290. state.orderPayload.items.map((item) => item.skuId),
  291. state.orderPayload.items.map((item) => item.categoryId),
  292. );
  293. if (code === 0) {
  294. state.couponInfo = data;
  295. }
  296. }
  297. onLoad(async (options) => {
  298. if (!options.data) {
  299. sheep.$helper.toast('参数不正确,请检查!');
  300. return;
  301. }
  302. state.orderPayload = JSON.parse(options.data);
  303. await getOrderInfo();
  304. await getCoupons();
  305. });
  306. </script>
  307. <style lang="scss" scoped>
  308. :deep() {
  309. .uni-input-wrapper {
  310. width: 320rpx;
  311. }
  312. .uni-easyinput__content-input {
  313. font-size: 28rpx;
  314. height: 72rpx;
  315. text-align: right !important;
  316. padding-right: 0 !important;
  317. .uni-input-input {
  318. font-weight: 500;
  319. color: #333333;
  320. font-size: 26rpx;
  321. height: 32rpx;
  322. margin-top: 4rpx;
  323. }
  324. }
  325. .uni-easyinput__content {
  326. display: flex !important;
  327. align-items: center !important;
  328. justify-content: right !important;
  329. }
  330. }
  331. .score-img {
  332. width: 36rpx;
  333. height: 36rpx;
  334. margin: 0 4rpx;
  335. }
  336. .order-item {
  337. height: 80rpx;
  338. .item-title {
  339. font-size: 28rpx;
  340. font-weight: 400;
  341. }
  342. .item-value {
  343. font-size: 28rpx;
  344. font-weight: 500;
  345. font-family: OPPOSANS;
  346. }
  347. .text-disabled {
  348. color: #bbbbbb;
  349. }
  350. .item-icon {
  351. color: $dark-9;
  352. }
  353. .remark-input {
  354. text-align: right;
  355. }
  356. .item-placeholder {
  357. color: $dark-9;
  358. font-size: 26rpx;
  359. text-align: right;
  360. }
  361. }
  362. .total-box-footer {
  363. height: 90rpx;
  364. .total-num {
  365. color: #333333;
  366. font-family: OPPOSANS;
  367. }
  368. }
  369. .footer-box {
  370. height: 100rpx;
  371. .submit-btn {
  372. width: 240rpx;
  373. height: 70rpx;
  374. font-size: 28rpx;
  375. font-weight: 500;
  376. .goto-pay-text {
  377. line-height: 28rpx;
  378. }
  379. }
  380. .cancel-btn {
  381. width: 240rpx;
  382. height: 80rpx;
  383. font-size: 26rpx;
  384. background-color: #e5e5e5;
  385. color: $dark-9;
  386. }
  387. }
  388. .title {
  389. font-size: 36rpx;
  390. font-weight: bold;
  391. color: #333333;
  392. }
  393. .subtitle {
  394. font-size: 28rpx;
  395. color: #999999;
  396. }
  397. .cicon-checkbox {
  398. font-size: 36rpx;
  399. color: var(--ui-BG-Main);
  400. }
  401. .cicon-box {
  402. font-size: 36rpx;
  403. color: #999999;
  404. }
  405. </style>