confirm.vue 15 KB

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