zhangxp
2023-06-21 ce3a176400b9ccb18a381c744ca04116831765d2
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
<template>
    <el-dialog :title="title" :visible.sync="dialogVisible" append-to-body="true" width="30%">
        <el-tag v-for="tag in tags" :key="tag" closable disable-transitions effect="Plain" size="medium"
            @click="handleClickTag(tag)" @close="handleCloseTag(tag)">
            <span> {{ tag.name }}</span>
        </el-tag>
        <el-divider v-if="tags.length !== 0"></el-divider>
        <el-form :model="saveParam" class="demo-form-inline" label-position="left" label-width="auto" :rules="rules">
            <el-form-item label="流程模板">
                <el-input placeholder="流程模板" v-model="saveParam.modelName" disabled></el-input>
            </el-form-item>
            <el-form-item label="流程名称" prop="processName">
                <el-input placeholder="流程名称" v-model="saveParam.processName">
                </el-input>
            </el-form-item>
            <el-form-item label="流程描述">
                <el-input placeholder="流程描述" type="textarea" :rows="4" v-model="saveParam.processDesc">
                </el-input>
            </el-form-item>
        </el-form>
        <el-divider></el-divider>
        <div class="btns-icon">
            <el-button icon="el-icon-star-off" circle @click="handleCollect"></el-button>
        </div>
        <el-form :model="collectParam" class="demo-form-inline" label-position="left" label-width="auto">
            <el-form-item :label="item.taskName" v-for="(item, index) in initFrom" :key="index">
                <el-select style="width: 80%;" filterable v-model="collectParam.flowTaskUsers[index]['userId']"
                    :placeholder="item.taskName" @change="handleSelect($event, index)">
                    <el-option :label="key.userNames" :value="key.userId" v-for="(key, keyi) in typeName"
                        :key="keyi"></el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="handleCancel">取 消</el-button>
            <el-button type="primary" @click="handleConfirm">确 定</el-button>
        </div>
    </el-dialog>
