confirm-order.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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="配送服务" value="快递 免邮" :arrow="false" :title-style="{ color: '#333' }"
  36. :value-style="{ color: '#333' }"></u-cell-item>
  37. <u-cell-item title="红包" :value="selectedPacket ? selectedPacket.name : ''" @click="showRedPacket = true"
  38. :title-style="{ color: '#333' }"></u-cell-item>
  39. <u-cell-item title="订单备注" :arrow="false" :title-style="{ color: '#333' }">
  40. <u-input slot="right-icon" v-model="submitData.remark" type="text" placeholder="无备注"
  41. input-align="right" :custom-style="{ color: '#999', minHeight: '28px' }" />
  42. </u-cell-item>
  43. <u-cell-item title="如遇缺货" :value="selectedStockOption.text || '其他商品继续发货'"
  44. @click="showStockShortage = true" :border-bottom="false"
  45. :title-style="{ color: '#ff4500', fontWeight: 'bold' }"></u-cell-item>
  46. </u-cell-group>
  47. </view>
  48. <!-- 底部栏 -->
  49. <view class="bottom-bar">
  50. <view class="order-summary">
  51. <view class="total">
  52. 共<text class="num">{{ preOrder.totalQuantity }}</text>本
  53. <text class="reduce-text" v-if="preOrder.discountMoney > 0">已降¥{{ preOrder.discountMoney }}</text>
  54. 合计: <text class="price">¥{{ preOrder.totalMoney }}</text>
  55. </view>
  56. <u-button type="primary" shape="circle" @click="submitOrder">提交订单</u-button>
  57. </view>
  58. </view>
  59. <submit-confirm ref="submitConfirmDialog" @confirm="handleConfirmSubmit"></submit-confirm>
  60. <red-packet-popup v-model="showRedPacket" @confirm="onRedPacketConfirm"></red-packet-popup>
  61. <stock-shortage-popup v-model="showStockShortage" @confirm="onStockShortageConfirm"></stock-shortage-popup>
  62. </view>
  63. </template>
  64. <script>
  65. import SubmitConfirm from "@/pages-car/components/submit-confirm.vue";
  66. import BuyBookItem from "@/pages-car/components/buy-book-item.vue";
  67. import RedPacketPopup from "@/pages-car/components/red-packet-popup.vue";
  68. import StockShortagePopup from "@/pages-car/components/stock-shortage-popup.vue";
  69. export default {
  70. components: {
  71. SubmitConfirm,
  72. BuyBookItem,
  73. RedPacketPopup,
  74. StockShortagePopup
  75. },
  76. data() {
  77. return {
  78. titleStyle: {
  79. "font-family": "PingFang SC",
  80. "font-weight": 400,
  81. color: "#333333",
  82. },
  83. books: [],
  84. defaultAddr: {},
  85. submitData: {
  86. cartIdList: [],
  87. addressId: "",
  88. remark: "",
  89. outOfStock: "2", // 默认为2
  90. userCouponIds: []
  91. },
  92. totalNum: 0,
  93. totalPrice: 0,
  94. totalReduced: 0,
  95. btnStyle: {
  96. width: '240rpx',
  97. height: '80rpx',
  98. lineHeight: '80rpx',
  99. background: 'linear-gradient(90deg, #ff8c00, #ff4500)',
  100. color: '#fff',
  101. fontSize: '30rpx',
  102. margin: '0'
  103. },
  104. showRedPacket: false,
  105. showStockShortage: false,
  106. selectedPacket: null,
  107. selectedStockOption: { text: '其他商品继续发货(缺货商品退款)', value: 2 },
  108. preOrder: {},// 预订单信息
  109. };
  110. },
  111. onLoad(options) {
  112. // 从本地存储获取提交订单数据
  113. const preSubmitOrderData = uni.getStorageSync('preSubmitOrderData');
  114. if (preSubmitOrderData) {
  115. this.preOrder = preSubmitOrderData;
  116. this.books = preSubmitOrderData.orderDetailList || [];
  117. this.defaultAddr = preSubmitOrderData.defaultAddress || {};
  118. //拼接提交数据
  119. this.submitData.cartIdList = preSubmitOrderData.cartIdList || [];
  120. this.submitData.addressId = this.defaultAddr.id || "";
  121. } else {
  122. this.$u.toast('参数错误');
  123. setTimeout(() => uni.navigateBack(), 1500);
  124. }
  125. },
  126. methods: {
  127. //添加或者选择地址
  128. handleAddress() {
  129. uni.navigateTo({
  130. url: `/pages-mine/pages/address/list?id=${this.defaultAddr.id}&isSelect=1`,
  131. });
  132. },
  133. onRedPacketConfirm(packet) {
  134. this.selectedPacket = packet;
  135. if (packet && packet.id) {
  136. this.submitData.userCouponIds = [packet.id];
  137. } else {
  138. this.submitData.userCouponIds = [];
  139. }
  140. // Recalculate price if needed
  141. },
  142. onStockShortageConfirm(option) {
  143. this.selectedStockOption = option;
  144. this.submitData.outOfStock = option.value;
  145. },
  146. submitOrder() {
  147. if (!this.submitData.addressId) {
  148. this.$u.toast("请选择收货地址");
  149. return;
  150. }
  151. // 显示确认弹窗
  152. this.$refs.submitConfirmDialog.openPopup();
  153. },
  154. // 确认提交订单
  155. handleConfirmSubmit() {
  156. uni.showLoading({ title: '提交中' });
  157. this.$u.api.submitShopOrderAjax(this.submitData).then((res) => {
  158. uni.hideLoading();
  159. if (res.code == 200) {
  160. uni.showToast({
  161. title: '下单成功',
  162. icon: "success",
  163. });
  164. uni.removeStorageSync("selectAddr");
  165. //存储订单信息
  166. uni.setStorageSync("orderBuyInfo", res.data);
  167. //跳转到 收银台页面
  168. uni.navigateTo({
  169. url: `/pages-car/pages/cashier-desk?id=${res.data.orderId}`
  170. })
  171. } else {
  172. this.$u.toast(res.msg || '下单失败');
  173. }
  174. }).catch(() => {
  175. uni.hideLoading();
  176. });
  177. },
  178. },
  179. onShow() {
  180. let selectAddr = uni.getStorageSync("selectAddr");
  181. if (selectAddr) {
  182. this.defaultAddr = selectAddr;
  183. this.submitData.addressId = selectAddr.id;
  184. uni.removeStorageSync("selectAddr"); // Clear after use
  185. }
  186. },
  187. };
  188. </script>
  189. <style lang="scss">
  190. .confirm-order {
  191. min-height: 100vh;
  192. background: #f5f5f5;
  193. padding: 20rpx 30rpx;
  194. padding-bottom: calc(env(safe-area-inset-bottom) + 120rpx);
  195. }
  196. .section-card {
  197. background: #fff;
  198. margin-bottom: 20rpx;
  199. padding: 30rpx;
  200. border-radius: 16rpx;
  201. box-sizing: border-box;
  202. }
  203. .u-required {
  204. color: #ff0000;
  205. margin-left: 8rpx;
  206. }
  207. .book-list {
  208. background: #fff;
  209. border-radius: 16rpx;
  210. margin-bottom: 20rpx;
  211. }
  212. .info-row {
  213. display: flex;
  214. justify-content: space-between;
  215. align-items: center;
  216. padding: 20rpx 0;
  217. font-size: 28rpx;
  218. color: #333;
  219. .label {
  220. &.red-label {
  221. color: #ff4500;
  222. font-weight: bold;
  223. }
  224. }
  225. .value {
  226. &.text-gray {
  227. color: #999;
  228. }
  229. }
  230. .mr-10 {
  231. margin-right: 10rpx;
  232. }
  233. }
  234. .bottom-bar {
  235. position: fixed;
  236. bottom: 0;
  237. left: 0;
  238. right: 0;
  239. background: #fff;
  240. padding: 20rpx 30rpx;
  241. padding-bottom: env(safe-area-inset-bottom);
  242. box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
  243. z-index: 9;
  244. .order-summary {
  245. display: flex;
  246. justify-content: space-between;
  247. align-items: center;
  248. .total {
  249. font-size: 28rpx;
  250. color: #666;
  251. .num {
  252. color: #333;
  253. font-weight: bold;
  254. margin: 0 4rpx;
  255. }
  256. .reduce-text {
  257. color: #38C148;
  258. margin-left: 10rpx;
  259. margin-right: 10rpx;
  260. background-color: #e6f9e9;
  261. padding: 4rpx 10rpx;
  262. border-radius: 4rpx;
  263. font-size: 24rpx;
  264. }
  265. .price {
  266. font-size: 36rpx;
  267. color: #ff4500;
  268. font-weight: bold;
  269. margin-left: 10rpx;
  270. }
  271. }
  272. }
  273. }
  274. .mt-20 {
  275. margin-top: 20rpx;
  276. }
  277. .ml-10 {
  278. margin-left: 10rpx;
  279. }
  280. </style>