import React, { Component } from "react";
import { Form, Button, Radio, Modal, Input, message, Switch } from "antd";
import { knowledgeList, auditList, addDeductionList, } from "@/dataDic.js";
/**
 * 高新纯咨询合同说明添加和详情
 */
const RadioButton = Radio.Button;
const RadioGroup = Radio.Group;
const radioStyle = {
  display: 'block',
  height: '30px',
  lineHeight: '30px',
};
let num = 1;
const FormItem = Form.Item;
class Gxczx extends Component {
  constructor(props) {
    super(props);
    this.state = {
      gxczx: "", //高新纯咨询合同说明弹窗
      knowledgeOther: "",
      auditOther: "",
      addDeductionOther: "",
    }
  }
  componentDidMount() {
  }
  componentWillUnmount() {
    num = 1
  }
  componentWillReceiveProps(nextProps) {
    const { knowledgeServices, auditServices, addDeductionServices,
      knowledgeOther, auditOther, addDeductionOther, isCreat = false } = this.props
    if (knowledgeServices != null && auditServices != null && addDeductionServices != null) {
      if (isCreat) {
        // 防止刷新进入,只能第一次渲染的时候触发   选择未签会让值变成-1(除了1,其他都归-1) 导致找不到label
        if (num == 1 && this.state.gxczx == "") {
          if (knowledgeServices != -1 && auditServices != -1 && addDeductionServices != -1) {
            this.setState({
              knowledgeText: knowledgeServices == 0
                ? knowledgeOther
                : knowledgeList.find(v => { return v.value == knowledgeServices }).label,
              auditText: auditServices == 0
                ? auditOther
                : auditList.find(v => { return v.value == auditServices }).label,
              addDeductionText: addDeductionServices == 0
                ? addDeductionOther
                : addDeductionList.find(v => { return v.value == addDeductionServices }).label,
              zscq: knowledgeServices == null
                ? null
                : (knowledgeServices != 1 ? -1 : 1),
              sjfw: auditServices == null
                ? null
                : (auditServices != 1 ? -1 : 1),
              jjkc: addDeductionServices == null
                ? null
                : (addDeductionServices != 1 ? -1 : 1),
            }, () => {
              num++
            })
          }
        }
      } else {
        this.setState({
          knowledgeText: knowledgeServices == 0
            ? knowledgeOther
            : knowledgeList.find(v => { return v.value == knowledgeServices }).label,
          auditText: auditServices == 0
            ? auditOther
            : auditList.find(v => { return v.value == auditServices }).label,
          addDeductionText: addDeductionServices == 0
            ? addDeductionOther
            : addDeductionList.find(v => { return v.value == addDeductionServices }).label,
        })
      }
    }
  }
  render() {
    const { knowledgeServices, auditServices, addDeductionServices, isCreat = false, isShow } = this.props
    return (
      
        {
          // 是否可编辑
          isCreat ?
            
              
                高新纯咨询合同说明              
                 { this.props.onSwitch(e) }} />
              
              {
                isShow &&
                
                  *知识产权}
                  >
                     {
                        num = 2
                        this.setState({
                          knowledgeServices: e.target.value == 1 ? 1 : undefined,
                          zscq: e.target.value,
                          gxczx: e.target.value == -1 ? "zscq" : "",
                        })
                        this.props.selknowledge({ knowledgeServices: e.target.value })
                      }}>
                      已签
                      未签
                    
                    
                      {this.props.knowledgeServices == 1 ? "" : this.state.knowledgeText}
                    
                  
                  *审计服务}
                  >
                     {
                        num = 2
                        this.setState({
                          auditServices: e.target.value == 1 ? 1 : undefined,
                          sjfw: e.target.value,
                          gxczx: e.target.value == -1 ? "sjfw" : "",
                        })
                        this.props.selaudit({ auditServices: e.target.value })
                      }}>
                      已签
                      未签
                    
                    
                      {this.props.auditServices == 1 ? "" : this.state.auditText}
                    
                  
                  *加计扣除服务}
                  >
                     {
                        num = 2
                        this.setState({
                          addDeductionServices: e.target.value == 1 ? 1 : undefined,
                          jjkc: e.target.value,
                          gxczx: e.target.value == -1 ? "jjkc" : ""
                        })
                        this.props.seladdDeduction({ addDeductionServices: e.target.value })
                      }}>
                      已签
                      未签
                    
                    
                      {this.props.addDeductionServices == 1 ? "" : this.state.addDeductionText}
                    
                  
                
              }
            
  :
            
              {
                (knowledgeServices == null || auditServices == null || addDeductionServices == null)
                  ? null :
                  
                    
                      高新纯咨询合同说明
                    
                    
                      
                        {}
                        
                          {knowledgeServices == 1 ? "" : this.state.knowledgeText}
                        
                      
                      
                        {}
                        
                          {auditServices == 1 ? "" : this.state.auditText}
                        
                      
                      
                        {}
                        
                          {addDeductionServices == 1 ? "" : this.state.addDeductionText}
                        
                      
                    
                   
              }
            
        }
        {
          this.state.gxczx != "" &&
          
 {
                  let reason = ""
                  if (this.state.gxczx == "zscq") {
                    if (this.state.knowledgeServices == undefined) {
                      message.warn("请选择原因!")
                      return
                    }
                    reason = this.state.knowledgeServices == 0
                      ? this.state.knowledgeOther
                      : knowledgeList.find(v => { return v.value == this.state.knowledgeServices }).label
                    this.setState({
                      knowledgeText: reason
                    })
                    this.props.selknowledge({ knowledgeServices: this.state.knowledgeServices, knowledgeOther: this.state.knowledgeOther })
                  } else if (this.state.gxczx == "sjfw") {
                    if (this.state.auditServices == undefined) {
                      message.warn("请选择原因!")
                      return
                    }
                    reason = this.state.auditServices == 0
                      ? this.state.auditOther
                      : auditList.find(v => { return v.value == this.state.auditServices }).label
                    this.setState({
                      auditText: reason
                    })
                    this.props.selaudit({ auditServices: this.state.auditServices, auditOther: this.state.auditOther })
                  } else if (this.state.gxczx == "jjkc") {
                    if (this.state.addDeductionServices == undefined) {
                      message.warn("请选择原因!")
                      return
                    }
                    reason = this.state.addDeductionServices == 0
                      ? this.state.addDeductionOther
                      : addDeductionList.find(v => { return v.value == this.state.addDeductionServices }).label
                    this.setState({
                      addDeductionText: reason
                    })
                    this.props.seladdDeduction({ addDeductionServices: this.state.addDeductionServices, addDeductionOther: this.state.addDeductionOther })
                  }
                  if (!reason) {
                    message.warn("请填写原因!")
                    return
                  }
                  if (!reason.replace(/\s+/g, '')) {
                    message.warn("请填写原因!")
                    return
                  }
                  this.setState({
                    gxczx: "",
                  })
                }}
              >确定
            ]
            }
          >
            {
              this.state.gxczx == "zscq" ?
                 { this.setState({ knowledgeServices: e.target.value }) }} value={this.state.knowledgeServices}>
                  {
                    knowledgeList.map(item =>
                      item.value != 1 &&
                      {item.label}
                        {(this.state.knowledgeServices === 0 && item.value == 0) ?
                           {
                              this.setState({
                                knowledgeOther: e.target.value
                              })
                            }}
                          /> : null}
                      
                    )
                  }
                 :
                this.state.gxczx == "sjfw" ?
                   { this.setState({ auditServices: e.target.value }) }} value={this.state.auditServices}>
                    {
                      auditList.map(item =>
                        item.value != 1 &&
                        {item.label}
                          {(this.state.auditServices === 0 && item.value == 0) ?
                             {
                                this.setState({
                                  auditOther: e.target.value
                                })
                              }}
                            /> : null}
                        
                      )
                    }
                   :
                  this.state.gxczx == "jjkc" &&
                   { this.setState({ addDeductionServices: e.target.value }) }} value={this.state.addDeductionServices}>
                    {
                      addDeductionList.map(item =>
                        item.value != 1 &&
                        {item.label}
                          {(this.state.addDeductionServices === 0 && item.value == 0) ?
                             {
                                this.setState({
                                  addDeductionOther: e.target.value
                                })
                              }}
                            /> : null}
                        
                      )
                    }
                  
            }
          
        }
      
 
    );
  }
}
export default Gxczx;