/*
 * Creator:     ML
 * CreatDate:   2020-06-16
 * descripts：  查看当前用户审核进度
 * */
import React from 'react';
import {Input, Row, Col, Divider, Form, Steps, Table, Popover } from 'antd';
import { $http } from '../../containers/config/https';
import './style/style.less';
import store from "store";


// 组件const
const Step = Steps.Step;
const formItemLayout = {    // label 和input宽度
    labelCol: { span: 4 },
    wrapperCol: { span: 19 },
};
const { TextArea } = Input;

const customDot = (dot, { status, index }) => (
    <Popover content={<span>step {index} status: {status}</span>}>
        {dot}
    </Popover>
);


class PersAuditProgress extends React.Component {
    constructor(props) {
        super(props)
        let userData = sessionStorage.getItem("userData") ? JSON.parse(sessionStorage.getItem("userData")) : {};
        this.state = {
            userData,
            dataGroup: [],  // 添加分组数据
            userInfo: {}, // 回显用户数据
            auditGroupAry: [],  // 审核数组
            dis: false,  // 不可选
            radioValue: [], // 默认radio
            persAuditDateId: '', //审核弹框主键
            userAuditFlag: '-1', //审核中1   通过0  未通过0
            userAuditResultCode: "-1"
        };
        // 医嘱子类table
        this.columnsGroup = [
            {
                title: '角色名称',
                dataIndex: 'CBGroupDesc',
                align: "center",
                key: '1',
                render: (text, record, index) => (
                    <span style={{ color: "#333", fontWeight: "600" }}>
                        {record.CBGroupDesc ? record.CBGroupDesc : record.auditGroupDesc}
                    </span>
                )
            }, {
                title: '审核结果',
                dataIndex: 'radioS',
                align: "center",
                key: '2',
                render: (text, record, index) => {
                    if (this.state.radioValue[index].userAuditStatus) {
                        if (this.state.radioValue[index].userAuditStatus === 'N') {
                            return (
                                <span style={{ color: "#333", fontWeight: "600" }}>审核不通过</span>
                            )
                        } else {
                            return (
                                <span style={{ color: "#333", fontWeight: "600" }}>审核通过</span>
                            )
                        }
                    }
                    return <span style={{ color: "#333", fontWeight: "600" }}>正在审核</span>
                }
            },
        ]

    }

    componentDidMount() {
        this.handleQuery()
        // 初始化设置table的高度以及表体的高度
        document.querySelector('.ant-table-body').style.height = store.getState().tableHeight.y - 290 + 'px';
    }
    // 查询当前用户审核信息
    handleQuery = () => {
        const { userData } = this.state
        let data = {
            params: [{
                hospID: userData && userData.hospID || "",
                userID: userData && userData.userID || "",
            }],
        };
        $http.post('urlS', this, {
            code: "01040027",
            data: data,
            success: function (res) {
                let errorCode = res.errorCode;
                if (errorCode === '0') {
                    for (var i = 0; i < res.result.Data.length; i++) {
                        res.result.Data[i].key = i;
                    }
                    this.setState({
                        tableData: res.result.Data && res.result.Data[0] || [],
                        PostData: res.result.CBPostAry,
                        total: res.result.TotalCount,
                        userAuditFlag: res.result.Data && res.result.Data[0] && res.result.Data[0].userAuditFlag || "-1",
                        userAuditResultCode: res.result.Data && res.result.Data[0] && res.result.Data[0].userAuditResultCode || "-1"
                    }, () => {
                        this.callbackData(userData && userData.userID || "",this.state.userAuditFlag) // 数据回显
                    })
                } else {
                    this.setState({
                        tableData: [],
                        total: 0
                    })
                }
            }
        });
    }
 

