confirm.vue 12 KB

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