msgPush.js 13.9 KB
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
import React,{Component} from 'react';
import './style.less';
import WhiteBar from '../../components/Common/WhiteBar';
import {Table,Input,Form,Button,Row,Col,Select,DatePicker,Message,Icon,Modal,Tree} from 'antd';
import axios from '@src/axios/index';
import Utils from '@src/utils/utils';
import { API_SYS_MSG } from '@src/Api';
import storage from '@src/utils/localStorage'

import { connect } from 'react-redux';
import { saveMsgStatus } from '@src/redux/common/action';

/* 消息推送 */
class MsgPush extends Component {
	state = {
		// 搜索表单状态
		expandStatus: false,
		// 搜索条件
		searchData: {},
		// 消息列表
		msgLists: [],
		// 分页信息
		pagination: {},
		// 加载状态
		isLoading: true,
		//按钮权限
		btnAuth: null,
		//是否显示操作列
	    isShowOpt: true,

	}

	// 查询页数和数量配置
	params = {
	    pageNum: 1,
	    pageSize: 10
	}
	componentWillMount () {
		let btnAuth = localStorage.btnAuth
        this.setState({btnAuth,})
      if(
        (btnAuth.indexOf('msgPush-edit') === -1 &&
        btnAuth.indexOf('msgPush-delete') === -1 &&
        btnAuth.indexOf('msgPush-stopOrStart') === -1) &&
        (btnAuth.indexOf('msgPush-pushAgain') === -1 && btnAuth.indexOf('msgPush-edit') === -1 &&
        btnAuth.indexOf('msgPush-delete') === -1 )){
        this.setState({isShowOpt: false})
      }
	}
	componentDidMount () {
		this.getMsgList();
	}
	// 消息新增
	addNewMsg = () => {
		this.props.history.push({
			pathname: '/home/msgpush/msgAddNew'
		});
	}
	// 消息修改
	upDateMsg = (item,records) => {
		this.props.history.push({
			pathname: '/home/msgpush/msgAddNew',
			state: records
		});
	}
	// 获取消息列表
	getMsgList = () => {
		let searchData = this.state.searchData;
		let _this = this;
		axios.ajax({
			url: API_SYS_MSG.getSysMsgListByCondition,
			data: {
				...this.params,
				...searchData
			}
		}).then((res) => {
			// 加key赋值
			let msgLists = [];
			msgLists = res.records.map((item,index) => {
				return {...item,key: index};
			});
			this.setState({
				isLoading: false,
				msgLists,
				pagination: Utils.pagination(res, (current) => {
		            _this.params.pageNum = current;
		            _this.setState({isLoading: true});
		            this.getMsgList(searchData);
		        })
			});
		});
	}
	// 查询获取列表信息
	search = (searchData) => {
		this.params.pageNum = 1;
		this.setState({isLoading: true});
		this.setState({searchData}, () => {
			this.getMsgList();
		});
	}
	// 重置查询
	reset = () => {
		this.params.pageNum = 1;
		this.setState({isLoading: true});
		this.setState({searchData: {}}, () => {
			this.getMsgList();
		});
	}
	// 表单折叠
	expandMenu = () => {
		this.setState({
	     	expandStatus: !this.state.expandStatus,
	    })
	}
	// 消息删除
	handleDelete = (item,id,messageTitle) => {
		Modal.confirm({
			title: '删除',
			content: `您要删除推送消息 : ${messageTitle} ?`,
			okText:"确认",
			cancelText:"取消",
			onOk: () => {
				axios.ajax({
					url: API_SYS_MSG.deleteSysMsg,
					data: {id}
				}).then((res) => {
					Message.success('删除成功');
					this.getMsgList();
				});
			}
		})
	}
	// 消息状态启/停用
	handleUsingStatus = (item,id,usingStatus) => {
		let optName ="停用",optStatus=1
		if(usingStatus==1){
           optName="启用"
           optStatus=2
		}
		Modal.confirm({
			title: '注意',
			content: `是否确认${optName}?`,
			okText:"确认",
			cancelText:"取消",
			onOk: () => {
				axios.ajax({
					url: API_SYS_MSG.updateUsingStatus,
					data: {
						id:id,
						usingStatus:optStatus}
				}).then((res) => {
					Message.success(`${optName}成功`);
					this.getMsgList();
				});
			}
		})

	}
	// 查看消息详情
	getMsgDetail = (item,id) => {
		this.props.history.push({
			pathname: `/home/msgpush/msgDetail/${id}`
		});
	}
	// 再次推送
	pushAgain = (records,item,id) => {
		let userInfo = storage.get('userInfo')
		axios.ajax({
			url: API_SYS_MSG.pushAgain,
			data: {id}
		}).then((res) => {
			//this.props.saveMsgStatus(true, 'MSGSTATUS')
			Message.success('推送消息成功');
		});
	}
	render () {
		const columns = [
			{title: '消息类型', width: 110, dataIndex: 'messageType', key: 'messageType',render: (messageType) => {
				return {'1':'pc','2':'app','3': '短信','4': '邮件','5':'微信'}[messageType]
			}},
			{title: '消息标题', width: 120, render: (item) => {
				let {messageTitle,id} = item;
				return (
					<Button className="tdWidth" onClick={(item) => {this.getMsgDetail(item,id)}} title={messageTitle}>{Utils.formatTableColumn(messageTitle)}</Button>
				);
			}},
			// {title: '内容',width: 120, className:'tdWidth',dataIndex: 'messageContent', key: 'messageContent', render: (messageContent) => {
			// 	return Utils.formatTableColumn(messageContent);
			// }},
			{title: '发送者', width: 120,dataIndex: 'pushAccount', className:"tdWidth", render: (pushAccount) => {
				return Utils.formatTableColumn(pushAccount);
			}},
			{title: '接受者',width: 120, dataIndex: 'receiverAccount', className:"tdWidth", key: 'receiverAccount', render: (receiverAccount) => {
				return  Utils.formatTableColumn(receiverAccount);
			}},
			{title: '执行时间',width: 160, dataIndex: 'pushTime',render: (pushTime) => {
				// return Utils.formateDateToYMDSFM(pushTime);
				return Utils.formateDateToDetail(pushTime, 'seconds');
			}},
			{title: '展示时间段',width: 250,render: (text, record, index) => {
				return (
					<div>
						<p style={{display: 'inline-block',textAlign:'center'}}>
							<p>{Utils.formateDateToYMD(record.displayBeginTime)}</p>
							<p>{Utils.formateDateToSFM(record.displayBeginTime)}</p>
						</p>
						<p style={{display: 'inline-block',padding:'0 10'}}>--</p>
						<p style={{display: 'inline-block',textAlign: 'center'}}>
							<p>{Utils.formateDateToYMD(record.displayEndTime)}</p>
							<p>{Utils.formateDateToSFM(record.displayEndTime)}</p>
						</p>
					</div>
				)
			}},
			{title: '推送状态',width: 120, dataIndex: 'pushStatus', key: 'pushStatus', render: (pushStatus) => {
				return {'1': '未推送','2':'推送中','3':'推送成功','4':'推送失败'}[pushStatus]
			}},
			{title: '状态',width: 100, dataIndex: 'usingStatus', key: 'usingStatus',render: (usingStatus) => {
				return {'1': '停用','2': '启用'}[usingStatus]
			}},
			{title: '创建时间',width: 120, dataIndex: 'createTime', key: 'createTime', render: (createTime) => {
				return Utils.formateDateToYMD(createTime)
			}},

		];
		if (this.state.isShowOpt) {
	        columns.push(
               {
	               	title: '操作',width: 350,className:'operatBtns',align: 'center',render: (item,record) => {
						let {pushFlag,pushStatus,usingStatus,id,messageType,messageTitle} = item;
						let records = record;
						if ((pushStatus == 1) && (usingStatus == 1)) {
							return (
								<div>
								    {
							          this.state.btnAuth.indexOf('msgPush-stopOrStart') !== -1 ?
							          <Button onClick={(item) => {this.handleUsingStatus(item,id,usingStatus)}}>启用</Button>
							          : ''
							        }
									{
							          this.state.btnAuth.indexOf('msgPush-edit') !== -1 ?
							          <Button onClick={(item) => {this.upDateMsg(item,records)}}>修改</Button>
							          : ''
							        }
							        {
							          this.state.btnAuth.indexOf('msgPush-delete') !== -1 ?
							          <Button onClick={(item) => {this.handleDelete(item,id,messageTitle)}}>删除</Button>
							          : ''
							        }


								</div>
							)
						} else if ((pushStatus == 2) && (usingStatus == 2)) {
							return '';
						} else if (pushStatus == 1 && usingStatus == 2) {
							return (
								<div>
								    {
							          this.state.btnAuth.indexOf('msgPush-stopOrStart') !== -1 ?
							          <Button onClick={(item) => {this.handleUsingStatus(item,id,usingStatus)}}>停用</Button>
							          : ''
							        }
									{
							          this.state.btnAuth.indexOf('msgPush-edit') !== -1 ?
							          <Button onClick={(item) => {this.upDateMsg(item,records)}}>修改</Button>
							          : ''
							        }
							        {
							          this.state.btnAuth.indexOf('msgPush-delete') !== -1 ?
							          <Button onClick={(item) => {this.handleDelete(item,id,messageTitle)}}>删除</Button>
							          : ''
							        }

								</div>
							)
						} else if ( (pushStatus == 3 || pushStatus == 4) && (usingStatus == 2) ) {
							return (
								<div>
								    {
							          this.state.btnAuth.indexOf('msgPush-pushAgain') !== -1 ?
							          <Button onClick={(item) => {this.pushAgain(records,item,id)}}>再次推送</Button>
							          : ''
							        }
									{
							          this.state.btnAuth.indexOf('msgPush-edit') !== -1 ?
							          <Button onClick={(item) => {this.upDateMsg(item,records)}}>修改</Button>
							          : ''
							        }
							        {
							          this.state.btnAuth.indexOf('msgPush-delete') !== -1 ?
							          <Button onClick={(item) => {this.handleDelete(item,id,messageTitle)}}>删除</Button>
							          : ''
							        }
								</div>
							)
						}
					}
				}
	        )
        }
		return (
			<div className="com-msgPush">
				<div className="searchWrap">
					<WhiteBar title="消息推送" />
					<div className='expandMenu iconfont icon-chazhaobiaodanliebiao' onClick={this.expandMenu} ></div>
						{
							this.state.expandStatus ?
							<SearchForm
								search={this.search}
								reset={this.reset}
							></SearchForm>
							: ''
						}
				</div>
				<div style={{marginTop:15,paddingLeft:20}}>
				    {
			          this.state.btnAuth.indexOf('msgPush-add') !== -1 ?
			          <Button onClick={this.addNewMsg}>新增</Button>
			          : ''
					}
				</div>
				<WhiteBar title="详细数据" />
				<div style={{padding: 10,background:'#fff'}}>
					<Table
						columns={columns}
						dataSource={this.state.msgLists}
						pagination={this.state.pagination}
						loading={this.state.isLoading}
						scroll={{ x: '120%' }}
					></Table>
				</div>
			</div>
		);
	}
}

