“dzb”
2022-10-21 a598d935a61fea27312fc57becd80e23bf09f788
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
<template>
    <div class="createUser">
        <main>
            <div class="mainContent">
                <el-form ref="user" label-width="140px" autoComplete="on" :model="role" :rules="createRoleRules"
                    label-position="right">
                    <!-- 消息栏目 -->
                    <el-form-item class="optionItem" label="消息栏目:" prop="messageType">
                        <div class="message-item">
                            <div class="message-item__left">
                                <el-select v-model="role.messageType" placeholder="请选择消息栏目">
                                    <el-option v-for="item in colList" :key="item.id" :label="item.columnName"
                                        :value="item.id">
                                    </el-option>
                                </el-select>
                            </div>
                            <span class="message-add" @click='dialogCreate = true'> 添加栏目</span>
                        </div>
                    </el-form-item>
                    <!-- 消息标题 -->
                    <el-form-item class="optionItems" label="消息标题:" prop="head">
                        <div class="message-item__left">
                            <el-input v-model="role.head" placeholder="请选择消息标题"></el-input>
                        </div>
                    </el-form-item>
                    <!-- 接收对象 -->
                    <el-form-item class="optionItem" label="接收对象:" prop="targetTo">
                        <div class="message-item__left">
                            <el-select v-model="role.targetTo" placeholder="请选择接收对象" >
                                <el-option :value="role.targetTo">
                                    <el-tree ref="tree" :data="departList" :props="defaultProps" show-checkbox
                                        @check="handleCheck" default-expand-all node-key="id">
                                    </el-tree>
                                </el-option>
                            </el-select>
                        </div>
                    </el-form-item>
                    <!-- 消息内容 -->
                    <el-form-item class="optionItem" label="消息内容:" prop="body">
                        <MyEditor ref="edit" @getMyBody="getMyBody"></MyEditor>
                        <!-- <el-input type="textarea" v-model="role.description" placeholder="请输入描述内容200字以内"></el-input> -->
                    </el-form-item>
                    <!-- 提醒方式 -->
                    <el-form-item class="optionItem" label="提醒方式:" prop="channelCode">
                        <el-radio-group v-model="role.channelCode">
                            <el-radio label="01">站内信</el-radio>
                            <el-radio label="02">邮件</el-radio>
                            <el-radio label="03">短信</el-radio>
                        </el-radio-group>
                        <span class="message-tip">(短信可用数: 1000条)</span>
                    </el-form-item>
                    <el-form-item>
                        <div class="optionBtn">
                            <el-button type="primary" @click.native.prevent="handleSubmit(0)" class="btn save">保存
                            </el-button>
                            <el-button type="primary" @click.native.prevent="handleSubmit(1)" class="btn submit">发布
                            </el-button>
                            <el-button type="primary" @click.native.prevent="handleView" class="btn submit">预览
                            </el-button>
                            <el-button class="btn cancel" @click.native.prevent="handleReset">重置</el-button>
                        </div>
                    </el-form-item>
                </el-form>
                <!-- 新增栏目 -->
                <el-dialog title="添加栏目" :visible.sync="dialogCreate" v-if="dialogCreate" width="60%"
                    :before-close="handleConfirmClose" append-to-body>
                    <MyColumnAdd @closeDialog="closeDialog"></MyColumnAdd>
                </el-dialog>
                <!-- 预览消息 -->
                <el-dialog title="消息预览" :visible.sync="dialogView" v-if="dialogView" width="60%"
                    :before-close="handleConfirmClose" append-to-body>
                    <MyColView  :info="info" @closeDialog="closeDialog"></MyColView>
                </el-dialog>
            </div>
        </main>
    </div>
