///卫生局维护
import React from 'react';
import { Select, Input, Row, Col, Button, Spin, Divider, Popconfirm, message, Icon, Form, Modal, Card, Switch, DatePicker, Popover, List } from 'antd';
import { $http } from '../../containers/config/https';
import '../../assets/css/system.css';
import PubilcTablePagination from '../common/PubilcTablePagination.jsx';
import store from './../../store/index';
import moment from 'moment';

const { Option } = Select;
const FormItem = Form.Item;

const formItemLayout = {
  labelCol: { span: 10 },
  wrapperCol: { span: 14 },
}
const paddRightCol = {
  paddingRight: "0px",
  paddingLeft: "10px"
}
const formItemLayoutType = {
  labelCol: { span: 2 },
  wrapperCol: { span: 22 }
}
const formItemLayoutTop = {
  labelCol: { span: 9 },
  wrapperCol: { span: 15 },
}

const HospitalMaintenance = Form.create()(
  class HospitalMaintenance extends React.Component {
    constructor(props) {
      super(props);
      this.state = {
        data: [],
        columns: [],
        total: 0,
        page: 1,
        pageSize: 10,
        baseParms: {},
        values: {},
        id: "",

        cityArr: [],
        areasArr: [],
        VillagesArr: [],
        hamletsArr: [],

        heightTable: "",
      }
    }
    componentDidMount() {
      // 初始化设置table的高度以及表体的高度 内容高度 height 
      if (document.querySelector('.ant-table-body')) {
        document.querySelector('.ant-table-body').style.height = store.getState().tableHeight.y - 40 + 'px'
      }
      this.getBaseParams();
    }
    //获取对应的医院基础信息数据
    getBaseParams = () => {
      let data = {
        params: [{
          hospID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).hospID : ''
        }],
      }
      this.getProvince('');
      $http.post("urlS", this, {
        code: "05100220",
        data: data,
        success: function (res) {
          if (+res.errorCode === 0) {
            this.setState({
              baseParms: { ...this.state.baseParms, ...{ supHealthBur: res.result.Data } }
            })
          } else {
            message.error('失败：' + res.errorMessage);
          }
        },
        error: function (error) {
          message.error('失败：' + error);
        }
      });
    }
    FindData = () => {
      const { propMethod: { findData } } = this.props;
      this.showModal(false);
      findData();
      this.reset();
    }
    // 页码改变的回调，参数是改变后的页码及每页条数
    PageChange = (page, pageSize) => {
      this.setState({ page: page, pageSize: pageSize }, () => {
        // 重新调用查询方法
        this.FindData()
      });
    }
    // 条数改变的回调
    onShowSizeChange = (current, size) => {
      this.setState({ page: current, pageSize: size }, () => {
        // 重新调用查询方法
        this.FindData()
      });
    }
    save = () => {
      this.props.form.validateFields((err, values) => {
        //const { page, pageSize } = this.state;
        const { data: params } = this.props;
        if (err) return;
        const session = sessionStorage.userData ? JSON.parse(sessionStorage.userData) : '';
        const hospID = session.hospID ? session.hospID : "";
        let par = {
          healthBurSeqNo: values.healthBurSeqNo || "",
          healthBurCode: values.healthBurCode || "",
          healthBurDesc: values.healthBurDesc || "",
          supHealthBurID: values.supHealthBurID || "",
          address: values.address || "",
          deanName: values.deanName || "",
          deanPhone: values.deanPhone || "",
          officePhone: values.officePhone || "",
          email: values.email || "",
          provinceId: values.provinceId || "",
          cityId: values.cityId || "",
          areaId: values.areaId || "",
          villageId: values.villageId || "",
          organizationCode: values.organizationCode || '',
          businesslicense: values.businesslicense || '',
          ZIPCode: values.ZIPCode || '',
          website: values.website || '',
          startDate: values.startDate ? moment(values.startDate).format('YYYY-MM-DD') : undefined,
          stopDate: values.stopDate ? moment(values.stopDate).format('YYYY-MM-DD') : '',
          updateUserID: session.userID ? session.userID : "",
        };
        if (params && params.healthBurID) {
          par = { ...par, ...{ healthBurID: params.healthBurID } };
          $http.post("urlS", this, {
            code: "05100242",
            data: {
              params: [par]
            },
            success: function (res) {
              if (+res.errorCode === 0) {
                message.success("修改成功")
                this.FindData();
              } else {
                message.error('失败：' + res.errorMessage);
              }
            },
            error: function (error) {
              message.error('失败：' + error);
            }
          });
        } else {
          //par = { ...par, ...{ hospId: hospID } };
          $http.post("urlS", this, {
            code: "05100241",
            data: {
              params: [par]
            },
            success: function (res) {
              if (+res.errorCode === 0) {
                message.success("新增成功")
                this.FindData();
              } else {
                message.error('失败：' + res.errorMessage);
              }
            },
            error: function (error) {
              message.error('失败：' + error);
            }
          });
        }
      })
    }
    // delete = () => {
    //     let data = {
    //         params: [{
    //             hospID: this.state.hospID,
    //             updateUserID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).userID : "",
    //         }],
    //     }
    //     $http.post("urlS", this, {
    //         code: "05100210",
    //         data: data,
    //         success: function (res) {
    //             if (+res.errorCode === 0) {
    //                 message.success("删除成功")
    //                 this.reset()
    //                 this.FindData()
    //             } else {
    //                 message.error('失败：' + res.errorMessage);
    //             }
    //         },
    //         error: function (error) {
    //             message.error('失败：' + error);
    //         }
    //     })
    // }
    reset = () => {
      this.props.form.resetFields();
      this.setState({
        params: {}
      })
    }
    // handleCountry = (value, option) => {
    //   if (value) {
    //     this.getProvince(value);
    //     this.props.form.setFieldsValue({ provinceId: undefined, cityId: undefined, areaId: undefined, villageId: undefined, hamletId: undefined })
    //   } else {
    //     this.props.form.setFieldsValue({ provinceId: undefined, cityId: undefined, areaId: undefined, villageId: undefined, hamletId: undefined })
    //     this.setState({
    //       cityArr: [],
    //       areasArr: [],
    //       VillagesArr: [],
    //       hamletsArr: []
    //     })
    //   }
    // }
    //选择清除省
    handleProvince = (value, option) => {
      if (value) {
        this.getCity(value);
        this.props.form.setFieldsValue({ cityId: undefined, areaId: undefined, villageId: undefined, hamletId: undefined })
      } else {
        this.props.form.setFieldsValue({ cityId: undefined, areaId: undefined, villageId: undefined, hamletId: undefined })
        this.setState({
          cityArr: [],
          areasArr: [],
          VillagesArr: [],
          hamletsArr: []
        })
      }
    }
    //选择市
    handleCity = (value, option) => {
      if (value) {
        this.getAreas(value);
        this.props.form.setFieldsValue({ areaId: undefined, villageId: undefined, hamletId: undefined })
      } else {
        this.props.form.setFieldsValue({ areaId: undefined, villageId: undefined, hamletId: undefined })
        this.setState({
          areasArr: [],
          VillagesArr: [],
          hamletsArr: []
        })
      }
    }
    //选择县
    handleAreas = (value) => {
      if (value) {
        this.getVillages(value)
        this.props.form.setFieldsValue({ villageId: undefined, hamletId: undefined })
      } else {
        this.props.form.setFieldsValue({ villageId: undefined, hamletId: undefined })
        this.setState({
          VillagesArr: [],
          hamletsArr: []
        })
      }
    }
    //选择乡
    handleVillages = (value) => {
      if (value) {
        this.getHamlet(value)
        this.props.form.setFieldsValue({ hamletId: undefined })
      } else {
        this.props.form.setFieldsValue({ hamletId: undefined })
        this.setState({
          hamletsArr: []
        })
      }
    }
    //市获取焦点
    onCityFocus = () => {
      let city = this.state.cityArr;
      let provinceID = this.props.form.getFieldValue("provID");
      if ((city.length === 0) && (provinceID)) {
        let newCity = []
        newCity = this.state.baseParms.provDataList.filter((item) => item.id == provinceID);
        this.setState({
          cityArr: newCity[0].cityDataList,
        })
      }
    }
    //县获取焦点
    onAreasFocus = () => {
      let area = this.state.areasArr
      let cityID = this.props.form.getFieldValue("cityID");
      if ((area.length === 0) && (cityID)) {
        this.getAreas(cityID);
      }
    }
    //乡获取焦点
    onVillagesFocus = () => {
      let village = this.state.VillagesArr
      let areaID = this.props.form.getFieldValue("areaID");
      if ((village.length === 0) && (areaID)) {
        this.getVillages(areaID);
      }
    }

    getProvince = (countryID = '') => {
      let data = {
        params: [{
          countryId: countryID
        }],
      }
      $http.post('urlS', this, {
        code: '03030024',
        data: data,
        success: function (res) {
          if (+res.errorCode === 0) {
            this.setState({
              baseParms: { ...this.state.baseParms, ...{ province: res.result } }
            })
          } else {
            this.setState({
              provinceArr: [],
              cityArr: [],
              areasArr: [],
              VillagesArr: [],
              hamletsArr: [],
            })
          }
        }
      })
    }
    getCity = (provinceID) => {
      let data = {
        params: [{
          provinceId: provinceID
        }],
      }
      $http.post('urlS', this, {
        code: '03030025',
        data: data,
        success: function (res) {
          if (+res.errorCode === 0) {
            this.setState({
              cityArr: res.result,
            })
          } else {
            this.setState({
              areasArr: [],
              VillagesArr: [],
              hamletsArr: [],
            })
          }
        }
      })
    }
    //选择市 加载县
    getAreas = (cityID) => {
      let data = {
        params: [{
          cityId: cityID
        }],
      }
      $http.post('urlS', this, {
        code: '03030006',
        data: data,
        success: function (res) {
          if (+res.errorCode === 0) {
            this.setState({
              areasArr: res.result,
            })
          } else {
            this.setState({
              areasArr: [],
              VillagesArr: [],
              hamletsArr: [],
            })
          }
        }
      })
    }
    //选择县时加载乡数据
    getVillages = (countyID) => {
      let data = {
        params: [{
          areaId: countyID,
        }],
      }
      $http.post('urlS', this, {
        code: '03030007',
        data: data,
        success: function (res) {
          if (+res.errorCode === 0) {
            this.setState({
              VillagesArr: res.result,
            })
          } else {
            this.setState({
              VillagesArr: [],
              hamletsArr: [],
            })
          }
        }
      })
    }
    getHamlet = (villageId) => {
      let data = {
        params: [{
          villageId: villageId,
        }],
      }
      $http.post('urlS', this, {
        code: '03030008',
        data: data,
        success: function (res) {
          if (+res.errorCode === 0) {
            this.setState({
              hamletsArr: res.result,
            })
          } else {
            this.setState({
              hamletsArr: [],
            })
          }
        }
      })
    }
    // 显示分页总条数
    showTotal(total) {
      return `共 ${total} 条`;
    }
    showModal = (bool) => {
      const { propMethod: { showModal } } = this.props;
      showModal(bool, this.getSelectData);
      this.reset();
    }
    getSelectData = (data) => {
      if (data) {
        if (data.countryId) {
          this.getProvince(data.countryId);
        }
        if (data.provinceId) {
          this.getCity(data.provinceId);
        }
        if (data.cityId) {
          this.getAreas(data.cityId);
        }
        if (data.areaId) {
          this.getVillages(data.areaId);
        }
        if (data.villageId) {
          this.getHamlet(data.villageId);
        }
      }
    }
    render() {
      const { modalVisible, data: params, propMethod } = this.props;
      const { getFieldDecorator } = this.props.form;
      const { baseParms, provinceArr, cityArr, areasArr, VillagesArr, hamletsArr } = this.state;

      //角色
      // let groupOp = []
      // baseParms.group && baseParms.group.map(item => {
      //   groupOp.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
      // })
      // //卡类型
      // let cardTypeOp = []
      // baseParms.cardType && baseParms.cardType.map(item => {
      //   cardTypeOp.push(<Option key={item.id} role={item.descripts} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
      // })
      // //性别
      // let sexOp = []
      // baseParms.sex && baseParms.sex.map(item => {
      //   sexOp.push(<Option key={item.id} role={item.descripts} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
      // })
      // //名族
      // let nationOp = []
      // baseParms.nation && baseParms.nation.map(item => {
      //   nationOp.push(<Option key={item.id} role={item.descripts} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
      // })
      // //患者类别
      // let patTypeOp = []
      // baseParms.patType && baseParms.patType.map(item => {
      //   patTypeOp.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
      // })
      //国家
      // let countryOp = []
      // baseParms.country && baseParms.country.map(item => {
      //   countryOp.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
      // })
      // 上级卫生局
      let supHealthBurOp = []
      baseParms.supHealthBur && baseParms.supHealthBur.map(item => {
        supHealthBurOp.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
      })
      //省
      let provinceOp = []
      baseParms.province && baseParms.province.map(item => {
        provinceOp.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
      })
      //市
      let cityOp = []
      cityArr && cityArr.map(item => {
        cityOp.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
      })
      if ((cityArr) && (cityArr.length === 0) && params && (params.cityID)) {
        cityOp.push(<Option key={params.cityID} role={params.cityDesc} title={params.cityDesc} value={String(params.cityID)}>{params.cityDesc}</Option>)
      }
      //县
      let areaOp = []
      areasArr && areasArr.map(item => {
        areaOp.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
      })
      if ((areasArr) && (areasArr.length === 0) && params && (params.areaID)) {
        areaOp.push(<Option key={params.areaID} role={params.areaDesc} title={params.areaDesc} value={String(params.areaID)}>{params.areaDesc}</Option>)
      }
      //乡
      let villagesOp = []
      VillagesArr && VillagesArr.map(item => {
        villagesOp.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
      })
      if ((VillagesArr) && (VillagesArr.length === 0) && params && (params.villageID)) {
        villagesOp.push(<Option key={params.villageID} role={params.villageDesc} title={params.villageDesc} value={String(params.villageID)}>{params.villageDesc}</Option>)
      }
      //村
      // let hamletOp = []
      // hamletsArr && hamletsArr.map(item => {
      //   hamletOp.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
      // })
      // if ((hamletsArr) && (hamletsArr.length === 0) && params && (params.hamletId)) {
      //   hamletOp.push(<Option key={params.hamletId} role={params.hamletDesc} title={params.hamletDesc} value={String(params.hamletId)}>{params.hamletDesc}</Option>)
      // }
      return (
        <Modal
          onCancel={() => this.showModal(false)}
          title={<span>{params ? '编辑卫生局' : '添加卫生局'}</span>}
          visible={modalVisible} width={1200}
          footer={
            null
          }
        >
          <Form style={{ height: "100%", overflow: "hidden auto" }}>
            <Row>
              <Col span={6} className="patNameDom">
                <FormItem {...formItemLayout} label='序号'>
                  {getFieldDecorator('healthBurSeqNo', {
                    initialValue: params && params.groupId ? healthBurSeqNo && params.healthBurSeqNo : undefined,
                    rules: [{ required: false, message: '', },
                    ],
                  })(
                    <Input />
                  )}
                </FormItem>
              </Col>
              <Col span={6}>
                <FormItem {...formItemLayout} label='代码'>
                  {getFieldDecorator('healthBurCode', {
                    initialValue: params && params.healthBurCode ? params.healthBurCode : undefined,
                    rules: [{ required: true, message: '请输入卫生局代码' }],
                  })(
                    <Input />
                  )}
                </FormItem>
              </Col>
              <Col span={6}>
                <FormItem {...formItemLayout} label='卫生局描述'>
                  {getFieldDecorator('healthBurDesc', {
                    initialValue: params && params.healthBurDesc ? params.healthBurDesc : undefined,
                    rules: [{ required: true, message: '请输入卫生局描述' }],
                  })(
                    <Input />
                  )}
                </FormItem>
              </Col>
              <Col span={6} >
                <FormItem {...formItemLayout} label='上级卫生局'>
                  {getFieldDecorator('supHealthBurID', {
                    initialValue: params && params.supHealthBurID ? String(params.supHealthBurID) : undefined,
                    rules: [{ required: false, message: '' }],
                  })(
                    <Select showSearch allowClear optionFilterProp="role" >
                      {supHealthBurOp}
                    </Select>
                  )}
                </FormItem>
              </Col>
            </Row>
            <Row>
              <Col span={6} className="patNameDom">
                <FormItem {...formItemLayout} label='组织机构代码'>
                  {getFieldDecorator('organizationCode', {
                    initialValue: params && params.organizationCode ? params.organizationCode : undefined,
                    rules: [{ required: true, message: '请输入组织机构代码', },
                    ],
                  })(
                    <Input />
                  )}
                </FormItem>
              </Col>
              <Col span={6} className="patNameDom">
                <FormItem {...formItemLayout} label='营业执照'>
                  {getFieldDecorator('businesslicense', {
                    initialValue: params && params.businesslicense ? params.businesslicense : undefined,
                    rules: [{ required: true, message: '请输入营业执照', },
                    ],
                  })(
                    <Input />
                  )}
                </FormItem>
              </Col>
              <Col span={6} className="patNameDom">
                <FormItem {...formItemLayout} label='邮编'>
                  {getFieldDecorator('ZIPCode', {
                    initialValue: params && params.ZIPCode ? params.ZIPCode : undefined,
                    rules: [{ required: true, message: '请输入邮编', },
                    ],
                  })(
                    <Input />
                  )}
                </FormItem>
              </Col>
              <Col span={6} className="patNameDom">
                <FormItem {...formItemLayout} label='网站地址'>
                  {getFieldDecorator('website', {
                    initialValue: params && params.website ? params.website : undefined,
                    rules: [{ required: true, message: '请输入网站地址', },
                    ],
                  })(
                    <Input />
                  )}
                </FormItem>
              </Col>
              <Col span={6} >
                <FormItem {...formItemLayout} label='省'>
                  {getFieldDecorator('provinceId', {
                    initialValue: params && params.provinceId ? String(params.provinceId) : undefined,
                    rules: [{ required: true, message: '请选择省' }],
                  })(
                    <Select onChange={this.handleProvince} showSearch allowClear optionFilterProp="role" >
                      {provinceOp}
                    </Select>
                  )}
                </FormItem>
              </Col>
              <Col span={6} >
                <FormItem {...formItemLayout} label='市'>
                  {getFieldDecorator('cityId', {
                    initialValue: params && params.cityId ? String(params.cityId) : undefined,
                    rules: [{ required: true, message: '请选择市' }],
                  })(
                    <Select onFocus={this.onCityFocus} onChange={this.handleCity} showSearch allowClear optionFilterProp="role" >
                      {cityOp}
                    </Select>
                  )}
                </FormItem>
              </Col>
              <Col span={6} >
                <FormItem {...formItemLayout} label='区'>
                  {getFieldDecorator('areaId', {
                    initialValue: params && params.areaId ? String(params.areaId) : undefined,
                    rules: [{ required: true, message: '请选择区' }],
                  })(
                    <Select onFocus={this.onAreasFocus} onChange={this.handleAreas} showSearch allowClear optionFilterProp="role" >
                      {areaOp}
                    </Select>
                  )}
                </FormItem>
              </Col>
              <Col span={6} >
                <FormItem {...formItemLayout} label='乡'>
                  {getFieldDecorator('villageId', {
                    initialValue: params && params.villageId ? String(params.villageId) : undefined,
                    rules: [{ required: false, message: '请选择乡' }],
                  })(
                    <Select onChange={this.handleVillages} onFocus={this.onVillagesFocus} showSearch allowClear optionFilterProp="role" >
                      {villagesOp}
                    </Select>
                  )}
                </FormItem>
              </Col>
              <Col span={6} className="patNameDom">
                <FormItem {...formItemLayout} label='卫生局地址'>
                  {getFieldDecorator('address', {
                    initialValue: params && params.address ? String(params.address) : undefined,
                    rules: [{ required: false, message: '' },
                    ],
                  })(
                    <Input />
                  )}
                </FormItem>
              </Col>
              {/* <Col span={6} >
                <FormItem {...formItemLayout} label='村'>
                  {getFieldDecorator('hamletId', {
                    initialValue: params && params.hamletId ? params && params.hamletId : undefined,
                    rules: [{ required: false, message: '请选择村' }],
                  })(
                    <Select showSearch allowClear optionFilterProp="role" >
                      {hamletOp}
                    </Select>
                  )}
                </FormItem>
              </Col> */}
              <Col span={6} >
                <FormItem {...formItemLayout} label='局长姓名'>
                  {getFieldDecorator('deanName', {
                    initialValue: params && params.deanName ? String(params.deanName) : undefined,
                    rules: [{ required: false, message: '' }],
                  })(
                    <Input />
                  )}
                </FormItem>
              </Col>
              <Col span={6} className="patNameDom">
                <FormItem {...formItemLayout} label='局长电话'>
                  {getFieldDecorator('deanPhone', {
                    initialValue: params && params.deanPhone ? params.deanPhone : undefined,
                    rules: [{ required: false, message: '', },
                    ],
                  })(
                    <Input />
                  )}
                </FormItem>
              </Col>
              <Col span={6} className="patNameDom">
                <FormItem {...formItemLayout} label='办公室电话'>
                  {getFieldDecorator('officePhone', {
                    initialValue: params && params.officePhone ? params.officePhone : undefined,
                    rules: [{ required: false, message: '', },
                    ],
                  })(
                    <Input />
                  )}
                </FormItem>
              </Col>
              <Col span={6} className="patNameDom">
                <FormItem {...formItemLayout} label='邮箱'>
                  {getFieldDecorator('email', {
                    initialValue: params && params.email ? params.email : undefined,
                    rules: [{ required: false, message: '请输入网站', },
                    ],
                  })(
                    <Input />
                  )}
                </FormItem>
              </Col>
              <Col span={6} >
                <FormItem label='生效日期' {...formItemLayout}>
                  {getFieldDecorator('startDate', {
                    initialValue: params && params.startDate ? moment(params.startDate, "YYYY-MM-DD") : undefined,
                    rules: [{ required: false, message: '' }],
                  })(
                    <DatePicker style={{ width: '100%' }} placeholder={'请选择生效日期'} disabledDate={(curDate) => {
                      return curDate && curDate > moment().endOf('day');
                    }} />
                  )}
                </FormItem>
              </Col >
              <Col span={6} >
                <FormItem label='失效日期' {...formItemLayout}>
                  {getFieldDecorator('stopDate', {
                    initialValue: params && params.stopDate ? moment(params.stopDate, "YYYY-MM-DD") : undefined,
                    rules: [{ required: false, message: '' }],
                  })(
                    <DatePicker style={{ width: '100%' }} placeholder={'请选择失效日期'} disabledDate={(curDate) => {
                      return curDate && curDate < moment().startOf('day');
                    }} />
                  )}
                </FormItem>
              </Col >
            </Row>
            <Row>
              <Col>
                <div style={{ display: "flex", justifyContent: "center" }}>
                  <Button style={{ marginRight: '30px' }} onClick={() => this.showModal(false)}>取消</Button>
                  <Button style={{ marginRight: '30px' }} type="primary" onClick={this.save}>{params && params.healthBurID ? "更新" : "新增"}</Button>
                  <Button type="primary" onClick={this.reset}>重置</Button>
                </div>
              </Col>
            </Row>
          </Form>
        </Modal>
      );
    }
  });

