book-audit.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <view class="book-audit">
  3. <view class="bg-white flex flex-a-c" style="padding: 20rpx;border-radius: 10rpx;">
  4. <image :src="detail.cover" mode="aspectFill" style="width: 80px;height: 100px;"></image>
  5. <view class="flex flex-d flex-1 ml-20">
  6. <text class="common-title mb-20">{{ detail.bookName }}</text>
  7. <text class="text-sm">ISBN: <text class="color-primary">{{ detail.isbn }}</text> </text>
  8. <text class="text-sm mt-6">作者: <text>{{ detail.author }}</text> </text>
  9. <text class="text-sm mt-6">出版社: <text>{{ detail.publish }}</text> </text>
  10. </view>
  11. </view>
  12. <view class="mt-20 bg-white price-info" style="border-radius: 10rpx;">
  13. <view class="flex">
  14. <view class="flex flex-a-c flex-1">
  15. <text class="label">定价</text>
  16. <text class="content">¥{{ detail.price }}</text>
  17. </view>
  18. <view class="flex flex-a-c flex-1">
  19. <text class="label">回收折扣</text>
  20. <text class="content">{{ detail.recycleDiscount }}折</text>
  21. </view>
  22. </view>
  23. <view class="flex flex-a-c">
  24. <view class="flex flex-a-c flex-1">
  25. <text class="label">预估金额</text>
  26. <text class="content">¥{{ auditBook.expectMoney }}</text>
  27. </view>
  28. <view class="flex flex-a-c flex-1">
  29. <text class="label">审核金额</text>
  30. <text class="content">¥{{ auditBook.finalMoney }}</text>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="mt-20">
  35. <u-subsection :list="list" mode="subsection" :current="current"
  36. @change="handleSectionChange"></u-subsection>
  37. <AuditInfo v-if="current == 0" :detail="auditBook" ref="auditInfoRef" />
  38. <FileInfo v-if="current == 2" :orderId="orderId" :annexType="2" :isbn="auditBook.isbn" />
  39. </view>
  40. <view class="fixed-bottom">
  41. <u-button type="warning" size="large" @click="handleScanCode">扫码</u-button>
  42. <u-button type="primary" size="large" @click="handleAudit">确定</u-button>
  43. </view>
  44. </view>
  45. </template>
  46. <script setup>
  47. import { ref } from 'vue'
  48. import { onLoad, onShow } from '@dcloudio/uni-app'
  49. import AuditInfo from './components/AuditInfo.vue'
  50. import FileInfo from './components/FileInfo.vue'
  51. const detail = ref({})
  52. // 获取图书详情 /app/book/getSimpleBookInfoByIsbn/{isbn}
  53. const getBookInfo = (isbn) => {
  54. uni.$u.http.get(`/app/book/getBookByIsbn/${isbn}`).then(res => {
  55. if (res.code == 200) {
  56. detail.value = res.data
  57. }
  58. })
  59. }
  60. const list = ref(['图书审核', '绑码', '附件信息'])
  61. const current = ref(0)
  62. const handleSectionChange = (index) => {
  63. current.value = index
  64. }
  65. //图书审核
  66. const auditData = ref([])
  67. const handleAuditSelected = (data) => {
  68. auditData.value = data.map((item, index) => {
  69. item.idx = index
  70. console.log(index, item.com, 'item.com', Array.isArray(item.com))
  71. item.com = Array.isArray(item.com) ? item.com.join(',') : item.com
  72. return item
  73. })
  74. console.log(auditData.value, 'auditData.value')
  75. }
  76. //存储已经扫码的图书
  77. const scannedBooks = ref([])
  78. //isbn正则校验是否符合
  79. function checkIsbn(isbn) {
  80. const isbn13Regex = /^(?:97[89]-?\d{1,5}-?\d{1,7}-?\d{1,6}-?\d)$/;
  81. if (isbn13Regex.test(isbn)) {
  82. return true
  83. }
  84. return false
  85. }
  86. //扫码之后的逻辑
  87. function handleScan(isbn) {
  88. if (!checkIsbn(isbn)) {
  89. let text = `不是正确的ISBN码`
  90. uni.$u.ttsModule.speak(text)
  91. return
  92. }
  93. let isbns = orderDetail.value.detailVoList.map(item => item.isbn)
  94. if (isbns.includes(isbn)) {
  95. let book = orderDetail.value.detailVoList.find(item => item.isbn == isbn)
  96. if (book.auditCommentList?.length > 0) {
  97. let text = ''
  98. if (book.auditCommentList.every(item => item.sts == 1)) {
  99. text = `${isbn}已审核为良好`
  100. uni.$u.ttsModule.speak(text)
  101. return
  102. }
  103. //已审核数量
  104. let hasAuditNum = book.auditCommentList.filter(item => item.sts !== 0).length || 0
  105. //未审核数量
  106. let notAuditNum = book.auditCommentList.filter(item => item.sts === 0).length || 0
  107. //极差数量
  108. let poorNum = book.auditCommentList?.filter(item => item.sts == 3).length || 0
  109. //已扫描书籍中当前isbn的数量
  110. let scannedNum = scannedBooks.value.filter(item => item == isbn).length || 0
  111. if (scannedNum >= notAuditNum + poorNum) {
  112. let text = `${isbn}已超出订单中的数量`
  113. return uni.$u.ttsModule.speak(text)
  114. } else {
  115. //扫描到套装书
  116. if (book.suit == 1) {
  117. let text = `${isbn}请注意套装书是否齐全`
  118. uni.$u.ttsModule.speak(text)
  119. }
  120. //扫描到需要取出的书
  121. if (book.bookWarn == 1) {
  122. let text = `请注意${isbn}需要取出`
  123. uni.$u.ttsModule.speak(text)
  124. }
  125. if (scannedNum >= notAuditNum && scannedNum < notAuditNum + poorNum) {
  126. let text = `${isbn}已审核为极差`
  127. uni.$u.ttsModule.speak(text)
  128. }
  129. scannedBooks.value.push(isbn)
  130. uni.setStorageSync('scannedBooks', scannedBooks.value)
  131. uni.navigateTo({
  132. url: `/pages/index/detail/batch-audit?orderId=${orderId.value}`
  133. })
  134. }
  135. }
  136. } else {
  137. let text = `此订单中不存在${isbn}这本书 `
  138. uni.$u.ttsModule.speak(text)
  139. }
  140. }
  141. //扫码
  142. function handleScanCode() {
  143. uni.scanCode({
  144. success: (res) => {
  145. handleScan(res.result)
  146. },
  147. })
  148. }
  149. const auditInfoRef = ref()
  150. //审核 /app/orderinfo/checkOrder
  151. const handleAudit = () => {
  152. let checkList = auditInfoRef.value?.formatReason(auditData.value)
  153. let checkUserInfo = uni.getStorageSync('checkUserInfo')
  154. if (checkUserInfo.userId) {
  155. checkUserId.value = checkUserInfo.userId
  156. } else {
  157. uni.$u.toast('请先选择审核人')
  158. }
  159. uni.$u.http.post('/app/orderinfo/checkOrder', {
  160. "checkUserId": checkUserId.value,
  161. "orderId": orderId.value,
  162. "checkList": checkList
  163. }).then(res => {
  164. if (res.code == 200) {
  165. uni.showToast({ title: '审核成功', icon: 'none' })
  166. uni.$u.ttsModule.speak('审核成功')
  167. uni.navigateBack()
  168. } else {
  169. uni.$u.toast(res.msg)
  170. }
  171. })
  172. }
  173. const auditBook = ref({})
  174. const checkUserId = ref()
  175. const orderId = ref()
  176. const orderDetail = ref({})
  177. onLoad((options) => {
  178. options.isbn && getBookInfo(options.isbn)
  179. scannedBooks.value = [options.isbn] //现存已扫描的图书,是否需要跳转批量审核
  180. auditBook.value = uni.getStorageSync('auditBook')
  181. orderId.value = options.orderId
  182. orderDetail.value = uni.getStorageSync('orderDetail')
  183. // #ifdef APP-PLUS
  184. uni.$u.useGlobalEvent((e) => {
  185. if (e.barcode) {
  186. handleScan(e.barcode)
  187. }
  188. })
  189. // #endif
  190. })
  191. onShow(() => {
  192. checkUserId.value = uni.getStorageSync('userInfo')?.userId
  193. auditBook.value = uni.getStorageSync('auditBook')
  194. orderDetail.value = uni.getStorageSync('orderDetail')
  195. })
  196. </script>
  197. <style lang="scss" scoped>
  198. .book-audit {
  199. padding: 20rpx;
  200. box-sizing: border-box;
  201. padding-bottom: 140rpx;
  202. .price-info {
  203. border-radius: 10rpx;
  204. .label {
  205. width: 150rpx;
  206. background-color: #cecece;
  207. padding: 16rpx 10rpx;
  208. text-align: center;
  209. border: 1rpx solid #e6e6e6;
  210. }
  211. .content {
  212. flex: 1;
  213. text-align: center;
  214. padding: 16rpx 10rpx;
  215. border: 1rpx solid #e6e6e6;
  216. }
  217. }
  218. }
  219. </style>