return-select.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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,
  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. list.forEach((audit, index) => {
  111. audit.isSelected = selectedBook?.auditCommentList[index]?.isSelected || false
  112. })
  113. book.auditCommentList = list
  114. return list.length > 0
  115. })
  116. this.isAllSelected = this.bookList.every(book =>
  117. book.auditCommentList.every(audit => audit.isSelected)
  118. );
  119. }
  120. })
  121. },
  122. //选择书籍
  123. handleSelectBook({ checked, index, isbn }) {
  124. let found = false;
  125. let updatedBook = null;
  126. this.bookList = this.bookList.map(book => {
  127. if (book.isbn === isbn) {
  128. const updatedAuditList = book.auditCommentList.map((audit, idx) => {
  129. if (idx === index) {
  130. found = true;
  131. return { ...audit, isSelected: checked };
  132. }
  133. return audit;
  134. });
  135. updatedBook = { ...book, auditCommentList: updatedAuditList };
  136. return updatedBook;
  137. }
  138. return book;
  139. });
  140. if (found) {
  141. // 检查是否所有书籍都被选中
  142. this.isAllSelected = this.bookList.every(book =>
  143. book.auditCommentList.every(audit => audit.isSelected)
  144. );
  145. }
  146. },
  147. //全选
  148. handleSelectAll({ value }) {
  149. this.isAllSelected = value;
  150. this.bookList = this.bookList.map(book => ({
  151. ...book,
  152. auditCommentList: book.auditCommentList.map(audit => ({
  153. ...audit,
  154. isSelected: value
  155. }))
  156. }));
  157. },
  158. //确认选择
  159. handleConfirm() {
  160. if (this.selectedBooks.length === 0) {
  161. uni.$u.toast('请选择要退回的书籍');
  162. return;
  163. }
  164. //筛选出来选中的书籍
  165. let selectedBooks = this.bookList.filter(book => {
  166. let list = book.auditCommentList.filter(audit => audit.isSelected)
  167. if (list.length > 0) {
  168. book.auditCommentList = list
  169. return book
  170. }
  171. })
  172. console.log(selectedBooks, 'xxxx');
  173. // 存储选中的书籍到本地
  174. uni.setStorageSync('selectedReturnBooks', { selectedBooks, returnFee: this.returnFee, length: this.selectedBooks.length });
  175. // 返回上一页
  176. uni.navigateBack({
  177. delta: 1
  178. });
  179. }
  180. }
  181. }
  182. </script>
  183. <style lang="scss" scoped>
  184. .order-detail {
  185. min-height: 100vh;
  186. background: #f8f8f8;
  187. padding-bottom: 230rpx;
  188. .desc-bg {
  189. background: #fafafa;
  190. padding: 20rpx 30rpx;
  191. border-radius: 10rpx;
  192. margin-top: 20rpx;
  193. }
  194. .info-block {
  195. background: #FFFFFF;
  196. padding: 30rpx;
  197. margin: 30rpx;
  198. border-radius: 10rpx;
  199. }
  200. .detail-bottom {
  201. flex-direction: column;
  202. padding-left: 0;
  203. padding-right: 0;
  204. padding-top: 0;
  205. }
  206. }
  207. .button-bottom {
  208. display: flex;
  209. flex-direction: column;
  210. justify-content: center;
  211. align-items: center;
  212. margin: 30rpx 0;
  213. background-color: #38C148;
  214. color: #ffffff;
  215. font-size: 24rpx;
  216. line-height: 32rpx;
  217. padding: 16rpx 0;
  218. border-radius: 10rpx;
  219. }
  220. .book-list {
  221. background: #FFFFFF;
  222. padding: 20rpx 30rpx;
  223. margin: 30rpx;
  224. border-radius: 10rpx;
  225. box-sizing: border-box;
  226. }
  227. </style>