confirm.vue 12 KB

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