confirm.vue 17 KB

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