class RoleMaintenance extends React.Component {
  constructor() {
    super();
    this.state = {
      // 角色名称
      name: undefined,
      // 关联岗位
      quarters: undefined,
      // 记录状态
      status: undefined,
      // 表格数据
      tableData: [],
      // 表格数据总条数
      total: 0,
      showLoading: true,
      page: 1,
      pageSize: 10,
      selectData: {}, // 下拉框数据
      headerHeight: 0,

      modalVisible: false,
      editData: {}
    };
    this.columns = [
      {
        key: 1,
        title: '卫生局代码',
        dataIndex: 'healthBurCode',
        align: "center",
        width: '15%'
      },
      {
        key: 2,
        title: '卫生局描述',
        dataIndex: 'healthBurDesc',
        align: "center",
        width: '10%'
      },
      {
        key: 3,
        title: '上级卫生局',
        dataIndex: 'supHealthBurDesc',
        align: "center",
        width: '10%'
      },
      {
        key: 5,
        title: '组织机构代码',
        dataIndex: 'organizationCode',
        align: "center",
        width: '10%'
      },
      {
        key: 6,
        title: '营业执照',
        dataIndex: 'businesslicense',
        align: "center",
        width: '10%'
      },
      {
        key: 7,
        title: '局长姓名',
        dataIndex: 'deanName',
        align: "center",
        width: '10%'
      },
      {
        key: 9,
        title: '地址',
        dataIndex: 'provDesc',
        align: "center",
        width: '28%',
        render: (text, record) => {
          let add = record.provinceDesc + '，' + record.cityDesc + '，' + record.areaDesc;
          add = record.villageDesc ? add + '，' + record.villageDesc : add;
          add = record.hamletDesc ? add + '，' + record.hamletDesc : add;
          return <span>{add}</span>
        }
      },
      {
        title: '操作',
        key: 10,
        align: "center",
        width: 130,
        fixed: 'right',
        render: (text, record) => (
          <span>
            <Icon type="edit" style={{ color: '#108EE9' }}></Icon>
            <span className='span' onClick={() => this.handleCompile(record)}>编辑</span>
            <Divider type="vertical" />
            <Icon type="delete" style={{ color: 'rgba(240,65,52,1)' }}></Icon>
            <Popconfirm title="删除不可恢复，你确定要删除吗?" onConfirm={() => this.handleDetele(record)} >
              <span className='span' style={{ color: 'rgba(240,65,52,1)' }}>删除</span>
            </Popconfirm>
          </span>
        ),
      }
    ]

  }

