confirm.vue 18 KB

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