confirm.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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?.price"
  19. :num="item?.count" />
  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. } from '@/sheep/hooks/useGoods';
  196. const state = reactive({
  197. orderPayload: {},
  198. orderInfo: {
  199. items: [], // 商品项列表
  200. price: {}, // 价格信息
  201. },
  202. addressInfo: {}, // 选择的收货地址
  203. showPoints: false, // 是否积分抵扣
  204. couponInfo: [], // 优惠劵列表
  205. showDiscount: false, // 是否展示营销活动
  206. currentMemberPoints: 0, //用户当前可用积分
  207. usedPoint: 0, //用户使用的积分
  208. currentTotalPrice: 0, //当前的整个订单的总价格
  209. currentDeliveryPrice: 0 // 当前订单的总运费
  210. });
  211. // 返回来的数据根据店铺名过滤 TODO
  212. const shopsByNames = computed(() => {
  213. console.log(state.orderInfo.shopRespVOMap)
  214. const shops = {};
  215. try {
  216. Object.keys(state.orderInfo.shopRespVOMap).forEach(shopId => {
  217. const shopName = state.orderInfo.shopNameMap[shopId];
  218. if (shopName) {
  219. shops[shopName] = state.orderInfo.shopRespVOMap[shopId];
  220. shops[shopName].remark = ""
  221. shops[shopName].shopId = shopId
  222. }
  223. });
  224. } catch (e) {
  225. // console.log(e)
  226. }
  227. return shops;
  228. });
  229. // 计算所有商品的总数
  230. const totalItemCount = computed(() => {
  231. let totalCount = 0;
  232. Object.values(shopsByNames.value).forEach(shop => {
  233. shop.items.forEach(item => {
  234. totalCount += item.count;
  235. });
  236. });
  237. return totalCount;
  238. });
  239. // 选择地址
  240. function onSelectAddress() {
  241. uni.$once('SELECT_ADDRESS', (e) => {
  242. changeConsignee(e.addressInfo);
  243. });
  244. console.log(state.orderPayload.spuType)
  245. // 如果是虚拟商品 进入选虚拟地址
  246. if(state.orderPayload.spuType){
  247. sheep.$router.go('/pages/user/address/list');
  248. }else{
  249. sheep.$router.go('/pages/user/dummyAddress/list');
  250. }
  251. }
  252. // 更改收货人地址&计算订单信息
  253. async function changeConsignee(addressInfo = {}) {
  254. if (!isEmpty(addressInfo)) {
  255. state.addressInfo = addressInfo;
  256. }
  257. await getOrderInfo();
  258. }
  259. // 使用积分
  260. async function onInputPoints(points) {
  261. if (points == undefined) {
  262. points = 0
  263. }
  264. const payprice = state.currentTotalPrice
  265. state.orderInfo.price.payPrice = (payprice - points) * 100
  266. state.usedPoint = points
  267. state.showPoints = false;
  268. }
  269. // 提交订单
  270. function onConfirm() {
  271. if (!state.addressInfo.id) {
  272. sheep.$helper.toast('请选择收货地址');
  273. return;
  274. }
  275. if(state.usedPoint > state.currentMemberPoints){
  276. sheep.$helper.toast('可用积分不足');
  277. return;
  278. }
  279. submitOrder();
  280. }
  281. // 创建订单&跳转
  282. async function submitOrder() {
  283. // 处理每个店铺的留言 以{店铺id:留言}的形式返回
  284. const shops = shopsByNames.value;
  285. const shopRemarks = {};
  286. Object.keys(shops).forEach(shopName => {
  287. const shop = shops[shopName];
  288. shopRemarks[shop.shopId] = shop.remark;
  289. });
  290. const {
  291. code,
  292. data
  293. } = await OrderApi.createOrder({
  294. items: state.orderPayload.items,
  295. couponId: state.orderPayload.couponId,
  296. addressId: state.addressInfo.id,
  297. deliveryType: state.orderPayload.spuType == 1 ? 1 : 3, // TODO 非繁人:需要支持【门店自提】
  298. pointStatus: false, // TODO 非繁人:需要支持【积分选择】
  299. combinationActivityId: state.orderPayload.combinationActivityId,
  300. combinationHeadId: state.orderPayload.combinationHeadId,
  301. seckillActivityId: state.orderPayload.seckillActivityId,
  302. payIntegral: state.usedPoint,
  303. shopRemarks: shopRemarks
  304. });
  305. if (code !== 0) {
  306. return;
  307. }
  308. // 更新购物车列表,如果来自购物车
  309. if (state.orderPayload.items[0].cartId > 0) {
  310. sheep.$store('cart').getList();
  311. }
  312. // 跳转到支付页面
  313. sheep.$router.redirect('/pages/pay/index', {
  314. id: data.payOrderId,
  315. });
  316. }
  317. // 检查库存 & 计算订单价格
  318. async function getOrderInfo() {
  319. // 每次查询设置订单之前 看有没有评论 如果有评论就存到shopRemarks
  320. const shops = shopsByNames.value
  321. let shopRemarks = {};
  322. if (Object.keys(shops).length !== 0) {
  323. Object.keys(shops).forEach(shopName => {
  324. const shop = shops[shopName];
  325. shopRemarks[shopName] = shop.remark;
  326. });
  327. }
  328. const {
  329. data,
  330. code
  331. } = await OrderApi.settlementOrder({
  332. items: state.orderPayload.items,
  333. couponId: state.orderPayload.couponId,
  334. addressId: state.addressInfo.id,
  335. deliveryType: state.orderPayload.spuType == 1 ? 1 : 3, // TODO 非繁人:需要支持【门店自提】
  336. pointStatus: false, // TODO 非繁人:需要支持【积分选择】
  337. combinationActivityId: state.orderPayload.combinationActivityId,
  338. combinationHeadId: state.orderPayload.combinationHeadId,
  339. seckillActivityId: state.orderPayload.seckillActivityId,
  340. usedPoint: state.usedPoint,
  341. addressType:state.orderPayload.spuType == 1 ? 1 : 2 //如果是虚拟产品
  342. });
  343. if (code !== 0) {
  344. return;
  345. }
  346. state.orderInfo = data;
  347. // 如果shopRemarks有评论的话 就放回shopsByNames
  348. if (Object.keys(shopRemarks).length !== 0) {
  349. Object.keys(shopRemarks).forEach(shopName => {
  350. shopsByNames.value[shopName].remark = shopRemarks[shopName]
  351. });
  352. }
  353. // 设置收货地址
  354. if (state.orderInfo.address) {
  355. state.addressInfo = state.orderInfo.address;
  356. }
  357. state.currentMemberPoints = points2point(state.orderInfo.currentQuota)
  358. state.currentTotalPrice = fen2yuan(state.orderInfo.price.payPrice)
  359. state.currentDeliveryPrice = fen2yuan(state.orderInfo.price.deliveryPrice)
  360. // console.log("父",state.currentTotalPrice)
  361. if(state.orderPayload.spuPayType == 2){
  362. state.usedPoint = state.currentTotalPrice - 0.01
  363. console.log(state.spuType)
  364. }
  365. }
  366. // 获取可用优惠券
  367. // async function getCoupons() {
  368. // const {
  369. // code,
  370. // data
  371. // } = await CouponApi.getMatchCouponList(
  372. // state.orderInfo.price.payPrice,
  373. // state.orderInfo.items.map((item) => item.spuId),
  374. // state.orderPayload.items.map((item) => item.skuId),
  375. // state.orderPayload.items.map((item) => item.categoryId),
  376. // );
  377. // if (code === 0) {
  378. // state.couponInfo = data;
  379. // }
  380. // }
  381. onLoad(async (options) => {
  382. if (!options.data) {
  383. sheep.$helper.toast('参数不正确,请检查!');
  384. return;
  385. }
  386. state.orderPayload = JSON.parse(options.data);
  387. await getOrderInfo();
  388. });
  389. </script>
  390. <style lang="scss" scoped>
  391. :deep() {
  392. .uni-input-wrapper {
  393. width: 320rpx;
  394. }
  395. .uni-easyinput__content-input {
  396. font-size: 28rpx;
  397. height: 72rpx;
  398. text-align: right !important;
  399. padding-right: 0 !important;
  400. .uni-input-input {
  401. font-weight: 500;
  402. color: #333333;
  403. font-size: 26rpx;
  404. height: 32rpx;
  405. margin-top: 4rpx;
  406. }
  407. }
  408. .uni-easyinput__content {
  409. display: flex !important;
  410. align-items: center !important;
  411. justify-content: right !important;
  412. }
  413. }
  414. .order-card-box,
  415. .address-box,
  416. .total-card-box {
  417. background: white;
  418. margin: 20rpx;
  419. border-radius: 20rpx;
  420. }
  421. .title-text {
  422. font-size: 30rpx;
  423. font-weight: bold;
  424. line-height: 42rpx;
  425. }
  426. .score-img {
  427. width: 36rpx;
  428. height: 36rpx;
  429. margin: 0 4rpx;
  430. }
  431. .order-item {
  432. height: 80rpx;
  433. .item-title {
  434. font-size: 28rpx;
  435. font-weight: 400;
  436. }
  437. .item-value {
  438. font-size: 28rpx;
  439. font-weight: 500;
  440. font-family: OPPOSANS;
  441. }
  442. .text-disabled {
  443. color: #bbbbbb;
  444. }
  445. .item-icon {
  446. color: $dark-9;
  447. }
  448. .remark-input {
  449. text-align: right;
  450. }
  451. .item-placeholder {
  452. color: $dark-9;
  453. font-size: 26rpx;
  454. text-align: right;
  455. }
  456. }
  457. .total-box-footer {
  458. height: 90rpx;
  459. .total-num {
  460. color: #333333;
  461. font-family: OPPOSANS;
  462. }
  463. }
  464. .footer-box {
  465. height: 100rpx;
  466. .submit-btn {
  467. width: 230rpx;
  468. height: 70rpx;
  469. font-size: 28rpx;
  470. font-weight: 500;
  471. .goto-pay-text {
  472. line-height: 28rpx;
  473. }
  474. }
  475. .cancel-btn {
  476. width: 230rpx;
  477. height: 80rpx;
  478. font-size: 26rpx;
  479. background-color: #e5e5e5;
  480. color: $dark-9;
  481. }
  482. }
  483. .title {
  484. font-size: 36rpx;
  485. font-weight: bold;
  486. color: #333333;
  487. }
  488. .subtitle {
  489. font-size: 28rpx;
  490. color: #999999;
  491. }
  492. .cicon-checkbox {
  493. font-size: 36rpx;
  494. color: var(--ui-BG-Main);
  495. }
  496. .cicon-box {
  497. font-size: 36rpx;
  498. color: #999999;
  499. }
  500. </style>