<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="factoryNo">
|
<el-input
|
v-model="dataForm.factoryNo"
|
placeholder="编号"
|
></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="名称" prop="factoryName">
|
<el-input
|
v-model="dataForm.factoryName"
|
placeholder="名称"
|
></el-input>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="城市" prop="city">
|
<template>
|
<div id="app">
|
<el-cascader
|
size="small"
|
:options="options"
|
v-model="dataForm.city"
|
@change="handleChange"
|
style="width: 100%;"
|
>
|
</el-cascader>
|
</div>
|
</template>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="公司" prop="companyId">
|
<el-select
|
v-model="dataForm.companyId"
|
filterable
|
placeholder="请选择"
|
style="width: 100%;"
|
>
|
<el-option
|
v-for="(item, index) in this.companyOptions"
|
:key="index"
|
:label="item.companyName"
|
:value="item.id"
|
>
|
</el-option>
|
</el-select>
|
</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 { regionData, CodeToText } from 'element-china-area-data'
|
import {
|
getObj,
|
addObj,
|
putObj,
|
loadCompany,
|
dataFormTransfer
|
} from '@/api/basic/factory'
|
|
export default {
|
data() {
|
return {
|
options: regionData,
|
visible: false,
|
dataForm: {
|
id: 0,
|
factoryName: '',
|
factoryNo: '',
|
selectCityOptionsStr: '',
|
city: [],
|
companyId: ''
|
},
|
dataRule: {
|
factoryName: [
|
{ required: true, message: '名称不能为空', trigger: 'blur' }
|
],
|
factoryNo: [
|
{ required: true, message: '编号不能为空', trigger: 'blur' }
|
],
|
city: [{ required: true, message: '城市不能为空', trigger: 'blur' }],
|
companyId: [
|
{ required: true, message: '公司不能为空', trigger: 'blur' }
|
]
|
},
|
companyOptions: [],
|
isSubmit: false
|
}
|
},
|
methods: {
|
handleChange() {
|
let buffer = ''
|
this.dataForm.city.forEach((item, i) => {
|
buffer += item + ','
|
})
|
buffer = buffer.substr(0, buffer.length - 1)
|
this.dataForm.selectCityOptionsStr = buffer
|
},
|
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
|
this.dataForm.city = response.data.data.city.split(',')
|
})
|
}
|
})
|
},
|
// 表单提交
|
dataFormSubmit() {
|
this.isSubmit = true
|
const transferData = {
|
factoryName: this.dataForm.factoryName,
|
factoryNo: this.dataForm.factoryNo,
|
city: this.dataForm.selectCityOptionsStr,
|
companyId: this.dataForm.companyId,
|
id: this.dataForm.id
|
}
|
this.$refs.dataForm.validate((valid) => {
|
if (valid) {
|
dataFormTransfer(transferData).then((res) => {
|
if (
|
res.data.data === true &&
|
res.data.code === 0 &&
|
this.dataForm.id === 0
|
) {
|
this.$message.success('添加成功!')
|
this.visible = false
|
this.$emit('refreshDataList')
|
} else if (
|
res.data.data === true &&
|
res.data.code === 0 &&
|
this.dataForm.id != 0
|
) {
|
this.$message.success('修改成功!')
|
this.visible = false
|
this.$emit('refreshDataList')
|
}
|
this.isSubmit = false
|
})
|
} else {
|
this.isSubmit = false
|
}
|
})
|
},
|
initCompanySelect() {
|
loadCompany().then((res) => {
|
this.companyOptions = res.data
|
})
|
}
|
},
|
created() {
|
this.initCompanySelect()
|
}
|
}
|
</script>
|
<style scoped></style>
|