| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- <!-- 用户编辑弹窗 -->
- <template>
- <el-dialog
- class="ele-dialog-form"
- :title="title"
- :visible.sync="visible"
- :before-close="handleClose"
- :close-on-click-modal="false"
- :close-on-press-escape="false"
- width="1000px"
- >
- <el-form ref="form" :model="form" :rules="rules" label-width="100px">
- <el-row>
- <el-col :span="8">
- <el-form-item
- label="工厂编码:"
- prop="code"
- style="margin-bottom: 22px"
- >
- <el-input
- clearable
- :maxlength="20"
- v-model="form.code"
- placeholder="请输入"
- />
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item
- label="工厂名称:"
- prop="name"
- style="margin-bottom: 22px"
- >
- <el-input
- clearable
- :maxlength="20"
- v-model="form.name"
- placeholder="请输入"
- />
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item
- label="所属公司:"
- prop="groupId"
- style="margin-bottom: 22px"
- >
- <ele-tree-select
- clearable
- :data="options.groupId"
- v-model="form.groupId"
- valueKey="id"
- labelKey="name"
- placeholder="请选择"
- default-expand-all
- />
- </el-form-item>
- </el-col>
- <el-col :span="16" style="margin-bottom: 22px">
- <el-form-item label="地址:" prop="location_city">
- <div class="location-warp">
- <el-cascader
- clearable
- style="width: 385px"
- v-model="form.location"
- :options="options.cityDataLabel"
- ></el-cascader>
- <el-input
- class="detail"
- clearable
- :maxlength="20"
- v-model="form.locationDetail"
- placeholder="请输入详细地址"
- />
- </div>
- </el-form-item>
- </el-col>
- <el-col :span="8" style="margin-bottom: 22px">
- <el-form-item label="状态:" prop="enabled">
- <div class="location-warp">
- <el-select
- v-model="form.enabled"
- v
- placeholder="请选择"
- style="width: 100%"
- >
- <el-option
- v-for="item in options.zt"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- >
- </el-option>
- </el-select>
- </div>
- </el-form-item>
- </el-col>
- </el-row>
- </el-form>
- <template v-slot:footer>
- <el-button @click="handleClose">取消</el-button>
- <el-button type="primary" :loading="loading" @click="save">
- 保存
- </el-button>
- </template>
- </el-dialog>
- </template>
- <script>
- import { cityDataLabel } from 'ele-admin/packages/utils/regions';
- import { listOrganizations } from '@/api/system/organization';
- import { saveOrUpdate } from '@/api/factoryModel';
- export default {
- data() {
- const defaultForm = {
- id: '',
- code: '',
- name: '',
- groupId: '',
- locationDetail: '',
- location: [],
- enabled: 1,
- parentId: '',
- type: 1 // FACTORY(1, "工厂"), WORKSHOP_PLAN(2, "厂房"), WORKSHOP(3, "车间"), LINE(4, "厂线");
- };
- return {
- defaultForm,
- // 表单数据
- form: { ...defaultForm },
- // 表单验证规则
- rules: {
- code: [{ required: true, message: '请输入', trigger: 'blur' }],
- name: [{ required: true, message: '请输入', trigger: 'blur' }],
- groupId: [{ required: true, message: '请输入', trigger: 'blur' }]
- },
- visible: false,
- type: '', // add/edit
- loading: false,
- options: {
- zt: [
- {
- label: '生效',
- value: 1
- },
- {
- label: '未生效',
- value: 0
- }
- ],
- groupId: [],
- cityDataLabel
- }
- };
- },
- computed: {
- title() {
- switch (this.type) {
- case 'add':
- return '新增工厂';
- break;
- case 'edit':
- return '编辑工厂';
- break;
- default:
- break;
- }
- }
- },
- created() {
- this.getGs();
- },
- methods: {
- open(type, row) {
- this.type = type;
- this.visible = true;
- if (type == 'edit') {
- this.form.id = row.id;
- this.form.code = row.code;
- this.form.name = row.name;
- this.form.groupId = row.groupId;
- this.form.enabled = row.enabled;
- this.form.parentId = row.parentId;
- this.form.type = row.type;
- this.form.location = row.extInfo.location.split('/');
- this.form.locationDetail = row.extInfo.locationDetail;
- }
- },
- /* 保存编辑 */
- save() {
- this.$refs.form.validate((valid) => {
- if (!valid) {
- return false;
- }
- this.loading = true;
- const data = {
- code: this.form.code,
- name: this.form.name,
- groupId: this.form.groupId,
- enabled: this.form.enabled,
- parentId: this.form.groupId,
- type: this.form.type,
- extInfo: this.setLocation()
- };
- if (this.type == 'edit') {
- data.id = this.form.id;
- }
- console.log(data);
- saveOrUpdate(data)
- .then((msg) => {
- this.loading = false;
- this.$message.success(msg);
- this.handleClose();
- this.$emit('done');
- })
- .catch((e) => {
- this.loading = false;
- this.$message.error(e.message);
- });
- });
- },
- restForm() {
- this.$refs.form.clearValidate();
- this.form = { ...this.defaultForm };
- },
- handleClose() {
- this.restForm();
- this.visible = false;
- },
- // 获取公司数据
- getGs() {
- listOrganizations().then((list) => {
- console.log(list);
- this.options.groupId = this.$util.toTreeData({
- data: list,
- idField: 'id',
- parentIdField: 'parentId'
- });
- });
- },
- setLocation() {
- return {
- location: this.form.location.join('/'),
- locationDetail: this.form.locationDetail
- };
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .location-warp {
- display: flex;
- .detail {
- margin-left: 10px;
- }
- }
- </style>
|