book-order.vue 11 KB

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