BookInfo.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view class="book-info">
  3. <template v-if="isShow">
  4. <view class="font-bold mt-12 mb-10" style="padding: 0 20rpx">
  5. {{ bookList.length }}条记录,共{{ detail.totalNum }}本,已审{{ auditNum || 0 }}本
  6. </view>
  7. <view class="font-light" style="padding: 0 20rpx">
  8. 其中已审:良好{{ getAuditCateNum(1) }}本,一般0本,极差{{ getAuditCateNum(3) }}本
  9. </view>
  10. </template>
  11. <view class="book-info-item bg-white mt-12" :style="{ backgroundColor: item.backgroundColor }"
  12. v-for="item in formatList" :key="item.title" :id="item.id" v-show="item?.title">
  13. <view class="book-info-item-title">{{ item.title }}</view>
  14. <view class="book-info-item-list">
  15. <BookItem v-for="book in item.list" :key="book.bookId" :item="book" @click="handleBookClick(book)" />
  16. </view>
  17. </view>
  18. </view>
  19. </template>
  20. <script setup>
  21. import { ref, watch, computed } from 'vue';
  22. import BookItem from './BookItem.vue';
  23. import toPinyin from "@/utils/toPinyin.js"
  24. const props = defineProps({
  25. bookList: {
  26. type: Array,
  27. default: () => [],
  28. },
  29. detail: {
  30. type: Object,
  31. default: () => ({})
  32. },
  33. isShow: {
  34. type: Boolean,
  35. default: true
  36. }
  37. })
  38. const emit = defineEmits(['get-all-firstLetter'])
  39. //计算已审书籍数量
  40. const auditNum = computed(() => {
  41. return props.bookList.reduce((total, item) => total + item.auditCommentList?.length || 0, 0)
  42. })
  43. function handleBookClick(book) {
  44. if (props.detail.status == 10) {
  45. uni.$u.ttsModule.speak('此订单已审核')
  46. return
  47. }
  48. //判断是否已经审核完
  49. // let auditNum = book.auditCommentList?.length || 0
  50. // if (book.num > auditNum) {
  51. uni.navigateTo({
  52. url: `/pages/index/detail/book-audit?isbn=${book.isbn}&orderId=${props.detail.orderId}`
  53. })
  54. uni.setStorageSync('auditBook', book)
  55. // } else {
  56. // uni.showToast({
  57. // title: '该书籍已审核完成',
  58. // icon: 'none'
  59. // })
  60. // uni.$u.ttsModule.speak('该书籍已审核完成')
  61. // }
  62. }
  63. function getAuditCateNum(cate) {
  64. let auditList = []
  65. props.bookList.forEach(v => {
  66. auditList.push(...(v.auditCommentList || []))
  67. })
  68. return auditList.filter(v => v.sts == cate).length
  69. }
  70. //格式化书籍列表
  71. const formatBookList = (list) => {
  72. const poorBooks = { title: '极差', list: [], backgroundColor: '#de868f', id: 'poor' };
  73. const goodBooks = { title: '良好', list: [], backgroundColor: '#81b337', id: 'good' };
  74. const otherBooks = [];
  75. //获取所有的首字母
  76. const allFirstLetter = [];
  77. const handleBookCategorization = (book) => {
  78. let firstLetter;
  79. const char = book.bookName.charAt(0);
  80. if (/^[A-Za-z]$/.test(char)) {
  81. firstLetter = char.toUpperCase();
  82. } else if (/^[\u4E00-\u9FA5]$/.test(char)) { //中文
  83. firstLetter = toPinyin.chineseToInitials(toPinyin.chineseToPinYin(char));
  84. } else {
  85. firstLetter = char
  86. }
  87. let bool = otherBooks.some(item => item.title == firstLetter);
  88. if (!bool) {
  89. otherBooks.push({ id: firstLetter, title: firstLetter, list: [{ ...book }] });
  90. allFirstLetter.push(firstLetter)
  91. emit('get-all-firstLetter', allFirstLetter)
  92. } else {
  93. otherBooks.find(item => item.title == firstLetter).list.push(book);
  94. }
  95. };
  96. list.forEach(book => {
  97. console.log(book, 'book')
  98. book.goodNum = book.auditCommentList?.filter(v => v.sts == 1).length || 0
  99. book.badNum = book.auditCommentList?.filter(v => v.sts == 3).length || 0
  100. // Check if book is fully audited (all items have been reviewed)
  101. const totalAudited = book.auditCommentList?.filter(v => v.sts !== 0).length || 0;
  102. const isFullyAudited = totalAudited === book.num;
  103. if (isFullyAudited) {
  104. // If any audit result is poor (sts === 3), push to poorBooks
  105. if (book.auditCommentList.some(v => v.sts === 3)) {
  106. poorBooks.list.push(book);
  107. } else if (book.auditCommentList.every(v => v.sts === 1)) {
  108. // If all audit results are good (sts === 1), push to goodBooks
  109. goodBooks.list.push(book);
  110. } else {
  111. handleBookCategorization(book);
  112. }
  113. } else {
  114. handleBookCategorization(book);
  115. }
  116. });
  117. return { poorBooks, goodBooks, otherBooks };
  118. }
  119. const formatList = ref([]);
  120. watch(() => props.bookList, (newVal) => {
  121. let { poorBooks, goodBooks, otherBooks } = formatBookList(newVal);
  122. let poor = poorBooks.list.length > 0 ? poorBooks : {}
  123. let good = goodBooks.list.length > 0 ? goodBooks : {}
  124. formatList.value = [...otherBooks, poor, good]
  125. console.log(formatList.value, 'xxxxx')
  126. }, { immediate: true, deep: true });
  127. </script>
  128. <style scoped>
  129. .book-info-item-title {
  130. padding: 10rpx 30rpx;
  131. font-size: 28rpx;
  132. font-weight: 600;
  133. border-bottom: 1px solid #e5e5e5;
  134. }
  135. </style>