confirm.vue 16 KB

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