batch-audit.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <view class="batch-audit">
  3. <BookItem v-for="(item, index) in scannedBooksDetail" :key="item.isbn" :item="item" showClose
  4. @close="(isbn) => handleClose(index, isbn)" />
  5. <view class="fixed-bottom">
  6. <u-button type="warning" size="large" @click="handleScanCode">扫码</u-button>
  7. <u-button type="primary" size="large" @click="showQualityModal">确定</u-button>
  8. </view>
  9. <u-modal :show="showModal" :title="'品相选择'" @cancel="closeModal" :showCancelButton="true"
  10. :closeOnClickOverlay="true" @confirm="handleAudit">
  11. <view class="quality-selector">
  12. <view class="quality-circle" :class="{ 'selected': isQualitySelected }" @click="toggleQuality">
  13. <text>良好</text>
  14. </view>
  15. </view>
  16. </u-modal>
  17. </view>
  18. </template>
  19. <script setup>
  20. import { ref } from 'vue'
  21. import { onLoad, onShow } from '@dcloudio/uni-app'
  22. import BookItem from './components/BookItem2.vue'
  23. const detailMap = ref({})
  24. const scannedBooksDetail = ref([])
  25. // 获取图书详情 /app/book/getSimpleBookInfoByIsbn/{isbn}
  26. const getBookInfo = (isbn) => {
  27. if (detailMap.value[isbn]) {
  28. scannedBooksDetail.value.push(detailMap.value[isbn])
  29. return
  30. }
  31. uni.$u.http.get(`/app/book/getSimpleBookInfoByIsbn/${isbn}`).then(res => {
  32. if (res.code == 200) {
  33. detailMap.value[isbn] = res.data
  34. scannedBooksDetail.value.push(res.data)
  35. console.log(scannedBooksDetail.value, 'xxaaxx')
  36. }
  37. })
  38. }
  39. const handleClose = (index, isbn) => {
  40. scannedBooksDetail.value.splice(index, 1)
  41. scannedBooks.value = scannedBooks.value.filter(item => item != isbn)
  42. }
  43. //isbn正则校验是否符合
  44. function checkIsbn(isbn) {
  45. const isbn13Regex = /^(?:97[89]-?\d{1,5}-?\d{1,7}-?\d{1,6}-?\d)$/;
  46. if (isbn13Regex.test(isbn)) {
  47. return true
  48. }
  49. return false
  50. }
  51. //存储已经扫码的图书
  52. const scannedBooks = ref([])
  53. //扫码之后的逻辑
  54. function handleScan(isbn) {
  55. if (!checkIsbn(isbn)) {
  56. let text = `不是正确的ISBN码`
  57. uni.$u.ttsModule.speak(text)
  58. return
  59. }
  60. let isbns = orderDetail.value.detailVoList.map(item => item.isbn)
  61. //订单总数本
  62. if (isbns.includes(isbn)) {
  63. let book = orderDetail.value.detailVoList.find(item => item.isbn == isbn)
  64. if (book.auditCommentList?.length > 0) {
  65. let text = ''
  66. if (book.auditCommentList.every(item => item.sts == 1)) {
  67. text = `${isbn}已审核为良好`
  68. uni.$u.ttsModule.speak(text)
  69. return
  70. }
  71. //已审核数量
  72. let hasAuditNum = book.auditCommentList.filter(item => item.sts !== 0).length || 0
  73. //未审核数量
  74. let notAuditNum = book.auditCommentList.filter(item => item.sts === 0).length || 0
  75. //极差数量
  76. let poorNum = book.auditCommentList?.filter(item => item.sts == 3).length || 0
  77. //已扫描书籍中当前isbn的数量
  78. let scannedNum = scannedBooks.value.filter(item => item == isbn).length || 0
  79. if (scannedNum >= notAuditNum + poorNum) {
  80. let text = `${isbn}已超出订单中的数量`
  81. return uni.$u.ttsModule.speak(text)
  82. } else {
  83. //扫描到套装书
  84. if (book.suit == 1) {
  85. let text = `${isbn}请注意套装书是否齐全`
  86. uni.$u.ttsModule.speak(text)
  87. }
  88. //扫描到需要取出的书
  89. if (book.bookWarn == 1) {
  90. let text = `请注意${isbn}需要取出`
  91. uni.$u.ttsModule.speak(text)
  92. }
  93. if (scannedNum >= notAuditNum && scannedNum < notAuditNum + poorNum) {
  94. let text = `${isbn}已审核为极差`
  95. uni.$u.ttsModule.speak(text)
  96. }
  97. scannedBooks.value.push(isbn)
  98. getBookInfo(isbn)
  99. }
  100. }
  101. } else {
  102. let text = `此订单中不存在${isbn}这本书 `
  103. uni.$u.ttsModule.speak(text)
  104. }
  105. }
  106. //扫码
  107. function handleScanCode() {
  108. uni.scanCode({
  109. success: (res) => {
  110. handleScan(res.result)
  111. },
  112. })
  113. }
  114. const checkUserId = ref()
  115. const orderId = ref()
  116. const orderDetail = ref({})
  117. const showModal = ref(false)
  118. const isQualitySelected = ref(false)
  119. const showQualityModal = () => {
  120. showModal.value = true
  121. }
  122. const closeModal = () => {
  123. showModal.value = false
  124. }
  125. const toggleQuality = () => {
  126. isQualitySelected.value = !isQualitySelected.value
  127. }
  128. //审核 /app/orderinfo/checkOrder
  129. const handleAudit = () => {
  130. if (!isQualitySelected.value) {
  131. uni.$u.toast('请选择品相')
  132. uni.$u.ttsModule.speak('请选择品相')
  133. return
  134. }
  135. let checkUserInfo = uni.getStorageSync('checkUserInfo')
  136. if (checkUserInfo.userId) {
  137. checkUserId.value = checkUserInfo.userId
  138. }
  139. uni.$u.http.post('/app/orderinfo/checkOrder', {
  140. "checkUserId": checkUserId.value,
  141. "orderId": orderId.value,
  142. "checkList": scannedBooks.value.map(isbn => ({ sts: 1, com: '', isbn }))
  143. }).then(res => {
  144. if (res.code == 200) {
  145. uni.showToast({ title: '审核成功', icon: 'none' })
  146. uni.$u.ttsModule.speak('审核成功')
  147. uni.navigateBack({ delta: 2 })
  148. } else {
  149. uni.$u.toast(res.msg)
  150. }
  151. })
  152. }
  153. onLoad((options) => {
  154. orderId.value = options.orderId
  155. orderDetail.value = uni.getStorageSync('orderDetail')
  156. scannedBooks.value = uni.getStorageSync('scannedBooks')
  157. scannedBooks.value.forEach(isbn => {
  158. getBookInfo(isbn)
  159. })
  160. // #ifdef APP-PLUS
  161. uni.$u.useGlobalEvent((e) => {
  162. if (e.barcode) {
  163. handleScan(e.barcode)
  164. }
  165. })
  166. // #endif
  167. })
  168. onShow(() => {
  169. checkUserId.value = uni.getStorageSync('userInfo')?.userId
  170. orderDetail.value = uni.getStorageSync('orderDetail')
  171. })
  172. </script>
  173. <style lang="scss" scoped>
  174. .batch-audit {
  175. padding: 20rpx;
  176. box-sizing: border-box;
  177. padding-bottom: 140rpx;
  178. }
  179. .quality-selector {
  180. display: flex;
  181. justify-content: center;
  182. align-items: center;
  183. padding: 30rpx 0;
  184. }
  185. .quality-circle {
  186. width: 120rpx;
  187. height: 120rpx;
  188. border-radius: 50%;
  189. background-color: #ccc;
  190. display: flex;
  191. justify-content: center;
  192. align-items: center;
  193. cursor: pointer;
  194. text {
  195. color: #fff;
  196. font-size: 28rpx;
  197. }
  198. &.selected {
  199. background-color: #4CAF50;
  200. }
  201. }
  202. </style>