confirm-order.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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.totalMoney || 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. } else {
  201. this.$u.toast('参数错误');
  202. setTimeout(() => uni.navigateBack(), 1500);
  203. }
  204. },
  205. methods: {
  206. //添加或者选择地址
  207. handleAddress() {
  208. uni.navigateTo({
  209. url: `/pages-mine/pages/address/list?id=${this.defaultAddr.id}&isSelect=1`,
  210. });
  211. },
  212. onRedPacketConfirm(packet) {
  213. this.selectedPacket = packet;
  214. if (packet && packet.userCouponId) {
  215. this.submitData.userCouponIds = [packet.userCouponId];
  216. } else {
  217. this.submitData.userCouponIds = [];
  218. }
  219. },
  220. onStockShortageConfirm(option) {
  221. this.selectedStockOption = option;
  222. this.submitData.outOfStock = option.value;
  223. },
  224. submitOrder() {
  225. if (!this.submitData.addressId) {
  226. this.$u.toast("请选择收货地址");
  227. return;
  228. }
  229. // 显示确认弹窗
  230. this.$refs.submitConfirmDialog.openPopup();
  231. },
  232. openDiscountDetail() {
  233. this.showDiscountDetail = true;
  234. },
  235. // 确认提交订单
  236. handleConfirmSubmit() {
  237. uni.showLoading({ title: '提交中' });
  238. this.$u.api.submitShopOrderAjax(this.submitData).then((res) => {
  239. uni.hideLoading();
  240. if (res.code == 200) {
  241. uni.showToast({
  242. title: '下单成功',
  243. icon: "success",
  244. });
  245. uni.removeStorageSync("selectAddr");
  246. //存储订单信息
  247. uni.setStorageSync("orderBuyInfo", res.data);
  248. //跳转到 收银台页面
  249. uni.navigateTo({
  250. url: `/pages-car/pages/cashier-desk?id=${res.data.orderId}`
  251. })
  252. } else {
  253. this.$u.toast(res.msg || '下单失败');
  254. }
  255. }).catch(() => {
  256. uni.hideLoading();
  257. });
  258. },
  259. },
  260. onShow() {
  261. let selectAddr = uni.getStorageSync("selectAddr");
  262. if (selectAddr) {
  263. this.defaultAddr = selectAddr;
  264. this.submitData.addressId = selectAddr.id;
  265. uni.removeStorageSync("selectAddr"); // Clear after use
  266. }
  267. },
  268. };
  269. </script>
  270. <style lang="scss">
  271. .confirm-order {
  272. min-height: 100vh;
  273. background: #f5f5f5;
  274. padding: 20rpx 30rpx;
  275. padding-bottom: calc(env(safe-area-inset-bottom) + 120rpx);
  276. }
  277. .section-card {
  278. background: #fff;
  279. margin-bottom: 20rpx;
  280. padding: 30rpx;
  281. border-radius: 16rpx;
  282. box-sizing: border-box;
  283. }
  284. .u-required {
  285. color: #ff0000;
  286. margin-left: 8rpx;
  287. }
  288. .book-list {
  289. background: #fff;
  290. border-radius: 16rpx;
  291. margin-bottom: 20rpx;
  292. }
  293. .info-row {
  294. display: flex;
  295. justify-content: space-between;
  296. align-items: center;
  297. padding: 20rpx 0;
  298. font-size: 28rpx;
  299. color: #333;
  300. .label {
  301. &.red-label {
  302. color: #ff4500;
  303. font-weight: bold;
  304. }
  305. }
  306. .value {
  307. &.text-gray {
  308. color: #999;
  309. }
  310. }
  311. .mr-10 {
  312. margin-right: 10rpx;
  313. }
  314. }
  315. .bottom-bar {
  316. position: fixed;
  317. bottom: 0;
  318. left: 0;
  319. right: 0;
  320. background: #fff;
  321. padding: 20rpx 30rpx;
  322. padding-bottom: env(safe-area-inset-bottom);
  323. box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
  324. z-index: 9;
  325. .order-summary {
  326. display: flex;
  327. justify-content: space-between;
  328. align-items: center;
  329. .total {
  330. font-size: 28rpx;
  331. color: #666;
  332. .num {
  333. color: #333;
  334. font-weight: bold;
  335. margin: 0 4rpx;
  336. }
  337. .reduce-text {
  338. color: #38C148;
  339. margin-left: 10rpx;
  340. margin-right: 10rpx;
  341. background-color: #e6f9e9;
  342. padding: 4rpx 10rpx;
  343. border-radius: 4rpx;
  344. font-size: 24rpx;
  345. }
  346. .price {
  347. font-size: 36rpx;
  348. color: #ff4500;
  349. font-weight: bold;
  350. margin-left: 10rpx;
  351. }
  352. }
  353. }
  354. }
  355. .mt-20 {
  356. margin-top: 20rpx;
  357. }
  358. .ml-10 {
  359. margin-left: 10rpx;
  360. }
  361. .discount-popup {
  362. padding: 30rpx;
  363. background-color: #fff;
  364. .popup-header {
  365. display: flex;
  366. justify-content: center;
  367. align-items: center;
  368. position: relative;
  369. padding-bottom: 30rpx;
  370. border-bottom: 1rpx solid #eee;
  371. font-size: 32rpx;
  372. font-weight: bold;
  373. color: #333;
  374. .close-icon {
  375. position: absolute;
  376. right: 0;
  377. top: 0;
  378. }
  379. }
  380. .discount-list {
  381. padding: 30rpx 0;
  382. .discount-item {
  383. display: flex;
  384. justify-content: space-between;
  385. align-items: center;
  386. padding: 20rpx 0;
  387. font-size: 28rpx;
  388. .label {
  389. color: #333;
  390. }
  391. .amount {
  392. color: #ff4500;
  393. font-weight: bold;
  394. }
  395. }
  396. }
  397. .popup-footer {
  398. margin-top: 20rpx;
  399. padding-bottom: env(safe-area-inset-bottom);
  400. }
  401. }
  402. </style>