confirm-order.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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. //存储订单信息
  258. uni.setStorageSync("orderBuyInfo", res.data);
  259. //跳转到 收银台页面
  260. uni.navigateTo({
  261. url: `/pages-car/pages/cashier-desk?id=${res.data.orderId}`
  262. })
  263. } else {
  264. this.$u.toast(res.msg || '下单失败');
  265. }
  266. }).catch(() => {
  267. uni.hideLoading();
  268. });
  269. },
  270. },
  271. onShow() {
  272. let selectAddr = uni.getStorageSync("selectAddr");
  273. if (selectAddr) {
  274. this.defaultAddr = selectAddr;
  275. this.submitData.addressId = selectAddr.id;
  276. uni.removeStorageSync("selectAddr"); // Clear after use
  277. this.refreshPreOrderData();
  278. }
  279. },
  280. };
  281. </script>
  282. <style lang="scss">
  283. .confirm-order {
  284. min-height: 100vh;
  285. background: #f5f5f5;
  286. padding: 20rpx 30rpx;
  287. padding-bottom: calc(env(safe-area-inset-bottom) + 120rpx);
  288. }
  289. .section-card {
  290. background: #fff;
  291. margin-bottom: 20rpx;
  292. padding: 30rpx;
  293. border-radius: 16rpx;
  294. box-sizing: border-box;
  295. }
  296. .u-required {
  297. color: #ff0000;
  298. margin-left: 8rpx;
  299. }
  300. .book-list {
  301. background: #fff;
  302. border-radius: 16rpx;
  303. margin-bottom: 20rpx;
  304. }
  305. .info-row {
  306. display: flex;
  307. justify-content: space-between;
  308. align-items: center;
  309. padding: 20rpx 0;
  310. font-size: 28rpx;
  311. color: #333;
  312. .label {
  313. &.red-label {
  314. color: #ff4500;
  315. font-weight: bold;
  316. }
  317. }
  318. .value {
  319. &.text-gray {
  320. color: #999;
  321. }
  322. }
  323. .mr-10 {
  324. margin-right: 10rpx;
  325. }
  326. }
  327. .bottom-bar {
  328. position: fixed;
  329. bottom: 0;
  330. left: 0;
  331. right: 0;
  332. background: #fff;
  333. padding: 20rpx 30rpx;
  334. padding-bottom: env(safe-area-inset-bottom);
  335. box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
  336. z-index: 9;
  337. .order-summary {
  338. display: flex;
  339. justify-content: space-between;
  340. align-items: center;
  341. .total {
  342. font-size: 28rpx;
  343. color: #666;
  344. .num {
  345. color: #333;
  346. font-weight: bold;
  347. margin: 0 4rpx;
  348. }
  349. .reduce-text {
  350. color: #38C148;
  351. margin-left: 10rpx;
  352. margin-right: 10rpx;
  353. background-color: #e6f9e9;
  354. padding: 4rpx 10rpx;
  355. border-radius: 4rpx;
  356. font-size: 24rpx;
  357. }
  358. .price {
  359. font-size: 36rpx;
  360. color: #ff4500;
  361. font-weight: bold;
  362. margin-left: 10rpx;
  363. }
  364. }
  365. }
  366. }
  367. .mt-20 {
  368. margin-top: 20rpx;
  369. }
  370. .ml-10 {
  371. margin-left: 10rpx;
  372. }
  373. .discount-popup {
  374. padding: 30rpx;
  375. background-color: #fff;
  376. .popup-header {
  377. display: flex;
  378. justify-content: center;
  379. align-items: center;
  380. position: relative;
  381. padding-bottom: 30rpx;
  382. border-bottom: 1rpx solid #eee;
  383. font-size: 32rpx;
  384. font-weight: bold;
  385. color: #333;
  386. .close-icon {
  387. position: absolute;
  388. right: 0;
  389. top: 0;
  390. }
  391. }
  392. .discount-list {
  393. padding: 30rpx 0;
  394. .discount-item {
  395. display: flex;
  396. justify-content: space-between;
  397. align-items: center;
  398. padding: 20rpx 0;
  399. font-size: 28rpx;
  400. .label {
  401. color: #333;
  402. }
  403. .amount {
  404. color: #ff4500;
  405. font-weight: bold;
  406. }
  407. }
  408. }
  409. .popup-footer {
  410. margin-top: 20rpx;
  411. padding-bottom: env(safe-area-inset-bottom);
  412. }
  413. }
  414. </style>