jiangping
2025-03-18 1b0cf0db5c82ea8308d2f338973a91555787c34d
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
<template>
  <GlobalAlertWindow
    :title="title"
    :visible.sync="visible"
    :confirm-working="isWorking"
    @confirm="changeTissue"
  >
    <el-form :model="form" ref="form" :rules="rules">
      <el-form-item label="所在部门" prop="departmentId">
        <el-cascader
          placeholder="请选择所属部门"
          v-model="form.departmentId"
          :options="departments()"
          :props="{ value: 'id', label: 'name', checkStrictly: true }"
          :show-all-levels="false"
        ></el-cascader>
      </el-form-item>
    </el-form>
  </GlobalAlertWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalAlertWindow from '@/components/common/GlobalAlertWindow'
// import ZuzhiSelect from './zuzhiSelect.vue'
import { updateById } from '@/api/system/user'
// import { fetchTree as treeComList } from '@/api/system/department'
export default {
  name: 'OperaUserChangeWindow',
  extends: BaseOpera,
  components: { GlobalAlertWindow },
  
  data () {
    return {
      // 表单数据
      form: {
        id: null,
        departmentId: null
      },
      // 验证规则
      rules: {
        name: [
          { required: true, message: '请选择所在部门', trigger: 'blur' }
        ]
      },
      departmentList: []
    }
  },
  inject: ['departments'],
  methods: {
    open (title, target) {
      this.title = title
      this.visible = true
      console.log('target', target)
      // 新建
      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]
        }
      })
    },
    changeTissue () {
 
      let departmentIds = JSON.parse(JSON.stringify(this.form.departmentId))
      // console.log(this.form.departmentId)
      
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.isWorking = true
          updateById({
            id: this.form.id,
            departmentId: departmentIds[departmentIds.length - 1]
          }).then(res => {
            this.$tip.success('更换部门成功')
            this.visible = false
            this.$emit('success')
          })
          .finally(() => {
            this.isWorking = false
          })
        } else {
          return false
        }
      })
    },
    handleChange (e) {
      // console.log(e)
      this.form.departmentId = e[e.length - 1]
    },
    /**
     * 确认更改部门
     */
    // confirm () {
    //   this.api.create({
    //     id: this.targetUser.id,
    //     departmentId: this.form.departmentId
    //   })
    //     .then((res) => {
    //       this.$tip.apiSuccess(res)
    //       this.visible = false
    //       this.$emit('success')
    //     }).catch((err) => {
    //       this.$tip.apiFailed(err)
    //     })
    // },
    // 打开部门窗口
    // open (title, target) {
    //   console.log(target, 'this.isShow')
    //   this.title = title
    //   this.targetUser = target
    //   this.visible = true
    //   this.form.departmentId = target.departmentId
    //   console.log(this.form, 'this.isShow')
    // },
    // changeModel (item) {
    //   if (item === '1') {
    //     console.log('vvvvisShow', this.isShow)
    //     this.isShow = false
    //   } else if (item === '2' || item === '3') {
    //     console.log('isShow', this.isShow)
    //     this.isShow = true
    //     console.log('isShowssss', this.isShow)
    //   }
    // }
 
  },
  mounted () {
    // this.changeModel()
  },
  created () {
    this.config({
      api: '/system/user',
      'field.id': 'id'
    })
    // this.treeComList()
  }
}
</script>