batch-audit.vue 6.5 KB

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