confirm-order.vue 17 KB

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