<template>
|
<div class="app-container">
|
<el-card class="search-card" shadow="never">
|
<el-form :model="searchForm" :inline="true">
|
<el-form-item label="质检单号:" style="width: 300px;">
|
<el-input v-model="searchForm.inspectionNo" placeholder="请输入质检单号" clearable />
|
</el-form-item>
|
<el-form-item label="质检状态:" style="width: 300px;">
|
<el-select v-model="searchForm.status" placeholder="请选择状态" clearable>
|
<el-option label="待质检" value="pending" />
|
<el-option label="质检中" value="inspecting" />
|
<el-option label="已完成" value="completed" />
|
</el-select>
|
</el-form-item>
|
<el-form-item>
|
<el-button type="primary" @click="handleSearch">搜索</el-button>
|
<el-button @click="resetSearch">重置</el-button>
|
</el-form-item>
|
</el-form>
|
</el-card>
|
|
<el-card class="table-card" shadow="never">
|
<div class="table-header">
|
<el-button type="primary" @click="openDialog('add')">新增质检单</el-button>
|
<el-button type="success" @click="handleBatchComplete">批量完成</el-button>
|
<el-button type="danger" @click="handleBatchDelete">批量删除</el-button>
|
</div>
|
|
<el-table :data="tableData" border v-loading="loading" @selection-change="handleSelectionChange">
|
<el-table-column type="selection" width="55" align="center" />
|
<el-table-column label="质检单号" prop="inspectionNo" width="180" />
|
<el-table-column label="到货单号" prop="arrivalNo" width="180" />
|
<el-table-column label="供应商名称" prop="supplierName" />
|
<el-table-column label="质检状态" prop="status" width="100">
|
<template #default="{ row }">
|
<el-tag :type="getStatusType(row.status)">{{ getStatusText(row.status) }}</el-tag>
|
</template>
|
</el-table-column>
|
<el-table-column label="合格数量" prop="qualifiedQuantity" width="100" />
|
<el-table-column label="不合格数量" prop="unqualifiedQuantity" width="100" />
|
<el-table-column label="质检时间" prop="inspectionTime" width="180" />
|
<el-table-column label="操作" width="200" align="center">
|
<template #default="{ row }">
|
<el-button type="primary" link @click="openDialog('edit', row)">编辑</el-button>
|
<el-button type="success" link @click="handleComplete(row)" v-if="row.status !== 'completed'">完成</el-button>
|
<el-button type="danger" link @click="handleDelete(row)">删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
</el-card>
|
|
<el-dialog v-model="dialogVisible" :title="dialogType === 'add' ? '新增质检单' : '编辑质检单'" width="1000px">
|
<el-form :model="formData" label-width="120px">
|
<el-row :gutter="20">
|
<el-col :span="12">
|
<el-form-item label="到货单号">
|
<el-select v-model="formData.arrivalNo" placeholder="请选择到货单" style="width: 100%">
|
<el-option label="AR20241201001" value="AR20241201001" />
|
<el-option label="AR20241201002" value="AR20241201002" />
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="供应商名称">
|
<el-input v-model="formData.supplierName" placeholder="供应商名称" readonly />
|
</el-form-item>
|
</el-col>
|
</el-row>
|
|
<el-form-item label="质检商品">
|
<div class="product-list" style="width: 100%;">
|
<el-table :data="formData.products" border width="100%">
|
<el-table-column label="商品名称" width="150">
|
<template #default="{ row }">
|
<el-input v-model="row.productName" placeholder="请输入商品名称" />
|
</template>
|
</el-table-column>
|
<el-table-column label="规格型号" width="150">
|
<template #default="{ row }">
|
<el-input v-model="row.specification" placeholder="请输入规格型号" />
|
</template>
|
</el-table-column>
|
<el-table-column label="到货数量" width="150">
|
<template #default="{ row }">
|
<el-input-number v-model="row.arrivalQuantity" :min="0" placeholder="数量" style="width: 100%;"/>
|
</template>
|
</el-table-column>
|
<el-table-column label="合格数量" width="150">
|
<template #default="{ row }">
|
<el-input-number v-model="row.qualifiedQuantity" :min="0" placeholder="数量" style="width: 100%;"/>
|
</template>
|
</el-table-column>
|
<el-table-column label="不合格数量" width="150">
|
<template #default="{ row }">
|
<el-input-number v-model="row.unqualifiedQuantity" :min="0" placeholder="数量" style="width: 100%;"/>
|
</template>
|
</el-table-column>
|
<el-table-column label="不合格原因" width="200">
|
<template #default="{ row }">
|
<el-input v-model="row.unqualifiedReason" placeholder="请输入不合格原因" />
|
</template>
|
</el-table-column>
|
<el-table-column label="操作" width="100">
|
<template #default="{ $index }">
|
<el-button type="danger" link @click="removeProduct($index)">删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
<div class="add-product-btn">
|
<el-button type="primary" @click="addProduct">添加商品</el-button>
|
</div>
|
</div>
|
</el-form-item>
|
|
<el-form-item label="质检员">
|
<el-input v-model="formData.inspector" placeholder="请输入质检员姓名" />
|
</el-form-item>
|
|
<el-form-item label="备注">
|
<el-input v-model="formData.remark" type="textarea" :rows="3" placeholder="请输入备注信息" />
|
</el-form-item>
|
</el-form>
|
<template #footer>
|
<el-button @click="dialogVisible = false">取消</el-button>
|
<el-button type="primary" @click="handleSubmit">确定</el-button>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script setup>
|
import { ref, reactive } from 'vue'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
const loading = ref(false)
|
const dialogVisible = ref(false)
|
const dialogType = ref('add')
|
const selectedRows = ref([])
|
|
const searchForm = reactive({
|
inspectionNo: '',
|
status: ''
|
})
|
|
const formData = reactive({
|
arrivalNo: '',
|
supplierName: '',
|
products: [],
|
inspector: '',
|
remark: ''
|
})
|
|
const mockData = [
|
{
|
id: 1,
|
inspectionNo: 'QI20241201001',
|
arrivalNo: 'AR20241201001',
|
supplierName: '供应商A',
|
status: 'completed',
|
qualifiedQuantity: 240,
|
unqualifiedQuantity: 10,
|
inspectionTime: '2024-12-01 16:30:00',
|
inspector: '张三',
|
remark: '质检完成'
|
}
|
]
|
|
const tableData = ref([...mockData])
|
|
const getStatusType = (status) => {
|
const statusMap = { pending: 'info', inspecting: 'warning', completed: 'success' }
|
return statusMap[status] || 'info'
|
}
|
|
const getStatusText = (status) => {
|
const statusMap = { pending: '待质检', inspecting: '质检中', completed: '已完成' }
|
return statusMap[status] || '未知'
|
}
|
|
const handleSearch = () => {
|
loading.value = true
|
setTimeout(() => { loading.value = false }, 500)
|
}
|
|
const resetSearch = () => {
|
Object.assign(searchForm, { inspectionNo: '', status: '' })
|
}
|
|
const openDialog = (type, row = {}) => {
|
dialogType.value = type
|
if (type === 'edit' && row.id) {
|
Object.assign(formData, {
|
arrivalNo: row.arrivalNo,
|
supplierName: row.supplierName,
|
inspector: row.inspector,
|
remark: row.remark
|
})
|
} else {
|
Object.assign(formData, {
|
arrivalNo: '',
|
supplierName: '',
|
products: [],
|
inspector: '',
|
remark: ''
|
})
|
}
|
dialogVisible.value = true
|
}
|
|
const handleSubmit = () => {
|
if (dialogType.value === 'add') {
|
const newInspection = {
|
id: Date.now(),
|
inspectionNo: `QI${Date.now()}`,
|
arrivalNo: formData.arrivalNo,
|
supplierName: formData.supplierName,
|
status: 'pending',
|
qualifiedQuantity: 0,
|
unqualifiedQuantity: 0,
|
inspectionTime: new Date().toLocaleString(),
|
inspector: formData.inspector,
|
remark: formData.remark
|
}
|
tableData.value.unshift(newInspection)
|
ElMessage.success('新增成功')
|
}
|
dialogVisible.value = false
|
}
|
|
const handleComplete = (row) => {
|
row.status = 'completed'
|
ElMessage.success('质检完成')
|
}
|
|
const handleDelete = (row) => {
|
ElMessageBox.confirm('确定要删除这条记录吗?', '提示', {
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
type: 'warning'
|
}).then(() => {
|
const index = tableData.value.findIndex(item => item.id === row.id)
|
if (index !== -1) {
|
tableData.value.splice(index, 1)
|
ElMessage.success('删除成功')
|
}
|
})
|
}
|
|
const handleBatchComplete = () => {
|
ElMessage.success('批量完成成功')
|
}
|
|
const handleBatchDelete = () => {
|
ElMessage.success('批量删除成功')
|
}
|
|
const handleSelectionChange = (rows) => {
|
selectedRows.value = rows
|
}
|
|
const addProduct = () => {
|
formData.products.push({
|
productName: '',
|
specification: '',
|
arrivalQuantity: 0,
|
qualifiedQuantity: 0,
|
unqualifiedQuantity: 0,
|
unqualifiedReason: ''
|
})
|
}
|
|
const removeProduct = (index) => {
|
formData.products.splice(index, 1)
|
}
|
</script>
|
|
<style scoped>
|
.app-container { padding: 20px; }
|
.search-card { margin-bottom: 20px; }
|
.table-card { margin-bottom: 20px; }
|
.table-header { margin-bottom: 20px; }
|
.product-list { border: 1px solid #dcdfe6; border-radius: 4px; padding: 15px; }
|
.product-item { margin-bottom: 15px; padding: 10px; background-color: #f5f7fa; border-radius: 4px; }
|
.add-product-btn { margin-top: 15px; text-align: center; }
|
</style>
|