</template>
<script>
import MyEditor from '@/components/edit'
import MyColumnAdd from '@/views/operate/message/mycontrol/createUser'
import MyColView from '../messageView'
export default {
    components: { MyEditor, MyColumnAdd,MyColView },
    data() {
        const validateNickname = (rule, value, callback) => {
            if (!value) {
                callback(new Error("请填写消息栏目"));
            } else {
                callback();
            }
        };
        const validatePass = (rule, value, callback) => {
            if (!value) {
                callback();
            } else {
                callback();
            }
        };
        const validateTruename = (rule, value, callback) => {
            if (value.length !== 0) {
                callback();
            } else {
                callback(new Error('请选择接收对象'));
            }
        };
        return {
            role: {
                messageType: '',
                head: '',
                targetTo: '',
                targetFrom: null,
                body: '',
                channelCode: '01',
            },
            createRoleRules: {
                messageType: [
                    { required: true, trigger: "blur", validator: validateNickname },
                ],
                head: [
                    { required: false, trigger: "blur", validator: validatePass },
                ],
                targetTo: [
                    { required: false, trigger: "blur", validator: validateTruename },
                ],
            },
            colList: [],
            departList: [],
            typeList: [],
            dialogCreate: false,
            dialogView: false,
            defaultProps: {
                children: 'children',
                label: 'departName',
                // disabled: function (data, node) {
                //     if (data.createTime) {
                //         return !data.leaf
                //     }
                // }
            },
            checkedList: [],
            tempNameArr:[],
            info:{},
            sendUser:""
        }
    },
    created() {
        this.setColumnList();
        this.setDepartList();
        this.getLoginUserInfo();
    },
    methods: {
        // 关闭弹窗
        handleConfirmClose(done) {
            this.$confirm('确认关闭?')
                .then(_ => {
                    done();
                })
        },
        // 设置栏目
        async setColumnList() {
            this.colList = await this.getColumnList();
        },
        // 获取栏目
        async getColumnList() {
            let arr;
            await this.$axios({
                method: 'get',
                url: 'sccg/message_column/getAllColumn'
            })
                .then(res => {
                    console.log(res);
                    arr = res.data;
                })
            return arr;
        },
        // 关闭弹窗
        closeDialog({ flag, index }) {
            this.dialogCreate = flag;
            if (index === 1) {
                // 重新设置栏目
                this.setColumnList();
            }
        },
        // 获取部门树
        async getDepartList() {
            let arr
            await this.$axios({
                method: 'get',
                url: 'sccg/depart/tree'
            })
                .then(res => {
                    arr = res.data
                })
            return arr;
        },
        // 设置部门树
        async setDepartList() {
            this.departList = await this.filterDepartList();
        },
        // 处理部门树
        async filterDepartList() {
            let arr = await this.getDepartList();
            const { setChildren } = this;
            // console.log(setChildren);
            arr.forEach(item => {
                setChildren(item);
            })
            return arr;
        },
        // 递归children
        setChildren(obj) {
            if (obj.children !== null) {
                if (obj.children.length !== 0) {
                    obj.children.forEach(item => {
                        return this.setChildren(item);
                    })
                }
            } else {
                if (obj.userInfoDTOS.length !== 0) {
                    obj.children = [];
                    obj.userInfoDTOS.forEach(item => {
                        obj.children.push({ id: item.userId, departName: item.username })
                    })
                }
            }
        },
        // 选中id
        handleCheck(data, node) {
            let arr = [],nameArr = []
            console.log(node.checkedNodes)
            node.checkedNodes.forEach(item => {
                if(!item.hasOwnProperty('departType')){
                    arr.push(item.id)
                    nameArr.push(item.departName)
                }
            })
            this.checkedList = arr
            this.tempNameArr = nameArr
            console.log(this.tempNameArr)
            this.role.targetTo = arr.length + '人'
        },
        // 新建/保存消息(1:新建,0保存消息)
        handleSubmit(mystatus) {
            this.$refs.user.validate((valid) => {
                if (valid) {
                    const { role, checkedList } = this;
                    console.log(checkedList);
                    this.$axios({
                        method: 'post',
                        url: 'sccg/message/sendMessage',
                        data: {
                            body: role.body,
                            channelCode: `${role.channelCode}`,
                            head: role.head,
                            messageType: role.messageType,
                            sendTime: new Date(),
                            targetTo: checkedList.join(','),
                            targetFrom: `${role.targetFrom}`,
                            status: mystatus,
                        }
                    })
                        .then(res => {
                            if (res.code === 200) {
                                this.$message({
                                    type: 'success',
                                    message: mystatus === 1 ? '发送成功' : '保存成功',
                                })
                                this.$emit('closeMyDialog', { flag: false, index: 1 });
                            }
                        })
                } else {
                    return false;
                }
            })
        },
        // 获得消息体
        getMyBody(obj) {
            console.log(obj);
            this.role.body = obj;
        },
        // 重置表单
        handleReset() {
            this.$refs.edit.editor.txt.clear();
            // this.$refs.edit.wangEditor.txt.html('<p><br></p>') 
            this.setDepartList();
            this.$refs.user.resetFields();
        },
        // 获取当前登录用户信息
        getLoginUserInfo() {
            const name = sessionStorage.getItem('name');
            this.$axios({
                method: 'get',
                url: 'sccg/admin/info?name=' + name,
            })
                .then(res => {
                    this.role.targetFrom = res.data.userId
                    this.sendUser = res.data.username
                })
        },
        // 消息预览
        handleView() {
            this.$refs.user.validate((valid) => {
                if (valid) {
                    const { role,getColText,tempNameArr,sendUser } = this
                    this.dialogView = true;
                    let info = {}
                    // 获得栏目消息
                    info.channelCode = role.channelCode === '01'? '站内信': role.channelCode === '02' ? '邮件':'短信'
                    info.messageType = getColText(role.messageType)
                    info.body = role.body
                    info.head = role.head
                    info.targetTo = tempNameArr
                    info.targetFrom = sendUser
                    this.info = info
                } else {
                    return false
                }
            })
        },
        // 获得栏目消息
        getColText(id){
            console.log(id)
            const {colList} = this
            let str = ''
            colList.forEach(item=>{
                item.id === id ? str = item.columnName : '' 
            })
            return str
        }
    },
    props: ['closeMyDialog']
}
</script>
<style lang="scss" scoped>
.createUser {
    border-radius: 1px;
    background-color: #09152f;
 
    main {
        text-align: left;
        padding: 0 55px;
        background-color: #09152f;
        padding-bottom: 50px;
 
        .mainContent {
            display: flex;
            justify-content: center;
            padding-top: 50px;
            &:deep(.el-dialog__title) {
                color: #4b9bb7;
            }
            &::v-deep .el-form-item__label {
                color: #4b9bb7;
            }
 
            &::v-deep .el-input__inner {
                width: 400px;
                background-color: #09152f;
                border: 1px solid #17324c;
            }
 
            .message-item__left {
                width: 400px;
            }
 
            .message-add {
                &:hover {
                    cursor: pointer;
                }
            }
 
            .el-form-item__content :deep(.el-select) {
                width: 400px;
            }
 
            :deep(.el-input) {
                width: 400px;
            }
 
            .message-item {
                display: flex;
 
                span {
                    margin-left: 20px;
                    color: #4b9bb7;
                }
            }
 
            .message-tip {
                margin-left: 20px;
            }
 
            :deep(.el-input--suffix) {
                width: 400px;
            }
 
            &::v-deep .el-textarea__inner {
                background-color: #09152f;
                border: 1px solid #17324c;
            }
 
            .el-form-item__content {
                width: 400px;
 
                .el-select {
                    width: 100%;
                }
            }
 
            .optionHandleSp {
                display: flex;
 
                .areaNumber,
                .moreNumber {
                    flex: 1;
                }
 
                .telNumber {
                    flex: 2;
                }
            }
 
            .optionBtn {
                display: flex;
                margin-top: 20px;
 
                .btn {
                    padding: 12px 50px;
                }
            }
 
        }
    }
}
</style>