|
|
@@ -8,6 +8,7 @@ import {
|
|
|
import {computed, nextTick, reactive, ref} from 'vue'
|
|
|
import type {FormInstance} from 'element-plus'
|
|
|
import {ElMessage} from 'element-plus'
|
|
|
+import {ElMessageBox} from 'element-plus'
|
|
|
|
|
|
const outerVisible = ref(false)
|
|
|
|
|
|
@@ -106,9 +107,8 @@ const submitItems = async () => {
|
|
|
ElMessage.warning('暂无数据可提交')
|
|
|
return
|
|
|
}
|
|
|
- console.log("=========",data)
|
|
|
const rest = JSON.parse(JSON.stringify(data.snItems))
|
|
|
-
|
|
|
+ console.log("提交=========",rest)
|
|
|
switch (data.title) {
|
|
|
case '维修':
|
|
|
const repairResult: any = await validation_repair(rest)
|
|
|
@@ -153,6 +153,7 @@ const submitForm = (event?: Event) => {
|
|
|
}
|
|
|
submitFormRef.value?.validate(async (valid: boolean) => {
|
|
|
if (valid) {
|
|
|
+ console.log("=====",data.fromData)
|
|
|
const extractedSN = extractSN(data.fromData.T_sn)
|
|
|
if (data.snItems.some((item: any) => item.T_sn === extractedSN)) {
|
|
|
data.fromData.T_sn = ''
|
|
|
@@ -166,8 +167,12 @@ const submitForm = (event?: Event) => {
|
|
|
return
|
|
|
}
|
|
|
// 1-已出库 2-待使用(已入库) 3-维修中 4-已报废
|
|
|
+ let obj:any = {LendUser:'',T_project:''}
|
|
|
if (data.title == '归还' ) {
|
|
|
const result: any = await readValidation({sn: extractedSN})
|
|
|
+ let {LendUser,T_project} = result.Data
|
|
|
+ obj.LendUser = LendUser
|
|
|
+ obj.T_project = T_project
|
|
|
if (result.Code !== 200) {
|
|
|
data.fromData.T_sn = ''
|
|
|
ElMessage.warning('查询SN失败!')
|
|
|
@@ -190,7 +195,7 @@ const submitForm = (event?: Event) => {
|
|
|
}
|
|
|
}
|
|
|
data.fromData.T_sn = ''
|
|
|
- data.snItems.unshift({...data.fromData, T_sn: extractedSN})
|
|
|
+ data.snItems.unshift({...data.fromData, T_sn: extractedSN,...obj})
|
|
|
ElMessage.success('已添加到待提交列表')
|
|
|
if ('speechSynthesis' in window) {
|
|
|
const utterance = new SpeechSynthesisUtterance('添加成功')
|
|
|
@@ -207,8 +212,123 @@ const submitForm = (event?: Event) => {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// ------------- 维修结束
|
|
|
|
|
|
+const showBatchInputDialog = ref(false)
|
|
|
+const batchSNText = ref('')
|
|
|
+const openBatchInputDialog = () => {
|
|
|
+ showBatchInputDialog.value = true
|
|
|
+ batchSNText.value = ''
|
|
|
+}
|
|
|
+/**
|
|
|
+ * 提交批量录入的SN
|
|
|
+ */
|
|
|
+const submitBatchSN = async () => {
|
|
|
+ if (!batchSNText.value.trim()) {
|
|
|
+ ElMessage.warning('请输入SN数据')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const processedSNs = processBatchSN(batchSNText.value)
|
|
|
+ if (processedSNs.length === 0) {
|
|
|
+ ElMessage.warning('没有有效的SN数据')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let successCount:number = 0
|
|
|
+ let failCount = 0
|
|
|
+ const failMessages: string[] = []
|
|
|
+ for (const sn of processedSNs) {
|
|
|
+ try{
|
|
|
+ // 检查是否已存在
|
|
|
+ if (data.snItems.some((item: any) => item.T_sn === sn)) {
|
|
|
+ failCount++
|
|
|
+ failMessages.push(`SN ${sn} 已存在`)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ // 检查SN状态
|
|
|
+ const result: any = await readValidation({sn: sn})
|
|
|
+ if (result.Code !== 200) {
|
|
|
+ failCount++
|
|
|
+ failMessages.push(`SN ${sn} 未出库不能归还`)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if (result.Data.T_state == 5) {
|
|
|
+ failCount++
|
|
|
+ failMessages.push(`SN ${sn} 设备已损坏`)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if (result.Data.T_state != 1) {
|
|
|
+ failCount++
|
|
|
+ failMessages.push(`SN ${sn} 未出库不能归还`)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ console.log('result',result)
|
|
|
+ // 添加到待提交列表
|
|
|
+ data.snItems.unshift({
|
|
|
+ T_sn: sn,
|
|
|
+ T_remark: result.Data.T_remark,
|
|
|
+ LendUser: result.Data.LendUser,
|
|
|
+ T_project: result.Data.T_project
|
|
|
+ })
|
|
|
+ successCount++
|
|
|
+ }catch (error: any) {
|
|
|
+ failCount++
|
|
|
+ const errorMsg = error?.message || error?.toString() || '未知错误'
|
|
|
+ failMessages.push(`SN ${sn} 处理失败: ${errorMsg}`)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 显示处理结果
|
|
|
+ if (successCount > 0) {
|
|
|
+ ElMessage.success(`成功添加 ${successCount} 条SN数据`)
|
|
|
+ if ('speechSynthesis' in window) {
|
|
|
+ const utterance = new SpeechSynthesisUtterance(`成功添加${successCount}条数据`)
|
|
|
+ window.speechSynthesis.speak(utterance)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (failCount > 0) {
|
|
|
+ // 显示详细的失败原因
|
|
|
+ const failMessageHTML = `<div style="margin-top: 10px;">
|
|
|
+ <p style="margin-bottom: 15px; font-weight: 500; color: #303133;">有 ${failCount} 条SN数据处理失败,具体原因如下:</p>
|
|
|
+ <div style="max-height: 400px; overflow-y: auto; padding-right: 5px;">
|
|
|
+ ${failMessages.map((msg, index) => `<div style="padding: 10px 0; border-bottom: 1px solid #ebeef5; line-height: 1.8;">
|
|
|
+ <span style="color: #909399; margin-right: 10px; font-weight: 500;">${index + 1}.</span>
|
|
|
+ <span style="color: #606266;">${msg}</span>
|
|
|
+ </div>`).join('')}
|
|
|
+ </div>
|
|
|
+ </div>`
|
|
|
+ ElMessageBox.alert(
|
|
|
+ failMessageHTML,
|
|
|
+ '批量录入失败详情',
|
|
|
+ {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ type: 'warning',
|
|
|
+ dangerouslyUseHTMLString: true
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关闭对话框并清空输入
|
|
|
+ showBatchInputDialog.value = false
|
|
|
+ batchSNText.value = ''
|
|
|
+ console.log(data.snItems)
|
|
|
+}
|
|
|
+/**
|
|
|
+ * 批量处理SN数据
|
|
|
+ * 去除前2个字符(03)和后6个字符(000001)
|
|
|
+ */
|
|
|
+const processBatchSN = (text: string): string[] => {
|
|
|
+ const lines = text.split('\n').map(line => line.trim()).filter(line => line.length > 0)
|
|
|
+ return lines.map(line => {
|
|
|
+ // 只有当前缀为03且后缀为000001时才截取中间值
|
|
|
+ if (line.startsWith('03') && line.endsWith('000001') && line.length > 8) {
|
|
|
+ return line.substring(2, line.length - 6).trim()
|
|
|
+ }
|
|
|
+ return line.trim()
|
|
|
+ }).filter(sn => sn.length > 0)
|
|
|
+}
|
|
|
const emit = defineEmits<{ (event: 'successFun', value:boolean): void }>()
|
|
|
|
|
|
defineExpose({
|
|
|
@@ -228,7 +348,11 @@ defineExpose({
|
|
|
@keyup.enter.prevent="submitForm"
|
|
|
@keydown.enter.prevent
|
|
|
@input="handleSNInput"
|
|
|
- ></el-input>
|
|
|
+ >
|
|
|
+ <template #append>
|
|
|
+ <el-button type="primary" @click="openBatchInputDialog()">批量录入</el-button>
|
|
|
+ </template>
|
|
|
+ </el-input>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="备注">
|
|
|
<el-input v-model="data.fromData.T_remark" type="textarea" placeholder="请输入备注"></el-input>
|
|
|
@@ -242,6 +366,8 @@ defineExpose({
|
|
|
<el-table-column type="index" label="序号" width="80"></el-table-column>
|
|
|
<!-- 添加序号列 -->
|
|
|
<el-table-column prop="T_sn" label="SN"></el-table-column>
|
|
|
+ <el-table-column v-if="data.title=='归还'" prop="LendUser" :label="data.title + '人'"></el-table-column>
|
|
|
+ <el-table-column v-if="data.title=='归还'" prop="T_project" :label="data.title + '项目'"></el-table-column>
|
|
|
<el-table-column prop="T_remark" label="备注"></el-table-column>
|
|
|
<el-table-column label="操作" width="180">
|
|
|
<template #default="scope">
|
|
|
@@ -259,13 +385,33 @@ defineExpose({
|
|
|
style="margin-top: 20px; text-align: right"
|
|
|
/>
|
|
|
<template #footer>
|
|
|
- <span class="dialog-footer">
|
|
|
- <el-button @click="outerVisible = false">取消</el-button>
|
|
|
- <el-button type="primary" @click="submitForm">添加到暂存</el-button>
|
|
|
- <!-- 新增提交按钮 -->
|
|
|
- <el-button type="primary" @click="submitItems">提交</el-button>
|
|
|
- </span>
|
|
|
+ <span class="dialog-footer">
|
|
|
+ <el-button @click="outerVisible = false">取消</el-button>
|
|
|
+ <el-button type="primary" @click="submitForm">添加到暂存</el-button>
|
|
|
+ <!-- 新增提交按钮 -->
|
|
|
+ <el-button type="primary" @click="submitItems">提交</el-button>
|
|
|
+ </span>
|
|
|
</template>
|
|
|
+ <!-- 批量录入SN对话框 -->
|
|
|
+ <el-dialog title="批量录入SN" v-model="showBatchInputDialog" width="60%">
|
|
|
+ <div style="margin-bottom: 10px;">
|
|
|
+ <p style="color: #909399; font-size: 12px;">
|
|
|
+ 提示:每行输入一个SN,系统会自动去除前2个字符(03)和后6个字符(000001)
|
|
|
+ </p>
|
|
|
+ </div>
|
|
|
+ <el-input
|
|
|
+ v-model="batchSNText"
|
|
|
+ type="textarea"
|
|
|
+ :rows="10"
|
|
|
+ placeholder="请输入SN数据,每行一个,例如: 032025138451413256000001 032025144612387706000001"
|
|
|
+ />
|
|
|
+ <template #footer>
|
|
|
+ <span class="dialog-footer">
|
|
|
+ <el-button @click="showBatchInputDialog = false">取消</el-button>
|
|
|
+ <el-button type="primary" @click="submitBatchSN">确认添加</el-button>
|
|
|
+ </span>
|
|
|
+ </template>
|
|
|
+ </el-dialog>
|
|
|
</el-dialog>
|
|
|
</div>
|
|
|
</template>
|