book-order.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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="../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 class="free-pickup mb-20 mt-20">
  28. <view class="pickup-title">免费上门取货</view>
  29. <view class="pickup-desc">书嗨将预约指定快递上门取件,邮费由书嗨承担</view>
  30. </view>
  31. <view class="flex-a flex-j-b time-card" style="padding: 0 10rpx" @click="showTimePicker = true">
  32. <view class="flex-a">
  33. <view :style="titleStyle" class="ml-10 font-28">取件时间</view>
  34. <text class="u-required">*</text>
  35. </view>
  36. <view class="flex-a">
  37. <view v-if="selectedTime.day" :style="titleStyle" class="ml-10"
  38. >{{ selectedTime.day }}
  39. {{ selectedTime.time }}
  40. </view>
  41. <view v-else :style="titleStyle" class="ml-10">请选择快递上门取件时间</view>
  42. <u-icon name="arrow-right" :size="28" color="#666" top="4"></u-icon>
  43. </view>
  44. </view>
  45. </view>
  46. <!-- 快递备注部分 -->
  47. <view class="section-card">
  48. <view class="flex-a flex-j-b mb-20" @click="showExpressPicker">
  49. <view class="flex-a">
  50. <view :style="titleStyle" class="font-28">快递备注</view>
  51. </view>
  52. <view class="flex-a">
  53. <view :style="titleStyle" class="ml-10">{{ submitData.expressDelivery || "请选择" }}</view>
  54. <u-icon name="arrow-right" :size="28" color="#666" top="3"></u-icon>
  55. </view>
  56. </view>
  57. <view class="express-desc"
  58. >请从【顺丰】或【京东】中选择可正常收寄的快递,如您不选择,则由系统根据区域情况自动分配</view
  59. >
  60. </view>
  61. <!-- 书籍列表 -->
  62. <view class="book-list">
  63. <book-item v-for="book in books" :key="book.id" :book="book"></book-item>
  64. </view>
  65. <!-- 底部栏 -->
  66. <view class="bottom-bar">
  67. <view class="agreement">
  68. <u-checkbox v-model="agreed" shape="circle">
  69. <text class="agreement-text">我已阅读并同意</text>
  70. <text class="agreement-link" @click="goToAgreement">《书嗨用户协议》</text>
  71. </u-checkbox>
  72. </view>
  73. <view class="order-summary">
  74. <view class="total">
  75. 共<text class="price">{{ totalBooks }}</text
  76. >件 预估回收价
  77. <text class="price">¥{{ totalPrice }}</text>
  78. </view>
  79. <u-button type="primary" @click="submitOrder" :custom-style="{ margin: 0 }">提交订单</u-button>
  80. </view>
  81. </view>
  82. <!-- 添加快递选择器 -->
  83. <u-picker
  84. v-model="showPicker"
  85. mode="selector"
  86. :range="expressList"
  87. @confirm="onExpressConfirm"
  88. @cancel="showPicker = false"
  89. range-key="name"
  90. ></u-picker>
  91. <pickup-time-picker :show.sync="showTimePicker" @confirm="onTimeConfirm"></pickup-time-picker>
  92. <submit-confirm ref="submitConfirmDialog" @confirm="handleConfirmSubmit"></submit-confirm>
  93. </view>
  94. </template>
  95. <script>
  96. import bookItem from "@/pages-home/components/BookItem.vue";
  97. import pickupTimePicker from "@/pages-home/components/PickupTimePicker.vue";
  98. import SubmitConfirm from "@/pages-home/components/SubmitConfirm.vue";
  99. export default {
  100. components: {
  101. bookItem,
  102. pickupTimePicker,
  103. SubmitConfirm,
  104. },
  105. data() {
  106. return {
  107. titleStyle: {
  108. "font-family": "PingFang SC",
  109. "font-weight": 400,
  110. color: "#333333",
  111. },
  112. agreed: false,
  113. books: [],
  114. showPicker: false,
  115. expressList: [],
  116. showTimePicker: false,
  117. selectedTime: {},
  118. defaultAddr: {},
  119. submitData: {
  120. expressDelivery: "",
  121. orderId: "",
  122. addressId: "",
  123. schedulePickupStartTime: "",
  124. schedulePickupEndTime: "",
  125. expressDelivery: "",
  126. remark: "",
  127. },
  128. };
  129. },
  130. computed: {
  131. totalBooks() {
  132. return this.books.reduce((sum, book) => sum + (book.num || 1), 0);
  133. },
  134. totalPrice() {
  135. return this.books.reduce((sum, book) => sum + book.recycleMoney, 0).toFixed(2);
  136. },
  137. },
  138. methods: {
  139. //时间选择
  140. onTimeConfirm(data) {
  141. this.selectedTime = data;
  142. //格式化提交数据的时间
  143. let date = this.$u.timeFormat(data.date, "yyyy-mm-dd");
  144. let times = data.time.split("-");
  145. this.submitData.schedulePickupStartTime = `${date} ${times[0]}`;
  146. this.submitData.schedulePickupEndTime = `${date} ${times[1]}`;
  147. console.log(date, this.submitData, "data");
  148. },
  149. //打开快递选择器
  150. showExpressPicker() {
  151. this.showPicker = true;
  152. },
  153. //确认选择快递
  154. onExpressConfirm(e) {
  155. if (!e.length) return;
  156. let item = this.expressList[e[0]];
  157. this.submitData.expressDelivery = item.name;
  158. this.showPicker = false;
  159. },
  160. //添加或者选择地址
  161. handleAddress() {
  162. uni.navigateTo({
  163. url: `/pages-mine/pages/address/list?id=${this.defaultAddr.id}&isSelect=1`,
  164. });
  165. },
  166. calculateTotal() {
  167. this.totalBooks = this.books.reduce((sum, book) => sum + book.quantity, 0);
  168. this.totalPrice = this.books
  169. .reduce((sum, book) => sum + book.quantity * parseFloat(book.price), 0)
  170. .toFixed(2);
  171. },
  172. submitOrder() {
  173. if (!this.submitData.addressId) {
  174. this.$u.toast("请选择取货地址");
  175. return;
  176. }
  177. if (!this.selectedTime.day) {
  178. this.$u.toast("请选择取件时间");
  179. return;
  180. }
  181. if (!this.agreed) {
  182. this.$u.toast("请先同意用户协议");
  183. return;
  184. }
  185. // 显示确认弹窗
  186. this.$refs.submitConfirmDialog.openPopup();
  187. },
  188. // 确认提交订单
  189. handleConfirmSubmit() {
  190. // 处理订单提交
  191. uni.$u.http.post("/token/order/submitOrder", this.submitData).then((res) => {
  192. if (res.code == 200) {
  193. uni.navigateTo({
  194. url: "/pages-home/pages/order-success",
  195. });
  196. uni.removeStorageSync("selectAddr");
  197. } else {
  198. uni.showToast({
  199. title: res.msg,
  200. icon: "none",
  201. });
  202. }
  203. });
  204. },
  205. //获取默认地址 /api/token/user/address/getDefault
  206. getDefaultAddress() {
  207. uni.$u.http.get("/token/user/address/getDefault").then((res) => {
  208. if (res.code == 200) {
  209. this.defaultAddr = res.data;
  210. this.submitData.addressId = this.defaultAddr.id;
  211. }
  212. });
  213. },
  214. //获取当前用户未提交订单 /api/token/order/lastOrder
  215. getLastOrder() {
  216. uni.$u.http.get("/token/order/lastOrder").then((res) => {
  217. if (res.code == 200) {
  218. this.books = res.data?.orderDetailList
  219. ? res.data.orderDetailList?.map((v) => {
  220. v.orderId = res.data.orderId;
  221. return v;
  222. })
  223. : [];
  224. this.submitData.orderId = this.books[0].orderId;
  225. }
  226. });
  227. },
  228. //获取预提交订单
  229. getPreSubmitOrder() {
  230. let orderId = uni.getStorageSync("orderId");
  231. uni.$u.http.get("/token/order/preSubmit?orderId=" + orderId).then((res) => {
  232. this.submitData.orderId = orderId;
  233. this.defaultAddr = res.data.defaultAddress;
  234. this.submitData.addressId = this.defaultAddr.id;
  235. this.books = res.data.orderDetailList;
  236. this.expressList = res.data.expressTypes.map((v) => ({
  237. name: v,
  238. }));
  239. });
  240. },
  241. goToAgreement() {
  242. uni.navigateTo({
  243. url: "/pages-home/pages/user-agreement",
  244. });
  245. },
  246. },
  247. mounted() {
  248. this.getPreSubmitOrder();
  249. },
  250. onShow() {
  251. let selectAddr = uni.getStorageSync("selectAddr");
  252. if (selectAddr) {
  253. this.defaultAddr = selectAddr;
  254. this.submitData.addressId = selectAddr.id;
  255. }
  256. },
  257. };
  258. </script>
  259. <style lang="scss">
  260. .book-order {
  261. min-height: 100vh;
  262. background: #f5f5f5;
  263. padding: 20rpx 30rpx;
  264. padding-bottom: calc(env(safe-area-inset-bottom) + 190rpx);
  265. }
  266. .section-card {
  267. background: #fff;
  268. margin-bottom: 20rpx;
  269. padding: 30rpx;
  270. border-radius: 10rpx;
  271. box-sizing: border-box;
  272. }
  273. .u-required {
  274. color: #ff0000;
  275. margin-left: 8rpx;
  276. }
  277. .time-card {
  278. height: 80rpx;
  279. background: #f8f8f8;
  280. border-radius: 10rpx;
  281. }
  282. .free-pickup {
  283. .pickup-title {
  284. font-weight: bold;
  285. font-size: 28rpx;
  286. color: #333333;
  287. margin-bottom: 10rpx;
  288. }
  289. .pickup-desc {
  290. font-family: PingFang SC;
  291. font-weight: 400;
  292. font-size: 28rpx;
  293. color: #999999;
  294. }
  295. }
  296. .express-desc {
  297. font-size: 24rpx;
  298. color: #666;
  299. line-height: 1.4;
  300. }
  301. .bottom-bar {
  302. position: fixed;
  303. bottom: 0;
  304. left: 0;
  305. right: 0;
  306. background: #fff;
  307. padding: 20rpx 30rpx;
  308. padding-bottom: env(safe-area-inset-bottom);
  309. .agreement {
  310. font-family: PingFang SC;
  311. font-weight: 500;
  312. font-size: 28rpx;
  313. color: #333333;
  314. &-link {
  315. color: #07c160;
  316. }
  317. }
  318. .order-summary {
  319. display: flex;
  320. justify-content: space-between;
  321. align-items: center;
  322. font-family: PingFang SC;
  323. font-weight: 500;
  324. font-size: 28rpx;
  325. color: #999999;
  326. .price {
  327. color: #ff0000;
  328. margin: 0 10rpx;
  329. }
  330. }
  331. }
  332. </style>