confirm.vue 16 KB

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