return-select.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <view class="order-detail">
  3. <!-- 书籍列表组件 -->
  4. <view class="book-list">
  5. <view class="header-info flex-a flex-j-b mb-20">
  6. <text class="common-title">卖书编号:{{ orderInfo.orderId }}</text>
  7. </view>
  8. <select-book-item :book="item" v-for="(item, index) in bookList" :key="index"
  9. @select="handleSelectBook"></select-book-item>
  10. </view>
  11. <!-- 收入信息区块 -->
  12. <view class="common-card" style="padding: 30rpx;margin: 30rpx;" @click="selectBooks">
  13. <view class="flex-a flex-j-b mb-20">
  14. <text class="common-text-2 font-30">退回邮费:</text>
  15. <text class="common-title" style="color: #FF0000;">{{ returnFee }}</text>
  16. </view>
  17. <view class="common-card flex-a flex-j-b" style="background: #fafafa;">
  18. <text class="common-text-2">书籍数量</text>
  19. <text class="common-text-2">{{ selectedBooks.length }}</text>
  20. </view>
  21. </view>
  22. <!-- 底部操作栏 -->
  23. <view class="bottom-fixed-con detail-bottom flex-d">
  24. <view class="flex-a" style="width: 100%;padding: 0 30rpx;">
  25. <u-checkbox v-model="isAllSelected" @change="handleSelectAll">全选</u-checkbox>
  26. <button class="confirm-btn" style="width:400rpx;margin-left: 100rpx;"
  27. @click="handleConfirm">确认选择</button>
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import OrderTimeline from '../components/order-timeline.vue'
  34. import BookList from '../components/book-list.vue'
  35. import CommonDialog from '@/components/common-dialog.vue';
  36. import selectBookItem from '../components/select-book-item.vue';
  37. export default {
  38. components: {
  39. OrderTimeline,
  40. BookList,
  41. CommonDialog,
  42. selectBookItem
  43. },
  44. data() {
  45. return {
  46. bookList: [],
  47. orderInfo: {},
  48. isAllSelected: false
  49. }
  50. },
  51. computed: {
  52. selectedBooks() {
  53. // 计算选中的书籍列表
  54. let selected = [];
  55. this.bookList.forEach(book => {
  56. book.auditCommentList.forEach(audit => {
  57. if (audit.isSelected) {
  58. selected.push({ ...book, selectedAudit: audit });
  59. }
  60. });
  61. });
  62. return selected;
  63. },
  64. returnFee() {
  65. // 如果是首单,显示免费退回
  66. if (this.orderInfo.firstOrder == 1) {
  67. return '首次免费退回';
  68. }
  69. const bookCount = this.selectedBooks.length;
  70. // 如果没有选择书籍,返回0
  71. if (bookCount === 0) {
  72. return '¥0.00';
  73. }
  74. // 5本以内收费4元,超过5本每本加收1元
  75. const baseFee = 5;
  76. const extraBooks = Math.max(0, bookCount - 4);
  77. const totalFee = baseFee + extraBooks;
  78. return `¥${totalFee.toFixed(2)}`;
  79. }
  80. },
  81. onLoad(options) {
  82. if (options.orderId) {
  83. this.getOrderInfo(options.orderId)
  84. }
  85. },
  86. methods: {
  87. copyOrderNo() {
  88. uni.setClipboardData({
  89. data: this.orderInfo.orderId.toString(),
  90. success: () => {
  91. uni.$u.toast('复制成功')
  92. }
  93. })
  94. },
  95. //获取订单信息
  96. getOrderInfo(orderId) {
  97. uni.$u.http.get('/token/order/getOrderDetail?orderId=' + orderId).then(res => {
  98. if (res.code === 200) {
  99. this.orderInfo = res.data;
  100. let selectedReturnBooks = uni.getStorageSync('selectedReturnBooks') || {};
  101. let selectedBooks = selectedReturnBooks.selectedBooks || [];
  102. this.bookList = res.data.detailVoList.filter(book => {
  103. let selectedBook = selectedBooks.find(selectedBook => selectedBook.isbn === book.isbn);
  104. let list = book.auditCommentList.filter(audit => audit.sts === 3)
  105. .sort((a, b) => {
  106. if (a.com === '无此书' && b.com !== '无此书') return 1;
  107. if (a.com !== '无此书' && b.com === '无此书') return -1;
  108. return 0;
  109. });
  110. if (list.length > 0) {
  111. list.forEach((audit, index) => {
  112. audit.isSelected = selectedBook?.auditCommentList[index]?.isSelected || false;
  113. });
  114. book.auditCommentList = list;
  115. return true;
  116. }
  117. return false;
  118. });
  119. this.$nextTick(() => {
  120. this.isAllSelected = this.bookList.every(book =>
  121. book.auditCommentList.every(audit => audit.isSelected)
  122. );
  123. });
  124. }
  125. });
  126. },
  127. //选择书籍
  128. handleSelectBook({ checked, index, isbn }) {
  129. const book = this.bookList.find(book => book.isbn === isbn);
  130. if (book && book.auditCommentList[index]) {
  131. book.auditCommentList[index].isSelected = checked;
  132. // 更新全选状态
  133. this.$nextTick(() => {
  134. this.isAllSelected = this.bookList.every(book =>
  135. book.auditCommentList.every(audit => audit.isSelected)
  136. );
  137. });
  138. }
  139. },
  140. //全选
  141. handleSelectAll({ value }) {
  142. this.isAllSelected = value;
  143. this.bookList.forEach(book => {
  144. book.auditCommentList.forEach(audit => {
  145. audit.isSelected = value;
  146. });
  147. });
  148. },
  149. //确认选择
  150. handleConfirm() {
  151. if (this.selectedBooks.length === 0) {
  152. uni.$u.toast('请选择要退回的书籍');
  153. return;
  154. }
  155. //筛选出来选中的书籍
  156. let selectedBooks = this.bookList.filter(book => {
  157. let list = book.auditCommentList.filter(audit => audit.isSelected)
  158. if (list.length > 0) {
  159. book.auditCommentList = list
  160. return book
  161. }
  162. })
  163. console.log(selectedBooks, 'xxxx');
  164. // 存储选中的书籍到本地
  165. uni.setStorageSync('selectedReturnBooks', { selectedBooks, returnFee: this.returnFee, length: this.selectedBooks.length });
  166. // 返回上一页
  167. uni.navigateBack({
  168. delta: 1
  169. });
  170. }
  171. }
  172. }
  173. </script>
  174. <style lang="scss" scoped>
  175. .order-detail {
  176. min-height: 100vh;
  177. background: #f8f8f8;
  178. padding-bottom: 230rpx;
  179. .desc-bg {
  180. background: #fafafa;
  181. padding: 20rpx 30rpx;
  182. border-radius: 10rpx;
  183. margin-top: 20rpx;
  184. }
  185. .info-block {
  186. background: #FFFFFF;
  187. padding: 30rpx;
  188. margin: 30rpx;
  189. border-radius: 10rpx;
  190. }
  191. .detail-bottom {
  192. flex-direction: column;
  193. padding-left: 0;
  194. padding-right: 0;
  195. padding-top: 0;
  196. }
  197. }
  198. .button-bottom {
  199. display: flex;
  200. flex-direction: column;
  201. justify-content: center;
  202. align-items: center;
  203. margin: 30rpx 0;
  204. background-color: #38C148;
  205. color: #ffffff;
  206. font-size: 24rpx;
  207. line-height: 32rpx;
  208. padding: 16rpx 0;
  209. border-radius: 10rpx;
  210. }
  211. .book-list {
  212. background: #FFFFFF;
  213. padding: 20rpx 30rpx;
  214. margin: 30rpx;
  215. border-radius: 10rpx;
  216. box-sizing: border-box;
  217. }
  218. </style>