confirm.vue 16 KB

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