import React, { PureComponent as Component } from 'react'; import { connect } from 'react-redux'; import PropTypes from 'prop-types'; import { Input, Button, message, Icon, Card, Alert, Modal, Switch, Row, Col, Tooltip } from 'antd'; import { fetchNewsData } from '../../../reducer/modules/news.js'; import { changeGroupMsg, fetchGroupList, setCurrGroup, fetchGroupMsg, updateGroupList, deleteGroup } from '../../../reducer/modules/group.js'; const { TextArea } = Input; import { trim } from '../../../common.js'; import _ from 'underscore'; import './GroupSetting.scss'; const confirm = Modal.confirm; @connect( state => { return { groupList: state.group.groupList, currGroup: state.group.currGroup, curUserRole: state.user.role }; }, { changeGroupMsg, fetchGroupList, setCurrGroup, fetchGroupMsg, fetchNewsData, updateGroupList, deleteGroup } ) class GroupSetting extends Component { constructor(props) { super(props); this.state = { currGroupDesc: '', currGroupName: '', showDangerOptions: false, custom_field1_name: '', custom_field1_enable: false, custom_field1_rule: false }; } static propTypes = { currGroup: PropTypes.object, curUserRole: PropTypes.string, changeGroupMsg: PropTypes.func, fetchGroupList: PropTypes.func, setCurrGroup: PropTypes.func, fetchGroupMsg: PropTypes.func, fetchNewsData: PropTypes.func, updateGroupList: PropTypes.func, deleteGroup: PropTypes.func, groupList: PropTypes.array }; initState(props) { this.setState({ currGroupName: props.currGroup.group_name, currGroupDesc: props.currGroup.group_desc, custom_field1_name: props.currGroup.custom_field1.name, custom_field1_enable: props.currGroup.custom_field1.enable }); } // 修改分组名称 changeName = e => { this.setState({ currGroupName: e.target.value }); }; // 修改分组描述 changeDesc = e => { this.setState({ currGroupDesc: e.target.value }); }; // 修改自定义字段名称 changeCustomName = e => { let custom_field1_rule = this.state.custom_field1_enable ? !e.target.value : false; this.setState({ custom_field1_name: e.target.value, custom_field1_rule }); }; // 修改开启状态 changeCustomEnable = e => { let custom_field1_rule = e ? !this.state.custom_field1_name : false; this.setState({ custom_field1_enable: e, custom_field1_rule }); }; componentWillMount() { // console.log('custom_field1',this.props.currGroup.custom_field1) this.initState(this.props); } // 点击“查看危险操作”按钮 toggleDangerOptions = () => { // console.log(this.state.showDangerOptions); this.setState({ showDangerOptions: !this.state.showDangerOptions }); }; // 编辑分组信息 editGroup = async () => { const id = this.props.currGroup._id; if (this.state.custom_field1_rule) { return; } const res = await this.props.changeGroupMsg({ group_name: this.state.currGroupName, group_desc: this.state.currGroupDesc, custom_field1: { name: this.state.custom_field1_name, enable: this.state.custom_field1_enable }, id: this.props.currGroup._id }); if (!res.payload.data.errcode) { message.success('修改成功!'); await this.props.fetchGroupList(this.props.groupList); this.props.updateGroupList(this.props.groupList); const currGroup = _.find(this.props.groupList, group => { return +group._id === +id; }); this.props.setCurrGroup(currGroup); this.props.fetchGroupMsg(this.props.currGroup._id); this.props.fetchNewsData(this.props.currGroup._id, 'group', 1, 10); } }; // 删除分组 deleteGroup = async () => { const that = this; const { currGroup } = that.props; const res = await this.props.deleteGroup({ id: currGroup._id }); if (!res.payload.data.errcode) { message.success('删除成功'); await that.props.fetchGroupList(); const currGroup = that.props.groupList[0] || { group_name: '', group_desc: '' }; that.setState({ groupList: that.props.groupList }); that.props.setCurrGroup(currGroup); } }; // 删除分组的二次确认 showConfirm = () => { const that = this; confirm({ title: '确认删除 ' + that.props.currGroup.group_name + ' 分组吗?', content: (
请输入分组名称确认此操作:
分组一旦删除,将无法恢复数据,请慎重操作!
只有超级管理员有权限删除分组。