yz
2021-01-29 177a4578502428ba21245db5575acd08bd9e7366
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<template>
  <div class="dept">
    <el-row :gutter="10">
      <el-col :xs="24" :sm="12">
        <div class="app-container">
          <div class="filter-container">
            <el-input v-model="deptName" :placeholder="$t('table.dept.deptName')" class="filter-item search-item" />
            <el-button class="filter-item" type="primary" @click="search">
              {{ $t('table.search') }}
            </el-button>
            <el-button class="filter-item" type="success" @click="reset">
              {{ $t('table.reset') }}
            </el-button>
            <el-dropdown v-has-any-permission="['dept:add','dept:delete','dept:export']" trigger="click" class="filter-item">
              <el-button>
                {{ $t('table.more') }}<i class="el-icon-arrow-down el-icon--right" />
              </el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item v-has-permission="['dept:add']" @click.native="add">{{ $t('table.add') }}</el-dropdown-item>
                <el-dropdown-item v-has-permission="['dept:delete']" @click.native="deleteDept">{{ $t('table.delete') }}</el-dropdown-item>
                <el-dropdown-item v-has-permission="['dept:export']" @click.native="exportExcel">{{ $t('table.export') }}</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
          <el-tree
            ref="deptTree"
            :data="deptTree"
            :check-strictly="true"
            show-checkbox
            accordion
            node-key="id"
            highlight-current
            :filter-node-method="filterNode"
            @node-click="nodeClick"
          />
        </div>
      </el-col>
      <el-col :xs="24" :sm="12">
        <el-tabs v-model="activeName">
          <el-tab-pane label="部门信息" name="first">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>{{ dept.deptId === '' ? this.$t('common.add') : this.$t('common.edit') }}</span>
              </div>
              <div>
                <el-form ref="form" :model="dept" :rules="rules" label-position="right" label-width="100px">
                  <el-form-item :label="$t('table.dept.parentId')" prop="parentId">
                    <treeselect
                      v-model="dept.parentId"
                      :multiple="false"
                      :options="deptTree"
                      :clear-value-text="$t('common.clear')"
                      placeholder=" "
                      style="width:100%"
                    />
                  </el-form-item>
                  <el-form-item :label="$t('table.dept.deptName')" prop="deptName">
                    <el-input v-model="dept.deptName" />
                  </el-form-item>
                  <el-form-item :label="$t('table.dept.orderNum')" prop="orderNum">
                    <el-input-number v-model="dept.orderNum" :min="0" :max="100" @change="handleNumChange" />
                  </el-form-item>
                  <el-form-item label="部门性质">
                    <el-select v-model="bmxz" placeholder="请选择">
                      <el-option label="分公司" value="1" />
                      <el-option label="部门" value="2" />
                      <el-option label="驻点" value="3" />
                    </el-select>
                  </el-form-item>
                  <el-form-item label="部门负责人">
                    <el-input />
                  </el-form-item>
                  <el-form-item label="联系电话">
                    <el-input />
                  </el-form-item>
                  <el-form-item label="部门智能">
                    <el-select v-model="bmzn" placeholder="请选择">
                      <el-option label="保安" value="1" />
                      <el-option label="后勤" value="2" />
                      <el-option label="管理" value="3" />
                    </el-select>
                  </el-form-item>
                  <el-form-item label="部门职责">
                    <el-input type="textarea" :rows="4" />
                  </el-form-item>
                </el-form>
              </div>
            </el-card>
            <el-card class="box-card" style="margin-top: -2rem;">
              <el-row>
                <el-col :span="24" style="text-align: right">
                  <el-button type="primary" plain :loading="buttonLoading" @click="submit">{{ dept.deptId === '' ? this.$t('common.add') : this.$t('common.edit') }}</el-button>
                </el-col>
              </el-row>
            </el-card>
          </el-tab-pane>
          <el-tab-pane label="岗位信息" name="second">
            <el-button type="danger" @click="showXzgw">添加岗位</el-button>
            <el-button type="primary">删除岗位</el-button>
            <el-table :data="jobData" style="width: 100%">
              <el-table-column prop="prop0" label="" width="180" />
              <el-table-column prop="prop1" label="序号" width="180" />
              <el-table-column prop="prop2" label="岗位名称" width="180" />
              <el-table-column prop="prop3" label="在岗人数" width="180" />
            </el-table>
          </el-tab-pane>
        </el-tabs>
 
      </el-col>
    </el-row>
    <el-dialog title="新增岗位" :visible.sync="dialogShowXzgw" width="50%">
      <el-form :model="baseicInformationForm" label-position="right" label-width="120px">
        <el-row>
          <el-col span="24">
            <el-form-item label="岗位名称">
              <el-input v-model="name" />
            </el-form-item>
            <el-form-item label="岗位描述">
              <el-input v-model="name" type="textarea" :rows="4" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogIsShow()">取 消</el-button>
        <el-button type="primary" @click="dialogIsShow()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
 
