confirm-order.vue 12 KB

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