confirm.vue 15 KB

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