<template>
|
<el-dialog
|
:title="!dataForm.id ? '新增' : '修改'"
|
:close-on-click-modal="false"
|
:visible.sync="visible"
|
>
|
<el-form
|
:model="dataForm"
|
:rules="dataRule"
|
ref="dataForm"
|
label-width="80px"
|
class="l-mes"
|
>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="编号" prop="number">
|
<el-input v-model="dataForm.number" placeholder="编号"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="名称" prop="name">
|
<el-input v-model="dataForm.name" placeholder="名称"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="工厂" prop="factoryId">
|
<el-select
|
v-model="dataForm.factoryId"
|
filterable
|
placeholder="请选择"
|
style="width:100%"
|
>
|
<el-option
|
v-for="(item, index) in this.factoryOptions"
|
:label="item.factoryName"
|
:value="item.id"
|
:key="index"
|
>
|
</el-option>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="所属车间" prop="workshop">
|
<el-select
|
v-model="dataForm.workshop"
|
filterable
|
placeholder="请选择"
|
style="width:100%"
|
>
|
<el-option
|
v-for="item in workshopList"
|
:key="item.id"
|
:label="item.label"
|
:value="item.value"
|
>
|
</el-option>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="位置" prop="position">
|
<el-input v-model="dataForm.position" placeholder="位置"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="邮箱" prop="email">
|
<el-input v-model="dataForm.email" placeholder="邮箱"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="供应商" prop="supplier">
|
<el-input
|
v-model="dataForm.supplier"
|
placeholder="供应商"
|
></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="制造商" prop="manufacturer">
|
<el-input
|
v-model="dataForm.manufacturer"
|
placeholder="制造商"
|
></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="型号规格" prop="typeSpecification">
|
<el-input
|
v-model="dataForm.typeSpecification"
|
placeholder="型号规格"
|
></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="制造日期" prop="manufactureDate">
|
<el-date-picker
|
style="width: 100%"
|
v-model="dataForm.manufactureDate"
|
type="date"
|
placeholder="选择日期"
|
value-format="yyyy-MM-dd HH:mm:ss"
|
>
|
</el-date-picker>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="安装日期" prop="installDate">
|
<el-date-picker
|
style="width: 100%"
|
v-model="dataForm.installDate"
|
type="date"
|
placeholder="选择日期"
|
value-format="yyyy-MM-dd HH:mm:ss"
|
>
|
</el-date-picker>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="状态" prop="state">
|
<el-select
|
v-model="dataForm.state"
|
placeholder="状态"
|
filterable
|
style="width: 100%"
|
>
|
<el-option
|
v-for="item in equipmentState"
|
:key="item.id"
|
:label="item.label"
|
:value="item.label"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="设备描述" prop="desc">
|
<el-input
|
v-model="dataForm.description"
|
placeholder="设备描述"
|
></el-input>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</el-form>
|
<span slot="footer" class="dialog-footer">
|
<el-button @click="visible = false">取消</el-button>
|
<el-button
|
type="primary"
|
:disabled="isSubmit"
|
v-thinclick="`dataFormSubmit`"
|
>确定</el-button
|
>
|
</span>
|
</el-dialog>
|
</template>
|
<script>
|
import { getObj, addObj, putObj } from '@/api/equipment/equipment'
|
import { loadFactoryList } from '@/api/basic/factory'
|
import { remote } from '../../../api/admin/dict'
|
export default {
|
data() {
|
return {
|
// options: regionData,
|
visible: false,
|
dataForm: {
|
id: 0,
|
number: '',
|
name: '',
|
factoryId: '',
|
workshop: '',
|
position: '',
|
email: '',
|
supplier: '',
|
manufacturer: '',
|
typeSpecification: '',
|
manufactureDate: '',
|
installDate: '',
|
state: '',
|
description: '',
|
value1: ''
|
},
|
dataRule: {
|
number: [{ required: true, message: '编号不能为空', trigger: 'blur' }],
|
name: [{ required: true, message: '名称不能为空', trigger: 'blur' }]
|
},
|
factoryOptions: [],
|
equipmentState: [],
|
isSubmit: false,
|
workshopList: []
|
}
|
},
|
methods: {
|
init(id) {
|
this.dataForm.id = id || 0
|
this.visible = true
|
this.$nextTick(() => {
|
this.$refs.dataForm.resetFields()
|
if (this.dataForm.id) {
|
getObj(this.dataForm.id).then((response) => {
|
this.dataForm = response.data.data
|
})
|
} else {
|
if (this.factoryOptions.length > 0) {
|
this.dataForm.factoryId = this.factoryOptions[0].id
|
}
|
}
|
})
|
},
|
// 表单提交
|
getEquipmentState() {
|
remote('equipment_state').then((response) => {
|
if (response.data.code === 0) {
|
this.equipmentState = response.data.data
|
}
|
})
|
},
|
dataFormSubmit() {
|
this.isSubmit = true
|
this.$refs.dataForm.validate((valid) => {
|
if (valid) {
|
if (this.dataForm.id) {
|
putObj(this.dataForm).then((data) => {
|
this.$message.success('修改成功')
|
this.visible = false
|
this.isSubmit = false
|
this.$emit('refreshDataList')
|
})
|
} else {
|
addObj(this.dataForm).then((data) => {
|
this.$message.success('添加成功')
|
this.visible = false
|
this.isSubmit = false
|
this.$emit('refreshDataList')
|
})
|
}
|
} else {
|
this.isSubmit = false
|
}
|
})
|
},
|
|
initFactorySelect() {
|
loadFactoryList().then((res) => {
|
this.factoryOptions = res.data
|
if (this.factoryOptions.length > 0) {
|
this.dataForm.factoryId = this.factoryOptions[0].id
|
}
|
})
|
}
|
},
|
|
created() {
|
this.initFactorySelect()
|
this.getEquipmentState()
|
|
remote('work_shop').then((response) => {
|
if (response.data.code === 0) {
|
this.workshopList = response.data.data
|
} else {
|
this.workshopList = []
|
}
|
})
|
}
|
}
|
</script>
|