You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
228 lines
7.0 KiB
Vue
228 lines
7.0 KiB
Vue
<template>
|
|
<Dialog v-model="dialogVisible" :title="dialogTitle" width="1500px">
|
|
<el-table
|
|
v-loading="loading"
|
|
:data="list"
|
|
:stripe="true"
|
|
:show-overflow-tooltip="true"
|
|
:row-key="getRowKey"
|
|
>
|
|
<el-table-column type="index" label="序号" align="center" width="60" />
|
|
<el-table-column label="名称" align="center" prop="name" min-width="160" />
|
|
<el-table-column label="作业方式" align="center" prop="tool" min-width="120" />
|
|
<el-table-column label="标准值" align="center" prop="standardVal" min-width="100" />
|
|
<el-table-column label="单位" align="center" prop="unitName" min-width="80" />
|
|
<el-table-column label="上限值" align="center" prop="upperVal" min-width="100" />
|
|
<el-table-column label="下限值" align="center" prop="lowerVal" min-width="100" />
|
|
<el-table-column label="图片" align="center" prop="images" width="160">
|
|
<template #default="scope">
|
|
<UploadImg
|
|
v-if="String(scope.row.zjResult) === '0'"
|
|
v-model="imageMap[String(scope.row.id)]"
|
|
:drag="false"
|
|
:show-btn-text="false"
|
|
width="64px"
|
|
height="64px"
|
|
/>
|
|
<el-image
|
|
v-else-if="scope.row.images"
|
|
:src="parseFirstImage(scope.row.images)"
|
|
:preview-src-list="parseImages(scope.row.images)"
|
|
preview-teleported
|
|
fit="cover"
|
|
style="width: 64px; height: 64px"
|
|
/>
|
|
<span v-else>-</span>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column label="备注" align="center" prop="remark" min-width="160" />
|
|
<el-table-column label="检验结果" align="center" prop="zjResult" width="120">
|
|
<template #default="scope">
|
|
<el-tag v-if="String(scope.row.zjResult) === '0'" type="info">待检测</el-tag>
|
|
<el-tag v-else-if="String(scope.row.zjResult) === '1'" type="success">通过</el-tag>
|
|
<el-tag v-else-if="String(scope.row.zjResult) === '2'" type="danger">不通过</el-tag>
|
|
<span v-else>-</span>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column label="操作" align="center" width="200" fixed="right">
|
|
<template #default="scope">
|
|
<el-radio-group
|
|
v-if="String(scope.row.zjResult) === '0'"
|
|
v-model="decisionMap[String(scope.row.id)]"
|
|
>
|
|
<el-radio :label="1">通过</el-radio>
|
|
<el-radio :label="2">不通过</el-radio>
|
|
</el-radio-group>
|
|
<span v-else>-</span>
|
|
</template>
|
|
</el-table-column>
|
|
</el-table>
|
|
|
|
<el-pagination
|
|
v-show="total > 0"
|
|
v-model:current-page="queryParams.pageNo"
|
|
v-model:page-size="queryParams.pageSize"
|
|
:background="true"
|
|
:page-sizes="[10, 20, 30, 50, 100]"
|
|
:pager-count="7"
|
|
:total="total"
|
|
class="mt-15px mb-15px flex justify-end"
|
|
layout="total, sizes, prev, pager, next, jumper"
|
|
@size-change="handleSizeChange"
|
|
@current-change="handleCurrentChange"
|
|
/>
|
|
|
|
<template #footer>
|
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
|
<el-button
|
|
type="primary"
|
|
@click="handleSave"
|
|
:loading="submitLoading"
|
|
:disabled="submitLoading || !isAllSelected()"
|
|
>
|
|
保 存
|
|
</el-button>
|
|
</template>
|
|
</Dialog>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import type { ZjTaskResultVO } from '@/api/mes/zjtask'
|
|
import { ZjTaskApi } from '@/api/mes/zjtask'
|
|
|
|
defineOptions({ name: 'ZjTaskResultDialog' })
|
|
|
|
const dialogVisible = ref(false)
|
|
const dialogTitle = ref('检验结果')
|
|
const loading = ref(false)
|
|
const submitLoading = ref(false)
|
|
|
|
const emit = defineEmits(['success'])
|
|
const message = useMessage()
|
|
|
|
const list = ref<ZjTaskResultVO[]>([])
|
|
const total = ref(0)
|
|
const taskId = ref<number | undefined>(undefined)
|
|
const decisionMap = reactive<Record<string, number | undefined>>({})
|
|
const imageMap = reactive<Record<string, string>>({})
|
|
|
|
const queryParams = reactive({
|
|
pageNo: 1,
|
|
pageSize: 10,
|
|
})
|
|
|
|
const open = async (id: number) => {
|
|
dialogVisible.value = true
|
|
dialogTitle.value = '检验结果'
|
|
taskId.value = id
|
|
for (const key of Object.keys(decisionMap)) delete decisionMap[key]
|
|
for (const key of Object.keys(imageMap)) delete imageMap[key]
|
|
queryParams.pageNo = 1
|
|
await getList()
|
|
}
|
|
|
|
defineExpose({ open })
|
|
|
|
const getList = async () => {
|
|
if (!taskId.value) return
|
|
loading.value = true
|
|
try {
|
|
const data = await ZjTaskApi.getZjTaskResultPage({
|
|
pageNo: queryParams.pageNo,
|
|
pageSize: queryParams.pageSize,
|
|
taskId: taskId.value,
|
|
})
|
|
list.value = data.list
|
|
total.value = data.total
|
|
for (const row of list.value) {
|
|
const id = row?.id
|
|
if (!id) continue
|
|
if (row.images && !imageMap[String(id)]) {
|
|
imageMap[String(id)] = parseFirstImage(row.images)
|
|
}
|
|
if (row.zjResult !== undefined && row.zjResult !== null && !decisionMap[String(id)]) {
|
|
decisionMap[String(id)] = Number(row.zjResult)
|
|
}
|
|
}
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
const handleSizeChange = () => {
|
|
queryParams.pageNo = 1
|
|
getList()
|
|
}
|
|
|
|
const handleCurrentChange = () => {
|
|
getList()
|
|
}
|
|
|
|
const getRowKey = (row: ZjTaskResultVO) => {
|
|
return String(row.id ?? '')
|
|
}
|
|
|
|
const handleSave = async () => {
|
|
if (!taskId.value) {
|
|
message.error('任务标识不存在,无法保存')
|
|
return
|
|
}
|
|
const currentTaskId = taskId.value
|
|
const hasUnselected = list.value.some((row) => {
|
|
if (!row?.id) return false
|
|
const decision = decisionMap[String(row.id)]
|
|
return decision !== 1 && decision !== 2
|
|
})
|
|
if (hasUnselected) {
|
|
message.error('请先为所有记录选择通过或不通过')
|
|
return
|
|
}
|
|
const payload: { id: number; taskId: number; images?: string; zjResult: number }[] = []
|
|
for (const row of list.value) {
|
|
if (!row?.id) continue
|
|
const decision = decisionMap[String(row.id)]
|
|
if (decision !== 1 && decision !== 2) continue
|
|
const img = imageMap[String(row.id)] || row.images
|
|
payload.push({ id: row.id, taskId: currentTaskId, images: img, zjResult: decision })
|
|
}
|
|
if (!payload.length) {
|
|
message.error('暂无需要保存的记录')
|
|
return
|
|
}
|
|
submitLoading.value = true
|
|
try {
|
|
await ZjTaskApi.batchUpdateZjTaskResults(payload)
|
|
message.success('更新成功')
|
|
emit('success')
|
|
dialogVisible.value = false
|
|
} catch {
|
|
message.error('更新失败')
|
|
} finally {
|
|
submitLoading.value = false
|
|
}
|
|
}
|
|
|
|
const parseImages = (value: any): string[] => {
|
|
if (!value) return []
|
|
if (Array.isArray(value)) return value.map(String).filter(Boolean)
|
|
return String(value)
|
|
.split(',')
|
|
.map((v) => v.trim())
|
|
.filter(Boolean)
|
|
}
|
|
|
|
const parseFirstImage = (value: any): string => {
|
|
return parseImages(value)[0] || ''
|
|
}
|
|
|
|
const isAllSelected = () => {
|
|
if (!list.value.length) return false
|
|
for (const row of list.value) {
|
|
if (!row?.id) continue
|
|
const decision = decisionMap[String(row.id)]
|
|
if (decision !== 1 && decision !== 2) return false
|
|
}
|
|
return true
|
|
}
|
|
</script>
|