confirm.vue 14 KB

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