| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- <template>
- <view class="batch-audit">
- <BookItem v-for="item in scannedBooksDetail" :key="item.isbn" :item="item" showClose />
- <view class="fixed-bottom">
- <u-button type="warning" size="large" @click="handleScanCode">扫码</u-button>
- <u-button type="primary" size="large" @click="showQualityModal">确定</u-button>
- </view>
- <u-modal :show="showModal" :title="'品相选择'" @cancel="closeModal" :showCancelButton="true"
- :closeOnClickOverlay="true" @confirm="handleAudit">
- <view class="quality-selector">
- <view class="quality-circle" :class="{ 'selected': isQualitySelected }" @click="toggleQuality">
- <text>良好</text>
- </view>
- </view>
- </u-modal>
- </view>
- </template>
- <script setup>
- import { ref } from 'vue'
- import { onLoad, onShow } from '@dcloudio/uni-app'
- import BookItem from './components/BookItem2.vue'
- const detailMap = ref({})
- const scannedBooksDetail = ref([])
- // 获取图书详情 /app/book/getSimpleBookInfoByIsbn/{isbn}
- const getBookInfo = (isbn) => {
- if (detailMap.value[isbn]) {
- scannedBooksDetail.value.push(detailMap.value[isbn])
- return
- }
- uni.$u.http.get(`/app/book/getSimpleBookInfoByIsbn/${isbn}`).then(res => {
- if (res.code == 200) {
- detailMap.value[isbn] = res.data
- scannedBooksDetail.value.push(res.data)
- console.log(scannedBooksDetail.value, 'xxaaxx')
- }
- })
- }
- //isbn正则校验是否符合
- function checkIsbn(isbn) {
- let reg = /(?:[0-9]+\-?){9}[0-9X]|(?:978|979)\-?(?:[0-9]+\-?){10}/
- if (reg.test(isbn)) {
- return true
- }
- return false
- }
- //存储已经扫码的图书
- const scannedBooks = ref([])
- //扫码之后的逻辑
- function handleScan(isbn) {
- if (!checkIsbn(isbn)) {
- let text = `不是正确的ISBN码`
- uni.$u.ttsModule.speak(text)
- return
- }
- let isbns = orderDetail.value.detailVoList.map(item => item.isbn)
- //订单总数本
- let totalNum = orderDetail.value.totalNum
- if (isbns.includes(isbn)) {
- let book = orderDetail.value.detailVoList.find(item => item.isbn == isbn)
- if (book.num == book.auditCommentList?.length) {
- let text = ''
- if (book.auditCommentList.every(item => item.sts == 1)) {
- text = `${isbn}已审核为良好`
- uni.$u.ttsModule.speak(text)
- return
- } else {
- text = `${isbn}已审核为极差`
- scannedBooks.value.push(isbn)
- uni.$u.ttsModule.speak(text)
- getBookInfo(isbn)
- }
- } else {
- //已审核数量
- let hasAuditNum = book.auditCommentList?.length || 0
- //未审核数量
- let notAuditNum = book.num - hasAuditNum
- //极差数量
- let poorNum = book.auditCommentList?.filter(item => item.sts == 3).length || 0
- //已扫描书籍中当前isbn的数量
- let scannedNum = scannedBooks.value.filter(item => item == isbn).length || 0
- console.log(scannedNum,poorNum,notAuditNum, 'scannedNum')
- if (scannedNum >= notAuditNum + poorNum) {
- let text = `${isbn}已超出订单中的数量`
- return uni.$u.ttsModule.speak(text)
- } else {
- //扫描到套装书
- if (book.suit == 1) {
- let text = `${isbn}请注意套装书是否齐全`
- uni.$u.ttsModule.speak(text)
- }
- //扫描到需要取出的书
- if (book.bookWarn == 1) {
- let text = `请注意${isbn}需要取出`
- uni.$u.ttsModule.speak(text)
- }
- if (scannedNum >= notAuditNum && scannedNum < notAuditNum + poorNum) {
- let text = `${isbn}已审核为极差`
- uni.$u.ttsModule.speak(text)
- }
- scannedBooks.value.push(isbn)
- getBookInfo(isbn)
- }
- }
- } else {
- let text = `此订单中不存在${isbn}这本书 `
- uni.$u.ttsModule.speak(text)
- }
- }
- //扫码
- function handleScanCode() {
- uni.scanCode({
- success: (res) => {
- handleScan(res.result)
- },
- })
- }
- const checkUserId = ref()
- const orderId = ref()
- const orderDetail = ref({})
- const showModal = ref(false)
- const isQualitySelected = ref(false)
- const showQualityModal = () => {
- showModal.value = true
- }
- const closeModal = () => {
- showModal.value = false
- }
- const toggleQuality = () => {
- isQualitySelected.value = !isQualitySelected.value
- }
- //审核 /app/orderinfo/checkOrder
- const handleAudit = () => {
- if (!isQualitySelected.value) {
- uni.$u.toast('请选择品相')
- uni.$u.ttsModule.speak('请选择品相')
- return
- }
- let checkUserInfo = uni.getStorageSync('checkUserInfo')
- if (checkUserInfo.userId) {
- checkUserId.value = checkUserInfo.userId
- }
- uni.$u.http.post('/app/orderinfo/checkOrder', {
- "checkUserId": checkUserId.value,
- "orderId": orderId.value,
- "checkList": scannedBooks.value.map(isbn => ({ sts: 1, com: '', isbn }))
- }).then(res => {
- if (res.code == 200) {
- uni.showToast({ title: '审核成功', icon: 'none' })
- uni.$u.ttsModule.speak('审核成功')
- uni.navigateBack({ delta: 2 })
- } else {
- uni.$u.toast(res.msg)
- }
- })
- }
- onLoad((options) => {
- orderId.value = options.orderId
- orderDetail.value = uni.getStorageSync('orderDetail')
- scannedBooks.value = uni.getStorageSync('scannedBooks')
- scannedBooks.value.forEach(isbn => {
- getBookInfo(isbn)
- })
- // #ifdef APP-PLUS
- uni.$u.useGlobalEvent((e) => {
- if (e.barcode) {
- handleScan(e.barcode)
- }
- })
- // #endif
- })
- </script>
- <style lang="scss" scoped>
- .batch-audit {
- padding: 20rpx;
- box-sizing: border-box;
- padding-bottom: 140rpx;
- }
- .quality-selector {
- display: flex;
- justify-content: center;
- align-items: center;
- padding: 30rpx 0;
- }
- .quality-circle {
- width: 120rpx;
- height: 120rpx;
- border-radius: 50%;
- background-color: #ccc;
- display: flex;
- justify-content: center;
- align-items: center;
- cursor: pointer;
- text {
- color: #fff;
- font-size: 28rpx;
- }
- &.selected {
- background-color: #4CAF50;
- }
- }
- </style>
|