zhaowei
2025-07-01 32f13d15d67172b9b2dd12d8c5c661c9602c7d2e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-form-model ref="form" :model="model" :rules="validatorRules" :labelCol="labelCol" :wrapperCol="wrapperCol">
      <a-form-model-item label="机构编码">
        <a-input placeholder="请输入机构编码" v-model="model.factoryCode"/>
      </a-form-model-item>
      <a-form-model-item label="机构名称" hasFeedback prop="factoryName">
        <a-input placeholder="请输入机构名称" v-model="model.factoryName"/>
      </a-form-model-item>
      <a-form-model-item :hidden="seen" label="上级机构">
        <a-tree-select style="width:100%" :dropdownStyle="{maxHeight:'200px',overflow:'auto'}" :treeData="departTree"
                       v-model="model.parentId" placeholder="请选择上级机构" disabled>
        </a-tree-select>
      </a-form-model-item>
      <a-form-model-item v-if="!seen&&(model.parentFactoryCategory==1||model.parentFactoryCategory==2)" label="机构类型"
                         hasFeedback
                         prop="factoryCategory">
        <a-select v-model="model.factoryCategory" placeholder="请选择机构类型">
          <a-select-option :value="2" v-if="model.parentFactoryCategory!=2">工区</a-select-option>
          <a-select-option :value="3">工段</a-select-option>
        </a-select>
      </a-form-model-item>
      <a-form-model-item label="排序">
        <a-input-number v-model="model.sorter"/>
      </a-form-model-item>
      <a-form-model-item label="备注">
        <a-textarea placeholder="请输入备注" v-model="model.remark"/>
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>
 
<script>
  import { getAction, postAction } from '@/api/manage'
  import { queryById } from '@/api/api'
 
  export default {
    name: 'EamProductionModal',
    data() {
      return {
        departTree: [],
        title: '操作',
        seen: false,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        confirmLoading: false,
        validatorRules: {
          factoryName: [{ required: true, message: '请输入机构名称!', trigger: 'change' }],
          factoryCategory: [{ required: true, message: '请选择机构类型!', trigger: 'change' }]
        },
        url: {
          queryById: '/eam/BaseFactory/queryIdTree',
          add: '/eam/BaseFactory/add'
        }
      }
    },
    methods: {
      loadTreeData() {
        const that = this
        getAction(that.url.queryById)
          .then((res) => {
            if (res.success) {
              that.departTree = []
              for (let i = 0; i < res.result.length; i++) {
                let temp = res.result[i]
                that.departTree.push(temp)
              }
            }
          })
      },
 
      add(record) {
        if (this.$refs.form) this.$refs.form.clearValidate()
        const parentFactoryCategory = record ? record.factoryCategory : ''
        const parentId = record ? record.id : ''
        if (parentId) this.seen = false
        else this.seen = true
        this.visible = true
        this.model = Object.assign({}, { parentId, parentFactoryCategory })
        if (parentFactoryCategory == 2) this.model.factoryCategory = +parentFactoryCategory + 1
        this.loadTreeData()
      },
 
      handleOk() {
        const that = this
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true
            postAction(this.url.add, this.model)
              .then((res) => {
                if (res.success) {
                  that.$notification.success({
                    message: '消息',
                    description: res.message
                  })
                  that.loadTreeData()
                  that.$emit('ok')
                } else {
                  that.$notification.warning({
                    message: '消息',
                    description: res.message
                  })
                }
              })
              .finally(() => {
                that.confirmLoading = false
                that.close()
              })
          } else {
            return false
          }
        })
      },
 
      close() {
        this.$emit('close')
        this.visible = false
      },
 
      handleCancel() {
        this.close()
      }
    }
  }
</script>