</template>
<script>
import { personnelInit, personnelCollect, cancelCollect, personnelSave, personnelDict } from '@/api/template/setPersonnel.js'
export default {
    name: 'SetPersonnel',
    props: {
        // 是否打开
        visible: {
            typeof: Boolean,
            default: false
        },
        // 标题
        title: {
            typeof: String,
            default: '流程审批'
        },
        // 参数:选择的id,多个以数组方式传递:['id','id'],模板id,模板用途,流程名字,流程模板
        parameter: {
            typeof: Object,
            default: () => { }
        },
        parameterKeys: {
            typeof: Object,
            default: () => {
                return {
                    ids: 'ids',
                    flowTemplate: 'flowTemplate',
                    code: 'code',
                    type: 'type'
                }
            }
        }
 
    },
    watch: {
        visible(n) {
            this.dialogVisible = n;
            if(n){
              this.apiInit()
              this.apiDict()
            }
        },
        dialogVisible(n) {
            this.$emit('update:visible', n)
        },
    },
    data() {
        return {
            dialogVisible: this.visible,
            isCollent: false,
            initFrom: [],
            tags: [],
            typeName: [],
            collectParam: {},
            saveParam: this.saveParam(),
            users: [],
            rules: {
                processName: [
                    { required: true, message: '模板名称不能为空', trigger: 'blur' },
                    { min: 1, max: 20, message: '长度在 3 到 20 个字符', trigger: 'blur' }
                ]
            }
        }
    },
 
    mounted() {
        // this.apiInit()
        // this.apiDict()
    },
    methods: {
        saveParam() {
            return {
                processName: this.parameter[this.parameterKeys.flowTemplate],
                topName: this.title,
                ids: this.parameter[this.parameterKeys.ids],
            }
        },
        userIndex(arr1) {
            return this.initFrom.findIndex(i => i.taskId === arr1)
        },
        async apiInit() {
            const response = await personnelInit({ type: this.parameter[this.parameterKeys.type], templateId: this.parameter[this.parameterKeys.code] })
            if (response.status === 200) {
                console.log(response)
                this.initFrom = response.data.data.user
                this.tags = response.data.data.collect
                const { modelKey, templateId, modelName } = response.data.data.flow
                let flowTaskUsers = response.data.data.user
                this.collectParam = { modelKey, templateId, flowTaskUsers: flowTaskUsers }
                console.log(this.collectParam)
                this.saveParam = { ...this.saveParam, modelKey, templateId, modelName }
                this.handleClickTag(this.tags[0])
            }
        },
        async apiDict() {
            const response = await personnelDict()
            console.log(response)
            if (response.status === 200) {
                console.log(response)
                const data = response.data.data
                this.typeName = data.map(item => {
                    const { account, deptName, id, realName } = item
                    let userNames = `${deptName} - ${realName} - ${account}`
                    return { userId: id, userName: realName, userNames: userNames }
                })
            }
        },
 
        handleCollect() {
            this.$prompt('请输入一个名字', '操作', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
            }).then(async ({ value }) => {
                console.log(this.users)
                this.collectParam.flowTaskUsers = this.users
                this.collectParam = { ...this.collectParam, name: value }
                console.log(this.collectParam)
                const response = await personnelCollect(this.collectParam)
                Console.log(response)
                if (response.status === 200) {
                    this.$nextTick(() => {
                        this.apiInit()
                    })
                    console.log(response)
                }
            }).catch(() => {
 
            });
        },
        async canCollect(name) {
            const response = await cancelCollect({ name: name })
            if (response.status === 200) {
                console.log(response)
                this.apiInit()
                this.isCollent = true
                this.$message({
                    type: 'success',
                    message: response.data.msg
                });
            }
        },
        async apiSave() {
            try {
                const response = await personnelSave(this.saveParam)
                if (response.status === 200) {
                    console.log(response)
                    this.$message({
                        type: 'success',
                        message: response.data.msg
                    });
                    this.done()
                }
            } catch {
                console.error('接口调用失败')
            }
        },
        handleClickTag(event) {
            console.log(event)
            console.log('tasks', this.collectParam)
            const flowTaskUsers = event.flowTaskUsers//collet.flowTaskUsers
            let tasks =  this.collectParam.flowTaskUsers;//user
            for(let i=0;i<tasks.length;i++){
                let thisFlowTaskUsers = tasks[i];
                console.log('thisFlowTaskUsers',thisFlowTaskUsers)
                for(let j=0;j<flowTaskUsers.length;j++){
                    let thisFflowTaskUsers = flowTaskUsers[j];
                    if(thisFlowTaskUsers.taskId==thisFflowTaskUsers.taskId){
                        thisFlowTaskUsers['userName']=thisFflowTaskUsers.userName;
                        thisFlowTaskUsers['userId']=thisFflowTaskUsers.userId;
                    }
                }
            }
            console.log(this.collectParam)
        },
        handleCloseTag(event) {
            console.log(event)
            this.canCollect(event.name)
        },
        handleSelect(event, index) {
            const res = this.typeName.find(item => item.userId === event)
            const { userName } = res
            let users = { ... this.collectParam.flowTaskUsers[index], userName }
            console.log(users)
            this.users[index] = users
        },
        done() {
            this.dialogVisible = false
        },
        handleCancel() {
            this.done()
        },
        handleConfirm() {
            console.log(this.saveParam)
            this.apiSave()
        }
    }
}
</script>
<style lang="scss">
.el-tag+.el-tag {
    margin-left: 10px;
    margin-top: 10px;
}
 
.button-new-tag {
    margin-left: 10px;
    height: 32px;
    line-height: 30px;
    padding-top: 0;
    padding-bottom: 0;
}
 
.input-new-tag {
    width: 90px;
    margin-left: 10px;
    vertical-align: bottom;
}
 
.btns-icon {
    display: flex;
    justify-content: end;
    padding-bottom: 10px;
}
</style>