confirm.vue 12 KB

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