forked from nsjcy/frontEnd/nsjcy

liuwh
2020-05-29 2fdc3dc444a2f8199866780205c0fa4b5ac40522
SunshineIns/src/page/CriminalExecution.jsx
@@ -3,132 +3,72 @@
import HeadView from '../view/HeadView';
import TableBtnView from '../view/TableBtnView';
import CommonSearchForm from '../view/CommonSearchForm';
import { Input, Button, DatePicker, Divider, message, Popconfirm, Select, Badge, Modal } from 'antd';
import { Input, Button, DatePicker, Divider, message, Popconfirm, Select, Tooltip, Modal, Row, Col } from 'antd';
import moment from 'moment';
import Fetch from '../fetch';
import TableView from '../view/TableView';
const Option = Select.Option;
function typeOfName(type) {
    switch (type) {
        case 1:
            return "跟踪帮教";
        case 2:
            return "合适成年人";
        case 3:
            return "社会调查";
        case 4:
            return "心理疏导";
        case 5:
            return "法律援助";
    }
}
const taskNodeIds = {
    1: '跟踪帮教',
    2: '合适成年人',
    3: '社会调查',
    4: '心理疏导',
    5: '法律援助',
}
const activityTypeList = [
    1,
    2,
    3,
    4,
    5
]
const activityStatusIds = {
    0: '未开始',
    1: '进行中',
    2: '已结束',
    99: '暂停',
}
const activityStatusList = [
    0,
    1,
    2
]
export default class CareList extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            data: [],
            formData: {
            list: [],
            formdata: {
                __key: Date.now(),
                page: 1,
                size: 10,
            },
            resetKey: Date.now(),
            loading: false
            loading: false,
            zIndex: '-1',
            savedate: {},
            display: 'none',
            fingerCode: ''
        };
    }
    componentDidMount() {
        document.title = '社会观护管理';
        this.getData();
        document.title = '刑执监督管理';
        let _this = this;
        window.addEventListener('message', function (e) {
            console.log('反馈', e)
            if (e.data) {
                _this.setState({
                    ...e.data
                })
            }
        }, false);
        _this.iframeAddEventListener();
        _this.getData();
    }
    getData = () => {
        const { formdata } = this.state;
        this.setState({ loading: true })
        console.log('formdata', formdata)
        Fetch.criminalQuery({ ...formdata })
            .then(res => {
                console.log("res", res)
                this.setState({
                    list: res.data.content,
                    loading: false
                });
            });
    }
    setFormData = data => {
        console.log('form', data);
        this.setState({
            formData: data,
            formdata: data,
        });
    }
    getData = () => {
        const { formData } = this.state;
        this.setState({ loading: true })
        Fetch.socialQuery({ ...formData })
            .then(res => {
                console.log(res)
                for (var i = 0; i < res.rows.length; i++) {
                    res.rows[i]['index'] = i + 1;
                }
                this.setState({
                    data: res.rows,
                    loading: false,
                });
            });
    }
    onInputChange = ({ target: { value, name } }) => {
        this.setState(({ formData }) => ({
            formData: {
                ...formData,
                [name]: value
            }
        }))
    }
    Seaech = () => {
        const { formData } = this.state;
        Fetch.getSweeping(formData)
            .then(res => {
                for (var i = 0; i < res.length; i++) {
                    res[i]['index'] = i + 1;
                }
                this.setState({
                    data: res
                });
            });
    }
    Reset = () => {
        this.setState({
            resetKey: Date.now(),
            formData: {}
        }, this.getData);
    }
    confirm = (e) => {
    deleteItems = (e) => {
        console.log(e);
        this.setState({ loading: true })
        Fetch.socialDelete(e).then(res => {
        Fetch.criminalDelete(e).then(res => {
            if (res.code == 0) {
                console.log(res)
                this.setState({ loading: false })
@@ -144,90 +84,133 @@
    showModal = (id) => {
        this.setState({
          visible: true,
            visible: true,
            zIndex: 1000,
            iframeKey: id,
            display: 'none',
            loading: true,
        });
        // Fetch.socialCompanyDetail(id)
        //   .then(res => {
        //     this.setState({ savedate: res })
        //   })
      }
        this.sendMsg();
        Fetch.criminalFind(id)
            .then(res => {
                console.log(res)
                this.setState({ savedate: res.data, fingerCode: res.data.fingerCode || '', loading: false })
            })
    }
    saveInputChange = ({ target: { value, name } }) => {
        this.setState(({ savedate }) => ({
            savedate: {
                ...savedate,
                [name]: value
            }
        }))
    }
    renderColumns = () => {
        return [{
            title: '任务标题',
            dataIndex: 'taskTitle',
            key: 'taskTitle'
            title: '编号',
            dataIndex: 'index',
            key: 'index',
            render: (text, item, index) => <span>{index + 1}</span>
        }, {
            title: '任务类型',
            dataIndex: 'taskType',
            key: 'taskType',
            render: text => <span>{typeOfName(text)}</span>
            title: ' 姓名',
            dataIndex: 'name',
            key: 'name',
        }, {
            title: '状态',
            dataIndex: 'status',
            key: 'status',
            render: text => (
                text == 0 ?
                    <Badge style={{ backgroundColor: '#6C757C' }} count={'未开始'} /> : text == 1 ? <Badge count={'进行中'} style={{ backgroundColor: '#F1C40F' }} /> : text == 2 ? <Badge count={'已结束'} style={{ backgroundColor: '#2ECC71' }} /> : <Badge count={'暂停'} style={{ backgroundColor: '#2ECC71' }} />
            )
            title: '牢房号',
            dataIndex: 'number',
            key: 'number',
        }, {
            title: '创建时间',
            title: '指纹唯一识别',
            dataIndex: 'fingerCode',
            key: 'fingerCode',
            render: text => <div className="nowrap">{text}</div>
        }, {
            title: '录入时间',
            dataIndex: 'createTime',
            key: 'createTime',
            render: text => <span>{moment(text).format("YYYY-MM-DD HH:mm")}</span>
        }, {
            title: '开始时间',
            dataIndex: 'startTime',
            key: 'startTime',
            render: text => <span>{moment(text).format("YYYY-MM-DD HH:mm")}</span>
        }, {
            title: '结束时间',
            dataIndex: 'endTime',
            key: 'endTime',
            render: text => <span>{moment(text).format("YYYY-MM-DD HH:mm")}</span>
            render: text => <span>{moment(text).format("YYYY-MM-DD")}</span>
        }, {
            title: '操作',
            key: 'action',
            render: (text, record) => (
                <span>
                    {
                        record.status == 0 ?
                            <React.Fragment>
                                <a onClick={() => this.showModal(record.id)}>编辑</a>
                                <Divider type="vertical" />
                                <Popconfirm
                                    title="确认删除任务吗?"
                                    id={record.id}
                                    onConfirm={e => this.confirm(record.id)}
                                    okText="确定"
                                    cancelText="取消"
                                >
                                    <a href="#">删除</a>
                                    <Divider type="vertical" />
                                </Popconfirm>
                                <a onClick={() => this.reboot(record.id, 99)}>暂停</a>
                            </React.Fragment> :
                            record.status == 1 ?
                                <React.Fragment>
                                    <a onClick={() => this.showModal(record.id)}>查看</a>
                                    <Divider type="vertical" />
                                    <a onClick={() => this.showModal(record.id)}>结束任务</a>
                                    <Divider type="vertical" />
                                    <a onClick={() => this.reboot(record.id, 99)}>暂停</a>
                                </React.Fragment> :
                                <React.Fragment>
                                    <a onClick={() => this.showModal(record.id)}>查看</a>
                                    <Divider type="vertical" />
                                    <a onClick={() => this.reboot(record.id, 0)}>重启</a>
                                </React.Fragment>
                    }
                    <label onClick={() => this.showModal(record.id)} className='theme-color' style={{ cursor: 'pointer' }}>编辑</label>
                    <Divider type="vertical" />
                    <Popconfirm
                        title="确认删除吗?"
                        id={record.id}
                        onConfirm={e => this.deleteItems(record.id)}
                        okText="确定"
                        cancelText="取消"
                    >
                        <label className='theme-color' style={{ cursor: 'pointer' }}>删除</label>
                    </Popconfirm>
                </span>
            ),
        }]
    }
    iframeAddEventListener = () => {
        let _this = this;
        this.iframeWin = this.refs.iframe && this.refs.iframe.contentWindow;
        this.refs.iframe && this.refs.iframe.addEventListener("load", function () {
            //代码能执行到这里说明已经载入成功完毕了
            //这里是回调函数
            _this.iframeWin.postMessage({
                fgData: false
            }, '*');
        }, false);
    }
    sendMsg = () => {
        this.iframeWin = this.refs.iframe && this.refs.iframe.contentWindow;
        this.iframeWin.postMessage({
            fgData: false
        }, '*');
    }
    //确认提交按钮
    handleOk = () => {
        const { savedate, fingerCode } = this.state;
        if (!savedate.name) {
            return message.warning("姓名不能为空");
        }
        if (!savedate.number) {
            return message.warning("牢房号不能为空");
        }
        if (!fingerCode) {
            return message.warning("请录入指纹");
        }
        this.setState({ btloading: true })
        Fetch.criminalSave({ ...savedate, fingerCode })
            .then(res => {
                if (res.code === 0) {
                    this.setState({
                        zIndex: '-1',
                        fingerCode: "",
                        btloading: false,
                        closeKey: Date.now()
                    }, this.getData);
                    message.success("提交成功!")
                }
            });
        this.setState({
        })
    }
    //取消按钮
    handleCancel = () => {
        this.setState({
            fingerCode: "",
            zIndex: '-1',
        });
    }
    render() {
        const { data, resetKey, visible, loading, savedate, closeKey, formData } = this.state;
        const { list, resetKey, visible, loading, btloading, savedate, closeKey, formdata, zIndex, display, fingerCode, iframeKey } = this.state;
        return (
            <div className="app-page">
                <HeadView history={this.props.history} />
@@ -235,9 +218,9 @@
                    <Button type="primary" size='large' onClick={() => this.showModal('new')}>新增</Button>
                </div>
                <div style={{ background: '#fff', margin: 20 }}>
                    <CommonSearchForm
                    {/* <CommonSearchForm
                        {...this.props}
                        formData={formData}
                        formData={formdata}
                        setFormData={this.setFormData}
                        searchonClick={this.searchonClick}
                        pathName={this.props.location.pathname}
@@ -251,29 +234,45 @@
                            {
                                type: 'input', name: '联系电话', label: '联系电话', key: 'companyTel'
                            },
                        ]} />
                    <TableView columns={this.renderColumns()} data={data} pageSize='10' size='default' loading={loading} />
                        ]} /> */}
                    <TableView columns={this.renderColumns()} data={list} pageSize='10' size='default' loading={loading} />
                </div>
                <Modal
                    zIndex={zIndex}
                    key={closeKey}
                    confirmLoading={loading}
                    visible={visible}
                    title="公司信息"
                    confirmLoading={btloading}
                    visible={true}
                    title="指纹录入"
                    onOk={this.handleOk}
                    onCancel={this.handleCancel}
                    bodyStyle={{ lineHeight: 4 }}
                    // footer={null}
                    width={'60%'}
                    bodyStyle={{ lineHeight: 4 }}
                >
                    <iframe
                        className="h-100"
                        style={{ width: '100%' }}
                        onLoad={() => { }}
                        ref="iframe"
                        src='../../asset/fingerprint/指纹登记.html'
                        width="100%"
                        scrolling="no"
                        frameBorder="0"
                    />
                    <Input addonBefore="姓名" name='name' onChange={this.saveInputChange} value={savedate.name || ''} />
                    <Input addonBefore="牢房号" name='number' onChange={this.saveInputChange} value={savedate.number || ''} />
                    <Input addonBefore="指纹唯一标识" name='fingerCode' value={fingerCode || ''} disabled addonAfter={<Row type="flex" style={{ flexWrap: 'nowrap' }}>
                        <Col style={{ cursor: 'pointer' }} onClick={() => this.setState({ display: 'block' })}>
                            录入指纹
                        </Col>
                    </Row>} />
                    <div style={{ display: display }}>
                        <Divider style={{ margin: '2px 0' }} />
                        <iframe
                            key={iframeKey}
                            style={{ width: '100%', height: '550px' }}
                            onLoad={() => { }}
                            ref="iframe"
                            src='./fingerprint/dengji.html'
                            width="100%"
                            scrolling="no"
                            frameBorder="0"
                        />
                    </div>
                </Modal>
                {/* </div> */}
            </div>
        )
    }