  componentDidMount() {
    // 初始化列表数据
    this.handleQuery();
    // 组件加载完毕关闭loading
    this.setState({ showLoading: false });
    this.getBaseParams();
  }
  getBaseParams = () => {
    let data = {
      params: [{
        // hospID: 
        hospID: ""
      }],
    }
    $http.post("urlS", this, {
      code: "05100220",
      data: data,
      success: function (res) {
        if (+res.errorCode === 0) {
          this.setState({
            supHealthBur: res.result.Data
          })
        } else {
          message.error('失败：' + res.errorMessage);
        }
      },
      error: function (error) {
        message.error('失败：' + error);
      }
    });
  }

  componentWillUnmount() {
    // 组件销毁前将静止让setState修改state的状态
    this.setState = (state, callback) => { return; }
  }

  // 调用子组件的连接事件
  onRef = (ref) => {
    this.child = ref
  }

  // 提供修改page和pageSize的回调函数
  compilePage(page, pageSize) {
    // 修改page，或者pageSize
    this.setState({ page: page, pageSize: pageSize }, () => {
      // 重新调用查询方法
      let { status, name, quarters } = this.state;
      this.getTableData();
    })
  }

  // 请求列表数据
  getTableData() {
    let { page, pageSize } = this.state;
    let data = {};
    this.props.form.validateFields((error, values) => {
      if (error) {
        return;
      }
      data = {
        params: [{
          inputValue: values && values.search ? values.search : '',
          supHealthBurID: values && values.supHealthBurIDs ? values.supHealthBurIDs : '',
        }],
        pagination: [{
          pageSize: pageSize,
          currentPage: page,
          // sortColumn: "",
          // sortOrder: ""
        }]
      };
      $http.post('urlS', this, {
        code: "05100240",
        data: data,
        success: function (res) {
          if (+res.errorCode === 0 && res.result) {
            this.setState({ tableData: res.result.Data, total: res.result.TotalCount }, () => {
              // 数据加载成功关闭loading
              this.child.handleLoading()
            })
          } else {
            this.setState({ tableData: [], total: 0 }, () => {
              // 数据加载成功关闭loading
              this.child.handleLoading();
            })
          }
        },
        error: function () {
          this.setState({ tableData: [], total: 0 }, () => {
            // 数据加载成功关闭loading
            this.child.handleLoading();
          })
        }
      });
    });

  }