export default {
  name: 'DeptManager',
  components: {
    Treeselect
  },
  data() {
    return {
      dialogShowXzgw: false,
      activeName: 'first',
      deptName: '',
      buttonLoading: false,
      deptTree: [],
      dept: this.initDept(),
      jobData: [{
        'prop0': '',
        'prop1': '1',
        'prop2': '市场部总监',
        'prop3': '1'
      }, {
        'prop0': '',
        'prop1': '2',
        'prop2': '市场部经理',
        'prop3': '2'
      }, {
        'prop0': '',
        'prop1': '3',
        'prop2': '高级客户经理',
        'prop3': '5'
      }, {
        'prop0': '',
        'prop1': '4',
        'prop2': '客户经理',
        'prop3': '10'
      }, {
        'prop0': '',
        'prop1': '5',
        'prop2': '销售内勤',
        'prop3': '1'
      }, {
        'prop0': '',
        'prop1': '6',
        'prop2': '销售助理',
        'prop3': '1'
      }],
      rules: {
        deptName: [{
          required: true,
          message: this.$t('rules.require'),
          trigger: 'blur'
        },
        {
          min: 3,
          max: 10,
          message: this.$t('rules.range3to10'),
          trigger: 'blur'
        }
        ]
      }
    }
  },
  mounted() {
    this.initDeptTree()
  },
  methods: {
    initDept() {
      return {
        deptId: '',
        deptName: '',
        parentId: null,
        orderNum: 0
      }
    },
    initDeptTree() {
      this.$get('system/dept').then((r) => {
        this.deptTree = r.data.data.rows
      })
    },
    exportExcel() {
      this.$download('system/dept/excel', {
        deptName: this.deptName
      }, `dept_${new Date().getTime()}.xlsx`)
    },
    handleNumChange(val) {
      this.dept.orderNum = val
    },
    filterNode(value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    },
    nodeClick(data) {
      this.dept.parentId = data.parentId
      if (this.dept.parentId === '0') {
        this.dept.parentId = null
      }
      this.dept.orderNum = data.orderNum
      this.dept.deptName = data.label
      this.dept.deptId = data.id
      this.$refs.form.clearValidate()
    },
    add() {
      this.resetForm()
      this.$message({
        message: this.$t('tips.createTips'),
        type: 'info'
      })
    },
    deleteDept() {
      const checked = this.$refs.deptTree.getCheckedKeys()
      if (checked.length === 0) {
        this.$message({
          message: this.$t('tips.noNodeSelected'),
          type: 'warning'
        })
      } else {
        this.$confirm(this.$t('tips.confirmDeleteNode'), this.$t('common.tips'), {
          confirmButtonText: this.$t('common.confirm'),
          cancelButtonText: this.$t('common.cancel'),
          type: 'warning'
        }).then(() => {
          this.dept.deptIds = checked.join(',')
          this.$delete(`system/dept/${this.dept.deptIds}`).then(() => {
            this.$message({
              message: this.$t('tips.deleteSuccess'),
              type: 'success'
            })
            this.reset()
          })
        }).catch(() => {
          this.$refs.deptTree.setCheckedKeys([])
        })
      }
    },
    search() {
      this.$refs.deptTree.filter(this.deptName)
    },
    reset() {
      this.initDeptTree()
      this.deptName = ''
      this.resetForm()
    },
    submit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.buttonLoading = true
          this.dept.createTime = this.dept.modifyTime = null
          if (this.dept.deptId) {
            this.$put('system/dept', { ...this.dept
            }).then(() => {
              this.buttonLoading = false
              this.$message({
                message: this.$t('tips.updateSuccess'),
                type: 'success'
              })
              this.reset()
            })
          } else {
            this.$post('system/dept', { ...this.dept
            }).then(() => {
              this.buttonLoading = false
              this.$message({
                message: this.$t('tips.createSuccess'),
                type: 'success'
              })
              this.reset()
            })
          }
        } else {
          return false
        }
      })
    },
    resetForm() {
      this.$refs.form.clearValidate()
      this.$refs.form.resetFields()
      this.dept = this.initDept()
    },
    showXzgw() {
      this.dialogShowXzgw = true
    }
  }
}
</script>
<style lang="scss" scoped>
  .dept {
    margin: 10px;
 
    .app-container {
      margin: 0 0 10px 0 !important;
    }
  }
 
  .el-card.is-always-shadow {
    box-shadow: none;
  }
 
  .el-card {
    border-radius: 0;
    border: none;
 
    .el-card__header {
      padding: 10px 20px !important;
      border-bottom: 1px solid #f1f1f1 !important;
    }
  }
</style>
<style lang="scss">
  .vue-treeselect__menu {
    max-height: 165px !important;
  }
</style>