apply.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <template>
  2. <view class="apply-page">
  3. <view class="common-card flex-a flex-j-b mb-20" @click="handleAddress" v-if="defaultAddr.id">
  4. <image src="../../pages-mine/static/adderss.png" style="width:40rpx;height: 40rpx;"></image>
  5. <view class="flex-d flex-1 ml-24" style="margin-right: 90rpx;">
  6. <view class="flex-a flex-j-b mb-10">
  7. <view :style="titleStyle">{{ defaultAddr.name }}</view>
  8. <view :style="titleStyle">{{ defaultAddr.mobile }}</view>
  9. </view>
  10. <view :style="titleStyle">地址:{{ defaultAddr.fullAddress }}</view>
  11. </view>
  12. <u-icon name="arrow-right" :size="28" color="#666" top="4"></u-icon>
  13. </view>
  14. <!-- 退回地址 -->
  15. <view v-else class="common-card flex-a flex-j-b mb-20" @click="handleAddress">
  16. <view class="flex-a">
  17. <u-icon name="plus-circle-fill" size="50" color="#38C148"></u-icon>
  18. <text class="required">退回地址</text>
  19. </view>
  20. <view class="flex-a">
  21. <view class="flex-d mr-10 flex-a-e">
  22. <text class="common-text-2 font-28">请添加</text>
  23. <text class="common-text font-24">提交后无法修改</text>
  24. </view>
  25. <u-icon name="arrow-right" size="32" color="#666666"></u-icon>
  26. </view>
  27. </view>
  28. <view class="common-card flex-a flex-j-b mb-20" style="padding: 30rpx;" @click="selectBooks">
  29. <text class="required">选择退回书籍</text>
  30. <view class="flex-a">
  31. <text class="common-text-2 font-26">{{ length ? `已选择${length}本` : '请选择' }}</text>
  32. <u-icon name="arrow-right" size="32" color="#666666"></u-icon>
  33. </view>
  34. </view>
  35. <!-- 退回书籍 -->
  36. <view class="common-card mb-20">
  37. <view class="common-title mb-20"> <text>订单编号: {{ orderId }}</text></view>
  38. <!-- 书籍列表 -->
  39. <select-book-item :book="item" v-for="(item, index) in bookItems" isReturn :key="index" />
  40. </view>
  41. <view class="common-card" style="padding: 30rpx;">
  42. <view class="flex-a flex-j-b mb-20">
  43. <text class="common-text-2 font-30">退回邮费:</text>
  44. <text class="common-title" style="color: #FF0000;">{{ returnFee }}</text>
  45. </view>
  46. <view class="common-card flex-a flex-j-b" style="background: #fafafa;">
  47. <text class="common-text-2">书籍数量</text>
  48. <text class="common-text-2">{{ length }}</text>
  49. </view>
  50. </view>
  51. <view class="bottom-fixed-con">
  52. <u-button type="primary" @click="handleConfirm">确认退回</u-button>
  53. </view>
  54. <CommonDialog ref="commonDialog" :title="dialogTitle" :showCancel="false">
  55. {{ dialogContent }}
  56. </CommonDialog>
  57. <CommonDialog ref="returnDialog" title="退回不通过书籍" :showFooter="false" width="88%">
  58. <view class="flex-a flex-j-b">
  59. <button class="confirm-btn plain" @click="handleApplyBack">我要取回</button>
  60. <button class="confirm-btn plain" @click="handleRecycleWare">仓库循环处理</button>
  61. </view>
  62. <view class="button-bottom" @click="handleRecycle">
  63. <text style="font-size: 32rpx;font-weight: bold;">按纸价回收</text>
  64. <text style="margin-top: 2px;">补贴 ¥{{ orderInfo.basicRecycleMoney || 0 }} 到余额</text>
  65. </view>
  66. </CommonDialog>
  67. <CommonDialog ref="recycleDialog" title="是否按纸价回收" @confirm="handleRecycleConfirm">
  68. 补贴 ¥{{ orderInfo.basicRecycleMoney || 0 }} 到余额
  69. </CommonDialog>
  70. <CommonDialog ref="recycleWare" title="是否仓库循环处理" @confirm="handleRecycleWareConfirm">
  71. 感谢您对环保事业的支持,仓库将循环处理
  72. </CommonDialog>
  73. </view>
  74. </template>
  75. <script>
  76. import OrderItem from '../components/order-item.vue'
  77. import selectBookItem from '../components/select-book-item.vue';
  78. import commonDialog from '../../components/common-dialog.vue';
  79. import CommonDialog from '../../components/common-dialog.vue';
  80. export default {
  81. components: {
  82. OrderItem,
  83. selectBookItem,
  84. commonDialog,
  85. CommonDialog
  86. },
  87. onLoad(options) {
  88. this.isOnLoad = true
  89. if (options.orderId) {
  90. this.orderId = options.orderId
  91. this.getOrderInfo(this.orderId)
  92. }
  93. },
  94. data() {
  95. return {
  96. defaultAddr: {},
  97. orderId: '',
  98. bookItems: [],
  99. returnFee: 0,
  100. length: 0,
  101. isOnLoad: true,
  102. orderInfo: {},
  103. dialogTitle: '提示',
  104. dialogContent: '无此书或品相良好的书籍不需要退回。'
  105. }
  106. },
  107. methods: {
  108. //确认退回
  109. handleConfirm() {
  110. // 检查是否有"无此书"的审核原因
  111. const hasNoSuchBook = this.bookItems.some(book =>
  112. book.auditCommentList.some(audit => audit.com === '无此书')
  113. );
  114. if (hasNoSuchBook) {
  115. this.dialogContent = '无此书或品相良好的书籍不需要退回。';
  116. this.$refs.commonDialog.openPopup();
  117. return;
  118. }
  119. // 验证地址是否已选择
  120. if (!this.defaultAddr.id) {
  121. uni.showToast({
  122. title: '请选择退回地址',
  123. icon: 'none'
  124. });
  125. return;
  126. }
  127. // 验证是否选择了书籍
  128. if (!this.bookItems.length) {
  129. uni.showToast({
  130. title: '请选择需要退回的书籍',
  131. icon: 'none'
  132. });
  133. return;
  134. }
  135. // 打开退回选项对话框
  136. this.$refs.returnDialog?.openPopup();
  137. },
  138. //我要取回 - 提交退回申请
  139. handleApplyBack() {
  140. // 构建请求参数
  141. const detailList = this.bookItems.map(book => ({
  142. isbn: book.isbn,
  143. num: book.auditCommentList.length
  144. }));
  145. const params = {
  146. orderId: this.orderId,
  147. addressId: this.defaultAddr.id,
  148. detailList: detailList
  149. };
  150. // 发起请求
  151. uni.showLoading({
  152. title: '提交中...'
  153. });
  154. uni.$u.http.post('/token/order/submitRefundOrder', params)
  155. .then(res => {
  156. if (res.code === 200) {
  157. if (res.data.firstOrder == 1) {
  158. // 提交成功后
  159. this.dialogContent = '提交成功'
  160. this.$refs.commonDialog.openPopup()
  161. uni.removeStorageSync('selectAddr')
  162. } else {
  163. //跳转去付款页面
  164. uni.navigateTo({
  165. url: `/pages-mine/pages/cashier-desk?id=${res.data.refundOrderId}`
  166. })
  167. }
  168. } else {
  169. uni.showToast({
  170. title: res.msg || '提交失败',
  171. icon: 'none'
  172. });
  173. }
  174. })
  175. .finally(() => {
  176. uni.hideLoading();
  177. });
  178. },
  179. //仓库循环处理
  180. handleRecycleWare() {
  181. this.$refs.recycleWare?.openPopup()
  182. },
  183. //仓库循环处理确认
  184. handleRecycleWareConfirm() {
  185. uni.$u.http.post('/token/order/notNeed', {
  186. orderId: this.orderId
  187. }).then(res => {
  188. if (res.code === 200) {
  189. uni.$u.toast(`已补贴 ${this.orderInfo.basicRecycleMoney || 0} 到余额`)
  190. uni.navigateBack()
  191. }
  192. })
  193. },
  194. //纸价回收
  195. handleRecycle() {
  196. this.$refs.recycleDialog?.openPopup()
  197. },
  198. //纸价回收确认
  199. handleRecycleConfirm() {
  200. uni.$u.http.post('/token/order/basicRecycle', {
  201. orderId: this.orderId
  202. }).then(res => {
  203. if (res.code === 200) {
  204. uni.$u.toast('纸价回收成功')
  205. uni.navigateBack()
  206. }
  207. })
  208. },
  209. // 选择书籍页面
  210. selectBooks() {
  211. uni.navigateTo({
  212. url: `/pages-mine/pages/return-select?orderId=${this.orderId}`
  213. })
  214. },
  215. //添加或者选择地址
  216. handleAddress() {
  217. uni.navigateTo({
  218. url: `/pages-mine/pages/address/list?id=${this.defaultAddr.id}&isSelect=1`
  219. })
  220. },
  221. //计算退回邮费
  222. calculateReturnFee() {
  223. // 如果是首单,显示免费退回
  224. if (this.orderInfo.firstOrder == 1) {
  225. return '首次免费退回';
  226. }
  227. const bookCount = this.length;
  228. // 如果没有选择书籍,返回0
  229. if (bookCount === 0) {
  230. return '¥0.00';
  231. }
  232. // 小于4本是5元,超出4本的,在5元的基础上一本加1
  233. const baseFee = 5;
  234. const extraBooks = Math.max(0, bookCount - 4);
  235. const totalFee = baseFee + extraBooks;
  236. return `¥${totalFee.toFixed(2)}`;
  237. },
  238. //获取订单信息
  239. getOrderInfo(orderId) {
  240. if (!this.isOnLoad) {
  241. return
  242. }
  243. uni.$u.http.get('/token/order/getOrderDetail?orderId=' + orderId).then(res => {
  244. if (res.code === 200) {
  245. this.isOnLoad = false
  246. this.orderInfo = res.data
  247. let length = 0
  248. // 过滤出已审核不良的书籍,作为默认选择的书籍
  249. this.bookItems = res.data.detailVoList.filter(book => {
  250. let list = book.auditCommentList.filter(audit => audit.sts === 3 && audit.com !== '无此书')
  251. list.forEach((audit, index) => {
  252. audit.isSelected = true
  253. })
  254. book.auditCommentList = list
  255. length += list.length
  256. return list.length > 0
  257. })
  258. this.length = length
  259. this.returnFee = this.calculateReturnFee()
  260. uni.setStorageSync('selectedReturnBooks', {
  261. selectedBooks: this.bookItems,
  262. returnFee: this.returnFee,
  263. length: this.length
  264. })
  265. }
  266. })
  267. },
  268. //获取选中的书籍
  269. getSelectedBooks() {
  270. let selectedReturnBooks = uni.getStorageSync('selectedReturnBooks')
  271. if (selectedReturnBooks) {
  272. this.bookItems = selectedReturnBooks.selectedBooks || []
  273. this.returnFee = selectedReturnBooks.returnFee || 0
  274. this.length = selectedReturnBooks.length || 0
  275. }
  276. },
  277. },
  278. onShow() {
  279. if (!this.isOnLoad) {
  280. this.getSelectedBooks()
  281. }
  282. //选择的地址信息
  283. this.defaultAddr = uni.getStorageSync('selectAddr') || {}
  284. },
  285. }
  286. </script>
  287. <style lang="scss" scoped>
  288. .apply-page {
  289. min-height: 100vh;
  290. background: #f5f7fa;
  291. padding: 20rpx;
  292. padding-bottom: calc(env(safe-area-inset-bottom) + 130rpx);
  293. .required {
  294. font-size: 32rpx;
  295. color: #333;
  296. font-weight: 400;
  297. position: relative;
  298. margin-left: 10rpx;
  299. &::after {
  300. content: '*';
  301. color: #fa3534;
  302. margin-left: 4rpx;
  303. }
  304. }
  305. }
  306. .button-bottom {
  307. display: flex;
  308. flex-direction: column;
  309. justify-content: center;
  310. align-items: center;
  311. margin: 30rpx 0;
  312. background-color: #38C148;
  313. color: #ffffff;
  314. font-size: 24rpx;
  315. line-height: 32rpx;
  316. padding: 16rpx 0;
  317. border-radius: 10rpx;
  318. }
  319. </style>