  // 查询
  handleQuery = () => {
    this.setState({ page: 1, pageSize: 10 }, () => {
      this.getTableData();
    })
  }

  // 新增跳转到新增界面
  handleAdd = () => {
    this.setState({ editData: { startDate: moment() } });
    this.showModal(true);
  }
  handleDetele = (record) => {
    let data = {
      params: [{
        updateUserID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).userID : "",
        healthBurID: record.healthBurID
      }]
    }
    $http.post('urlADS', this, {
      code: '05100243',
      data: data,
      success: function (res) {
        if (+res.errorCode === 0) {
          message.success('删除成功');
          // 刷新列表数据
          this.handleQuery();
        }
      }
    })
  }
  // 编辑
  handleCompile = (record) => {
    this.setState({ editData: record });
    this.modalRef.getSelectData(record);
    this.showModal(true);
  }
  //控制模态框显示
  showModal = (bool) => {
    this.setState({ modalVisible: bool });
  }

  render() {
    const { getFieldDecorator } = this.props.form;
    const { supHealthBur } = this.state
    // 组件所需参数
    const param = {
      // 表头配置
      columns: this.columns,
      // 表格数据
      data: this.state.tableData,
      // 数据总条数
      total: this.state.total,
      // 当前页数
      page: this.state.page,
      // 表格的宽度
      x: '100%',
      y: store.getState().tableHeight.y + 81 - this.state.headerHeight,
      height: store.getState().tableHeight.y + 50 - this.state.headerHeight + 'px',
    }
    // 上级卫生局
    let supHealthBurOps = []
    supHealthBur && supHealthBur.map(item => {
      supHealthBurOps.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
    })
    return (
      <Spin tip="加载中..." spinning={this.state.showLoading}>
        <div>
          <Form>
            <Row style={{ margin: '23px 0 0 0' }}>
              <Col span={5} style={paddRightCol}>
                <FormItem {...formItemLayoutType}>
                  {getFieldDecorator('search', {
                    initialValue: undefined,
                    rules: [{ required: false, message: '' }],
                  })(
                    <Input placeholder="描述/代码回车搜索 支持模糊搜索" allowClear onPressEnter={this.handleQuery}></Input>
                  )}
                </FormItem>
              </Col>
              <Col span={3} >
                <FormItem {...formItemLayoutTop} label='上级卫生局'>
                  {getFieldDecorator('supHealthBurIDs', {
                    initialValue: undefined,
                    rules: [{ required: false, message: '' }],
                  })(
                    <Select showSearch allowClear optionFilterProp="role" >
                      {supHealthBurOps}
                    </Select>
                  )}
                </FormItem>
              </Col>
              <Col span={1} style={{ margin: "0 16px" }}>
                <FormItem {...formItemLayout}>
                  {getFieldDecorator('btn', {
                    initialValue: undefined,
                    rules: [{ required: false, message: '' }],
                  })(
                    <Button onClick={this.handleQuery} style={{ margin: '4px 15px 20px 0', background: 'rgba(255,255,255,1)' }}>查询</Button>
                  )}
                </FormItem>
              </Col>
              <Col span={2}>
                <FormItem {...formItemLayout}>
                  {getFieldDecorator('newAdd', {
                    initialValue: undefined,
                    rules: [{ required: false, message: '' }],
                  })(
                    <Button icon="plus" onClick={this.handleAdd} style={{ background: 'rgba(247,128,93,1)', color: '#fff', margin: '4px 0 0 0' }}>新增卫生局</Button>
                  )}
                </FormItem>
              </Col>
            </Row>
          </Form>
        </div>
        <div style={{ width: '100%', height: '10px', background: '#f0f2f5' }}></div>
        <div style={{ padding: '24px 0 0 0' }} className="table-body-height">
          {/* handelThis将夫组件的属性与方法给子组件访问 */}
          <PubilcTablePagination param={param} handelThis={this} onRef={this.onRef} />
        </div>
        <HospitalMaintenance wrappedComponentRef={(el) => this.modalRef = el} data={this.state.editData} modalVisible={this.state.modalVisible} propMethod={{ showModal: this.showModal, findData: this.handleQuery }} />
      </Spin>
    )
  }
}
export default Form.create()(RoleMaintenance);