jiangping
2023-10-24 349bcef9a96391d22522a3409adf5a89e7e70a95
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<template>
  <GlobalWindow
    :title="title"
    :visible.sync="visible"
    :confirm-working="isWorking"
    @confirm="confirm"
  >
    <el-form :model="form" ref="form" style="margin-top:15px">
      <el-form-item label="权限类型:" prop="type">
        <el-select v-model="form.type" clearable filterable placeholder="请选择权限类型">
          <el-option
            v-for="(item, index) in options"
            :key="index"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item v-if="form.type == 4" label="自定义部门:" prop="customData">
        <el-cascader
          :options="departments"
          v-model="form.customData"
          :props=defaultProps
          clearable
        ></el-cascader>
      </el-form-item>
 
    </el-form>
  </GlobalWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
// import Treeselect from 'vue-treeselect'
import { createRoleDataPermission } from '@/api/system/systemRole'
import { treeComList } from '@/api/ext/companyUserExt'
  // import the styles
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
export default {
  name: 'OperaSystemRoleWindow',
  extends: BaseOpera,
  components: { GlobalWindow },
  data () {
    return {
      options: [
        { name: '全部', id: 0 },
        { name: '所属部门及下属部门', id: 1 },
        { name: '所属部门及其子孙部门', id: 2 },
        { name: '仅所属部门', id: 3 },
        { name: '自定义部门', id: 4 }
      ],
      // 表单数据
      form: {
        businessCode: null,
        createTime: null,
        createUser: null,
        customData: [],
        id: null,
        roleId: null,
        type: 0
      },
      defaultProps: {
        multiple: true,
        checkStrictly: true,
        children: 'children',
        label: 'name',
        value: 'id',
        emitPath: false
      },
      departments: []
    }
  },
  created () {
    this.config({
      api: '/system/systemRole',
      'field.id': 'id'
    })
    this.treeComList()
  },
  methods: {
    // 部门树状结构数据
    treeComList () {
      treeComList({})
        .then(res => {
          // this.departments = this.tree([res])
          this.departments = [res]
        })
    },
    open (title, target) {
      // console.log(title, target)
      this.title = title
      this.visible = true
      // 新建
      if (target == null) {
        this.$nextTick(() => {
          this.$refs.form.resetFields()
          this.form[this.configData['field.id']] = null
        })
        return
      }
      // 编辑
      this.$nextTick(() => {
        for (const key in this.form) {
          this.form[key] = target[key]
        }
        console.log(target);
        if (target.customData === null || target.customData === '') {
          this.form.customData = []
        } else {
          let customD  = this.form.customData.split(',')
          this.form.customData = customD.map((item) => { return parseInt(item) })
        }
      })
    },
    __confirmCreate () {
      // console.log(JSON.stringify(this.form.customData));
      // return
      this.$refs.form.validate((valid) => {
        if (!valid) {
          return
        }
 
        this.isWorking = true
        let data = JSON.parse(JSON.stringify(this.form))
        if (this.form.type === 4) {
          data.customData = this.form.customData.join(',')
        } else {
          data.customData = ''
        }
        createRoleDataPermission(data)
          .then(() => {
            this.visible = false
            this.$tip.apiSuccess('新建成功')
            this.$emit('success')
          })
          .catch(e => {
            this.$tip.apiFailed(e)
          })
          .finally(() => {
            this.isWorking = false
          })
      })
    },
    __confirmEdit () {
      // console.log(JSON.stringify(this.form.customData));
      // return
      this.$refs.form.validate((valid) => {
        if (!valid) {
          return
        }
        // 调用更新接口
        this.isWorking = true
        let data = JSON.parse(JSON.stringify(this.form))
        if (this.form.type === 4) {
          data.customData = this.form.customData.join(',')
        } else {
          data.customData = ''
        }
        createRoleDataPermission(data)
          .then(() => {
            this.visible = false
            this.$tip.apiSuccess('修改成功')
            this.$emit('success')
          })
          .catch(e => {
            this.$tip.apiFailed(e)
          })
          .finally(() => {
            this.isWorking = false
          })
      })
    }
  }
}
</script>