BookInfo.vue 4.3 KB

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