confirm.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <template>
  2. <s-layout title="确认订单">
  3. <!-- v-if="state.orderInfo.need_address === 1" -->
  4. <!-- 这个判断先删除 -->
  5. <view class="bg-white address-box ss-m-b-14 ss-r-b-10" @tap="onSelectAddress">
  6. <s-address-item :item="state.addressInfo" :hasBorderBottom="false">
  7. <view class="ss-rest-button"><text class="_icon-forward"></text></view>
  8. </s-address-item>
  9. </view>
  10. <view class="order-card-box ss-m-b-14">
  11. <s-goods-item v-for="item in state.orderInfo.goods_list" :key="item.goods_id"
  12. :img="item.current_sku_price.image || item.goods.image" :title="item.goods.title"
  13. :skuText="item.current_sku_price?.goods_sku_text" :price="item.current_sku_price.price"
  14. :num="item.goods_num" marginBottom="10">
  15. <template #top>
  16. <view class="order-item ss-flex ss-col-center ss-row-between ss-p-x-20 bg-white">
  17. <view class="item-title">配送方式</view>
  18. <view class="ss-flex ss-col-center">
  19. <text class="item-value">{{ item.dispatch_type_text }}</text>
  20. </view>
  21. </view>
  22. </template>
  23. </s-goods-item>
  24. <view class="order-item ss-flex ss-col-center ss-row-between ss-p-x-20 bg-white ss-r-10">
  25. <view class="item-title">订单备注</view>
  26. <view class="ss-flex ss-col-center">
  27. <uni-easyinput maxlength="20" placeholder="建议留言前先与商家沟通" v-model="state.orderPayload.remark"
  28. :inputBorder="false" :clearable="false"></uni-easyinput>
  29. </view>
  30. </view>
  31. </view>
  32. <!-- 合计 -->
  33. <view class="bg-white total-card-box ss-p-20 ss-m-b-14 ss-r-10">
  34. <view class="total-box-content border-bottom">
  35. <view class="order-item ss-flex ss-col-center ss-row-between">
  36. <view class="item-title">商品金额</view>
  37. <view class="ss-flex ss-col-center">
  38. <text class="item-value ss-m-r-24">¥{{ state.orderInfo.goods_amount }}</text>
  39. </view>
  40. </view>
  41. <view class="order-item ss-flex ss-col-center ss-row-between"
  42. v-if="state.orderPayload.order_type === 'score'">
  43. <view class="item-title">扣除积分</view>
  44. <view class="ss-flex ss-col-center">
  45. <image :src="sheep.$url.static('/static/img/shop/goods/score1.svg')" class="score-img"></image>
  46. <text class="item-value ss-m-r-24">{{ state.orderInfo.score_amount }}</text>
  47. </view>
  48. </view>
  49. <view class="order-item ss-flex ss-col-center ss-row-between">
  50. <view class="item-title">运费</view>
  51. <view class="ss-flex ss-col-center">
  52. <text class="item-value ss-m-r-24">+¥{{ state.orderInfo.dispatch_amount }}</text>
  53. </view>
  54. </view>
  55. <view class="order-item ss-flex ss-col-center ss-row-between"
  56. v-if="state.orderPayload.order_type != 'score'">
  57. <!-- <view v-if="state.orderInfo.coupon_discount_fee > 0" class="order-item ss-flex ss-col-center ss-row-between"> -->
  58. <view class="item-title">优惠券</view>
  59. <view class="ss-flex ss-col-center" @tap="state.showCoupon = true">
  60. <text class="item-value text-red"
  61. v-if="state.orderPayload.coupon_id">-¥{{ state.orderInfo.coupon_discount_fee }}</text>
  62. <text class="item-value"
  63. :class="state.couponInfo.can_use?.length > 0 ? 'text-red' : 'text-disabled'" v-else>{{
  64. state.couponInfo.can_use?.length > 0
  65. ? state.couponInfo.can_use?.length + '张可用'
  66. : '暂无可用优惠券'
  67. }}</text>
  68. <text class="_icon-forward item-icon"></text>
  69. </view>
  70. </view>
  71. <view class="order-item ss-flex ss-col-center ss-row-between"
  72. v-if="state.orderInfo.promo_infos?.length">
  73. <!-- <view v-if="state.orderInfo.promo_discount_fee > 0" class="order-item ss-flex ss-col-center ss-row-between"> -->
  74. <view class="item-title">活动优惠</view>
  75. <view class="ss-flex ss-col-center" @tap="state.showDiscount = true">
  76. <text class="item-value text-red"> -¥{{ state.orderInfo.promo_discount_fee }} </text>
  77. <text class="_icon-forward item-icon"></text>
  78. </view>
  79. </view>
  80. </view>
  81. <view class="total-box-footer ss-font-28 ss-flex ss-row-right ss-col-center ss-m-r-28">
  82. <view class="total-num ss-m-r-20">共{{ state.totalNumber }}件</view>
  83. <view>合计:</view>
  84. <view class="total-num text-red"> ¥{{ state.orderInfo.pay_fee }} </view>
  85. <view class="ss-flex" v-if="state.orderPayload.order_type === 'score'">
  86. <view class="total-num ss-font-30 text-red ss-m-l-4"> + </view>
  87. <image :src="sheep.$url.static('/static/img/shop/goods/score1.svg')" class="score-img"></image>
  88. <view class="total-num ss-font-30 text-red">{{ state.orderInfo.score_amount }}</view>
  89. </view>
  90. </view>
  91. </view>
  92. <!-- 发票 -->
  93. <view class="bg-white ss-p-20 ss-r-20">
  94. <view class="order-item ss-flex ss-col-center ss-row-between">
  95. <view class="item-title">发票申请</view>
  96. <view class="ss-flex ss-col-center" @tap="onSelectInvoice">
  97. <text class="item-value">{{ state.invoiceInfo.name || '无需开具发票' }}</text>
  98. <text class="_icon-forward item-icon"></text>
  99. </view>
  100. </view>
  101. </view>
  102. <!-- 选择优惠券弹框 -->
  103. <s-coupon-select v-model="state.couponInfo" :show="state.showCoupon" @confirm="onSelectCoupon"
  104. @close="state.showCoupon = false" />
  105. <!-- 满额折扣弹框 -->
  106. <s-discount-list v-model="state.orderInfo" :show="state.showDiscount" @close="state.showDiscount = false" />
  107. <!-- 底部 -->
  108. <su-fixed bottom :opacity="false" bg="bg-white" placeholder :noFixed="false" :index="200">
  109. <view class="footer-box border-top ss-flex ss-row-between ss-p-x-20 ss-col-center">
  110. <view class="total-box-footer ss-flex ss-col-center">
  111. <view class="total-num ss-font-30 text-red"> ¥{{ state.orderInfo.pay_fee }} </view>
  112. <view v-if="state.orderPayload.order_type === 'score'" class="ss-flex">
  113. <view class="total-num ss-font-30 text-red ss-m-l-4">+</view>
  114. <image :src="sheep.$url.static('/static/img/shop/goods/score1.svg')" class="score-img"></image>
  115. <view class="total-num ss-font-30 text-red">{{ state.orderInfo.score_amount }}</view>
  116. </view>
  117. </view>
  118. <button class="ss-reset-button ui-BG-Main-Gradient ss-r-40 submit-btn ui-Shadow-Main" @tap="onConfirm">
  119. {{ exchangeNow ? '立即兑换' : '提交订单' }}
  120. </button>
  121. </view>
  122. </su-fixed>
  123. </s-layout>
  124. </template>
  125. <script setup>
  126. import {
  127. reactive,
  128. computed
  129. } from 'vue';
  130. import {
  131. onLoad,
  132. onPageScroll,
  133. onShow
  134. } from '@dcloudio/uni-app';
  135. import sheep from '@/sheep';
  136. import {
  137. isEmpty
  138. } from 'lodash';
  139. const state = reactive({
  140. orderPayload: {},
  141. orderInfo: {},
  142. addressInfo: {},
  143. invoiceInfo: {},
  144. totalNumber: 0,
  145. showCoupon: false,
  146. couponInfo: [],
  147. showDiscount: false,
  148. });
  149. // 立即兑换(立即兑换无需跳转收银台)
  150. const exchangeNow = computed(
  151. () => state.orderPayload.order_type === 'score' && state.orderInfo.pay_fee == 0,
  152. );
  153. // 选择地址
  154. function onSelectAddress() {
  155. uni.$once('SELECT_ADDRESS', (e) => {
  156. changeConsignee(e.addressInfo);
  157. });
  158. sheep.$router.go('/pages/user/address/list');
  159. }
  160. // 更改收货人地址&计算订单信息
  161. async function changeConsignee(addressInfo = {}) {
  162. if (isEmpty(addressInfo)) {
  163. const {
  164. code,
  165. data
  166. } = await sheep.$api.user.address.default();
  167. console.log(data, '默认收货地址');
  168. if (code === 0 && !isEmpty(data)) {
  169. console.log('执行赋值')
  170. addressInfo = data;
  171. }
  172. }
  173. if (!isEmpty(addressInfo)) {
  174. state.addressInfo = addressInfo;
  175. state.orderPayload.address_id = state.addressInfo.id;
  176. }
  177. getOrderInfo();
  178. }
  179. // 选择优惠券
  180. async function onSelectCoupon(e) {
  181. state.orderPayload.coupon_id = e || 0;
  182. getOrderInfo();
  183. state.showCoupon = false;
  184. }
  185. // 选择发票信息
  186. function onSelectInvoice() {
  187. uni.$once('SELECT_INVOICE', (e) => {
  188. state.invoiceInfo = e.invoiceInfo;
  189. state.orderPayload.invoice_id = e.invoiceInfo.id || 0;
  190. });
  191. sheep.$router.go('/pages/user/invoice/list');
  192. }
  193. // 提交订单/立即兑换
  194. function onConfirm() {
  195. if (!state.orderPayload.address_id && state.orderInfo.need_address === 1) {
  196. sheep.$helper.toast('请选择收货地址');
  197. return;
  198. }
  199. if (exchangeNow.value) {
  200. uni.showModal({
  201. title: '提示',
  202. content: '确定使用积分立即兑换?',
  203. cancelText: '再想想',
  204. success: async function(res) {
  205. if (res.confirm) {
  206. submitOrder();
  207. }
  208. },
  209. });
  210. } else {
  211. submitOrder();
  212. }
  213. }
  214. // 创建订单&跳转
  215. async function submitOrder() {
  216. const {
  217. error,
  218. data
  219. } = await sheep.$api.order.create(state.orderPayload);
  220. if (error === 0) {
  221. // 更新购物车列表
  222. if (state.orderPayload.from === 'cart') {
  223. sheep.$store('cart').getList();
  224. }
  225. if (exchangeNow.value) {
  226. sheep.$router.redirect('/pages/pay/result', {
  227. orderSN: data.order_sn,
  228. });
  229. } else {
  230. sheep.$router.redirect('/pages/pay/index', {
  231. orderSN: data.order_sn,
  232. });
  233. }
  234. }
  235. }
  236. // 检查库存&计算订单价格
  237. async function getOrderInfo() {
  238. console.log(state.orderPayload, '计算价格传参')
  239. // let {code, data} = await sheep.$api.order.calc(state.orderPayload);
  240. // let data = await sheep.$api.order.calc(state.orderPayload);
  241. console.log(state.orderPayload.items)
  242. let data = await sheep.$api.order.calc({
  243. deliveryType: 1,
  244. pointStatus: false,
  245. items: state.orderPayload.items
  246. });
  247. console.log(data, '修改后的获取订单详细数据')
  248. return;
  249. if (error === 0) {
  250. state.totalNumber = 0;
  251. state.orderInfo = data;
  252. state.orderInfo.goods_list.forEach((item) => {
  253. state.totalNumber += item.goods_num;
  254. });
  255. }
  256. }
  257. // 获取可用优惠券
  258. async function getCoupons() {
  259. const {
  260. error,
  261. data
  262. } = await sheep.$api.order.coupons(state.orderPayload);
  263. if (error === 0) {
  264. state.couponInfo = data;
  265. }
  266. }
  267. onLoad(async (options) => {
  268. console.log(options)
  269. if (options.data) {
  270. state.orderPayload = JSON.parse(options.data);
  271. changeConsignee();
  272. if (state.orderPayload.order_type !== 'score') {
  273. getCoupons();
  274. }
  275. }
  276. });
  277. </script>
  278. <style lang="scss" scoped>
  279. :deep() {
  280. .uni-input-wrapper {
  281. width: 320rpx;
  282. }
  283. .uni-easyinput__content-input {
  284. font-size: 28rpx;
  285. height: 72rpx;
  286. text-align: right !important;
  287. padding-right: 0 !important;
  288. .uni-input-input {
  289. font-weight: 500;
  290. color: #333333;
  291. font-size: 26rpx;
  292. height: 32rpx;
  293. margin-top: 4rpx;
  294. }
  295. }
  296. .uni-easyinput__content {
  297. display: flex !important;
  298. align-items: center !important;
  299. justify-content: right !important;
  300. }
  301. }
  302. .score-img {
  303. width: 36rpx;
  304. height: 36rpx;
  305. margin: 0 4rpx;
  306. }
  307. .order-item {
  308. height: 80rpx;
  309. .item-title {
  310. font-size: 28rpx;
  311. font-weight: 400;
  312. }
  313. .item-value {
  314. font-size: 28rpx;
  315. font-weight: 500;
  316. font-family: OPPOSANS;
  317. }
  318. .text-disabled {
  319. color: #bbbbbb;
  320. }
  321. .item-icon {
  322. color: $dark-9;
  323. }
  324. .remark-input {
  325. text-align: right;
  326. }
  327. .item-placeholder {
  328. color: $dark-9;
  329. font-size: 26rpx;
  330. text-align: right;
  331. }
  332. }
  333. .total-box-footer {
  334. height: 90rpx;
  335. .total-num {
  336. color: #333333;
  337. font-family: OPPOSANS;
  338. }
  339. }
  340. .footer-box {
  341. height: 100rpx;
  342. .submit-btn {
  343. width: 240rpx;
  344. height: 70rpx;
  345. font-size: 28rpx;
  346. font-weight: 500;
  347. .goto-pay-text {
  348. line-height: 28rpx;
  349. }
  350. }
  351. .cancel-btn {
  352. width: 240rpx;
  353. height: 80rpx;
  354. font-size: 26rpx;
  355. background-color: #e5e5e5;
  356. color: $dark-9;
  357. }
  358. }
  359. .title {
  360. font-size: 36rpx;
  361. font-weight: bold;
  362. color: #333333;
  363. }
  364. .subtitle {
  365. font-size: 28rpx;
  366. color: #999999;
  367. }
  368. .cicon-checkbox {
  369. font-size: 36rpx;
  370. color: var(--ui-BG-Main);
  371. }
  372. .cicon-box {
  373. font-size: 36rpx;
  374. color: #999999;
  375. }
  376. </style>