/*
 * Creator:     ML
 * CreatDate:   2019-08-20
 * descripts：  个人信息  修改默认登录角色
*/
import React from 'react';
import { Form, Row, Col, Input, Select, DatePicker, Button, Modal, Table, message, Divider,Switch } from 'antd';
import { $http } from '../../../containers/config/https';
const SettingDefaultLoginSection = Form.create()(
  class SettingDefaultLoginSection extends React.Component {
    constructor(props) {
      super(props)
      this.state = {
        recordData:[]
      }
    }
    componentDidMount() {
      this.getLoc()
      this.props.onSettingDefaultLoginSection(this)
    }
    getLoc=()=>{
        let data = {}
        data = {
         "params": [{
             userCode: JSON.parse(sessionStorage.userData).userCode,
             currentLocFlag: "Y"

         }],
        "session":[{
            "loginIp": window.location && window.location.protocol && window.location.host ? (window.location.host.split(":")[0]) : (window.location && window.location.origin ?
                (window.location.origin.split(":")[0]+window.location.origin.split(":")[1]).split("//")[1] : "")
        }]
     };
     $http.post('urlDeault', this, {
         code: "01040043",
         data: data,
         success: function (res) {
             if (+res.errorCode === 0 && res.result) {
                 for (var i = 0; i < res.result.logonLocAry.length; i++) {
                     res.result.logonLocAry[i].key = i;
                 }
                 this.setState({
                    recordData: res.result.logonLocAry
                 })
             }
         }
     });
    }
    //是否默认
    handleSwithChange=(val,record)=>{
        // console.log(val,record)
        let data = {}
        data = {
            params: [{
                userID:JSON.parse(sessionStorage.userData).userID,
                updateUserID:JSON.parse(sessionStorage.userData).userID,
                power:"defaultLogonLoc",
                currentDefLogLocID:record.logonLocLogID,
                }],
     };
     $http.post('urlS', this, {
         code: "01040090",
         data: data,
         success: function (res) {
             if (+res.errorCode === 0) {
                if(val==true){
                    message.success(
                        this.props.localeProvider&&this.props.localeProvider.PersonalInformationSuccessfullyModified?this.setMessage('PersonalInformationSuccessfullyModified', 'descripts'):"修改成功"
                    );
                }
                this.getLoc()
             }
         }
     });
    }
 //国际化
 setMessage(name, message) {
    return this.props.localeProvider ? this.props.localeProvider[name][message] : ''
}

    render() {
      const {   } = this.state
      let localeData = this.props.localeProvider
      const columns = [
        {
            width: 40,
            align: "center",
            title: '角色',
            dataIndex: 'logonGroupDesc',
            key: 'fundus',
            editable: true,
        },
        {
            width: 80,
            align: "center",
            title: '科室',
            dataIndex: 'logonLocDesc',
            key: 'breast',
            editable: true,
        },
        {
            width: 60,
            align: "center",
            title: '医院',
            dataIndex: 'logonHospDesc',
            key: 'perineum',
            editable: true,
        },
        {
            title: '默认',
            dataIndex: 'operation',
            key: 'action',
            align: "center",
            width: 20,
            render: (text, record, index) => {
                    return (
                          <Switch  checked={record.logLocIsDefault&&record.logLocIsDefault=="Y"?true:false}  checkedChildren="是" unCheckedChildren="否" onChange={(val)=>this.handleSwithChange(val,record)}  />
                    )
            }
        }
    ];
      return (
        <div>
    <p style={{fontWeight:"600",fontSize:"14px"}}>{localeData&&localeData.PersonalInformationCurrentUserListOfAllRoles?this.setMessage('PersonalInformationCurrentUserListOfAllRoles', 'descripts'):"当前用户所有角色列表"}</p>
        <Table
            columns={columns}
            pagination={false}
            dataSource={this.state.recordData && this.state.recordData.length > 0 ? this.state.recordData : []}
            rowKey={(row) => {
                return row.id
            }}
            className="clearBackground"
            bordered
        />
        </div>
      )
    }
  })
export default SettingDefaultLoginSection