/* 查询表单组件 */
const SearchForm = Form.create()(
	class extends Component {
		state = {}
		componentDidMount () {}
		// 查询
		search = () => {
			let searchData = this.props.form.getFieldsValue();
			console.log(searchData);
			this.props.search(searchData);
		}
		// 重置
		reset = () => {
			this.props.form.resetFields();
			this.props.reset();
		}
		render () {
			const FormItem = Form.Item;
			const Option = Select.Option;
			const {getFieldDecorator}  = this.props.form;
			return (
				<div className="com-search">
					<Form layout="vertical">
						<Row gutter={10}>
							<Col span={5}>
								<FormItem label="标题名称">
                                    {
                                        getFieldDecorator('messageTitle',{
                                            rules: []
                                        })(<Input type="text"  placeholder="标题名称" />)
                                    }
                                </FormItem>
							</Col>
							<Col span={5}>
								<FormItem label="消息类型">
                                    {
                                        getFieldDecorator('messageType',{
                                            rules: []
                                        })(
                                        	<Select placeholder="消息类型">
                                                <Option value={1}>pc</Option>
                                                <Option value={2}>app</Option>
                                                <Option value={3}>短信</Option>
                                                <Option value={4}>邮件</Option>
                                                <Option value={5}>微信</Option>
                                            </Select>
                                        )
                                    }
                                </FormItem>
							</Col>
							<Col span={5}>
								<FormItem label="推送状态">
                                    {
                                        getFieldDecorator('pushStatus',{
                                            rules: []
                                        })(
                                        	<Select placeholder="推送状态">
                                                <Option value={1}>未推送</Option>
                                                <Option value={2}>推送中</Option>
                                                <Option value={3}>推送成功</Option>
                                                <Option value={4}>推送失败</Option>
                                            </Select>
                                        )
                                    }
                                </FormItem>
							</Col>
							<Col span={5}>
								<FormItem label="消息状态">
                                    {
                                        getFieldDecorator('usingStatus',{
                                            rules: []
                                        })(
                                        	<Select placeholder="消息状态">
                                                <Option value={1}>停用</Option>
                                                <Option value={2}>启用</Option>
                                            </Select>
                                        )
                                    }
                                </FormItem>
							</Col>
							<Col span={4}>
								<Button onClick={this.search} style={{background: '#00BB29',color:'#fff',marginTop: 28}}>查询</Button>
								<Button onClick={this.reset} style={{marginLeft: 15,background:'#ED1719',color:'#fff'}}>重置</Button>
							</Col>
						</Row>
					</Form>
				</div>
			);
		}
	}
)
export default connect(state => ({
  msgStatus: state.msgStatus
}), {
  saveMsgStatus,
})(MsgPush)