confirm.vue 12 KB

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