confirm-order.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. <template>
  2. <view class="confirm-order">
  3. <!-- 收货地址部分 -->
  4. <view class="section-card">
  5. <view class="flex-a flex-j-b mb-20" @click="handleAddress" v-if="defaultAddr.id">
  6. <image src="/pages-mine/static/adderss.png" style="width: 40rpx; height: 40rpx"></image>
  7. <view class="flex-d flex-1 ml-24" style="margin-right: 90rpx">
  8. <view class="flex-a flex-j-b mb-10">
  9. <view :style="titleStyle">收货人:{{ defaultAddr.name }}</view>
  10. <view :style="titleStyle">{{ defaultAddr.mobile }}</view>
  11. </view>
  12. <view :style="titleStyle">地址:{{ defaultAddr.fullAddress }}</view>
  13. </view>
  14. <u-icon name="arrow-right" :size="28" color="#666" top="4"></u-icon>
  15. </view>
  16. <view class="flex-a flex-j-b" @click="handleAddress" v-else>
  17. <view class="flex-a">
  18. <u-icon name="plus-circle-fill" :size="48" color="#38C148" top="2"></u-icon>
  19. <view :style="titleStyle" class="ml-10 font-30">添加收货地址</view>
  20. <text class="u-required">*</text>
  21. </view>
  22. <view class="flex-a">
  23. <view :style="titleStyle" class="ml-10">请添加</view>
  24. <u-icon name="arrow-right" :size="28" color="#666" top="4"></u-icon>
  25. </view>
  26. </view>
  27. </view>
  28. <!-- 商品列表 -->
  29. <view class="book-list">
  30. <buy-book-item v-for="(book, index) in books" :key="index" :book="book"></buy-book-item>
  31. </view>
  32. <!-- 订单信息 -->
  33. <view class="section-card mt-20" style="padding: 0; overflow: hidden;">
  34. <u-cell-group :border="false">
  35. <u-cell-item title="配送服务"
  36. :value="!preOrder.expressMoney ? '快递 免邮' : '快递费 ' + preOrder.expressMoney + '元'" :arrow="false"
  37. :title-style="{ color: '#333' }" :value-style="{ color: '#333' }"></u-cell-item>
  38. <u-cell-item title="红包" :value="redPacketText" @click="showRedPacket = true"
  39. :title-style="{ color: '#333' }"></u-cell-item>
  40. <u-cell-item title="订单备注" :arrow="false" :title-style="{ color: '#333' }">
  41. <u-input slot="right-icon" v-model="submitData.remark" type="text" placeholder="无备注"
  42. input-align="right" :custom-style="{ color: '#999', minHeight: '28px' }" />
  43. </u-cell-item>
  44. <u-cell-item title="如遇缺货" :value="selectedStockOption.text || '其他商品继续发货'"
  45. @click="showStockShortage = true" :border-bottom="false"
  46. :title-style="{ color: '#ff4500', fontWeight: 'bold' }"></u-cell-item>
  47. </u-cell-group>
  48. </view>
  49. <!-- 优惠详情区块 -->
  50. <view class="section-card mt-20" style="padding: 0; overflow: hidden;" v-if="(preOrder.discountList && preOrder.discountList.length > 0) || preOrder.totalReduceMoney > 0">
  51. <u-cell-group :border="false">
  52. <u-cell-item title="优惠详情" :arrow="false" :border-bottom="true"
  53. :title-style="{ color: '#333', fontWeight: 'bold' }"></u-cell-item>
  54. <template v-if="preOrder.discountList && preOrder.discountList.length > 0">
  55. <u-cell-item v-for="(item, index) in preOrder.discountList" :key="index"
  56. :title="item.discountActivityMsg" :value="'-¥' + item.discountMoney"
  57. :arrow="false" :border-bottom="true"
  58. :title-style="{ color: '#666' }" :value-style="{ color: '#ff4500', fontWeight: 'bold' }"></u-cell-item>
  59. </template>
  60. <template v-if="preOrder.totalReduceMoney > 0">
  61. <u-cell-item title="分享降价" :value="'-¥' + preOrder.totalReduceMoney"
  62. :arrow="false" :border-bottom="false"
  63. :title-style="{ color: '#666' }" :value-style="{ color: '#ff4500', fontWeight: 'bold' }"></u-cell-item>
  64. </template>
  65. </u-cell-group>
  66. </view>
  67. <!-- 底部栏 -->
  68. <view class="bottom-bar">
  69. <view class="order-summary">
  70. <view class="total">
  71. 共<text class="num">{{ preOrder.totalQuantity }}</text>本
  72. <text class="reduce-text" v-if="preOrder.totalDiscountMoney > 0" @click="openDiscountDetail">已降¥{{
  73. preOrder.totalDiscountMoney }}</text>
  74. 合计: <text class="price">¥{{ preOrder.payMoney }}</text>
  75. </view>
  76. <u-button type="primary" shape="circle" @click="submitOrder">提交订单</u-button>
  77. </view>
  78. </view>
  79. <submit-confirm ref="submitConfirmDialog" @confirm="handleConfirmSubmit"></submit-confirm>
  80. <red-packet-popup v-model="showRedPacket" :list="preOrder.couponList"
  81. @confirm="onRedPacketConfirm"></red-packet-popup>
  82. <stock-shortage-popup v-model="showStockShortage" @confirm="onStockShortageConfirm"></stock-shortage-popup>
  83. <!-- 优惠明细弹窗 -->
  84. <u-popup v-model="showDiscountDetail" mode="bottom" border-radius="24">
  85. <view class="discount-popup">
  86. <view class="popup-header">
  87. <text>优惠明细</text>
  88. <u-icon name="close" size="28" color="#999" class="close-icon"
  89. @click="showDiscountDetail = false"></u-icon>
  90. </view>
  91. <view class="discount-list">
  92. <view class="discount-item" v-for="(item, index) in preOrder.discountList" :key="index" v-if="preOrder.discountList && preOrder.discountList.length > 0">
  93. <text class="label">{{ item.discountActivityMsg }}</text>
  94. <text class="amount">-¥{{ item.discountMoney }}</text>
  95. </view>
  96. <view class="discount-item" v-if="preOrder.totalReduceMoney > 0">
  97. <text class="label">分享降价</text>
  98. <text class="amount">-¥{{ preOrder.totalReduceMoney }}</text>
  99. </view>
  100. </view>
  101. <view class="popup-footer">
  102. <u-button type="primary" shape="circle" @click="showDiscountDetail = false">确认</u-button>
  103. </view>
  104. </view>
  105. </u-popup>
  106. </view>
  107. </template>
  108. <script>
  109. import SubmitConfirm from "@/pages-car/components/submit-confirm.vue";
  110. import BuyBookItem from "@/pages-car/components/buy-book-item.vue";
  111. import RedPacketPopup from "@/pages-car/components/red-packet-popup.vue";
  112. import StockShortagePopup from "@/pages-car/components/stock-shortage-popup.vue";
  113. export default {
  114. components: {
  115. SubmitConfirm,
  116. BuyBookItem,
  117. RedPacketPopup,
  118. StockShortagePopup
  119. },
  120. data() {
  121. return {
  122. titleStyle: {
  123. "font-family": "PingFang SC",
  124. "font-weight": 400,
  125. color: "#333333",
  126. },
  127. books: [],
  128. defaultAddr: {},
  129. submitData: {
  130. cartIdList: [],
  131. addressId: "",
  132. remark: "",
  133. outOfStock: "2", // 默认为2
  134. userCouponIds: []
  135. },
  136. totalNum: 0,
  137. totalPrice: 0,
  138. totalReduced: 0,
  139. btnStyle: {
  140. width: '240rpx',
  141. height: '80rpx',
  142. lineHeight: '80rpx',
  143. background: 'linear-gradient(90deg, #ff8c00, #ff4500)',
  144. color: '#fff',
  145. fontSize: '30rpx',
  146. margin: '0'
  147. },
  148. showRedPacket: false,
  149. showStockShortage: false,
  150. showDiscountDetail: false,
  151. selectedPacket: null,
  152. selectedStockOption: { text: '其他商品继续发货(缺货商品退款)', value: 2 },
  153. preOrder: {},// 预订单信息
  154. };
  155. },
  156. computed: {
  157. redPacketText() {
  158. if (!this.preOrder.couponList || this.preOrder.couponList.length === 0) {
  159. return '暂无红包';
  160. }
  161. return this.selectedPacket ? this.selectedPacket.couponName : '请选择';
  162. },
  163. finalTotalMoney() {
  164. let total = parseFloat(this.preOrder.payMoney || 0);
  165. return total < 0 ? '0.00' : total.toFixed(2);
  166. },
  167. },
  168. onLoad(options) {
  169. // 从本地存储获取提交订单数据
  170. const preSubmitOrderData = uni.getStorageSync('preSubmitOrderData');
  171. if (preSubmitOrderData) {
  172. this.preOrder = preSubmitOrderData;
  173. this.books = preSubmitOrderData.orderDetailList || [];
  174. this.defaultAddr = preSubmitOrderData.defaultAddress || {};
  175. //拼接提交数据
  176. this.submitData.cartIdList = preSubmitOrderData.cartIdList || [];
  177. this.submitData.addressId = this.defaultAddr.id || "";
  178. }
  179. if (options.cartIdList) {
  180. // 从 URL 参数接收 cartIdList(再来一单场景)
  181. try {
  182. this.submitData.cartIdList = JSON.parse(options.cartIdList);
  183. // 加载订单预览数据
  184. this.refreshPreOrderData();
  185. } catch (e) {
  186. console.error('解析 cartIdList 失败:', e);
  187. this.$u.toast('参数错误');
  188. setTimeout(() => uni.navigateBack(), 1500);
  189. return;
  190. }
  191. }
  192. },
  193. methods: {
  194. //添加或者选择地址
  195. handleAddress() {
  196. uni.navigateTo({
  197. url: `/pages-mine/pages/address/list?id=${this.defaultAddr.id}&isSelect=1`,
  198. });
  199. },
  200. onRedPacketConfirm(packet) {
  201. this.selectedPacket = packet;
  202. if (packet && packet.userCouponId) {
  203. this.submitData.userCouponIds = [packet.userCouponId];
  204. } else {
  205. this.submitData.userCouponIds = [];
  206. }
  207. this.refreshPreOrderData();
  208. },
  209. onStockShortageConfirm(option) {
  210. this.selectedStockOption = option;
  211. this.submitData.outOfStock = option.value;
  212. },
  213. submitOrder() {
  214. if (!this.submitData.addressId) {
  215. this.$u.toast("请选择收货地址");
  216. return;
  217. }
  218. // 显示确认弹窗
  219. this.$refs.submitConfirmDialog.openPopup();
  220. },
  221. openDiscountDetail() {
  222. this.showDiscountDetail = true;
  223. },
  224. // 刷新订单预览数据
  225. refreshPreOrderData() {
  226. uni.showLoading({ title: '加载中' });
  227. this.$u.api.preSubmitOrderAjax({
  228. cartIdList: this.submitData.cartIdList,
  229. addressId: this.submitData.addressId,
  230. userCouponIds: this.submitData.userCouponIds
  231. }).then(res => {
  232. uni.hideLoading();
  233. if (res.code == 200) {
  234. this.preOrder = res.data || {};
  235. this.books = res.data.orderDetailList || [];
  236. if (res.data.defaultAddress) {
  237. this.defaultAddr = res.data.defaultAddress;
  238. }
  239. } else {
  240. this.$u.toast(res.msg || '刷新失败');
  241. }
  242. }).catch(() => {
  243. uni.hideLoading();
  244. });
  245. },
  246. // 确认提交订单
  247. handleConfirmSubmit() {
  248. uni.showLoading({ title: '提交中' });
  249. this.$u.api.submitShopOrderAjax(this.submitData).then((res) => {
  250. uni.hideLoading();
  251. if (res.code == 200) {
  252. uni.showToast({
  253. title: '下单成功',
  254. icon: "success",
  255. });
  256. uni.removeStorageSync("selectAddr");
  257. uni.removeStorageSync("preSubmitOrderData");
  258. //存储订单信息
  259. uni.setStorageSync("orderBuyInfo", res.data);
  260. //跳转到 收银台页面
  261. uni.navigateTo({
  262. url: `/pages-car/pages/cashier-desk?id=${res.data.orderId}`
  263. })
  264. } else {
  265. this.$u.toast(res.msg || '下单失败');
  266. }
  267. }).catch(() => {
  268. uni.hideLoading();
  269. });
  270. },
  271. },
  272. onShow() {
  273. let selectAddr = uni.getStorageSync("selectAddr");
  274. if (selectAddr) {
  275. this.defaultAddr = selectAddr;
  276. this.submitData.addressId = selectAddr.id;
  277. uni.removeStorageSync("selectAddr"); // Clear after use
  278. this.refreshPreOrderData();
  279. }
  280. },
  281. };
  282. </script>
  283. <style lang="scss">
  284. .confirm-order {
  285. min-height: 100vh;
  286. background: #f5f5f5;
  287. padding: 20rpx 30rpx;
  288. padding-bottom: calc(env(safe-area-inset-bottom) + 120rpx);
  289. }
  290. .section-card {
  291. background: #fff;
  292. margin-bottom: 20rpx;
  293. padding: 30rpx;
  294. border-radius: 16rpx;
  295. box-sizing: border-box;
  296. }
  297. .u-required {
  298. color: #ff0000;
  299. margin-left: 8rpx;
  300. }
  301. .book-list {
  302. background: #fff;
  303. border-radius: 16rpx;
  304. margin-bottom: 20rpx;
  305. }
  306. .info-row {
  307. display: flex;
  308. justify-content: space-between;
  309. align-items: center;
  310. padding: 20rpx 0;
  311. font-size: 28rpx;
  312. color: #333;
  313. .label {
  314. &.red-label {
  315. color: #ff4500;
  316. font-weight: bold;
  317. }
  318. }
  319. .value {
  320. &.text-gray {
  321. color: #999;
  322. }
  323. }
  324. .mr-10 {
  325. margin-right: 10rpx;
  326. }
  327. }
  328. .bottom-bar {
  329. position: fixed;
  330. bottom: 0;
  331. left: 0;
  332. right: 0;
  333. background: #fff;
  334. padding: 20rpx 30rpx;
  335. padding-bottom: env(safe-area-inset-bottom);
  336. box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
  337. z-index: 9;
  338. .order-summary {
  339. display: flex;
  340. justify-content: space-between;
  341. align-items: center;
  342. .total {
  343. font-size: 28rpx;
  344. color: #666;
  345. .num {
  346. color: #333;
  347. font-weight: bold;
  348. margin: 0 4rpx;
  349. }
  350. .reduce-text {
  351. color: #38C148;
  352. margin-left: 10rpx;
  353. margin-right: 10rpx;
  354. background-color: #e6f9e9;
  355. padding: 4rpx 10rpx;
  356. border-radius: 4rpx;
  357. font-size: 24rpx;
  358. }
  359. .price {
  360. font-size: 36rpx;
  361. color: #ff4500;
  362. font-weight: bold;
  363. margin-left: 10rpx;
  364. }
  365. }
  366. }
  367. }
  368. .mt-20 {
  369. margin-top: 20rpx;
  370. }
  371. .ml-10 {
  372. margin-left: 10rpx;
  373. }
  374. .discount-popup {
  375. padding: 30rpx;
  376. background-color: #fff;
  377. .popup-header {
  378. display: flex;
  379. justify-content: center;
  380. align-items: center;
  381. position: relative;
  382. padding-bottom: 30rpx;
  383. border-bottom: 1rpx solid #eee;
  384. font-size: 32rpx;
  385. font-weight: bold;
  386. color: #333;
  387. .close-icon {
  388. position: absolute;
  389. right: 0;
  390. top: 0;
  391. }
  392. }
  393. .discount-list {
  394. padding: 30rpx 0;
  395. .discount-item {
  396. display: flex;
  397. justify-content: space-between;
  398. align-items: center;
  399. padding: 20rpx 0;
  400. font-size: 28rpx;
  401. .label {
  402. color: #333;
  403. }
  404. .amount {
  405. color: #ff4500;
  406. font-weight: bold;
  407. }
  408. }
  409. }
  410. .popup-footer {
  411. margin-top: 20rpx;
  412. padding-bottom: env(safe-area-inset-bottom);
  413. }
  414. }
  415. </style>