schemeDetail.jsx 21.7 KB
Newer Older
1 2
import React, { useState, useEffect, useRef } from 'react'
import SiteModal from '@/components/Modal/SiteModa';
3
import { Form, Input, notification, Select, Checkbox, message, Button, Card, Switch as Switchs } from 'antd'
4 5 6 7 8
import BaseForm from '@/components/BaseForm/index';
import { Switch } from 'react-router';
import { iteratee } from 'lodash';
import styles from './schemeDetail.less';
import v from 'voca';
9 10

import { UsergroupDeleteOutlined } from '@ant-design/icons';
11 12 13 14 15
import VisibleRoleModal from '../messageManage/projectManage/components/RolseSelect/VisibleRoleModal'
import VisibleIISAgentConfig from '../messageManage/projectManage/components/IISAgentConfig/VisibleIISAgentConfig'
import { GetMessageTemplate } from '@/services/platform/messagemanage'
import moment from 'moment'
import { UpdateMessageConfig, InsertMessageConfig, AddIISAgentConfig } from '@/services/platform/messagemanage'
16
import { useHistory } from 'react-router-dom';
17 18 19 20
const { Item } = Form;

const EditModal = props => {

21
    const history = useHistory();
22 23
    const [form] = Form.useForm();
    const [loading, setLoading] = useState(false);
24
    const [plan,setPlan]= useState('');
25 26
    const [isStart, setIsStart] = useState(false);
    const [IISConfig, setIISConfig] = useState(null)
27 28
    const [isUse, setIsUse] = useState("0")
    const [btnType, setBtnType] = useState("定时推送")
29 30 31 32 33 34 35 36 37 38 39
    const { template, confirmModal } = props.location.state
    const [currentTrench, setCurrentTrench] = useState({
        isMessageShow: false,
        isAPPShow: false,
        isWEBShow: false,
        isWXShow: false
    })
    const [APP_ITEMS, setAPP_ITEMS] = useState([])
    const [WEB_ITEMS, setWEB_ITEMS] = useState([])
    const [WX_ITEMS, setWX_ITEMS] = useState([])
    const [MES_ITEMS, setMES_ITEMS] = useState([])
40
    const [listType, setListType] = useState([{ title: '定时推送', desc: '用于周期性简报的定时推送,如智能巡检、运行周报。' }, { title: '监控报警', desc: '设备硬件故障,阈值超限,状态突变,采集超时等异常情况报警。' }, { title: '工单办理', desc: '在工单系统中,针对特定人员的通知,包括工作办理、审核、会签、回退等操作。' }, { title: '平台公告', desc: '由运维人员向所有用户或特定用户发送的事务公告,如系统升级、维护。' }])
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

    useEffect(() => {
        GetMessageTemplate().then(
            res => {
                if (res.code === 0) {
                    let arr1 = []
                    let arr2 = []
                    let arr3 = []
                    let arr4 = []
                    res.data.map((item, index) => {
                        if (item.Type === "公众号") {
                            arr1.push(item)
                        }
                        if (item.Type === "短信") {
                            arr2.push(item)
                        }
                        if (item.Type === "APP") {
                            arr3.push(item)
                        }
                        if (item.Type === "WEB") {
                            arr4.push(item)
                        }
                    })
                    setAPP_ITEMS(arr3)
                    setMES_ITEMS(arr2)
66
                    console.log('arr1', arr1);
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
                    setWX_ITEMS(arr1)
                    setWEB_ITEMS(arr4)
                }
            }
        )
    }, [])
    useEffect(() => {
        if (template.ThemeName) {
            form.setFieldsValue({
                name: template.MsgType,
                isStart: template.IsStarted === "0" ? "关闭" : "开启",
                to_person: template.PushGroup,
                push_mode: template.PushMode === null ? '' : template.PushMode.split(","),

                app_template: template.AppTemplateID,
                app_path: template.AppFunctionPath,
83
                wx_template: template.PublicTemplateID ? parseInt(template.PublicTemplateID) : '',
84 85 86 87 88 89
                h5_path: template.PublicPath,
                miniprogram_path: template.MiniAppRoute,
                web_template: template.WebTemplateID,
                web_path: template.WebFunctionPath,
                message_template: template.MsgTemplateID,
            })
90 91 92
            setPlan(template.MsgType)
            setBtnType(template.type)
            setIsUse(template.IsStarted)
93 94 95
            setCurrentTrench({
                isAPPShow: template.PushMode && template.PushMode.split(",").indexOf("平台弹框") > -1 ? true : false,
                isWXShow: template.PushMode && template.PushMode.split(",").indexOf("公众号推送") > -1 ? true : false,
96 97
                isWEBShow: template.PushMode && template.PushMode.split(",").indexOf("平台弹框") > -1 ? true : false,
                isMessageShow: template.PushMode && template.PushMode.split(",").indexOf("短信推送") > -1 ? true : false,
98 99
            })
        }
100 101 102
        else {
            setBtnType('定时推送')
        }
103 104 105

    }, [props])
    const onNameChange = (e) => {
106 107 108
     
        setPlan(e.target.value)
      
109 110 111 112
    }

    const onSubmit = () => {
        let fv = form.getFieldValue()
113 114
        console.log('fv',fv);
        let push_mode = ((currentTrench.isAPPShow || currentTrench.isWEBShow) ? '平台弹框' : '') + (currentTrench.isWXShow ? ',公众号推送' : '') + (currentTrench.isMessageShow ? ',短信推送' : '')
115 116 117 118 119
        if (template.ThemeName) {
            let a = {
                ID: template.ID,
                ThemeName: template.ThemeName,
                MsgType: fv.name,
120
                PublicTemplateID: fv.wx_template.toString(),
121 122 123 124 125 126 127 128 129 130 131 132 133
                PublicConfig: template.PublicConfig,
                PublicPath: fv.h5_path,
                MsgTemplateName: template.MsgTemplateName,
                MsgTemplateCode: template.MsgTemplateCode,
                MsgConfig: template.MsgConfig,
                MiniAppRoute: fv.miniprogram_path,
                AppFunctionPath: fv.app_path,
                AppConfig: template.AppConfig,
                WebFunctionPath: fv.web_path,
                WebConfig: template.WebConfig,
                IsDelete: template.IsDelete,
                InputTime: moment().format("YYYY-MM-DD HH:mm:ss"),
                Pusher: template.Pusher,
134
                PushMode: push_mode,
135
                PushPath: template.PushPath,
136
                IsStarted: isUse,
137 138 139
                MsgTemplateID: fv.message_template,
                AppTemplateID: fv.app_template,
                WebTemplateID: fv.web_template,
140
                PushGroup: fv.to_person ? fv.to_person.toString() : ''
141
            }
142

143 144 145 146 147 148 149 150
            UpdateMessageConfig(a).then(
                res => {
                    if (res.code === 0) {
                        if (IISConfig) {
                            AddIISAgentConfig(IISConfig).then(
                                res => {
                                    if (res.code === 0) {
                                        message.success("保存成功")
151

152 153 154 155 156 157
                                    }
                                }
                            )
                        } else {
                            message.success("保存成功")

158 159 160 161 162 163 164 165
                        }
                    }
                    else {
                        notification.error({
                            message: '提示',
                            duration: 3,
                            description: res.msg,
                        });
166 167 168 169 170 171 172 173
                    }
                }
            )

        } else {
            let b = {
                ThemeName: "定时推送",
                MsgType: fv.name,
174
                PublicTemplateID: fv.wx_template?fv.wx_template.toString():null,
175 176 177 178 179 180 181 182 183 184 185 186 187
                PublicConfig: template.PublicConfig,
                PublicPath: fv.h5_path,
                MsgTemplateName: template.MsgTemplateName,
                MsgTemplateCode: template.MsgTemplateCode,
                MsgConfig: template.MsgConfig,
                MiniAppRoute: fv.miniprogram_path,
                AppFunctionPath: fv.app_path,
                AppConfig: template.AppConfig,
                WebFunctionPath: fv.web_path,
                WebConfig: template.WebConfig,
                IsDelete: template.IsDelete,
                InputTime: moment().format("YYYY-MM-DD HH:mm:ss"),
                Pusher: template.Pusher,
188
                PushMode: push_mode,
189
                PushPath: template.PushPath,
190
                IsStarted: isUse,
191 192 193
                MsgTemplateID: fv.message_template,
                AppTemplateID: fv.app_template,
                WebTemplateID: fv.web_template,
194
                PushGroup: fv.to_person ? fv.to_person.toString() : ''
195 196 197 198 199 200 201 202 203
            }
            InsertMessageConfig(b).then(
                res => {
                    if (res.code === 0) {
                        if (IISConfig) {
                            AddIISAgentConfig(IISConfig).then(
                                res => {
                                    if (res.code === 0) {
                                        message.success("保存成功")
204 205 206 207 208 209 210 211

                                    }
                                    else{
                                        notification.error({
                                            message: '提示',
                                            duration: 3,
                                            description: res.msg,
                                        });
212 213 214 215 216 217 218
                                    }
                                }
                            )
                        } else {
                            message.success("保存成功")
                        }
                    }
219 220 221 222 223 224 225
                    else {
                        notification.error({
                            message: '提示',
                            duration: 3,
                            description: res.msg,
                        });
                    }
226 227 228 229 230
                }
            )
        }

    }
231

232

233 234 235 236 237 238 239 240
    const onIISAgentSubmit = (value) => {
        setIISConfig(value)

    }

    const onPushSubmit = (value) => {
        console.log(value, "onPushSubmit")
    }
241 242 243 244 245 246 247 248 249
    const layout = {
        layout: 'horizontal',
        labelCol: {
            span: 2,
        },
        wrapperCol: {
            span: 24,
        },
    };
250 251
    const onChange = (value) => {
             setIsUse(value?'1':'0')
252 253 254 255 256 257 258
    }
    const back = () => {
        history.push('/platformCenter/notify')
    }
    const tailLayout = {
        wrapperCol: { offset: 21, span: 24 },
    };
259 260 261 262
    const onTypeChange = (value, type) => {
        let data = { ...currentTrench }
        data[type] = value
        setCurrentTrench(data)
263
    }
264
    return (
265 266

        <div className={styles.editModal_container}>
267
            <Form form={form}  {...layout} onFinish={onSubmit}>
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
                <div className={styles.content}>
                    <Card title="方案" style={{ width: '100%' }}>
                        <Item
                            label="方案名称"
                            name="name"
                            rules={[
                                {
                                    required: true,
                                    message: '请输入方案名称',
                                },
                            ]}
                        >
                            <Input style={{ width: '25rem' }} placeholder="请输入方案名称" disabled={template.ThemeName ? true : false} onChange={onNameChange} />
                        </Item>
                        <Item
                            label="方案类型"

                        >
                            <div className={styles.cardList}>
                                {listType.map(item => {
288
                                    return <div key={item.title} className={styles.cardListItem}><Button type={item.title === btnType ? 'primary' : 'default'} style={{ cursor: 'not-allowed', marginRight: '1rem' }} >{item.title}</Button> <span>{item.desc}</span></div>
289 290 291 292 293 294
                                })}

                            </div>
                        </Item>

                    </Card>
295 296 297 298 299 300 301 302
                    {btnType === '定时推送' && (<Card title="推送信息" style={{ width: '100%', marginTop: '1rem' }}>
                        <div style={{ display: 'flex', alignItems: 'center' }}>
                            <Item
                                label="推送组"
                                name="to_person"
                                labelCol={{ span: 5 }}
                                style={{ paddingTop: '1.6rem', width: '35rem' }}
                            >
303
                                <VisibleRoleModal
304
                                    style={{ display: 'flex', width: '35rem', alignItems: 'center' }}
305
                                    onSubmit={onPushSubmit}
306 307 308 309 310 311
                                    selectValue={template && template.PushGroup ? template.PushGroup : []}
                                    title={<UsergroupDeleteOutlined style={{ fontSize: '18px' }} />} />
                            </Item>

                            <div style={{ display: 'flex', width: '30rem', margin: '0 2rem', alignItems: 'center' }}>
                                推送计划: <VisibleIISAgentConfig agentConfig={template.item && template.item.AgentConfig} value={plan} onIISAgentSubmit={onIISAgentSubmit} />
312 313
                            </div>
                            <span>
314
                                是否启用:<Switchs checked={isUse === '0' ? false : true} onChange={onChange} />
315 316 317
                            </span>
                        </div>

318
                    </Card>)}
319 320
                    <div className={styles.push_trench}>
                        {
321 322 323 324

                            <div className={styles.trench_card}>
                                <div className={styles.card_title}>
                                    <div className={styles.lable}>APP</div>
325
                                    <Switchs onChange={e => onTypeChange(e, 'isAPPShow')} checked={currentTrench.isAPPShow} />
326
                                </div>
327 328 329 330
                                <div className={styles.card_body}>
                                    <Item
                                        label="模板"
                                        name="app_template"
shaoan123's avatar
shaoan123 committed
331
                                        labelCol={{ span: 3 }}
332
                                    >
333
                                        <Select style={{ width: '97%' }} disabled={!currentTrench.isAPPShow} >
334 335 336 337 338 339 340 341 342 343 344 345
                                            {
                                                APP_ITEMS.map((item, idx) => {
                                                    return (
                                                        <Select.Option value={item.Id} key={idx}>{item.LikeName}</Select.Option>
                                                    )
                                                })
                                            }
                                        </Select>
                                    </Item>
                                    <Item
                                        label="功能路径"
                                        name="app_path"
shaoan123's avatar
shaoan123 committed
346
                                        labelCol={{ span: 3 }}
347
                                    >
348
                                        <Input style={{ width: '97%' }} disabled={!currentTrench.isAPPShow} placeholder="请输入功能路径" />
349 350 351 352
                                    </Item>
                                </div>
                            </div>

353 354
                        }
                        {
355 356 357 358

                            <div className={styles.trench_card}>
                                <div className={styles.card_title}>
                                    <div className={styles.lable}>微信</div>
359
                                    <Switchs onChange={e => onTypeChange(e, 'isWXShow')} checked={currentTrench.isWXShow} />
360
                                </div>
361 362 363 364 365 366
                                <div className={styles.card_body}>
                                    <Item
                                        label="模板"
                                        name="wx_template"
                                        labelCol={{ span: 4 }}
                                    >
367
                                        <Select style={{ width: '97%' }} disabled={!currentTrench.isWXShow} >
368 369 370 371 372 373 374 375 376 377 378 379 380 381
                                            {
                                                WX_ITEMS.map((item, idx) => {
                                                    return (
                                                        <Select.Option value={item.Id} key={idx}>{item.LikeName}</Select.Option>
                                                    )
                                                })
                                            }
                                        </Select>
                                    </Item>
                                    <Item
                                        label="H5路由"
                                        name="h5_path"
                                        labelCol={{ span: 4 }}
                                    >
382
                                        <Input style={{ width: '97%' }} disabled={!currentTrench.isWXShow} placeholder="请输入功能路径" />
383 384 385 386 387 388
                                    </Item>
                                    <Item
                                        label="小程序路由"
                                        name="miniprogram_path"
                                        labelCol={{ span: 4 }}
                                    >
389
                                        <Input style={{ width: '97%' }} disabled={!currentTrench.isWXShow} placeholder="请输入功能路径" />
390 391 392 393
                                    </Item>
                                </div>
                            </div>

394 395
                        }
                        {
396 397 398 399

                            <div className={styles.trench_card}>
                                <div className={styles.card_title}>
                                    <div className={styles.lable}>WEB</div>
400
                                    <Switchs onChange={e => onTypeChange(e, 'isWEBShow')} checked={currentTrench.isWEBShow} />
401
                                </div>
402 403 404 405
                                <div className={styles.card_body}>
                                    <Item
                                        label="模板"
                                        name="web_template"
shaoan123's avatar
shaoan123 committed
406
                                        labelCol={{ span: 3 }}
407
                                    >
408
                                        <Select style={{ width: '97%' }} disabled={!currentTrench.isWEBShow}>
409 410 411 412 413 414 415 416 417 418 419 420
                                            {
                                                WEB_ITEMS.map((item, idx) => {
                                                    return (
                                                        <Select.Option value={item.Id} key={idx}>{item.LikeName}</Select.Option>
                                                    )
                                                })
                                            }
                                        </Select>
                                    </Item>
                                    <Item
                                        label="功能路径"
                                        name="web_path"
shaoan123's avatar
shaoan123 committed
421
                                        labelCol={{ span: 3 }}
422
                                    >
423
                                        <Input style={{ width: '97%' }} disabled={!currentTrench.isWEBShow} placeholder="请输入功能路径" />
424 425 426 427
                                    </Item>
                                </div>
                            </div>

428 429 430
                        }

                        {
431 432 433 434

                            <div className={styles.trench_card}>
                                <div className={styles.card_title}>
                                    <div className={styles.lable}>短信推送</div>
435
                                    <Switchs onChange={e => onTypeChange(e, 'isMessageShow')} checked={currentTrench.isMessageShow} />
436
                                </div>
437 438 439 440 441 442
                                <div className={styles.card_body}>
                                    <Item
                                        label="模板"
                                        name="message_template"
                                        labelCol={{ span: 4 }}
                                    >
443
                                        <Select style={{ width: '97%' }} disabled={!currentTrench.isMessageShow} >
444 445 446 447 448 449 450 451 452 453 454 455
                                            {
                                                MES_ITEMS.map((item, idx) => {
                                                    return (
                                                        <Select.Option value={item.Id} key={idx}>{item.LikeName}</Select.Option>
                                                    )
                                                })
                                            }
                                        </Select>
                                    </Item>
                                </div>
                            </div>

456 457
                        }
                    </div>
458 459 460 461 462 463 464 465 466 467 468 469

                </div>
                <Item  {...tailLayout} style={{ marginTop: '1rem' }}>
                    <Button htmlType="button" onClick={back} style={{ marginRight: '2rem' }}>
                        返回
                    </Button>
                    <Button type="primary" htmlType="submit">
                        确定
                    </Button>
                </Item>
            </Form>
            <div>
470
            </div>
471
        </div>
472 473 474
    )
}
export default EditModal;