book-order.vue 15 KB

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