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