apply.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. closeDialog() {
  139. this.$refs.returnDialog?.closePopup()
  140. },
  141. //我要取回 - 提交退回申请
  142. handleApplyBack() {
  143. // 构建请求参数
  144. const detailList = this.bookItems.map(book => ({
  145. isbn: book.isbn,
  146. num: book.auditCommentList.length
  147. }));
  148. const params = {
  149. orderId: this.orderId,
  150. addressId: this.defaultAddr.id,
  151. detailList: detailList
  152. };
  153. // 发起请求
  154. uni.showLoading({
  155. title: '提交中...'
  156. });
  157. uni.$u.http.post('/token/order/submitRefundOrder', params)
  158. .then(res => {
  159. if (res.code === 200) {
  160. if (res.data.firstOrder == 1) {
  161. // 提交成功后
  162. this.dialogContent = '提交成功'
  163. this.$refs.commonDialog.openPopup()
  164. uni.removeStorageSync('selectAddr')
  165. this.closeDialog()
  166. } else {
  167. //跳转去付款页面
  168. uni.navigateTo({
  169. url: `/pages-mine/pages/cashier-desk?id=${res.data.refundOrderId}`
  170. })
  171. }
  172. } else {
  173. uni.showToast({
  174. title: res.msg || '提交失败',
  175. icon: 'none'
  176. });
  177. }
  178. })
  179. .finally(() => {
  180. uni.hideLoading();
  181. });
  182. },
  183. //仓库循环处理
  184. handleRecycleWare() {
  185. this.$refs.recycleWare?.openPopup()
  186. this.closeDialog()
  187. },
  188. //仓库循环处理确认
  189. handleRecycleWareConfirm() {
  190. uni.$u.http.post('/token/order/notNeed', {
  191. orderId: this.orderId
  192. }).then(res => {
  193. if (res.code === 200) {
  194. uni.$u.toast(`已补贴 ${this.orderInfo.basicRecycleMoney || 0} 到余额`)
  195. uni.navigateBack()
  196. } else {
  197. uni.$u.toast(res.msg || '仓库循环处理失败')
  198. }
  199. })
  200. },
  201. //纸价回收
  202. handleRecycle() {
  203. this.$refs.recycleDialog?.openPopup()
  204. this.closeDialog()
  205. },
  206. //纸价回收确认
  207. handleRecycleConfirm() {
  208. uni.$u.http.post('/token/order/basicRecycle', {
  209. orderId: this.orderId
  210. }).then(res => {
  211. if (res.code === 200) {
  212. uni.$u.toast('纸价回收成功')
  213. uni.navigateBack()
  214. } else {
  215. uni.$u.toast(res.msg || '纸价回收失败')
  216. }
  217. })
  218. },
  219. // 选择书籍页面
  220. selectBooks() {
  221. uni.navigateTo({
  222. url: `/pages-mine/pages/return-select?orderId=${this.orderId}`
  223. })
  224. },
  225. //添加或者选择地址
  226. handleAddress() {
  227. uni.navigateTo({
  228. url: `/pages-mine/pages/address/list?id=${this.defaultAddr.id}&isSelect=1`
  229. })
  230. },
  231. //计算退回邮费
  232. calculateReturnFee() {
  233. // 如果是首单,显示免费退回
  234. if (this.orderInfo.firstOrder == 1) {
  235. return '首次免费退回';
  236. }
  237. const bookCount = this.length;
  238. // 如果没有选择书籍,返回0
  239. if (bookCount === 0) {
  240. return '¥0.00';
  241. }
  242. // 小于4本是5元,超出4本的,在5元的基础上一本加1
  243. const baseFee = 5;
  244. const extraBooks = Math.max(0, bookCount - 4);
  245. const totalFee = baseFee + extraBooks;
  246. return `¥${totalFee.toFixed(2)}`;
  247. },
  248. //获取订单信息
  249. getOrderInfo(orderId) {
  250. if (!this.isOnLoad) {
  251. return
  252. }
  253. uni.$u.http.get('/token/order/getOrderDetail?orderId=' + orderId).then(res => {
  254. if (res.code === 200) {
  255. this.isOnLoad = false
  256. this.orderInfo = res.data
  257. let length = 0
  258. // 过滤出已审核不良的书籍,作为默认选择的书籍
  259. this.bookItems = res.data.detailVoList.filter(book => {
  260. let list = book.auditCommentList.filter(audit => audit.sts === 3 && audit.com !== '无此书')
  261. list.forEach((audit, index) => {
  262. audit.isSelected = true
  263. })
  264. book.auditCommentList = list
  265. length += list.length
  266. return list.length > 0
  267. })
  268. this.length = length
  269. this.returnFee = this.calculateReturnFee()
  270. uni.setStorageSync('selectedReturnBooks', {
  271. selectedBooks: this.bookItems,
  272. returnFee: this.returnFee,
  273. length: this.length
  274. })
  275. }
  276. })
  277. },
  278. //获取选中的书籍
  279. getSelectedBooks() {
  280. let selectedReturnBooks = uni.getStorageSync('selectedReturnBooks')
  281. if (selectedReturnBooks) {
  282. this.bookItems = selectedReturnBooks.selectedBooks || []
  283. this.returnFee = selectedReturnBooks.returnFee || 0
  284. this.length = selectedReturnBooks.length || 0
  285. }
  286. },
  287. },
  288. onShow() {
  289. if (!this.isOnLoad) {
  290. this.getSelectedBooks()
  291. }
  292. //选择的地址信息
  293. this.defaultAddr = uni.getStorageSync('selectAddr') || {}
  294. },
  295. }
  296. </script>
  297. <style lang="scss" scoped>
  298. .apply-page {
  299. min-height: 100vh;
  300. background: #f5f7fa;
  301. padding: 20rpx;
  302. padding-bottom: calc(env(safe-area-inset-bottom) + 130rpx);
  303. .required {
  304. font-size: 32rpx;
  305. color: #333;
  306. font-weight: 400;
  307. position: relative;
  308. margin-left: 10rpx;
  309. &::after {
  310. content: '*';
  311. color: #fa3534;
  312. margin-left: 4rpx;
  313. }
  314. }
  315. }
  316. .button-bottom {
  317. display: flex;
  318. flex-direction: column;
  319. justify-content: center;
  320. align-items: center;
  321. margin: 30rpx 0;
  322. background-color: #38C148;
  323. color: #ffffff;
  324. font-size: 24rpx;
  325. line-height: 32rpx;
  326. padding: 16rpx 0;
  327. border-radius: 10rpx;
  328. }
  329. </style>