confirm.vue 14 KB

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