book-audit.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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">{{ detail.price }}</text>
  27. </view>
  28. <view class="flex flex-a-c flex-1">
  29. <text class="label">审核金额</text>
  30. <text class="content">{{ '0.00' }}</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. let reg = /(?:[0-9]+\-?){9}[0-9X]|(?:978|979)\-?(?:[0-9]+\-?){10}/
  81. if (reg.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. //订单总数本
  95. let totalNum = orderDetail.value.totalNum
  96. if (isbns.includes(isbn)) {
  97. let book = orderDetail.value.detailVoList.find(item => item.isbn == isbn)
  98. if (book.num == book.auditCommentList?.length) {
  99. let text = ''
  100. if (book.auditCommentList.every(item => item.sts == 1)) {
  101. text = `${isbn}已审核为良好`
  102. uni.$u.ttsModule.speak(text)
  103. return
  104. } else {
  105. text = `${isbn}已审核为极差`
  106. scannedBooks.value.push(isbn)
  107. uni.$u.ttsModule.speak(text)
  108. uni.setStorageSync('scannedBooks', scannedBooks.value)
  109. uni.navigateTo({
  110. url: `/pages/index/detail/batch-audit?orderId=${orderId.value}`
  111. })
  112. }
  113. } else {
  114. //已审核数量
  115. let hasAuditNum = book.auditCommentList?.length || 0
  116. //未审核数量
  117. let notAuditNum = book.num - hasAuditNum
  118. //极差数量
  119. let poorNum = book.auditCommentList?.filter(item => item.sts == 3).length || 0
  120. //已扫描书籍中当前isbn的数量
  121. let scannedNum = scannedBooks.value.filter(item => item == isbn).length || 0
  122. if (scannedNum >= notAuditNum + poorNum) {
  123. let text = `${isbn}已超出订单中的数量`
  124. return uni.$u.ttsModule.speak(text)
  125. } else {
  126. //扫描到套装书
  127. if (book.suit == 1) {
  128. let text = `${isbn}请注意套装书是否齐全`
  129. uni.$u.ttsModule.speak(text)
  130. }
  131. //扫描到需要取出的书
  132. if (book.bookWarn == 1) {
  133. let text = `请注意${isbn}需要取出`
  134. uni.$u.ttsModule.speak(text)
  135. }
  136. if (scannedNum >= notAuditNum && scannedNum < notAuditNum + poorNum) {
  137. let text = `${isbn}已审核为极差`
  138. uni.$u.ttsModule.speak(text)
  139. }
  140. scannedBooks.value.push(isbn)
  141. console.log(scannedBooks.value, 'book-audit')
  142. uni.setStorageSync('scannedBooks', scannedBooks.value)
  143. uni.navigateTo({
  144. url: `/pages/index/detail/batch-audit?orderId=${orderId.value}`
  145. })
  146. }
  147. }
  148. } else {
  149. let text = `此订单中不存在${isbn}这本书 `
  150. uni.$u.ttsModule.speak(text)
  151. }
  152. }
  153. //扫码
  154. function handleScanCode() {
  155. uni.scanCode({
  156. success: (res) => {
  157. handleScan(res.result)
  158. },
  159. })
  160. }
  161. const auditInfoRef = ref()
  162. //审核 /app/orderinfo/checkOrder
  163. const handleAudit = () => {
  164. let checkList = auditInfoRef.value?.formatReason(auditData.value)
  165. let checkUserInfo = uni.getStorageSync('checkUserInfo')
  166. if (checkUserInfo.userId) {
  167. checkUserId.value = checkUserInfo.userId
  168. } else {
  169. uni.$u.toast('请先选择审核人')
  170. }
  171. uni.$u.http.post('/app/orderinfo/checkOrder', {
  172. "checkUserId": checkUserId.value,
  173. "orderId": orderId.value,
  174. "checkList": checkList
  175. }).then(res => {
  176. if (res.code == 200) {
  177. uni.showToast({ title: '审核成功', icon: 'none' })
  178. uni.$u.ttsModule.speak('审核成功')
  179. uni.navigateBack()
  180. } else {
  181. uni.$u.toast(res.msg)
  182. }
  183. })
  184. }
  185. const auditBook = ref({})
  186. const checkUserId = ref()
  187. const orderId = ref()
  188. const orderDetail = ref({})
  189. onLoad((options) => {
  190. options.isbn && getBookInfo(options.isbn)
  191. scannedBooks.value = [options.isbn] //现存已扫描的图书,是否需要跳转批量审核
  192. auditBook.value = uni.getStorageSync('auditBook')
  193. orderId.value = options.orderId
  194. orderDetail.value = uni.getStorageSync('orderDetail')
  195. // #ifdef APP-PLUS
  196. uni.$u.useGlobalEvent((e) => {
  197. if (e.barcode) {
  198. handleScan(e.barcode)
  199. }
  200. })
  201. // #endif
  202. })
  203. onShow(() => {
  204. checkUserId.value = uni.getStorageSync('userInfo')?.userId
  205. })
  206. </script>
  207. <style lang="scss" scoped>
  208. .book-audit {
  209. padding: 20rpx;
  210. box-sizing: border-box;
  211. padding-bottom: 140rpx;
  212. .price-info {
  213. border-radius: 10rpx;
  214. .label {
  215. width: 150rpx;
  216. background-color: #cecece;
  217. padding: 16rpx 10rpx;
  218. text-align: center;
  219. border: 1rpx solid #e6e6e6;
  220. }
  221. .content {
  222. flex: 1;
  223. text-align: center;
  224. padding: 16rpx 10rpx;
  225. border: 1rpx solid #e6e6e6;
  226. }
  227. }
  228. }
  229. </style>