confirm-order.vue 16 KB

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