//草药配置
import React from 'react';
import { Form, Row, Col, Input, Table, Select, DatePicker, Popconfirm, Button, Modal, message, Divider, Tooltip, Icon, Spin, Card, Checkbox, Badge, Fragment, Pagination } from 'antd';
import moment from 'moment';
import { $http } from '../../containers/config/https';
import store from '../../store';
import './css/OrderTemple.less';

const userData = sessionStorage.userData ? JSON.parse(sessionStorage.userData) : {}
const FormItem = Form.Item;
const Option = Select.Option;
const formItemLayout = {
  labelCol: { span: 7 },
  wrapperCol: { span: 15 },
}
const formItemLayoutCheck = {
  labelCol: { span: 3 },
  wrapperCol: { span: 24 },
}
const formItemLayoutLoc = {
  labelCol: { span: 12 },
  wrapperCol: { span: 10 },
}
const formItemLayout104 = {
  labelCol: { span: 10 },
  wrapperCol: { span: 14 },
}
const formItemLayout814 = {
  labelCol: { span: 8 },
  wrapperCol: { span: 14 },
}
const paddingZero = {
  padding: 0
}
const ConfigHerbal = Form.create()(
  class ConfigHerbal extends React.Component {
    cacheOriginData = {};
    constructor() {
      super()
      this.state = {
        leftTableData: [],//右边双击后的表格数据
        rowId: "",//表格行id 设置颜色
        ordShow: false,//当前模板显示
        baseAddMate: [],//草药配置 附加材料选择
        baseFrequency: [],//草药配置 默认频次
        baseUsage: [],//草药配置 默认用法
        baseFrying: [],//代煎费
        baseCourse: [],//疗程
        baseEmergencyLoc: [],//门急诊默认接收科室
        baseHospitalizationLoc: [],//住院默认接收科室
        baseSubclassifications: [],//子分类
        baseFryingGetLocs: [],//代煎接收科室
        baseEmergencyGetLocs: [],//急诊代煎接收科室
        consumpTion: [],//用量
        autoCumpChecked: false,
        autoAddChecked: false,
        disfrying: false,
        emergencyChecked: false,
        hospitalizationChecked: false,

        selectrow: "",//获取行 当前选中行
        newOpen: [],
        selectedRowKeys_right: [],//子分类
        selectedRowKeys_rightFry: [],//代煎接收科室
        selectedRowKeys_rightEme: [],//急诊代煎接收科室
        selectedRowKeys_treatment: [],//门/急诊接收科室
        selectedRowKeys_hospital: [],//住院接收科室
        selectedRowIds_O: [],
        selectedRowIds_Fry: [],
        selectedRowIds_Eme: [],
        selectedRowIds_Ent: [],
        selectedRowIds_Tal: [],
        isMod: -1,//是否修改
        ordTempletID: "",//左侧表格row id
        visible: false,
        rightInfo: {},
        modifyInfo: {},
        checked: true,
        emergencyLocData: [],//门急诊接收科室动态下拉框
        hospitalizationLocData: [],//住院接收科室动态下拉框
        tableLoading: false,
        selectData: [],
        //煎药方式
        baseCookType: [],
        selectedRowKeys_cookType: [],
        selectedRowIds_cookType: [],
        cookTypeData: [],// 默认煎药方式动态下拉框

      }
      this.detailDeInput = React.createRef();
    }
    componentDidMount = () => {
      // 初始化设置table的高度以及表体的高度
      if (document.querySelector('.ant-table-body')) {
        document.querySelector('.ant-table-body').style.height = store.getState().tableHeight.y + 'px'
        this.getHerbalConfig()
        this.getSelect()
        this.getSelectData()
      }
    }
    // 获取服用要求
    getSelectData = () => {
      let data = {
        params: [
          {
            usageExplainFlag: '1',
          }
        ]
      }
      $http.post('urlS', this, {
        code: "03050018",
        data: data,
        success: function (res) {
          if (+res.errorCode === 0) {
            this.setState({ selectData: res })
          }
        }
      })
    }

    //获取草药配置模板类型下拉框数据
    getSelect = () => {
      let data = {}
      data = {
        params: [{
          hospID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).hospID : "",
          addMaterialFlag: "Y",
          freqFlag: "Y",
          usageFlag: "Y",
          ordSubCatFlag: "Y",
          recLocFlag: "Y",
          cookTypeFlag: "Y",
        }],
      }
      $http.post('urlS', this, {
        code: '03050082',
        data: data,
        success: function (res) {
          if (+res.errorCode === 0) {
            this.setState({
              baseCookType: res.data.cookTypeList,
              baseAddMate: res.data.addMaterialList,
              baseFrequency: res.data.freqList,
              baseUsage: res.data.usageList,
              baseEmergencyLoc: res.data.recLocList,
              baseHospitalizationLoc: res.data.recLocList,
              baseSubclassifications: res.data.ordSubCatList,
              baseFryingGetLocs: res.data.recLocList,
              baseEmergencyGetLocs: res.data.recLocList,
            })
          }
        }
      })
    }
    //获取草药剂型表格信息
    getHerbalConfig = (num) => {
      let data = {}
      data = {
        params: [{
          hospID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).hospID : "",
          searchCode: "",
          active: this.state.checked == true ? "Y" : " "
        }],
      }
      $http.post('urlS', this, {
        code: '03050079',
        data: data,
        success: function (res) {
          if (+res.errorCode === 0) {
            // console.log("获取草药剂型表格信息",res)
            this.setState({
              leftTableData: res.data
            })
            if (res.data && res.data.length > 0) {
              // console.log("this.state.ordTempletID",this.state.ordTempletID)
              if (num == "1") {
                this.getDeatil(res.data[res.data.length - 1].id)
                this.setState({
                  rowId: res.data[res.data.length - 1].id,
                  ordTempletID: res.data[res.data.length - 1].id,
                })
              }
              else if (num == "2") {
                this.getDeatil(this.state.ordTempletID)
                this.setState({
                  rowId: this.state.ordTempletID,
                  ordTempletID: this.state.ordTempletID,
                })
              }
              // else {
              //   this.getDeatil(res.data[0].id)
              //   this.setState({
              //     rowId: res.data[0].id,
              //     ordTempletID: res.data[0].id,
              //   })
              // }
            }
          }
        }
      })
    }
    //获取草药配置模板明细
    getDeatil = (herbalFromID) => {
      this.setState({
        tableLoading: true
      })
      let data = {}
      data = {
        params: [{
          herbalFromID: herbalFromID,
        }],
      }
      // this.restRight()
      $http.post('urlS', this, {
        code: '03050081',
        data: data,
        success: function (res) {
          // console.log(res,this.state.selectedRowKeys_right)
          if (+res.errorCode === 0 && res.data) {
            let arr = []
            let arrID = []
            let arrT = []
            let attTID = []
            let arrS = []
            let arrSID = []
            let arrR = []
            let arrRID = []
            let arrRd = []
            let arrH = []
            let arrHID = []
            let arrHd = []
            let arrK = []
            let arrKe = []
            this.setState({
              emergencyLocData: [],
              hospitalizationLocData: [],
              cookTypeData: [],
            })
            // this.setState({
            //   rightInfo: res.data,
            //   selectedRowKeys_right: arr,
            //   selectedRowKeys_rightFry: arrT,//代煎接收科室
            //   selectedRowKeys_rightEme: arrS,//急诊代煎接收科室
            //   selectedRowKeys_treatment: arrR,//门/急诊接收科室
            //   selectedRowKeys_hospital: arrH,//住院接收科室
            //   autoCumpChecked: res.data.autMaterialFlag == "Y" ? true : false,
            //   autoAddChecked: res.data.autTisaneFeeFlag == "Y" ? true : false,
            //   disfrying: res.data.noTisaneFeeFlag == "Y" ? true : false,
            //   emergencyChecked: res.data.defaultFlagO == "Y" ? true : false,
            //   hospitalizationChecked: res.data.defaultFlagI == "Y" ? true : false,
            // })
            this.props.form.setFieldsValue({
              addMate: res.data.addMaterialID,
              Frequency: res.data.freqID,
              usage: res.data.usageID,
              course: res.data.durQty,
              consumption: res.data.doseQty,
              emergencyLoc: res.data.defRecLocOID,
              hospitalizationLoc: res.data.defRecLocIID,
              usageExplainID: res.data.usageExplainID,
              cookTypeID: res.data.cookTypeID,
            })
            //子分类
            this.state.baseSubclassifications.map((items, indexs) => {
              res.data.subCatList.map((ites, is) => {
                if (ites == items.id) {
                  arr.push(indexs)
                }
              })
            })
            //代煎接收科室
            this.state.baseFryingGetLocs.map((iteme, indexe) => {
              res.data.tRecLocList.map((itee, ie) => {
                if (itee == iteme.id) {
                  arrT.push(indexe)
                }
              })
            })
            //急诊代煎接收科室
            this.state.baseEmergencyGetLocs.map((itemr, indexr) => {
              res.data.tEMRecLocList.map((iter, ir) => {
                if (iter == itemr.id) {
                  arrS.push(indexr)
                }
              })
            })
            //门诊接收科室
            this.state.baseEmergencyGetLocs.map((item, index) => {
              res.data.recLocList.map((ite, ir) => {
                if (ite == item.id) {
                  arrR.push(index)
                  arrRd.push(item)
                  this.setState({
                    emergencyLocData: arrRd
                  })
                }
              })
            })
            //住院接收科室
            this.state.baseEmergencyGetLocs.map((itemd, indexd) => {
              res.data.iRecLocList.map((ite, ir) => {
                if (ite == itemd.id) {
                  arrH.push(indexd)
                  arrHd.push(itemd)
                  this.setState({
                    hospitalizationLocData: arrHd
                  })
                }
              })
            })
               //煎药方式
              this.state.baseCookType.map((item, index) => {
                res.data.cookTypeList.map((ite, ir) => {
                  if (ite == item.id) {
                    arrK.push(index)
                    arrKe.push(item)
                    this.setState({
                      cookTypeData: arrKe
                    })
                  }
                })
              })
            this.setState({
              rightInfo: res.data,
              selectedRowKeys_right: arr,//子分类
              selectedRowIds_O: res.data.subCatList,
              selectedRowKeys_rightFry: arrT,//代煎接收科室
              selectedRowIds_Fry: res.data.tRecLocList,
              selectedRowKeys_rightEme: arrS,//急诊代煎接收科室
              selectedRowIds_Eme: res.data.tEMRecLocList,
              selectedRowKeys_treatment: arrR,//门/急诊接收科室
              selectedRowIds_Ent: res.data.recLocList,
              selectedRowKeys_hospital: arrH,//住院接收科室
              selectedRowIds_Tal: res.data.iRecLocList,
              autoCumpChecked: res.data.autMaterialFlag == "Y" ? true : false,
              autoAddChecked: res.data.autTisaneFeeFlag == "Y" ? true : false,
              disfrying: res.data.noTisaneFeeFlag == "Y" ? true : false,
              emergencyChecked: res.data.defaultFlagO == "Y" ? true : false,
              hospitalizationChecked: res.data.defaultFlagI == "Y" ? true : false,
              selectedRowIds_cookType:res.data.cookTypeList,
              selectedRowKeys_cookType:arrK,//煎药方式
            }, () => {
              this.setState({
                tableLoading: false
              })
            })

          }
        }
      })
    }
    //点击Row 左侧表格
    onClickRow = (record) => {
      return {
        onClick: () => {
          // this.props.form.resetFields();
          //  this.props.form.setFieldsValue({
          //       addMate: res.data.addMaterialID,
          //       Frequency: res.data.freqID,
          //       usage: res.data.usageID,
          //       course: re.data.durQty,
          //       consumption: res.data.doseQty,
          //       emergencyLoc: res.data.defRecLocOID,
          //       hospitalizationLoc: res.data.defRecLocIID,
          //     })
          if (record.id) {
            if (this.state.rowId === "") {
              this.setState({
                rowId: record.id,
                ordTempletID: record.id,
              });
              this.getDeatil(record.id)
            } else {
              if (this.state.rowId !== record.id) {
                this.setState({
                  rowId: record.id,
                  ordTempletID: record.id,
                });
                this.getDeatil(record.id)
              } else {
                this.setState({
                  rowId: "",
                  ordTempletID: ""
                });
              }
            }
          }
          // this.setState({
          //   rowId: record.id,
          //   ordTempletID: record.id,
          // })
          // this.getDeatil(record.id)
        },
        onDoubleClick: () => {
          this.setState({
            rowId: "",
            ordTempletID: ""
          });
        }
      };
    }
    //重置右侧明细
    restRight = () => {
      this.props.form.setFieldsValue({
        addMate: undefined,
        Frequency: undefined,
        usage: undefined,
        course: undefined,
        consumption: undefined,
        emergencyLoc: undefined,
        hospitalizationLoc: undefined,
        usageExplainID: undefined,
        cookTypeID: undefined
      })
      this.setState({
        autoCumpChecked: false,
        autoAddChecked: false,
        disfrying: false,
        emergencyChecked: false,
        hospitalizationChecked: false,
        selectedRowKeys_right: [],
        selectedRowKeys_rightFry: [],
        selectedRowKeys_rightEme: [],
        selectedRowKeys_treatment: [],
        selectedRowKeys_hospital: [],
        selectedRowIds_O: [],
        selectedRowIds_Ent: [],
        selectedRowIds_Tal: [],
        selectedRowIds_Fry: [],
        selectedRowIds_Eme: [],
        selectedRowKeys_cookType: [],
        selectedRowIds_cookType: [],
      })
    }
    //设置点击row颜色 --左侧表格
    setRowClassName = (record) => {
      return record.id === this.state.rowId ? 'clickRowStyle' : '';
    }
    //编辑/删除  草药配置项表格行
    toggleEditable = (e, data, num) => {
      e.stopPropagation()
      if (num == "1") {
        this.props.form.setFieldsValue({ code: data.code });
        this.props.form.setFieldsValue({ descripts: data.descripts });
        this.props.form.setFieldsValue({ startDate: moment(data.startDate) });
        this.props.form.setFieldsValue({ stopDate: data.stopDate ? moment(data.stopDate) : undefined });
        this.setState({
          modifyInfo: data,
          isMod: 1,
          visible: true,
          ordTempletID: data.id,
          rowId: data.id,
        }, () => {
          return
        })
      } else {
        //删除 草药配置项表格行
        let datas = {}
        datas = {
          params: [{
            herbalFromID: data.id,
            userID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).userID : "",
          }],
        }
        $http.post('urlS', this, {
          code: '03050078',
          data: datas,
          success: function (res) {
            if (+res.errorCode === 0) {
              message.success("删除成功");
              this.getHerbalConfig()
              this.setState({
                rowId: "",
                ordTempletID: ""
              });
            }
          }
        })
      }
    }
    //初始化信息
    initData = () => {
      this.setState({
        ordShow: false,
        modifyInfo: {}
      })
    }
    //点击添加/修改遗嘱模板弹窗取消按钮
    handleCancel = () => {
      this.setState({
        visible: false
      })
      this.initData()
    }
    // 阻止默认事件
    handleStopPropagation = (e) => {
      if (typeof e == 'object') {
        e.stopPropagation();
      }
    }
    //新增草药配置项模板
    addOrd = () => {
      this.setState({
        visible: true,
        isMod: -1,
      })
      this.initData()
    }
    //右侧勾选check                   
    changeChecked = (e, num) => {
      switch (num) {
        case 1:
          this.setState({
            autoCumpChecked: e.target.checked
          })
          break;
        case 2:
          this.setState({
            autoAddChecked: e.target.checked
          })
          break;
        case 3:
          this.setState({
            disfrying: e.target.checked
          })
          break;
        case 4:
          this.setState({
            emergencyChecked: e.target.checked
          })
          break;
        case 5:
          this.setState({
            hospitalizationChecked: e.target.checked
          })
          break;
        default:

      }
    }
    //保存右侧明细
    saveRight = () => {
      this.props.form.validateFields((err, values) => {
        let data = {}
        data = {
          params: [{
            herbalFromID: this.state.ordTempletID || "",
            userID: userData && userData ? sessionStorage.userData ? JSON.parse(sessionStorage.userData).userID : "" : "",
            freqID: values.Frequency || "",
            usageID: values.usage || "",
            durQty: values.course || "",
            doseQty: values.consumption || "",
            addMaterialID: values.addMate || "",
            tisaneFeeID: "",
            autMaterialFlag: this.state.autoCumpChecked == true ? "Y" : "N",
            AutTisaneFeeFlag: this.state.autoAddChecked == true ? "Y" : "N",
            noTisaneFeeFlag: this.state.disfrying == true ? "Y" : "N",
            defRecLocOID: values.emergencyLoc || "",
            defRecLocIID: values.hospitalizationLoc || "",
            usageExplainID: values.usageExplainID || "",
            defaultFlagO: this.state.emergencyChecked == true ? "Y" : "N",
            defaultFlagI: this.state.hospitalizationChecked == true ? "Y" : "N",
            subCatList: this.state.selectedRowIds_O || [],
            recLocList: this.state.selectedRowIds_Ent || [],
            iRecLocList: this.state.selectedRowIds_Tal || [],
            tRecLocList: this.state.selectedRowIds_Fry || [],
            tEMRecLocList: this.state.selectedRowIds_Eme || [],
            cookTypeID: values.cookTypeID || "",
            cookTypeList: this.state.selectedRowIds_cookType || []
          }],
        }
        $http.post('urlS', this, {
          code: '03050080',
          data: data,
          success: function (res) {
            if (+res.errorCode === 0) {
              message.success("保存成功")
            }
          }
        })
      })
    }
    //重置
    // rest=()=>{
    //   this.props.form.setFieldsValue({
    //     addMate: undefined,
    //     Frequency: undefined,
    //     usage: undefined,
    //     course: undefined,
    //     consumption: undefined,
    //     emergencyLoc: undefined,
    //     hospitalizationLoc: undefined,
    //   })
    //   this.restRight()
    // }

    initData = () => {
      this.setState({
        isMod: -1,
      })
      this.props.form.setFieldsValue({ code: undefined });
      this.props.form.setFieldsValue({ descripts: undefined });
      this.props.form.setFieldsValue({ startDate: moment() });
      this.props.form.setFieldsValue({ stopDate: undefined });
    }
    //点击添加/修改草药配置弹窗确认按钮
    handleOk = (e) => {
      this.props.form.validateFields((err, values) => {
        if (!err) {
          let data = {}
          data = {
            params: [{
              herbalFromID: this.state.isMod == 1 ? this.state.ordTempletID : "",
              code: values.code,
              descripts: values.descripts,
              hospID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).hospID : "",
              startDate: values.startDate && values.startDate ? moment(values.startDate).format('YYYY-MM-DD') : "",
              stopDate: values.stopDate && values.stopDate ? moment(values.stopDate).format('YYYY-MM-DD') : "",
              userID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).userID : "",
            }],
          }
          $http.post('urlS', this, {
            code: '03050077',
            data: data,
            success: function (res) {
              if (+res.errorCode === 0) {
                this.setState({
                  visible: false
                })
                if (this.state.isMod == 1) {
                  message.success("修改成功");
                  this.getHerbalConfig("2")
                  this.setState({
                    rowId: this.state.ordTempletID,
                  });
                } else {
                  message.success("新建成功");
                  this.getHerbalConfig("1")
                }
                this.initData()
              } else {

              }
            }
          })
        }
      })
    }
    //点击是否生效
    changeCheckedFlag = (e) => {
      this.setState({
        checked: e.target.checked
      }, () => {
        this.getHerbalConfig()
      })
    }
    render() {
      const { getFieldDecorator } = this.props.form;
      let { rightInfo, tableLoading, selectData } = this.state
      const antIcon = <Icon type="loading" style={{ fontSize: 24 }} spin />
      //附加材料选择
      let addMaterials = []
      this.state.baseAddMate && this.state.baseAddMate.map(item => {
        addMaterials.push(<Option key={item.id} value={String(item.id)}>{item.descripts}</Option>)
      })
      //默认频次
      let frequencys = []
      this.state.baseFrequency && this.state.baseFrequency.map(item => {
        frequencys.push(<Option key={item.id} value={String(item.id)}>{item.descripts}</Option>)
      })

      //默认用法
      let usages = []
      this.state.baseUsage && this.state.baseUsage.map(item => {
        usages.push(<Option key={item.id} value={String(item.id)}>{item.descripts}</Option>)
      })

      //代煎费
      let fryings = []
      this.state.baseFrying && this.state.baseFrying.map(item => {
        fryings.push(<Option key={item.id} value={String(item.id)}>{item.descripts}</Option>)
      })

      //默认疗程
      let courses = []
      this.state.baseCourse && this.state.baseCourse.map(item => {
        courses.push(<Option key={item.id} value={String(item.id)}>{item.descripts}</Option>)
      })

      //默认用量 
      let consumptions = []
      this.state.consumpTion && this.state.consumpTion.map(item => {
        consumptions.push(<Option key={item.id} value={String(item.id)}>{item.descripts}</Option>)
      })

      //门急诊默认接收科室
      let emergencyLocs = []
      this.state.emergencyLocData && this.state.emergencyLocData.map(item => {
        emergencyLocs.push(<Option key={item.id} value={String(item.id)}>{item.descripts}</Option>)
      })

      //住院默认接收科室
      let hospitalizationLocs = []
      this.state.hospitalizationLocData && this.state.hospitalizationLocData.map(item => {
        hospitalizationLocs.push(<Option key={item.id} value={String(item.id)}>{item.descripts}</Option>)
      })


      // 服用要求
      let usageExplainOption = selectData.usageExplain && selectData.usageExplain.map((item, index) => {
        return (<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
      })
      //煎药方式
      let cookTypeOption = []
      this.state.cookTypeData && this.state.cookTypeData.map((item, index) => {
        cookTypeOption.push(<Option key={index} value={item.id} title={item.descripts} seatchprop={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
      })

      //子分类
      let subclassifications = []
      this.state.baseSubclassifications && this.state.baseSubclassifications.map(item => {
        subclassifications.push(<Option key={item.id} value={String(item.id)}>{item.descripts}</Option>)
      })

      //代煎接收科室
      let fryingGetLocs = []
      this.state.baseFryingGetLocs && this.state.baseFryingGetLocs.map(item => {
        fryingGetLocs.push(<Option key={item.id} value={String(item.id)}>{item.descripts}</Option>)
      })


      //急诊代煎接收科室
      let emergencyGetLocs = []
      this.state.baseEmergencyGetLocs && this.state.baseEmergencyGetLocs.map(item => {
        emergencyGetLocs.push(<Option key={item.id} value={String(item.id)}>{item.descripts}</Option>)
      })
      let addMate = []
      this.state.baseUsage && this.state.baseUsage.map(item => {
        addMate.push(<Option key={item.id} value={String(item.id)}>{item.descripts}</Option>)
      })
      //右侧明细 煎药
      const cookTypeColumns = [
        {
          align: "center",
          title: '煎药方式',
          dataIndex: 'descripts',
          key: 'descripts',
          editable: true,
        },
      ]
      //左侧处方剂型
      const leftColumns = [
        {
          width: 80,
          align: "center",
          title: '代码',
          dataIndex: 'code',
          key: 'code',
          editable: true,
          render: (text, record) => {
            if (record.editable) {
              return (
                <Input
                  onClick={this.handleStopPropagation}
                  value={text}
                  autoFocus
                  onChange={e => this.handleFieldChange(e, 'code', record)}
                  placeholder="代码"
                />);
            }
            return text;
          }
        },
        {
          width: 150,
          align: "center",
          title: '名称',
          dataIndex: 'descripts',
          key: 'descripts',
          editable: true,

        },
        {
          width: 80,
          align: "center",
          title: '有效标志',
          dataIndex: 'active',
          key: 'active',
          editable: true,
          render: (text, record, index) => {
            if (text == "Y") {
              text = "生效"
              return text
            } if (text == "N") {
              text = "失效"
              return text
            }
            return text;
          },
        },
        {
          title: '操作',
          dataIndex: 'operation',
          align: "center",
          key: 'ordTempletEdit',
          width: 80,
          render: (text, record, index) => {
            return (
              <span>
                <a onClick={(e) => this.toggleEditable(e, record, "1")}>编辑</a>
                <Divider type="vertical" />
                {/* <a style={{color:"red"}} onClick={(e) => this.toggleEditable(record,"2")}>删除</a> */}
                <Popconfirm title="是否要删除此行" onConfirm={(e) => this.toggleEditable(e, record, "2")}>
                  <a style={{ color: "red" }} >删除</a>
                </Popconfirm>
              </span>
            )
          }
        }
      ];
      //右侧明细 子分类
      const childColumns = [
        {
          align: "center",
          title: '子分类',
          dataIndex: 'descripts',
          key: 'descripts',
          editable: true,
        },]
      //右侧明细 代煎接收科室
      const fryingColumns = [
        {
          align: "center",
          title: '代煎接收科室',
          dataIndex: 'descripts',
          key: 'descripts',
          editable: true,
        },
      ]
      //右侧明细 急诊代煎接收科室
      const emergencyColumns = [
        {
          align: "center",
          title: '急诊代煎接收科室',
          dataIndex: 'descripts',
          key: 'descripts',
          editable: true,
        },
      ]
      //右侧明细 门/急诊接收科室
      const entrgencyColumns = [
        {
          align: "center",
          title: '门/急诊接收科室',
          dataIndex: 'descripts',
          key: 'descripts',
          editable: true,
        },
      ]
      //右侧明细 住院接收科室
      const talrgencyColumns = [
        {
          align: "center",
          title: '住院接收科室',
          dataIndex: 'descripts',
          key: 'descripts',
          editable: true,
        },
      ]

      //子分类
      const rowSelection_right = {
        selectedRowKeys: this.state.selectedRowKeys_right,
        onChange: (selectedRowKeys, selectedRows) => {
          let selectrow = "";
          if (selectedRowKeys.length === 0) {
          } else {
            selectrow = selectedRowKeys[selectedRowKeys.length - 1];
          }
          let arr = []
          selectedRows.map((item, i) => {
            arr.push(item.id)
          })
          this.setState({ selectedRowIds_O: arr, selectrow: selectrow, selectedRow_right: selectedRows, selectedRowKeys_right: selectedRowKeys }, () => {
          });
        },
        onSelectAll: (selected, selectedRows, changeRows) => {
          let arr = []
          selectedRows.map((item, i) => {
            arr.push(item.id)
          })
          this.setState({ selectedRowIds_O: arr, selectedRow_right: selectedRows });
        }
      };
      //代煎接收科室
      const rowSelection_rightFry = {
        selectedRowKeys: this.state.selectedRowKeys_rightFry,
        onChange: (selectedRowKeys, selectedRows) => {
          let selectrow = "";
          if (selectedRowKeys.length === 0) {
          } else {
            selectrow = selectedRowKeys[selectedRowKeys.length - 1];
          }
          let arr = []
          selectedRows.map((item, i) => {
            arr.push(item.id)
          })
          this.setState({ selectedRowIds_Fry: arr, selectrow: selectrow, selectedRow_right: selectedRows, selectedRowKeys_rightFry: selectedRowKeys }, () => {
          });
        },
        onSelectAll: (selected, selectedRows, changeRows) => {
          let arr = []
          selectedRows.map((item, i) => {
            arr.push(item.id)
          })
          this.setState({ selectedRowIds_Fry: arr, selectedRow_right: selectedRows });
        }
      };
      //急诊代煎接收科室
      const rowSelection_rightEme = {
        selectedRowKeys: this.state.selectedRowKeys_rightEme,
        onChange: (selectedRowKeys, selectedRows) => {
          let selectrow = "";
          if (selectedRowKeys.length === 0) {
          } else {
            selectrow = selectedRowKeys[selectedRowKeys.length - 1];
          }
          let arr = []
          selectedRows.map((item, i) => {
            arr.push(item.id)
          })
          this.setState({ selectedRowIds_Eme: arr, selectrow: selectrow, selectedRow_right: selectedRows, selectedRowKeys_rightEme: selectedRowKeys }, () => {
          });
        },
        onSelectAll: (selected, selectedRows, changeRows) => {
          let arr = []
          selectedRows.map((item, i) => {
            arr.push(item.id)
          })
          this.setState({ selectedRowIds_Eme: arr, selectedRow_right: selectedRows });
        }
      };
      //门/急诊接收科室
      const rowSelection_rightEnt = {
        selectedRowKeys: this.state.selectedRowKeys_treatment,
        onChange: (selectedRowKeys, selectedRows) => {
          let selectrow = "";
          if (selectedRowKeys.length === 0) {
          } else {
            selectrow = selectedRowKeys[selectedRowKeys.length - 1];
          }
          let arr = []
          selectedRows.map((item, i) => {
            arr.push(item.id)
          })
          this.props.form.setFieldsValue({ emergencyLoc: undefined })
          this.setState({ selectedRowIds_Ent: arr, selectrow: selectrow, emergencyLocData: selectedRows, selectedRowKeys_treatment: selectedRowKeys }, () => {
          });
        },
        onSelectAll: (selected, selectedRows, changeRows) => {
          let arr = []
          selectedRows.map((item, i) => {
            arr.push(item.id)
          })
          this.setState({ selectedRowIds_Ent: arr, emergencyLocData: selectedRows });
        }
      };
      //住院接收科室
      const rowSelection_rightTal = {
        selectedRowKeys: this.state.selectedRowKeys_hospital,
        onChange: (selectedRowKeys, selectedRows) => {
          let selectrow = "";
          if (selectedRowKeys.length === 0) {
          } else {
            selectrow = selectedRowKeys[selectedRowKeys.length - 1];
          }
          let arr = []
          selectedRows.map((item, i) => {
            arr.push(item.id)
          })
          this.props.form.setFieldsValue({ hospitalizationLoc: undefined })
          this.setState({ selectedRowIds_Tal: arr, selectrow: selectrow, hospitalizationLocData: selectedRows, selectedRowKeys_hospital: selectedRowKeys }, () => {
          });
        },
        onSelectAll: (selected, selectedRows, changeRows) => {
          let arr = []
          selectedRows.map((item, i) => {
            arr.push(item.id)
          })
          this.setState({ selectedRowIds_Tal: arr, hospitalizationLocData: selectedRows });
        }
      };
      //煎药方式
      const rowSelection_rightCookType = {
        selectedRowKeys: this.state.selectedRowKeys_cookType,
        onChange: (selectedRowKeys, selectedRows) => {
          let selectrow = "";
          if (selectedRowKeys.length === 0) {
          } else {
            selectrow = selectedRowKeys[selectedRowKeys.length - 1];
          }
          let arr = []
          selectedRows.map((item, i) => {
            arr.push(item.id)
          })
          this.props.form.setFieldsValue({ cookTypeID: undefined })
          this.setState({ selectedRowIds_cookType: arr, selectrow: selectrow, cookTypeData: selectedRows, selectedRowKeys_cookType: selectedRowKeys }, () => {
          });
        },
        onSelectAll: (selected, selectedRows, changeRows) => {
          let arr = []
          selectedRows.map((item, i) => {
            arr.push(item.id)
          })
          this.setState({ selectedRowIds_cookType: arr, cookTypeData: selectedRows });
        }
      };
      return (
        <div>
          <Row gutter={60}>
            <Col span={8}>
              <Card title="处方剂型(按代码字母顺序排序)" bordered={false} style={{ position: "relative" }} className="moreInfoCard">
                <Button
                  style={{ width: '30%', marginTop: 16, marginBottom: 8 }}
                  type="dashed"
                  onClick={this.addOrd}
                  icon="plus"
                >新增配置
                </Button>
                <Row style={{ position: "absolute", top: "78px", right: "0" }}>
                  <Checkbox checked={this.state.checked} onChange={this.changeCheckedFlag}>仅显示生效</Checkbox>
                </Row>
                <Table
                  columns={leftColumns}
                  pagination={false}
                  rowClassName={this.setRowClassName}
                  onRow={this.onClickRow}
                  dataSource={this.state.leftTableData && this.state.leftTableData.length > 0 ? this.state.leftTableData : []}
                  // rowSelection={rowSelection_right}
                  className="clearBackground"
                />
              </Card>
            </Col>
            <Modal
              key='2'
              width='600px'
              visible={this.state.visible}
              title={this.state.isMod != 1 ? "新增草药配置" : "编辑草药配置"}
              onOk={this.handleOk}
              onCancel={this.handleCancel}
              footer={[
                <Button key="submitc" type="primary" onClick={this.handleCancel}>取消</Button>,
                <Button key="submits" type="primary" onClick={this.handleOk}>确定</Button>,
              ]}>
              <div>
                <Form>
                  <Row gutter={60}>
                  </Row>
                  <Row gutter={60}>
                    <Col span={12}>
                      <FormItem label='代码' wrapperCol={{ span: 17 }} labelCol={{ span: 7 }}>
                        {getFieldDecorator('code', {
                          initialValue: this.state.modifyInfo && this.state.modifyInfo ? this.state.modifyInfo.code : undefined,
                          rules: [{ required: true, message: '请填写代码' }],
                        })(
                          <Input placeholder="不能超过15字" />
                        )}
                      </FormItem>
                    </Col>
                    <Col span={12}>
                      <FormItem label='名称' wrapperCol={{ span: 17 }} labelCol={{ span: 7 }}>
                        {getFieldDecorator('descripts', {
                          initialValue: this.state.modifyInfo && this.state.modifyInfo ? this.state.modifyInfo.descripts : undefined,
                          rules: [{ required: true, message: '请填写名称' }],
                        })(
                          <Input />
                        )}
                      </FormItem>
                    </Col>
                  </Row>
                  <Row gutter={60}>
                    <Col span={12}>
                      <FormItem label='生效日期' wrapperCol={{ span: 17 }} labelCol={{ span: 7 }}>
                        {getFieldDecorator('startDate', {
                          initialValue: this.state.modifyInfo && this.state.modifyInfo ? moment(this.state.modifyInfo.startDate) : moment(),
                          rules: [{ required: true, message: '请选择生效日期' }],
                        })(
                          <DatePicker style={{ width: '100%' }} disabledDate={(curDate) => {
                            return curDate && curDate > moment().endOf('day');
                          }} />
                        )}
                      </FormItem>
                    </Col>
                    <Col span={12}>
                      <FormItem label='失效日期' wrapperCol={{ span: 17 }} labelCol={{ span: 7 }}>
                        {getFieldDecorator('stopDate', {
                          initialValue: this.state.modifyInfo && this.state.modifyInfo.stopDate != "" ? moment(this.state.modifyInfo.stopDate) : undefined,
                          rules: [{ required: false, message: '' }],
                        })(
                          <DatePicker style={{ width: '100%' }} disabledDate={(curDate) => {
                            return curDate < moment(this.props.form.getFieldValue('stopDate')).format('YYYY-MM-DD');
                          }} />
                        )}
                      </FormItem>
                    </Col>
                  </Row>
                </Form>
              </div>
            </Modal>
            <Col span={16} >
              <Card title="明细" bordered={false} style={{ marginRight: "4px", height: (store.getState().tableHeight.y + 160 + "px") }}>
                <p style={{ display: (this.state.ordTempletID ? "none" : "block") }}>暂无明细,请选择配置项或者新增配置</p>
                <Form style={{ display: (this.state.ordTempletID ? "block" : "none") }}>
                  <Row gutter={12}>
                    <Col span={6}>
                      <FormItem  {...formItemLayout} label='附加材料'>
                        {getFieldDecorator('addMate', {
                          initialValue: rightInfo.addMaterialID ? rightInfo.addMaterialID : undefined,
                          rules: [{ required: false, message: ' ' }],
                        })(
                          <Select allowClear>
                            {addMaterials}
                          </Select>
                        )}
                      </FormItem>
                    </Col>
                    <Col span={6}>
                      <FormItem  {...formItemLayout} label='默认频次'>
                        {getFieldDecorator('Frequency', {
                          initialValue: rightInfo.freqID ? rightInfo.freqID : undefined,
                          rules: [{ required: false, message: ' ' }],
                        })(
                          <Select allowClear>
                            {frequencys}
                          </Select>
                        )}
                      </FormItem>
                    </Col>
                    <Col span={6}>
                      <FormItem  {...formItemLayout} label='默认用法'>
                        {getFieldDecorator('usage', {
                          initialValue: rightInfo.usageID ? rightInfo.usageID : undefined,
                          rules: [{ required: false, message: ' ' }],
                        })(
                          <Select allowClear>
                            {usages}
                          </Select>
                        )}
                      </FormItem>
                    </Col>
                    {/* <Col span={6}>
                        <FormItem  {...formItemLayout} label='代煎费'>
                            {getFieldDecorator('frying', {
                                initialValue: undefined,
                                rules: [{ required: false, message: ' ' }],
                            })(
                                <Select>
                                    {fryings}
                                </Select>
                            )}
                        </FormItem>
                    </Col> */}
                    <Col span={6}>
                      <FormItem  {...formItemLayout} label='用药副数'>
                        {getFieldDecorator('course', {
                          initialValue: rightInfo.durQty ? rightInfo.durQty : undefined,
                          rules: [{ required: false, message: ' ' }],
                          getValueFromEvent: (event) => {
                            return event.target.value.replace(/\D|^0/g, '')
                          },
                        })(
                          <Input></Input>
                        )}
                      </FormItem>
                    </Col>
                  </Row>
                  <Row gutter={12}>
                    <Col span={6} style={{paddingLeft:"10px"}}>
                      <FormItem  {...formItemLayout814} label='默认用量(g)'>
                        {getFieldDecorator('consumption', {
                          initialValue: rightInfo.doseQty ? rightInfo.doseQty : undefined,
                          rules: [{ required: false, message: ' ' }],
                          getValueFromEvent: (event) => {
                            return event.target.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".").replace(/[^\d.]/g, "").replace(/^\./g, "").replace(/^0/g, "")
                          },
                        })(
                          <Input />
                        )}
                      </FormItem>
                    </Col>
                    <Col span={6}>
                      <FormItem  {...formItemLayoutLoc} label='门急诊默认接收科室'>
                        {getFieldDecorator('emergencyLoc', {
                          initialValue: rightInfo.defRecLocOID ? rightInfo.defRecLocOID : undefined,
                          rules: [{ required: false, message: ' ' }],
                        })(
                          <Select allowClear>
                            {emergencyLocs}
                          </Select>
                        )}
                      </FormItem>
                    </Col>
                    <Col span={6}>
                      <FormItem  {...formItemLayoutLoc} label='住院默认接收科室'>
                        {getFieldDecorator('hospitalizationLoc', {
                          initialValue: rightInfo.defRecLocIID ? rightInfo.defRecLocIID : undefined,
                          rules: [{ required: false, message: ' ' }],
                        })(
                          <Select allowClear>
                            {hospitalizationLocs}
                          </Select>
                        )}
                      </FormItem>
                    </Col>
                    <Col span={6}>
                      <FormItem  {...formItemLayout} label='服用要求'>
                        {getFieldDecorator('usageExplainID', {
                          initialValue: rightInfo.usageExplainID ? rightInfo.usageExplainID : undefined,
                          rules: [{ required: false, message: ' ' }],
                        })(
                          <Select allowClear>
                            {usageExplainOption}
                          </Select>
                        )}
                      </FormItem>
                    </Col>
                  </Row>
                  <Row gutter={24}>
                  <Col span={4} style={{paddingLeft:"16px"}}>
                      <FormItem  {...formItemLayout104} label='煎药方式'>
                        {getFieldDecorator('cookTypeID', {
                          initialValue: rightInfo.cookTypeID ? rightInfo.cookTypeID : undefined,
                          rules: [{ required: false, message: ' ' }],
                        })(
                          <Select allowClear style={{ width: "138%" }}>
                            {cookTypeOption}
                          </Select>
                        )}
                      </FormItem>
                    </Col>
                    <Col span={5} style={{ paddingLeft: "34px", boxSizing: "border-box" }}>
                      <FormItem  {...formItemLayoutCheck} >
                        {getFieldDecorator('autoCump', {
                          initialValue: undefined,
                          rules: [{ required: false, message: ' ' }],
                        })(
                          <Checkbox checked={this.state.autoCumpChecked} onChange={(e) => this.changeChecked(e, 1)}>自动计算附加材料数量</Checkbox>
                        )}
                      </FormItem>
                    </Col>
                    <Col span={4} style={paddingZero}>
                      <FormItem  {...formItemLayoutCheck} >
                        {getFieldDecorator('autoAdd', {
                          initialValue: undefined,
                          rules: [{ required: false, message: ' ' }],
                        })(
                          <Checkbox checked={this.state.autoAddChecked} onChange={(e) => this.changeChecked(e, 2)}>住院自动增加代煎费</Checkbox>
                        )}
                      </FormItem>
                    </Col>
                    <Col span={3} style={paddingZero}>
                      <FormItem  {...formItemLayoutCheck}>
                        {getFieldDecorator('disfrying', {
                          initialValue: undefined,
                          rules: [{ required: false, message: ' ' }],
                        })(
                          <Checkbox checked={this.state.disfrying} onChange={(e) => this.changeChecked(e, 3)}>禁用代煎勾选</Checkbox>
                        )}
                      </FormItem>
                    </Col>
                    <Col span={4} style={paddingZero}>
                      <FormItem  {...formItemLayoutCheck} >
                        {getFieldDecorator('emergency', {
                          initialValue: undefined,
                          rules: [{ required: false, message: ' ' }],
                        })(
                          <Checkbox checked={this.state.emergencyChecked} onChange={(e) => this.changeChecked(e, 4)}>门诊默认处方型剂</Checkbox>
                        )}
                      </FormItem>
                    </Col>
                    <Col span={4} style={paddingZero}>
                      <FormItem  {...formItemLayoutCheck}>
                        {getFieldDecorator('hospitalization', {
                          initialValue: undefined,
                          rules: [{ required: false, message: ' ' }],
                        })(
                          <Checkbox checked={this.state.hospitalizationChecked} onChange={(e) => this.changeChecked(e, 5)}>住院默认处方型剂</Checkbox>
                        )}
                      </FormItem>
                    </Col>
                  </Row>
                  <Spin spinning={tableLoading} indicator={antIcon}>
                    <Row gutter={12} className="childDom">
                      <Col span={6}>
                        <Table
                          columns={childColumns}
                          pagination={false}
                          rowClassName={this.childRowClassNames}
                          dataSource={this.state.baseSubclassifications}
                          rowSelection={rowSelection_right}
                          className="childTableDom"
                        />
                      </Col>
                      <Col span={6}>
                        <Table
                          columns={fryingColumns}
                          pagination={false}
                          rowClassName={this.childRowClassNames}
                          dataSource={this.state.baseEmergencyLoc}
                          rowSelection={rowSelection_rightFry}
                          className="childTableDom"
                        />
                      </Col>
                      <Col span={6}>
                        <Table
                          columns={emergencyColumns}
                          pagination={false}
                          rowClassName={this.childRowClassNames}
                          dataSource={this.state.baseEmergencyLoc}
                          rowSelection={rowSelection_rightEme}
                          className="childTableDom"
                        />
                      </Col>
                      {/* 门诊 */}
                      <Col span={6}>
                        <Table
                          columns={entrgencyColumns}
                          pagination={false}
                          rowClassName={this.childRowClassNames}
                          dataSource={this.state.baseEmergencyLoc}
                          rowSelection={rowSelection_rightEnt}
                          className="childTableDom"
                        />
                      </Col>
                      {/* 住院 */}
                      <Col span={6}>
                        <Table
                          columns={talrgencyColumns}
                          pagination={false}
                          rowClassName={this.childRowClassNames}
                          dataSource={this.state.baseEmergencyLoc}
                          rowSelection={rowSelection_rightTal}
                          className="childTableDom childTableTopDom"
                        />
                      </Col>
                      {/* 煎药 */}
                      <Col span={6}>
                        <Table
                          columns={cookTypeColumns}
                          pagination={false}
                          rowClassName={this.childRowClassNames}
                          dataSource={this.state.baseCookType}
                          rowSelection={rowSelection_rightCookType}
                          className="childTableDom childTableTopDom"
                        />
                      </Col>
                    </Row>
                  </Spin>
                  <Row style={{ position: "absolute", right: "0", bottom: "0" }}>
                    <Button style={{ background: 'rgba(66,185,131,1)', color: '#fff', marginRight: "16px" }} onClick={this.saveRight}>保存</Button>
                    <Button style={{ background: 'rgba(66,185,131,1)', color: '#fff', }} onClick={this.restRight}>重置</Button>
                  </Row>
                </Form>
              </Card>
            </Col>
          </Row>
        </div>
      )
    }
  })
export default ConfigHerbal