book-order.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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. <u-icon name="question-circle-fill" color="#333333" size="36" @click="showRules"></u-icon>
  79. </view>
  80. <u-button type="primary" @click="submitOrder" :custom-style="{ margin: 0 }">提交订单</u-button>
  81. </view>
  82. </view>
  83. <!-- 添加快递选择器 -->
  84. <u-picker
  85. v-model="showPicker"
  86. mode="selector"
  87. :range="expressList"
  88. @confirm="onExpressConfirm"
  89. @cancel="showPicker = false"
  90. range-key="name"
  91. ></u-picker>
  92. <pickup-time-picker :show.sync="showTimePicker" @confirm="onTimeConfirm"></pickup-time-picker>
  93. <submit-confirm ref="submitConfirmDialog" @confirm="handleConfirmSubmit"></submit-confirm>
  94. </view>
  95. </template>
  96. <script>
  97. import bookItem from "@/pages-home/components/BookItem.vue";
  98. import pickupTimePicker from "@/pages-home/components/PickupTimePicker.vue";
  99. import SubmitConfirm from "@/pages-home/components/SubmitConfirm.vue";
  100. export default {
  101. components: {
  102. bookItem,
  103. pickupTimePicker,
  104. SubmitConfirm,
  105. },
  106. data() {
  107. return {
  108. titleStyle: {
  109. "font-family": "PingFang SC",
  110. "font-weight": 400,
  111. color: "#333333",
  112. },
  113. agreed: false,
  114. books: [],
  115. showPicker: false,
  116. expressList: [],
  117. showTimePicker: false,
  118. selectedTime: {},
  119. defaultAddr: {},
  120. submitData: {
  121. expressDelivery: "",
  122. orderId: "",
  123. addressId: "",
  124. schedulePickupStartTime: "",
  125. schedulePickupEndTime: "",
  126. expressDelivery: "",
  127. remark: "",
  128. },
  129. };
  130. },
  131. computed: {
  132. totalBooks() {
  133. return this.books.reduce((sum, book) => sum + (book.num || 1), 0);
  134. },
  135. totalPrice() {
  136. return this.books.reduce((sum, book) => sum + book.recycleMoney, 0).toFixed(2);
  137. },
  138. },
  139. methods: {
  140. showRules() {
  141. uni.navigateTo({
  142. url: '/pages-mine/pages/rules-for-sellbooks'
  143. })
  144. },
  145. //时间选择
  146. onTimeConfirm(data) {
  147. this.selectedTime = data;
  148. //格式化提交数据的时间
  149. let date = this.$u.timeFormat(data.date, "yyyy-mm-dd");
  150. let times = data.time.split("-");
  151. this.submitData.schedulePickupStartTime = `${date} ${times[0]}`;
  152. this.submitData.schedulePickupEndTime = `${date} ${times[1]}`;
  153. console.log(date, this.submitData, "data");
  154. },
  155. //打开快递选择器
  156. showExpressPicker() {
  157. this.showPicker = true;
  158. },
  159. //确认选择快递
  160. onExpressConfirm(e) {
  161. if (!e.length) return;
  162. let item = this.expressList[e[0]];
  163. this.submitData.expressDelivery = item.name;
  164. this.showPicker = false;
  165. },
  166. //添加或者选择地址
  167. handleAddress() {
  168. uni.navigateTo({
  169. url: `/pages-mine/pages/address/list?id=${this.defaultAddr.id}&isSelect=1`,
  170. });
  171. },
  172. calculateTotal() {
  173. this.totalBooks = this.books.reduce((sum, book) => sum + book.quantity, 0);
  174. this.totalPrice = this.books
  175. .reduce((sum, book) => sum + book.quantity * parseFloat(book.price), 0)
  176. .toFixed(2);
  177. },
  178. submitOrder() {
  179. if (!this.submitData.addressId) {
  180. this.$u.toast("请选择取货地址");
  181. return;
  182. }
  183. if (!this.selectedTime.day) {
  184. this.$u.toast("请选择取件时间");
  185. return;
  186. }
  187. if (!this.agreed) {
  188. this.$u.toast("请先同意用户协议");
  189. return;
  190. }
  191. // 显示确认弹窗
  192. this.$refs.submitConfirmDialog.openPopup();
  193. },
  194. // 确认提交订单
  195. handleConfirmSubmit() {
  196. // 处理订单提交
  197. uni.$u.http.post("/token/order/submitOrder", this.submitData).then((res) => {
  198. if (res.code == 200) {
  199. uni.navigateTo({
  200. url: "/pages-home/pages/order-success",
  201. });
  202. uni.removeStorageSync("selectAddr");
  203. } else {
  204. uni.showToast({
  205. title: res.msg,
  206. icon: "none",
  207. });
  208. }
  209. });
  210. },
  211. //获取默认地址 /api/token/user/address/getDefault
  212. getDefaultAddress() {
  213. uni.$u.http.get("/token/user/address/getDefault").then((res) => {
  214. if (res.code == 200) {
  215. this.defaultAddr = res.data;
  216. this.submitData.addressId = this.defaultAddr.id;
  217. }
  218. });
  219. },
  220. //获取当前用户未提交订单 /api/token/order/lastOrder
  221. getLastOrder() {
  222. uni.$u.http.get("/token/order/lastOrder").then((res) => {
  223. if (res.code == 200) {
  224. this.books = res.data?.orderDetailList
  225. ? res.data.orderDetailList?.map((v) => {
  226. v.orderId = res.data.orderId;
  227. return v;
  228. })
  229. : [];
  230. this.submitData.orderId = this.books[0].orderId;
  231. }
  232. });
  233. },
  234. //获取预提交订单
  235. getPreSubmitOrder() {
  236. let orderId = uni.getStorageSync("orderId");
  237. uni.$u.http.get("/token/order/preSubmit?orderId=" + orderId).then((res) => {
  238. this.submitData.orderId = orderId;
  239. this.defaultAddr = res.data.defaultAddress;
  240. this.submitData.addressId = this.defaultAddr.id;
  241. this.books = res.data.orderDetailList;
  242. this.expressList = res.data.expressTypes.map((v) => ({
  243. name: v,
  244. }));
  245. });
  246. },
  247. goToAgreement() {
  248. uni.navigateTo({
  249. url: "/pages-home/pages/user-agreement",
  250. });
  251. },
  252. },
  253. mounted() {
  254. this.getPreSubmitOrder();
  255. },
  256. onShow() {
  257. let selectAddr = uni.getStorageSync("selectAddr");
  258. if (selectAddr) {
  259. this.defaultAddr = selectAddr;
  260. this.submitData.addressId = selectAddr.id;
  261. }
  262. //处理从/pages-home/pages/order-success页面返回的情况,在执行返回一级页面
  263. let pages = getCurrentPages();
  264. let currentPage = pages[pages.length - 1];
  265. console.log(pages, currentPage, "currentPage");
  266. if (currentPage.route == "pages-home/pages/order-success") {
  267. uni.navigateBack({
  268. delta: 1,
  269. });
  270. }
  271. },
  272. };
  273. </script>
  274. <style lang="scss">
  275. .book-order {
  276. min-height: 100vh;
  277. background: #f5f5f5;
  278. padding: 20rpx 30rpx;
  279. padding-bottom: calc(env(safe-area-inset-bottom) + 190rpx);
  280. }
  281. .section-card {
  282. background: #fff;
  283. margin-bottom: 20rpx;
  284. padding: 30rpx;
  285. border-radius: 10rpx;
  286. box-sizing: border-box;
  287. }
  288. .u-required {
  289. color: #ff0000;
  290. margin-left: 8rpx;
  291. }
  292. .time-card {
  293. height: 80rpx;
  294. background: #f8f8f8;
  295. border-radius: 10rpx;
  296. }
  297. .free-pickup {
  298. .pickup-title {
  299. font-weight: bold;
  300. font-size: 28rpx;
  301. color: #333333;
  302. margin-bottom: 10rpx;
  303. }
  304. .pickup-desc {
  305. font-family: PingFang SC;
  306. font-weight: 400;
  307. font-size: 28rpx;
  308. color: #999999;
  309. }
  310. }
  311. .express-desc {
  312. font-size: 24rpx;
  313. color: #666;
  314. line-height: 1.4;
  315. }
  316. .bottom-bar {
  317. position: fixed;
  318. bottom: 0;
  319. left: 0;
  320. right: 0;
  321. background: #fff;
  322. padding: 20rpx 30rpx;
  323. padding-bottom: env(safe-area-inset-bottom);
  324. .agreement {
  325. font-family: PingFang SC;
  326. font-weight: 500;
  327. font-size: 28rpx;
  328. color: #333333;
  329. &-link {
  330. color: #07c160;
  331. }
  332. }
  333. .order-summary {
  334. display: flex;
  335. justify-content: space-between;
  336. align-items: center;
  337. font-family: PingFang SC;
  338. font-weight: 500;
  339. font-size: 28rpx;
  340. color: #999999;
  341. .price {
  342. color: #ff0000;
  343. margin: 0 10rpx;
  344. }
  345. }
  346. }
  347. </style>