confirm.vue 14 KB

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