jinlin
2024-01-31 9025b9cf7ec8610003d445a31d93e35e7bd73c2e
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
<template>
  <zt-dialog ref="dialog" @confirm="formSubmit" append-to-body>
    <el-form :model="dataForm" ref="dataForm" :disabled="dataForm.disabled" label-width="120px">
      <zt-form-item prop="code" :label="$t('dept.code')" rules='required'>
        <el-input v-model="dataForm.code" :placeholder="$t('dept.code')"></el-input>
      </zt-form-item>
      <zt-form-item prop="name" :label="$t('dept.name')" rules='required'>
        <el-input v-model="dataForm.name" :placeholder="$t('dept.name')"></el-input>
      </zt-form-item>
      <zt-form-item prop="shortName" :label="$t('dept.shortName')" rules='required'>
        <el-input v-model="dataForm.shortName" :placeholder="$t('dept.shortName')"></el-input>
      </zt-form-item>
      <zt-form-item :label="$t('dept.parentName')" prop="pid" rules='required'>
        <zt-combo-tree v-model="dataForm.pid" :datas="deptList"/>
      </zt-form-item>
      <zt-form-item prop="nature" :label="$t('dept.type')" rules='required'>
        <zt-dict v-model="dataForm.nature" dict="dept_type" :radio="true" :placeholder="$t('dept.type')"></zt-dict>
      </zt-form-item>
      <zt-form-item prop="sort" :label="$t('dept.sort')">
        <el-input-number v-model="dataForm.sort" controls-position="right" :min="0"
                        :label="$t('dept.sort')"></el-input-number>
      </zt-form-item>
    </el-form>
  </zt-dialog>
</template>
 
<script>
  export default {
    props: {
      companyId: {
        type: String,
        required: true
      },
      companyName: {
        type: String,
        required: true
      }
    },
    data() {
      return {
        deptList: [],
        deptListVisible: false,
        dataForm: {
          id: '',
          name: '',
          pid: '',
          shortName: '',
          code: '',
          nature: 0,
          parentName: '',
          companyId: 0,
          sort: 0
        }
      }
    },
    computed: {
    },
    methods: {
      init() {
        this.getDeptList()
      },
      // 获取部门列表
      async getDeptList() {
        let res = await this.$http.get('/sys/dept/list?companyId=' + this.companyId)
        if (res.success) {
          this.deptList = [{
            id: this.companyId, name: this.companyName, children: res.data
          }]
        }
      },
      // 获取信息
      async getInfo() {
        let res = await this.$http.get(`/sys/dept/${this.dataForm.id}`)
        this.dataForm = {
          ...this.dataForm,
          ...res.data
        }
      },
      // 表单提交
      async formSubmit() {
        this.dataForm.companyId = this.companyId
        let res = await this.$http[!this.dataForm.id ? 'post' : 'put']('/sys/dept', this.dataForm)
        if (res.success) {
          await this.$tip.success()
          this.$refs.dialog.close()
          this.$emit('refreshDataList')
        }
      }
    }
  }
</script>