book-order.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template>
  2. <view class="book-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="section-card">
  30. <view class="flex-a flex-j-b mb-20">
  31. <view class="flex-a">
  32. <view :style="titleStyle" class="font-28">订单备注</view>
  33. </view>
  34. <view class="flex-a" style="flex: 1; justify-content: flex-end;">
  35. <u-input v-model="submitData.remark" type="text" placeholder="选填,请先和商家协商一致" :custom-style="{textAlign: 'right'}" />
  36. </view>
  37. </view>
  38. </view>
  39. <!-- 书籍列表 -->
  40. <view class="book-list">
  41. <book-item v-for="book in books" :key="book.id" :book="book"></book-item>
  42. </view>
  43. <!-- 底部栏 -->
  44. <view class="bottom-bar">
  45. <view class="order-summary">
  46. <view class="total">
  47. 共<text class="price">{{ totalNum }}</text>件
  48. 合计: <text class="price">¥{{ totalMoney }}</text>
  49. <text v-if="totalDiscount > 0" style="font-size: 24rpx; color: #999; margin-left: 10rpx;">(已优惠 ¥{{ totalDiscount }})</text>
  50. </view>
  51. <u-button type="primary" @click="submitOrder" :custom-style="{ margin: 0 }">提交订单</u-button>
  52. </view>
  53. </view>
  54. <submit-confirm ref="submitConfirmDialog" @confirm="handleConfirmSubmit" title="确认提交订单" content="请确认收货地址和商品信息无误"></submit-confirm>
  55. </view>
  56. </template>
  57. <script>
  58. import bookItem from "@/pages-home/components/BookItem.vue";
  59. import SubmitConfirm from "@/pages-home/components/SubmitConfirm.vue";
  60. export default {
  61. components: {
  62. bookItem,
  63. SubmitConfirm,
  64. },
  65. data() {
  66. return {
  67. titleStyle: {
  68. "font-family": "PingFang SC",
  69. "font-weight": 400,
  70. color: "#333333",
  71. },
  72. books: [],
  73. defaultAddr: {},
  74. cartIdList: [], // 接收参数
  75. submitData: {
  76. cartIdList: [],
  77. addressId: "",
  78. remark: "",
  79. userCouponIds: [],
  80. },
  81. totalNum: 0,
  82. totalMoney: 0,
  83. totalDiscount: 0,
  84. };
  85. },
  86. onLoad(options) {
  87. if (options.cartIds) {
  88. this.cartIdList = options.cartIds.split(',').map(Number);
  89. this.submitData.cartIdList = this.cartIdList;
  90. this.getPreSubmitOrder();
  91. } else {
  92. this.$u.toast('参数错误');
  93. setTimeout(() => uni.navigateBack(), 1500);
  94. }
  95. },
  96. methods: {
  97. // 添加或者选择地址
  98. handleAddress() {
  99. uni.navigateTo({
  100. url: `/pages-mine/pages/address/list?id=${this.defaultAddr.id}&isSelect=1`,
  101. });
  102. },
  103. submitOrder() {
  104. if (!this.submitData.addressId) {
  105. this.$u.toast("请选择收货地址");
  106. return;
  107. }
  108. // 显示确认弹窗
  109. this.$refs.submitConfirmDialog.openPopup();
  110. },
  111. // 确认提交订单
  112. handleConfirmSubmit() {
  113. uni.showLoading({ title: '提交中' });
  114. this.$u.api.submitShopOrderAjax(this.submitData).then((res) => {
  115. uni.hideLoading();
  116. if (res.code == 200) {
  117. // 支付逻辑待定,暂时跳转成功页或提示
  118. this.$u.toast('下单成功');
  119. setTimeout(() => {
  120. uni.redirectTo({
  121. url: "/pages-home/pages/order-success",
  122. });
  123. }, 1000);
  124. uni.removeStorageSync("selectAddr");
  125. } else {
  126. this.$u.toast(res.msg || '下单失败');
  127. }
  128. }).catch(() => {
  129. uni.hideLoading();
  130. });
  131. },
  132. // 获取预提交订单信息
  133. getPreSubmitOrder() {
  134. uni.showLoading({ title: '加载中' });
  135. this.$u.api.preSubmitOrderAjax({
  136. cartIdList: this.cartIdList
  137. }).then((res) => {
  138. uni.hideLoading();
  139. if (res.code === 200) {
  140. const data = res.data;
  141. // 地址信息
  142. if (data.defaultAddress) {
  143. this.defaultAddr = data.defaultAddress;
  144. this.submitData.addressId = this.defaultAddr.id;
  145. }
  146. // 商品列表
  147. this.books = data.orderDetailList || [];
  148. // 价格汇总
  149. this.totalMoney = data.totalMoney;
  150. this.totalDiscount = data.discountMoney || 0;
  151. this.totalNum = data.totalQuantity;
  152. } else {
  153. this.$u.toast(res.msg || '获取订单信息失败');
  154. }
  155. }).catch(() => {
  156. uni.hideLoading();
  157. });
  158. },
  159. },
  160. onShow() {
  161. let selectAddr = uni.getStorageSync("selectAddr");
  162. if (selectAddr) {
  163. this.defaultAddr = selectAddr;
  164. this.submitData.addressId = selectAddr.id;
  165. }
  166. },
  167. };
  168. </script>
  169. <style lang="scss">
  170. .book-order {
  171. min-height: 100vh;
  172. background: #f5f5f5;
  173. padding: 20rpx 30rpx;
  174. padding-bottom: calc(env(safe-area-inset-bottom) + 120rpx);
  175. }
  176. .section-card {
  177. background: #fff;
  178. margin-bottom: 20rpx;
  179. padding: 30rpx;
  180. border-radius: 10rpx;
  181. box-sizing: border-box;
  182. }
  183. .u-required {
  184. color: #ff0000;
  185. margin-left: 8rpx;
  186. }
  187. .book-list {
  188. margin-bottom: 20rpx;
  189. }
  190. .bottom-bar {
  191. position: fixed;
  192. bottom: 0;
  193. left: 0;
  194. right: 0;
  195. background: #fff;
  196. padding: 20rpx 30rpx;
  197. padding-bottom: env(safe-area-inset-bottom);
  198. box-shadow: 0 -2rpx 10rpx rgba(0,0,0,0.05);
  199. .order-summary {
  200. display: flex;
  201. justify-content: space-between;
  202. align-items: center;
  203. .total {
  204. font-size: 28rpx;
  205. color: #333;
  206. .price {
  207. color: #ff0000;
  208. font-size: 32rpx;
  209. font-weight: bold;
  210. margin: 0 8rpx;
  211. }
  212. }
  213. }
  214. }
  215. </style>