bonus-ui/src/views/toolsManage/codeToolsLedger/index.vue

534 lines
18 KiB
Vue
Raw Normal View History

2025-11-13 17:51:15 +08:00
<template>
<!-- 基础页面 -->
<div class="app-container">
2025-11-14 16:26:33 +08:00
<el-card v-show="showSearch" style="margin-bottom: 20px">
<el-form :model="queryParams" ref="queryForm" size="small" inline @submit.native.prevent>
<el-form-item label="工具专业" prop="fourthParentId">
<el-select
v-model="queryParams.fourthParentId"
placeholder="请选择工具专业"
clearable
filterable
@change="(val) => changeType(val, '2')"
style="width: 240px"
>
<el-option v-for="item in fourthParentList" :key="item.id" :label="item.label" :value="item.id" />
</el-select>
</el-form-item>
<el-form-item label="施工类型" prop="greatGrandparentId">
<el-select
v-model="queryParams.greatGrandparentId"
placeholder="请选择施工类型"
clearable
filterable
:disabled="!queryParams.fourthParentId"
@change="(val) => changeType(val, '3')"
style="width: 240px"
>
<el-option v-for="item in greatGrandparentList" :key="item.id" :label="item.label" :value="item.id" />
</el-select>
</el-form-item>
<el-form-item label="工具类型" prop="grandparentTypeId">
<el-select
v-model="queryParams.grandparentTypeId"
placeholder="请选择工具类型"
clearable
filterable
:disabled="!queryParams.greatGrandparentId"
@change="(val) => changeType(val, '4')"
style="width: 240px"
>
<el-option v-for="item in grandparentTypeList" :key="item.id" :label="item.label" :value="item.id" />
</el-select>
</el-form-item>
<el-form-item label="工具名称" prop="parentTypeId">
<el-select
v-model="queryParams.parentTypeId"
placeholder="请选择工具名称"
clearable
filterable
:disabled="!queryParams.grandparentTypeId"
style="width: 240px"
>
<el-option v-for="item in parentTypeList" :key="item.id" :label="item.label" :value="item.id" />
</el-select>
</el-form-item>
<el-form-item label="规格型号" prop="typeName">
2025-11-13 17:51:15 +08:00
<el-input
2025-11-14 16:26:33 +08:00
v-model="queryParams.typeName"
placeholder="请输入规格型号"
2025-11-13 17:51:15 +08:00
clearable
@keyup.enter.native="handleQuery"
style="width: 240px"
/>
</el-form-item>
2025-11-14 16:26:33 +08:00
<el-form-item label="工具编码" prop="toolCode">
<el-input
v-model="queryParams.toolCode"
placeholder="请输入规格型号"
2025-11-13 17:51:15 +08:00
clearable
2025-11-14 16:26:33 +08:00
@keyup.enter.native="handleQuery"
2025-11-13 17:51:15 +08:00
style="width: 240px"
/>
</el-form-item>
<!-- 表单按钮 -->
2025-11-20 18:02:34 +08:00
<el-form-item style="margin-left:1100px">
2025-11-13 17:51:15 +08:00
<el-button type="primary" icon="el-icon-search" @click="handleQuery">查询</el-button>
<el-button icon="el-icon-refresh" @click="handleReset">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
2025-11-20 18:02:34 +08:00
<div style="font-size: 20px; font-weight: 800">编码工具台账列表</div>
2025-11-13 17:51:15 +08:00
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList" />
</el-row>
2025-11-14 16:26:33 +08:00
<el-table
v-loading="isLoading"
:data="tableList"
highlight-current-row
border
stripe
:max-height="650"
style="width: 100%"
>
2025-11-13 17:51:15 +08:00
<el-table-column
type="index"
width="55"
label="序号"
align="center"
:index="(index) => (queryParams.pageNum - 1) * queryParams.pageSize + index + 1"
/>
<el-table-column
v-for="(column, index) in tableColumns"
show-overflow-tooltip
:key="index"
:label="column.label"
:prop="column.prop"
align="center"
>
2025-11-14 16:26:33 +08:00
<!-- render插槽 -->
<template v-slot="{ row }">
<component :is="column.render ? { render: (h) => column.render(h, { row }) } : 'span'">
{{ !column.render ? row[column.prop] : '' }}
</component>
2025-11-13 17:51:15 +08:00
</template>
</el-table-column>
2025-11-14 16:26:33 +08:00
<el-table-column label="操作" align="center">
2025-11-13 17:51:15 +08:00
<template slot-scope="{ row }">
2025-11-14 16:26:33 +08:00
<el-button size="mini" type="text" icon="el-icon-zoom-in" @click="handleDialog(row, true)">查看</el-button>
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleDialog(row, false)">编辑</el-button>
2025-11-13 17:51:15 +08:00
</template>
2025-11-14 16:26:33 +08:00
</el-table-column>
2025-11-13 17:51:15 +08:00
</el-table>
<!-- 分页 -->
<pagination
v-show="total > 0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
</el-card>
<!-- 弹框 -->
2025-11-14 16:26:33 +08:00
<el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="60%" v-loading="isLoading">
<el-form
ref="dialogForm"
:model="dialogForm"
label-width="110px"
size="small"
inline
@submit.native.prevent
:disabled="isView"
>
<el-form-item label="工具专业" prop="fourthParentName">
<el-input v-model="dialogForm.fourthParentName" placeholder="请输入工具专业" readonly style="width: 240px" />
2025-11-13 17:51:15 +08:00
</el-form-item>
2025-11-14 16:26:33 +08:00
<el-form-item label="施工类型" prop="greatGrandparentName">
<el-input
v-model="dialogForm.greatGrandparentName"
placeholder="请输入工具专业"
readonly
style="width: 240px"
/>
</el-form-item>
<el-form-item label="工具类型" prop="grandparentTypeName">
<el-input
v-model="dialogForm.grandparentTypeName"
placeholder="请输入工具专业"
readonly
style="width: 240px"
/>
</el-form-item>
<el-form-item label="工具名称" prop="parentTypeName">
<el-input v-model="dialogForm.parentTypeName" placeholder="请输入工具专业" readonly style="width: 240px" />
</el-form-item>
<el-form-item label="规格型号" prop="typeName">
<el-input v-model="dialogForm.typeName" placeholder="请输入工具专业" readonly style="width: 240px" />
</el-form-item>
<el-form-item label="工具编码" prop="toolCode">
<el-input v-model="dialogForm.toolCode" placeholder="请输入工具专业" readonly style="width: 240px" />
</el-form-item>
<el-form-item label="计量单位" prop="unitName">
<el-select v-model="dialogForm.unitName" placeholder="请选择计量单位" clearable style="width: 240px">
<el-option
v-for="dict in dict.type.dev_unit_type"
:key="dict.label"
:label="dict.label"
:value="dict.label"
/>
</el-select>
</el-form-item>
<!-- 厂家 -->
<el-form-item label="生产厂家">
<el-select v-model="dialogForm.supplierId" placeholder="请选择厂家" clearable style="width: 240px">
<el-option
v-for="item in manufacturerSelect"
:key="item.id"
:label="item.label"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
<!-- 出厂日期 -->
<el-form-item label="出厂日期">
<el-date-picker
v-model="dialogForm.productionDate"
type="date"
clearable
placeholder="选择出厂日期"
value-format="yyyy-MM-dd"
style="width: 240px"
/>
</el-form-item>
<el-form-item label="本次检验时间">
<el-date-picker
v-model="dialogForm.lastCheckDate"
type="date"
clearable
placeholder="选择本次检验时间"
value-format="yyyy-MM-dd"
style="width: 240px"
/>
</el-form-item>
<el-form-item label="资产原值">
<el-input-number
v-model="dialogForm.originCost"
:min="0"
:max="99999999"
:controls="false"
:precision="0"
style="width: 240px"
/>
</el-form-item>
<el-form-item label="原始编码">
<el-input v-model="dialogForm.identifyCode" maxlength="999" style="width: 240px" />
</el-form-item>
<el-form-item label="下次检验时间">
<el-date-picker
v-model="dialogForm.nextCheckDate"
type="date"
clearable
placeholder="选择下次检验时间"
value-format="yyyy-MM-dd"
style="width: 240px"
/>
</el-form-item>
<el-form-item label="工具状态">
<el-input v-model="dialogForm.identifyCode" readonly style="width: 240px" />
</el-form-item>
<div v-for="(item, index) in dialogForm.propertyVoList" :key="index">
<el-form-item label="特征项">
<el-input v-model="item.propertyName" placeholder="请输入特征项" style="width: 240px" />
</el-form-item>
<el-form-item label="特征值">
<div style="display: flex; align-items: center">
<el-input v-model="item.propertyValue" placeholder="请输入特征值" style="width: 240px" />
<i
v-if="index == dialogForm.propertyVoList.length - 1 && dialogForm.propertyVoList.length < 9 && !isView"
class="el-icon-circle-plus-outline"
@click="handleProperty('add', index)"
style="color: #67c23a; font-size: 24px; margin-left: 8px"
/>
<i
v-if="index != 0 && !isView"
class="el-icon-remove-outline"
@click="handleProperty('remove', index)"
style="color: #f56c6c; font-size: 24px; margin-left: 8px"
/>
</div>
</el-form-item>
</div>
<el-form-item label="附件" prop="fileList">
<FileUpload
v-model="dialogForm.fileList"
:value="dialogForm.fileList"
:limit="9"
:fileType="['doc', 'xls', 'pdf', 'jpg', 'jpeg', 'png']"
:isView="isView"
@input="handleImage"
/>
2025-11-13 17:51:15 +08:00
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
2025-11-14 16:26:33 +08:00
<el-button v-if="!isView" type="primary" @click="submit"> </el-button>
<el-button @click="dialogVisible = false">{{ isView ? '关 闭' : '取 消' }}</el-button>
2025-11-13 17:51:15 +08:00
</span>
</el-dialog>
</div>
</template>
<script>
2025-11-14 16:26:33 +08:00
import { getListCodeApi, getToolSelectApi, updateByIdApi } from '@/api/toolsManage'
import { getManufacturerSelectApi } from '@/api/EquipmentLedger'
import FileUpload from '@/components/FileUpload'
2025-11-13 17:51:15 +08:00
export default {
2025-11-14 16:26:33 +08:00
name: 'CodeToolsLedger',
dicts: ['dev_unit_type'],
components: { FileUpload },
2025-11-13 17:51:15 +08:00
data() {
return {
isLoading: false,
showSearch: true,
queryParams: {
pageNum: 1,
pageSize: 10,
2025-11-14 16:26:33 +08:00
parentId: '0',
level: '1',
fourthParentId: null, // 工具专业
greatGrandparentId: null, // 施工类型
grandparentTypeId: null, // 工具类型
parentTypeId: null, // 工具名称
typeName: null, // 规格型号
toolCode: null,
2025-11-13 17:51:15 +08:00
},
2025-11-14 16:26:33 +08:00
fourthParentList: [],
greatGrandparentList: [],
grandparentTypeList: [],
parentTypeList: [],
2025-11-13 17:51:15 +08:00
total: 0, // 总条数
// 表头
tableColumns: [
2025-11-14 16:26:33 +08:00
{ label: '工具专业', prop: 'fourthParentName' },
{ label: '施工类型', prop: 'greatGrandparentName' },
{ label: '工具类型', prop: 'grandparentTypeName' },
{ label: '工具名称', prop: 'parentTypeName' },
{ label: '规格型号', prop: 'typeName' },
{ label: '计量单位', prop: 'unitName' },
{ label: '工具编码', prop: 'toolCode' },
2025-11-24 18:11:54 +08:00
{
label: "工具状态",
prop: "status",
width: 120,
render: (h, { row }) => {
// 定义状态与 el-tag 属性的映射关系
// 这样做比 switch/case 更清晰,也更容易维护
const statusOptions = {
0: { text: "在库", type: "success" },
1: { text: "在用", type: "info" },
2: { text: "在修", type: "warning" },
3: { text: "已报废", type: "danger" },
};
// 获取当前状态对应的配置,如果没有则用默认值
const option = statusOptions[row.status] || {
text: "未知状态",
type: "",
};
return h(
"el-tag", // 1. 要创建的组件是 el-tag
{
props: {
type: option.type,
size: "mini",
},
},
option.text
);
},
},
2025-11-14 16:26:33 +08:00
{ label: '下次检验时间', prop: 'nextCheckDate' },
{ label: '生产厂家', prop: 'supplierName', width: 200 },
{ label: '出厂日期', prop: 'productionDate' },
{ label: '资产原值', prop: 'originCost' },
{ label: '原始编码', prop: 'identifyCode' },
2025-11-13 17:51:15 +08:00
],
// 表格数据
tableList: [],
2025-11-14 16:26:33 +08:00
isView: false,
dialogTitle: '编码设备管理',
2025-11-13 17:51:15 +08:00
dialogVisible: false,
dialogForm: {
2025-11-14 16:26:33 +08:00
fourthParentName: '',
greatGrandparentName: '',
grandparentTypeName: '',
parentTypeName: '',
typeName: '',
unitName: '',
supplierId: '',
productionDate: '',
lastCheckDate: '',
originCost: null,
identifyCode: '',
nextCheckDate: '',
propertyVoList: [],
fileList: null,
2025-11-13 17:51:15 +08:00
},
2025-11-14 16:26:33 +08:00
manufacturerSelect: [],
2025-11-13 17:51:15 +08:00
}
},
created() {
2025-11-14 16:26:33 +08:00
this.getList()
this.getSelectList()
2025-11-13 17:51:15 +08:00
},
methods: {
// 查询
handleQuery() {
this.queryParams.pageNum = 1
this.getList()
},
// 重置
handleReset() {
this.queryParams.pageNum = 1
this.queryParams.pageSize = 10
2025-11-14 16:26:33 +08:00
this.queryParams.parentId = '0'
this.queryParams.level = '1'
this.$refs.queryForm.resetFields()
2025-11-13 17:51:15 +08:00
this.getList()
},
// 获取列表
async getList() {
console.log('列表-查询', this.queryParams)
this.isLoading = true
try {
2025-11-14 16:26:33 +08:00
const params = { ...this.queryParams }
const res = await getListCodeApi(params)
this.tableList = res.rows || []
this.total = res.total || 0
2025-11-13 17:51:15 +08:00
} catch (error) {
this.tableList = []
this.total = 0
} finally {
this.isLoading = false
}
},
2025-11-14 16:26:33 +08:00
// 下拉
async getSelectList() {
try {
const params = { ...this.queryParams }
const res = await getToolSelectApi(params)
if (this.queryParams.level == '1') {
this.fourthParentList = res.data || []
} else if (this.queryParams.level == '2') {
this.greatGrandparentList = res.data || []
} else if (this.queryParams.level == '3') {
this.grandparentTypeList = res.data || []
} else if (this.queryParams.level == '4') {
this.parentTypeList = res.data || []
}
} catch (error) {
console.log('🚀 ~ error:', error)
}
},
changeType(val, level) {
console.log('🚀 ~ val, type:', val, level)
if (level == '2') {
this.queryParams.parentId = val
this.queryParams.greatGrandparentId = null
this.queryParams.grandparentTypeId = null
this.queryParams.parentTypeId = null
this.greatGrandparentList = []
this.grandparentTypeList = []
this.parentTypeList = []
} else if (level == '3') {
this.queryParams.parentId = this.queryParams.greatGrandparentId
this.queryParams.grandparentTypeId = null
this.queryParams.parentTypeId = null
this.grandparentTypeList = []
this.parentTypeList = []
} else if (level == '4') {
this.queryParams.parentId = this.queryParams.grandparentTypeId
this.queryParams.parentTypeId = null
this.parentTypeList = []
}
this.queryParams.level = level
if (!val) return
this.getSelectList()
},
// 获取厂家
async getManufacturerSelect() {
try {
const res = await getManufacturerSelectApi()
this.manufacturerSelect = res.data
} catch (error) {}
},
handleProperty(type, index) {
if (type == 'add') {
this.dialogForm.propertyVoList.push({
propertyName: '',
propertyValue: '',
})
} else {
this.dialogForm.propertyVoList.splice(index, 1)
}
},
2025-11-13 17:51:15 +08:00
handleDialog(row, type) {
2025-11-14 16:26:33 +08:00
this.dialogTitle = type ? '编码设备管理' : '编码设备详情'
this.isView = type
2025-11-13 17:51:15 +08:00
this.dialogVisible = true
2025-11-14 16:26:33 +08:00
this.getManufacturerSelect()
this.$nextTick(() => {
2025-11-13 17:51:15 +08:00
this.$refs.dialogForm.resetFields()
2025-11-14 16:26:33 +08:00
this.dialogForm = { ...this.dialogForm, ...row }
if (!this.dialogForm.propertyVoList || this.dialogForm.propertyVoList.length == 0) {
this.dialogForm.propertyVoList = [
{
propertyName: '',
propertyValue: '',
},
]
}
console.log('🚀 ~ this.dialogForm:', this.dialogForm)
})
2025-11-13 17:51:15 +08:00
},
2025-11-14 16:26:33 +08:00
handleImage(file) {
console.log('🚀 ~ file:', file)
console.log('🚀 ~ file.url:', this.dialogForm.fileList)
2025-11-13 17:51:15 +08:00
},
2025-11-14 16:26:33 +08:00
async submit() {
console.log('🚀 ~ methods.submit:', this.dialogForm)
this.isLoading = true
2025-11-13 17:51:15 +08:00
try {
2025-11-14 16:26:33 +08:00
await updateByIdApi(this.dialogForm)
this.$message({
type: 'success',
message: '操作成功!',
})
this.dialogVisible = false
this.getList()
2025-11-13 17:51:15 +08:00
} catch (error) {
2025-11-14 16:26:33 +08:00
console.log('🚀 ~ error:', error)
2025-11-13 17:51:15 +08:00
} finally {
this.isLoading = false
}
},
},
}
</script>
2025-11-14 16:26:33 +08:00
<style lang="scss" scoped>
::v-deep .el-input-number.is-without-controls .el-input__inner {
text-align: left;
}
</style>