完善采购入库单,一物一码设备扫码功能
parent
1984f0faa6
commit
ec1b0a80f5
|
|
@ -224,6 +224,7 @@ export enum DICT_TYPE {
|
||||||
ERP_PRODUCT_COMMON_PROPERTIES = 'erp_product_common_properties', // 产品普通属性
|
ERP_PRODUCT_COMMON_PROPERTIES = 'erp_product_common_properties', // 产品普通属性
|
||||||
ERP_PRODUCT_INPUT_PROPERTIES = 'erp_product_input_properties', // 产品输入属性
|
ERP_PRODUCT_INPUT_PROPERTIES = 'erp_product_input_properties', // 产品输入属性
|
||||||
ERP_PRODUCT_BRAND = 'erp_product_brand', // 产品品牌
|
ERP_PRODUCT_BRAND = 'erp_product_brand', // 产品品牌
|
||||||
|
ERP_PRODUCT_QR_MATCH='erp_product_qr_match', // 产品二维码匹配方式
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,43 @@
|
||||||
import { toNumber } from 'lodash-es'
|
import { toNumber } from 'lodash-es'
|
||||||
|
import { getStrDictOptions, DICT_TYPE } from '@/utils/dict'
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从字典获取规则
|
||||||
|
*/
|
||||||
|
export const matchRulesFromDictOptions = (s : string) => {
|
||||||
|
// 从字典获取规则
|
||||||
|
const dictOptions = getStrDictOptions(DICT_TYPE.ERP_PRODUCT_QR_MATCH)
|
||||||
|
//获取长度相关
|
||||||
|
const longMatch = dictOptions.filter((item) => {
|
||||||
|
return item.value === 'long'
|
||||||
|
})
|
||||||
|
const longMatchValue = longMatch[0].label
|
||||||
|
//将长度拼接字符串转换为数组
|
||||||
|
const longMatchArr = longMatchValue.split(',')
|
||||||
|
//判断数组中元素是否包含传入的字符串长度
|
||||||
|
const longMatchResult = longMatchArr.some((item) => {
|
||||||
|
return item === s.length.toString()
|
||||||
|
})
|
||||||
|
if (!longMatchResult) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
//获取头部正则相关
|
||||||
|
const headMatch = dictOptions.filter((item) => {
|
||||||
|
return item.value === 'head'
|
||||||
|
})
|
||||||
|
const headMatchValue = headMatch[0].label
|
||||||
|
//将头部正则拼接字符串转换为数组
|
||||||
|
const headMatchArr = headMatchValue.split(',')
|
||||||
|
//判断数组中元素是否包含传入的字符串头部
|
||||||
|
const headMatchResult = headMatchArr.some((item) => {
|
||||||
|
return s.startsWith(item)
|
||||||
|
})
|
||||||
|
if (!headMatchResult) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -286,6 +286,19 @@ const submitForm = async () => {
|
||||||
// 校验表单
|
// 校验表单
|
||||||
await formRef.value.validate()
|
await formRef.value.validate()
|
||||||
await itemFormRef.value.validate()
|
await itemFormRef.value.validate()
|
||||||
|
//校验每行的码的数量和入库数量是否一致
|
||||||
|
const items = formData.value.items
|
||||||
|
for (let i = 0; i < items.length; i++) {
|
||||||
|
const item = items[i]
|
||||||
|
//先判断本行是否需要一物一码
|
||||||
|
if (item.ifQr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (item.qrCodeLineCount !== item.count) {
|
||||||
|
message.error(`第 ${i + 1} 行的入库数量和码的数量不同`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
// 提交请求
|
// 提交请求
|
||||||
formLoading.value = true
|
formLoading.value = true
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
<el-form
|
<el-form
|
||||||
ref="formRef"
|
ref="formRef"
|
||||||
:model="formData"
|
:model="formData"
|
||||||
|
|
@ -87,27 +89,29 @@
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
|
||||||
<el-table-column
|
<el-table-column
|
||||||
label="原数量"
|
label="已入库/原数量"
|
||||||
fixed="right"
|
fixed="right"
|
||||||
min-width="80"
|
min-width="120"
|
||||||
v-if="formData[0]?.totalCount != null"
|
v-if="formData[0]?.totalCount != null"
|
||||||
>
|
>
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-form-item class="mb-0px!">
|
<el-form-item class="mb-0px!">
|
||||||
<el-input disabled v-model="row.totalCount" :formatter="erpCountInputFormatter" />
|
<el-input disabled :value="`${row.inCount}/${row.totalCount}`" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column
|
<el-table-column
|
||||||
label="已入库"
|
label="码"
|
||||||
fixed="right"
|
fixed="right"
|
||||||
min-width="80"
|
min-width="40"
|
||||||
v-if="formData[0]?.inCount != null"
|
|
||||||
>
|
>
|
||||||
<template #default="{ row }">
|
<template #default="{ row , $index}">
|
||||||
<el-form-item class="mb-0px!">
|
<el-form-item class="mb-0px!">
|
||||||
<el-input disabled v-model="row.inCount" :formatter="erpCountInputFormatter" />
|
<el-button :disabled="row.ifQr" @click="openQrDialog($index)" link>
|
||||||
|
<Icon icon="fa:qrcode" />
|
||||||
|
</el-button>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
|
@ -187,22 +191,48 @@
|
||||||
<el-table-column align="center" fixed="right" label="操作" width="60">
|
<el-table-column align="center" fixed="right" label="操作" width="60">
|
||||||
<template #default="{ $index }">
|
<template #default="{ $index }">
|
||||||
<el-button :disabled="formData.length === 1" @click="handleDelete($index)" link>
|
<el-button :disabled="formData.length === 1" @click="handleDelete($index)" link>
|
||||||
—
|
<span v-show="formData.length > 1 && !disabled" style="color: red;">—</span>
|
||||||
|
<span v-show="formData.length === 1 || disabled">—</span>
|
||||||
</el-button>
|
</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
</el-form>
|
</el-form>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<!-- 一物一码扫码弹窗 -->
|
||||||
|
<Dialog
|
||||||
|
:title="productName"
|
||||||
|
v-model="qrDialogVisible"
|
||||||
|
:appendToBody="true"
|
||||||
|
>
|
||||||
|
<!-- 显示有效行数 -->
|
||||||
|
<div>输入的有效行数: {{ qrCodeLineCount }}</div>
|
||||||
|
<div>需要扫描数: {{ qrNeedCount }}</div>
|
||||||
|
|
||||||
|
<el-input type="textarea" v-model="qrCodes" :rows="10" @input="onQrCodeChange" />
|
||||||
|
<template #footer>
|
||||||
|
<el-button @click="submitQr" type="primary">
|
||||||
|
确 定
|
||||||
|
</el-button>
|
||||||
|
<el-button @click="qrDialogVisible = false">取 消</el-button>
|
||||||
|
</template>
|
||||||
|
</Dialog>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { WarehouseApi as WarehouseLocactionApi ,WarehouseLocationVO} from '@/api/erp/warehouse'
|
import { WarehouseApi as WarehouseLocactionApi ,WarehouseLocationVO} from '@/api/erp/warehouse'
|
||||||
|
|
||||||
import { StockApi } from '@/api/erp/stock/stock'
|
import { StockApi } from '@/api/erp/stock/stock'
|
||||||
import {
|
import {
|
||||||
erpCountInputFormatter,
|
erpCountInputFormatter,
|
||||||
erpPriceInputFormatter,
|
erpPriceInputFormatter,
|
||||||
erpPriceMultiply,
|
erpPriceMultiply,
|
||||||
getSumValue
|
getSumValue,
|
||||||
|
matchRulesFromDictOptions
|
||||||
} from '@/utils'
|
} from '@/utils'
|
||||||
import { WarehouseApi, WarehouseVO } from '@/api/erp/stock/warehouse'
|
import { WarehouseApi, WarehouseVO } from '@/api/erp/stock/warehouse'
|
||||||
|
|
||||||
|
|
@ -210,6 +240,7 @@ const props = defineProps<{
|
||||||
items: undefined
|
items: undefined
|
||||||
disabled: false
|
disabled: false
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const formLoading = ref(false) // 表单的加载中
|
const formLoading = ref(false) // 表单的加载中
|
||||||
const formData = ref([])
|
const formData = ref([])
|
||||||
const formRules = reactive({
|
const formRules = reactive({
|
||||||
|
|
@ -222,6 +253,87 @@ const formRef = ref([]) // 表单 Ref
|
||||||
const warehouseList = ref<WarehouseVO[]>([]) // 仓库列表
|
const warehouseList = ref<WarehouseVO[]>([]) // 仓库列表
|
||||||
const locationList = ref<WarehouseLocationVO[]>([]) // 仓库列表
|
const locationList = ref<WarehouseLocationVO[]>([]) // 仓库列表
|
||||||
const defaultWarehouse = ref<WarehouseVO>(undefined) // 默认仓库
|
const defaultWarehouse = ref<WarehouseVO>(undefined) // 默认仓库
|
||||||
|
//一物一码弹窗
|
||||||
|
const qrDialogVisible = ref(false)
|
||||||
|
// 扫码内容
|
||||||
|
const qrCodes = ref('')
|
||||||
|
// 当前点击行
|
||||||
|
const currentRow = ref<typeof props.items[0]>(undefined)
|
||||||
|
// 当前行号
|
||||||
|
const currentRowIndex = ref(-1)
|
||||||
|
// 一物一码弹窗名
|
||||||
|
const productName = ref('')
|
||||||
|
// 记录二维码文本域中的有效行数
|
||||||
|
const qrCodeLineCount = ref(0);
|
||||||
|
const message = useMessage() // 消息弹窗
|
||||||
|
// 需要扫描二维码个数
|
||||||
|
const qrNeedCount = computed(() => {
|
||||||
|
return currentRow.value?.count
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// 监听二维码文本域内容的变化
|
||||||
|
const onQrCodeChange = () => {
|
||||||
|
// 检查 qrCode.value 是否为 undefined 或 null
|
||||||
|
if (qrCodes.value) {
|
||||||
|
const lines = qrCodes.value.split('\n');
|
||||||
|
// 先将每一行去除首尾空格
|
||||||
|
const trimmedLines = lines.map(line => line.trim());
|
||||||
|
const validLines = trimmedLines.filter(line =>{
|
||||||
|
return matchRulesFromDictOptions(line)
|
||||||
|
});
|
||||||
|
// 去重
|
||||||
|
const uniqueLines = [...new Set(validLines)];
|
||||||
|
qrCodeLineCount.value = uniqueLines.length;
|
||||||
|
|
||||||
|
// 检查有效行数是否超过 row.count
|
||||||
|
if (currentRow.value && qrCodeLineCount.value > currentRow.value.count) {
|
||||||
|
message.warning('输入的有效行数不能超过该产品的数量!');
|
||||||
|
// 截取多余的行数
|
||||||
|
qrCodes.value = validLines.slice(0, currentRow.value.count).join('\n');
|
||||||
|
qrCodeLineCount.value = currentRow.value.count;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qrCodeLineCount.value = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 控制一物一码弹窗
|
||||||
|
const openQrDialog = (index:number) => {
|
||||||
|
// 确保 currentRow 更新为当前点击的行
|
||||||
|
currentRow.value = formData.value[index] ; // 使用解构赋值确保创建一个新对象
|
||||||
|
currentRowIndex.value = index;
|
||||||
|
// 检查当前行是否有二维码数据
|
||||||
|
if (currentRow.value.qrcodes) {
|
||||||
|
qrCodes.value = currentRow.value.qrcodes;
|
||||||
|
} else {
|
||||||
|
qrCodes.value = ''; // 如果没有二维码数据,清空文本域
|
||||||
|
}
|
||||||
|
// 更新弹窗标题
|
||||||
|
productName.value = currentRow.value.productName;
|
||||||
|
// 重新计算有效行数
|
||||||
|
onQrCodeChange();
|
||||||
|
// 显示弹窗
|
||||||
|
qrDialogVisible.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 提交扫码 */
|
||||||
|
const submitQr = async () => {
|
||||||
|
// 扫码内容不能为空
|
||||||
|
if (qrCodes.value == null || qrCodes.value == undefined || qrCodes.value === '') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 找到当前行在 formData 中的索引
|
||||||
|
const index = currentRowIndex.value; // 获取当前行的索引
|
||||||
|
if (index !== -1 && formData.value[index]) { // 确保索引有效且对应行存在
|
||||||
|
// 更新 formData 中对应行的 qrcode 值
|
||||||
|
formData.value[index].qrcodes = qrCodes.value;
|
||||||
|
//更新有效行数
|
||||||
|
formData.value[index].qrCodeLineCount = qrCodeLineCount.value;
|
||||||
|
}
|
||||||
|
// 关闭弹窗
|
||||||
|
qrDialogVisible.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
/** 初始化设置入库项 */
|
/** 初始化设置入库项 */
|
||||||
watch(
|
watch(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue