confirm.vue 11 KB

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