    // 数据回显
    callbackData = (id, flag) => {
        let data = {
            "params": [{
                userID: id
            }]
        };
        let code
        if (flag === '1') {
            code = '01040064'
        } else {
            code = '01040054'
        }
        $http.post('urlS', this, {
            code: code,
            data: data,
            success: function (res) {
                let errorCode = res.errorCode;
                if (errorCode === '0') {

                    for (var i = 0; i < res.result.userAuditLogAry.length; i++) {
                        res.result.userAuditLogAry[i].key = i;
                    }

                    let auditGroupAry = []  // 审核数组

                    res.result.userAuditLogAry.map((item, i) => {
                        auditGroupAry.push({
                            CBGroupID: '',
                            userAuditStatus: ''
                        })
                    })
                    this.setState({
                        dataGroup: [], // 回显用户数据（避免回显radio不更改）
                    })
                    this.setState({
                        userInfo: res.result, // 回显用户数据
                        dataGroup: res.result.userAuditLogAry, // 回显用户数据
                        dis: true,
                        auditGroupAry: auditGroupAry,
                        radioValue: res.result.userAuditLogAry
                    }, () => {
                        // console.log(this.state.userInfo)
                    })
                }
            }
        });
    }
    render() {
        const { getFieldDecorator } = this.props.form;
        const { userInfo, userData } = this.state
        return (
            <div style={{ padding: "14px" }}>
                <Row >
                    <Col span={16} offset={4}>
                        <Steps current={1} progressDot={customDot} className="steps" style={{ whiteSpace: 'nowrap' }}>
                            <Step title={this.state.userAuditFlag == "-1" ? "未发起申请" : "发起申请"} description={userInfo.userApplyDate || '' + ' ' + userInfo.userApplyTime || ''} />
                            <Step title={userInfo.userAuditResult} description={userInfo.userAuditLogDesc} />
                            {/* {userInfo.groupAuditObj ? (userInfo.groupAuditObj.auditFlag === '0' ? <Step title={userInfo.firstAuditDesc ? userInfo.firstAuditDesc + '审核' : '' + '审核'} /> : <Step description={userInfo.groupAuditObj.auditDateTime} title={userInfo.groupAuditObj.applyResult + ' ' + userInfo.groupAuditObj.secondAuditDesc + userInfo.groupAuditObj.finalAudResult} />) : ''} */}
                        </Steps>
                    </Col>
                </Row>
                <Form layout="vertical" className="depart-form info-dom" >
                    <Divider orientation="left">基本资料</Divider>
                    <Row style={{ lineHeight: '30px' }}>
                        <Col span={6}>
                            姓名：<span>{userInfo && userInfo.userDesc || "--"}</span>
                        </Col>
                        <Col span={6}>
                            性别：<span>{userInfo && userInfo.userSexDesc || "--"}</span>
                        </Col>
                        <Col span={6}>
                            证件类型：<span>{userInfo && userInfo.userCredTypeDesc || "--"}</span>
                        </Col>
                        <Col span={6}>
                            证件号码：<span>{userInfo && userInfo.userCredNo || "--"}</span>
                        </Col>
                    </Row>
                    <Row style={{ lineHeight: '30px' }} >
                        <Col span={6}>
                            出生日期：<span>{userInfo && userInfo.userDOB || "--"}</span>
                        </Col>
                        <Col span={6}>
                            手机号码：<span>{userInfo && userInfo.userMobile || "--"}</span>
                        </Col>
                        <Col span={6}>
                            职称：<span>{userInfo && userInfo.userTitleDesc || "--"}</span>
                        </Col>
                        <Col span={6}>
                            人员工号：<span>{userData && userData.userCode || "--"}</span>
                        </Col>
                    </Row>
                    <Divider orientation="left">医院岗位</Divider>
                    <Row style={{ lineHeight: '30px' }}>
                        <Col span={6}>
                            所属医院： <span>{userInfo && userInfo.userApplyHospDesc || "--"}</span>
                        </Col>
                        <Col span={6}>
                            所属科室： <span>{userInfo && userInfo.userApplyLocDesc || "--"}</span>
                        </Col>
                        <Col span={6}>
                            申请岗位： <span>{userInfo && userInfo.userPostDesc || "--"}</span>
                        </Col>
                    </Row>
                    <Divider orientation="left">关联角色</Divider>
                    <Row className="mB30">
                        <Col span={24} >
                            <Table bordered dataSource={this.state.dataGroup} columns={this.columnsGroup} pagination={false}
                                style={{ height: store.getState().tableHeight.y - 290 + 'px', overflow: 'auto' }}
                            />
                        </Col>
                    </Row>
                    <Row style={{ display: (this.state.userAuditResultCode == "0" ? "block" : "none") }}>
                        <Col span={24} >
                            <Form.Item label="拒绝原因："  {...formItemLayout} >
                                {getFieldDecorator('auditMarks', {
                                    initialValue: userInfo && userInfo.userAuditRemarks || "--",
                                    rules: [],
                                })(
                                    <TextArea style={{ border: "0", background: "#fff", cursor: "default", color: "#333", fontWeight: "600" }} rows={3} maxLength="30" disabled={this.state.dis} />
                                )}
                            </Form.Item>
                        </Col>
                    </Row>
                </Form>
            </div>

        )
    }
}

const PersAuditProgressFrom = Form.create()(PersAuditProgress);

export default PersAuditProgressFrom