|
@@ -1,11 +1,17 @@
|
|
|
<template>
|
|
<template>
|
|
|
<view class="container">
|
|
<view class="container">
|
|
|
<view class="main-content">
|
|
<view class="main-content">
|
|
|
|
|
+ <view class="input-group">
|
|
|
|
|
+ <u-input :customStyle="customStyle" :placeholder-style="placeholderStyle"
|
|
|
|
|
+ v-model="repository.repositoryName" placeholder="请选择仓库" readonly border="surround" />
|
|
|
|
|
+ <u-button :customStyle="customStyle" type="info" color="#a4adb3" @click="selectRepository"
|
|
|
|
|
+ text="选择" />
|
|
|
|
|
+ </view>
|
|
|
<view class="input-group">
|
|
<view class="input-group">
|
|
|
<u-input :customStyle="customStyle" :placeholder-style="placeholderStyle" v-model="form.isbn"
|
|
<u-input :customStyle="customStyle" :placeholder-style="placeholderStyle" v-model="form.isbn"
|
|
|
- placeholder="扫描/输入ISBN" border="surround" />
|
|
|
|
|
|
|
+ placeholder="扫描/输入ISBN" border="surround" clearable />
|
|
|
<u-button :customStyle="customStyle" type="info" color="#a4adb3" @click="handleBarcode(form.isbn)"
|
|
<u-button :customStyle="customStyle" type="info" color="#a4adb3" @click="handleBarcode(form.isbn)"
|
|
|
- text="确定" />
|
|
|
|
|
|
|
+ text="查询" />
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
|
|
|
|
@@ -19,20 +25,27 @@
|
|
|
import {
|
|
import {
|
|
|
reactive,
|
|
reactive,
|
|
|
ref,
|
|
ref,
|
|
|
|
|
+ onMounted,
|
|
|
onUnmounted
|
|
onUnmounted
|
|
|
} from 'vue';
|
|
} from 'vue';
|
|
|
import {
|
|
import {
|
|
|
- onLoad,
|
|
|
|
|
onShow
|
|
onShow
|
|
|
} from '@dcloudio/uni-app'
|
|
} from '@dcloudio/uni-app'
|
|
|
|
|
|
|
|
|
|
+const STORAGE_KEY = 'codeStorageLastRepository'
|
|
|
|
|
+
|
|
|
const placeholderStyle = "font-size:32rpx"
|
|
const placeholderStyle = "font-size:32rpx"
|
|
|
const customStyle = reactive({
|
|
const customStyle = reactive({
|
|
|
height: '90rpx'
|
|
height: '90rpx'
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+const repository = ref({
|
|
|
|
|
+ id: '',
|
|
|
|
|
+ repositoryName: ''
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
const form = ref({
|
|
const form = ref({
|
|
|
- "isbn": ""
|
|
|
|
|
|
|
+ isbn: ""
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
let barcodeLock = false
|
|
let barcodeLock = false
|
|
@@ -40,43 +53,68 @@ let lastBarcode = ''
|
|
|
let lastBarcodeAt = 0
|
|
let lastBarcodeAt = 0
|
|
|
const BARCODE_DEBOUNCE_MS = 2000
|
|
const BARCODE_DEBOUNCE_MS = 2000
|
|
|
|
|
|
|
|
|
|
+function loadLastRepository() {
|
|
|
|
|
+ const lastRepository = uni.getStorageSync(STORAGE_KEY)
|
|
|
|
|
+ if (lastRepository) {
|
|
|
|
|
+ repository.value = {
|
|
|
|
|
+ id: lastRepository.id || '',
|
|
|
|
|
+ repositoryName: lastRepository.repositoryName || ''
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function selectRepository() {
|
|
|
|
|
+ uni.navigateTo({
|
|
|
|
|
+ url: '/pages/index/wms/warehouse-select?type=repository&repositoryId=' + (repository.value.id || ''),
|
|
|
|
|
+ fail: (err) => {
|
|
|
|
|
+ console.error('跳转仓库选择页失败', err)
|
|
|
|
|
+ uni.$u.toast('打开仓库选择页失败')
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function scanCode() {
|
|
function scanCode() {
|
|
|
|
|
+ if (!repository.value.id) {
|
|
|
|
|
+ return uni.$u.toast('请先选择仓库')
|
|
|
|
|
+ }
|
|
|
uni.scanCode({
|
|
uni.scanCode({
|
|
|
success: (res) => {
|
|
success: (res) => {
|
|
|
form.value.isbn = res.result;
|
|
form.value.isbn = res.result;
|
|
|
handleBarcode(res.result)
|
|
handleBarcode(res.result)
|
|
|
},
|
|
},
|
|
|
- fail: (err) => {
|
|
|
|
|
|
|
+ fail: () => {
|
|
|
uni.$u.toast('扫码失败')
|
|
uni.$u.toast('扫码失败')
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-//isbn正则校验是否符合
|
|
|
|
|
function checkIsbn(isbn) {
|
|
function checkIsbn(isbn) {
|
|
|
const isbn13Regex = /^(?:97[89]-?\d{1,5}-?\d{1,7}-?\d{1,6}-?\d)$/;
|
|
const isbn13Regex = /^(?:97[89]-?\d{1,5}-?\d{1,7}-?\d{1,6}-?\d)$/;
|
|
|
- if (isbn13Regex.test(isbn)) {
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
- return false;
|
|
|
|
|
|
|
+ return isbn13Regex.test(isbn);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function handleBarcode(code) {
|
|
function handleBarcode(code) {
|
|
|
|
|
+ if (!repository.value.id) {
|
|
|
|
|
+ return uni.$u.toast('请先选择仓库')
|
|
|
|
|
+ }
|
|
|
if (!code) return uni.$u.toast('请输入ISBN')
|
|
if (!code) return uni.$u.toast('请输入ISBN')
|
|
|
|
|
|
|
|
const now = Date.now()
|
|
const now = Date.now()
|
|
|
if (barcodeLock) return
|
|
if (barcodeLock) return
|
|
|
if (code === lastBarcode && now - lastBarcodeAt < BARCODE_DEBOUNCE_MS) return
|
|
if (code === lastBarcode && now - lastBarcodeAt < BARCODE_DEBOUNCE_MS) return
|
|
|
|
|
|
|
|
- // 验证ISBN格式
|
|
|
|
|
if (!checkIsbn(code)) {
|
|
if (!checkIsbn(code)) {
|
|
|
return uni.$u.ttsModule.speak('不是正确的ISBN码')
|
|
return uni.$u.ttsModule.speak('不是正确的ISBN码')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
barcodeLock = true
|
|
barcodeLock = true
|
|
|
uni.$u.http.post('/activation/bookActivationInfo/queryBookBasicByIsbn/' + code).then(res => {
|
|
uni.$u.http.post('/activation/bookActivationInfo/queryBookBasicByIsbn/' + code).then(res => {
|
|
|
- if (res.code == 200) {
|
|
|
|
|
|
|
+ if (res.code == 200 && res.data) {
|
|
|
uni.setStorageSync('bookInfo', res.data)
|
|
uni.setStorageSync('bookInfo', res.data)
|
|
|
|
|
+ uni.setStorageSync('codeStorageCurrentRepository', {
|
|
|
|
|
+ id: repository.value.id,
|
|
|
|
|
+ repositoryName: repository.value.repositoryName
|
|
|
|
|
+ })
|
|
|
uni.navigateTo({
|
|
uni.navigateTo({
|
|
|
url: '/pages/index/wms/code-storage-add?isbn=' + encodeURIComponent(code)
|
|
url: '/pages/index/wms/code-storage-add?isbn=' + encodeURIComponent(code)
|
|
|
})
|
|
})
|
|
@@ -84,13 +122,32 @@ function handleBarcode(code) {
|
|
|
lastBarcode = code
|
|
lastBarcode = code
|
|
|
lastBarcodeAt = Date.now()
|
|
lastBarcodeAt = Date.now()
|
|
|
} else {
|
|
} else {
|
|
|
- uni.$u.toast('未找到该书籍')
|
|
|
|
|
|
|
+ uni.$u.toast(res.msg)
|
|
|
|
|
+ uni.$u.ttsModule.speak(res.msg)
|
|
|
}
|
|
}
|
|
|
}).finally(() => {
|
|
}).finally(() => {
|
|
|
barcodeLock = false
|
|
barcodeLock = false
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+onMounted(() => {
|
|
|
|
|
+ loadLastRepository()
|
|
|
|
|
+ uni.$on('updateRepository', (data) => {
|
|
|
|
|
+ repository.value = {
|
|
|
|
|
+ id: data.id,
|
|
|
|
|
+ repositoryName: data.repositoryName
|
|
|
|
|
+ }
|
|
|
|
|
+ uni.setStorageSync(STORAGE_KEY, {
|
|
|
|
|
+ id: data.id,
|
|
|
|
|
+ repositoryName: data.repositoryName
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+onShow(() => {
|
|
|
|
|
+ loadLastRepository()
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
// #ifdef APP-PLUS
|
|
// #ifdef APP-PLUS
|
|
|
const { unregister } = uni.$u.useEventListener((e) => {
|
|
const { unregister } = uni.$u.useEventListener((e) => {
|
|
|
form.value.isbn = e.barcode
|
|
form.value.isbn = e.barcode
|
|
@@ -99,6 +156,7 @@ const { unregister } = uni.$u.useEventListener((e) => {
|
|
|
// #endif
|
|
// #endif
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
onUnmounted(() => {
|
|
|
|
|
+ uni.$off('updateRepository')
|
|
|
// #ifdef APP-PLUS
|
|
// #ifdef APP-PLUS
|
|
|
unregister();
|
|
unregister();
|
|
|
// #endif
|
|
// #endif
|
|
@@ -128,4 +186,4 @@ onUnmounted(() => {
|
|
|
.scan-button {
|
|
.scan-button {
|
|
|
width: 100%;
|
|
width: 100%;
|
|
|
}
|
|
}
|
|
|
-</style>
|
|
|
|
|
|
|
+</style>
|