import React, { Component } from "react";
import {
  AutoComplete, Button, Icon, Form, Input, message,
  Modal, Radio, Select, Spin, Tag, DatePicker,
  Checkbox
} from "antd";
import { boutique } from "../../dataDic";
import $ from "jquery";
import { getboutique, splitUrl } from "../../tools";
import moment from "moment";
import { vipYear, YearList } from "../../dataDic";
import ImgList from "../imgList";

const FormItem = Form.Item;
const Option = Select.Option;
const RadioGroup = Radio.Group;
const confirm = Modal.confirm;
const CheckboxGroup = Checkbox.Group;

const formItemLayout = {
  labelCol: { span: 8 },
  wrapperCol: { span: 14 },
};

/**
 *  编辑项目  和  查看项目详情
 */

class newEditProject extends Component {
  constructor(props) {
    super(props);
    this.state = {
      commodityName: '',//项目名称
      commodityQuantity: '',//项目数量
      patentType: 0,
      officialCost: '',
      costReduction: '',
      commodityPrice: '',//项目价格
      main: '',//主要项目 0否 1是
      lastYearCapital: '',//上年度总资本
      lastYearIncome: '',//上年度总资本
      taskComment: '',//项目说明
      declarationBatch: '',
      ifCertificationFee: '',
      displayFees: "none",
      customerArr: [],
      patentTypeList: [],
      loading: false,
      orgCodeUrl: [],
      patentTransfer: props.dataInfor ? props.dataInfor.patentTransfer : 0, //收否为专利转让 0 否 1 是
      serviceLife: [],
      isVip: undefined,
      histYear: [],
      contractTerm: [],//合同期
      addyear: undefined,//
      isGive: undefined,//是否赠送
      splitList: [],//子集
      addFrom: false,
      isMedit: 0,
      isYear: false,//审计是否需要修改上年度年份
      checkType: [], //会员项目勾选的类型
      newCheck: [], // 子项勾选的类型
    }
    this.getpatentTypeList = this.getpatentTypeList.bind(this);
    this.setValue = this.setValue.bind(this);
  }

  componentDidMount() {
    this.getpatentTypeList();
    this.setValue();
  }

  setValue() {
    const { dataInfor, children = "splitList", type = "", readOnly } = this.props;
    if (!(dataInfor && Object.keys(dataInfor).length > 0)) { return; }
    if (type == "change") {
      // 变更编辑  taskType  0通用 1专利 2软著 3审计 4双软 5高新 6商标
      if (dataInfor.taskType === 1) {
        this.setState({
          displayFees: "block",
          costReduction: dataInfor.costReduction,
          officialCost: dataInfor.officialCost,
          patentType: dataInfor.patentType ? dataInfor.patentType : 0,
        });
      } else {
        this.setState({
          displayFees: "none",
        });
      }
    } else {
      // 正常编辑 type  0通用 1专利 2软著 3审计 4双软 5高新 6商标
      if (dataInfor.type === 1) {
        this.setState({
          displayFees: "block",
          costReduction: dataInfor.costReduction,
          officialCost: dataInfor.officialCost,
          patentType: dataInfor.patentType ? dataInfor.patentType : 0,
        });
      } else {
        this.setState({
          displayFees: "none",
        });
      }
    }

    let llist = []
    if (dataInfor[children] && dataInfor[children].length > 0) {
      for (var i = 0; i < dataInfor[children].length; i++) {
        // if (dataInfor.splitList[i].commodityId == dataInfor.commodityId) {
        //   llist.push(dataInfor.splitList[i].serviceYear != dataInfor.serviceYear && dataInfor.splitList[i].serviceYear)
        // }
        if (dataInfor[children][i].type != 3) {
          llist.push(dataInfor[children][i].serviceYear)
        }
      }
    }
    let newCheckType = []
    if (dataInfor.projectType == 1) {
      if (dataInfor.htMember == 1) {
        newCheckType.push(1)
      }
      if (dataInfor.additionalDeduction == 1) {
        newCheckType.push(2)
      }
      if (dataInfor.rdAwardsubsidy == 1) {
        newCheckType.push(3)
      }
    }
    this.setState({
      jid: dataInfor.id, //项目ID
      kid: dataInfor.commodityId, //商品ID
      commodityName: dataInfor.commodityName, //项目名称
      commodityPrice: dataInfor.commodityPrice, //金额
      commodityQuantity: dataInfor.commodityQuantity, //数量
      patentTypeName: dataInfor.patentTypeName,//专利类型名称
      taskComment: dataInfor.cSort == 6 ? undefined : dataInfor.taskComment, //备注
      main: dataInfor.main.toString(), //是否为主要
      addState: 0,
      addnextVisible: true,
      addProjectType: type == "change" ? dataInfor.taskType : dataInfor.type,
      declarationBatch: dataInfor.declarationBatch || 1,//申报批次(只有高新有)
      ifCertificationFee: isNaN(parseInt(dataInfor.ifCertificationFee)) ? '' : dataInfor.ifCertificationFee,//是否包含认证费
      isIso: dataInfor.commodityName.indexOf("贯标") !== -1,
      orgCodeUrl: dataInfor.pictureUrl ? splitUrl(dataInfor.pictureUrl, ",", globalConfig.avatarHost + "/upload") : [],//
      isYear: !dataInfor.lastYear ? true : false,//
      lastYear: dataInfor.lastYear,//上年度年份
      lastYearCapital: dataInfor.lastYearCapital,//上年度总资本
      lastYearIncome: dataInfor.lastYearIncome,//上年度总收入
      isVip: dataInfor.cSort,
      yearSum: dataInfor.yearSum,//会员总服务年限
      serviceLife: !dataInfor.serviceLife ? [] : JSON.parse(dataInfor.serviceLife), // 会员服务年限
      contractTerm: (!dataInfor.contractTerm || (dataInfor.contractTerm.indexOf("-") == -1)) ? [] : JSON.parse(dataInfor.contractTerm), // 合同期
      serviceYear: dataInfor.cSort == 6 ? undefined : dataInfor.serviceYear,//本次派单
      histYear: llist, // 本次已派单
      splitList: dataInfor[children] || [],
      tid: dataInfor.id, // 父级项目id
      isMedit: readOnly ? 3 : dataInfor.cSort == 6 ? 0 : 1,// 会员项目默认0不可编辑   普通项目默认1可编辑
      projectType: dataInfor.projectType, // 会员项目类型
      checkType: newCheckType, // 会员项目勾选类型

      technologyProjectType: dataInfor.technologyProjectType, //科技项目
      ordinaryRisk: dataInfor.ordinaryRisk, //知识产权申请类型
      days: dataInfor.days, // 软著 天数
      scheme: dataInfor.scheme, // 软著 方案
    });
  }

  onChange(text) {
    const { type = "", dataInfor } = this.props
    if (isNaN(parseFloat(this.state.commodityPrice))) {
      message.warning("请输入正确的金额！");
      return false;
    }
    let reg = /^([0]|[1-9][0-9]*)$/;
    if (
      !this.state.commodityQuantity ||
      !reg.test(this.state.commodityQuantity)
    ) {
      message.warning("请输入正确服务数量！");
      return false;
    }
    // 3审计
    if (this.state.addProjectType == "3") {
      if (this.state.serviceLife.length === 0) {
        message.warning("请选择服务年限！");
        return
      }
      if (this.state.serviceLife.length != this.state.commodityQuantity) {
        message.warning("服务数量与服务年限不符！");
        return
      }
      if (this.state.isYear && !this.state.lastYear) {
        message.warning("请选择上年度年份！");
        return
      }
      if (isNaN(parseFloat(this.state.lastYearCapital))) {
        message.warning("请输入正确的企业上年度总资本！");
        return
      }
      if (isNaN(parseFloat(this.state.lastYearIncome))) {
        message.warning("请输入正确的企业上年度总收入！");
        return
      }
    }
    if (!this.state.main) {
      message.warning("请选择是否为主要项目！");
      return false;
    }
    // 5高新
    if (this.state.addProjectType === 5) {
      if (!this.state.declarationBatch) {
        message.warning("请选择企业要求申报批次!");
        return
      }
      if (!this.state.serviceYear) {
        message.warning("请选择申报年份!");
        return
      }
    }
    if (this.state.isVip == 6) {
      // if (this.state.yearSum === undefined) {
      //   message.warning("请选择会员总服务年限！");
      //   return
      // }
      if (this.state.serviceLife.length === 0) {
        message.warning("请添加会员服务年限！");
        return
      }
      // if (this.state.serviceLife.length != this.state.yearSum) {
      //   message.warning("会员服务年限与总年限不符合！");
      //   return
      // }
      // if (this.state.serviceYear === undefined) {
      //   message.warning("请选择本次派单年份！");
      //   return
      // }
      // if (this.state.projectType == 1 && !this.state.checkType.includes(1)) {
      //   message.warning("请勾选高新会员");
      //   return
      // }
      if (this.state.contractTerm.length === 0 || this.state.contractTerm[1] == "") {
        message.warning("请填写合同期！");
        return
      }
    }
    if (this.state.isVip == 3) { //科技项目
      if (!this.state.technologyProjectType && this.state.technologyProjectType != 0) {
        message.warning("请选择科技项目!");
        return
      }
    }
    if (this.state.isVip == 8 && this.state.addProjectType != 2) { //知识产权
      if (!this.state.ordinaryRisk && this.state.ordinaryRisk != 0) {
        message.warning("请选择申请类型!");
        return
      }
    }
    if (this.state.addProjectType == 2) {
      if (!this.state.days && this.state.days != 0) {//天数
        message.warning("请选择是否加急!");
        return
      }
      if (!this.state.scheme && this.state.scheme != 0) {//方案
        message.warning("请选择是否有方案!");
        return
      }
    }
    this.setState({
      loading: true,
    });
    let infor = {
      id: this.state.jid, //项目ID
      commodityId: this.state.kid, //商品ID
      orderNo: this.props.orderNo, //订单编号
      main: this.state.main, //是否为主要
      commodityPrice: this.state.commodityPrice, //金额
      commodityQuantity: this.state.commodityQuantity, //数量
      taskComment: this.state.taskComment, //备注
    }
    if (this.state.displayFees === 'block') {
      infor.officialCost = this.state.officialCost //是否有官费
      infor.costReduction = (this.state.patentType === 0 || this.state.patentType === 2) ? this.state.costReduction : 0//是否有费减
      infor.patentType = this.state.patentType //专利类型
    }
    if (this.state.isIso) {
      infor.ifCertificationFee = this.state.ifCertificationFee || undefined;//是否包含认证费用
    }
    if (this.state.addProjectType == "3") {//审计
      infor.serviceLife = JSON.stringify(this.state.serviceLife) //服务年限
      infor.lastYear = this.state.lastYear //上年度年份
      infor.lastYearCapital = this.state.lastYearCapital //上年度总资本
      infor.lastYearIncome = this.state.lastYearIncome //上年度总收入
    }
    if (this.state.addProjectType == "5") {//高新
      infor.declarationBatch = this.state.declarationBatch || undefined//申报批次
      infor.serviceYear = this.state.serviceYear //申报年份
    }
    if (this.state.isVip == 6) {//会员
      infor.yearSum = this.state.yearSum //会员总服务年限
      infor.serviceLife = JSON.stringify(this.state.serviceLife) //会员服务年限
      // infor.serviceYear = this.state.serviceYear //本次派单年份
      infor.contractTerm = JSON.stringify(this.state.contractTerm)//合同期
      if (this.state.projectType == 1) {
        infor.htMember = this.state.checkType.includes(1) ? 1 : 0
        infor.additionalDeduction = this.state.checkType.includes(2) ? 1 : 0
        infor.rdAwardsubsidy = this.state.checkType.includes(3) ? 1 : 0
      }
    }
    if (this.state.isVip == 3) { //科技项目
      infor.technologyProjectType = this.state.technologyProjectType
    }
    if (this.state.isVip == 8 && this.state.addProjectType != 2) { //知识产权
      infor.ordinaryRisk = this.state.ordinaryRisk
    }
    if (this.state.addProjectType == 2) {
      infor.days = this.state.days //天数
      infor.scheme = this.state.scheme   //方案
    }
    // 新开单与签单项目变更 -- 编辑项目
    if (type == "change") {
      infor.id = dataInfor.id
      infor.type = dataInfor.tid ? 2 : 1
      infor.tid = dataInfor.tid
    }
    $.ajax({
      method: "POST",
      dataType: "json",
      crossDomain: false,
      url: globalConfig.context + type == "change"
        ? "/api/admin/orderChange/updateChangeTask"
        : "/api/admin/newOrder/updateOrderTask",
      data: infor,
    }).done(
      function (data) {
        this.setState({
          loading: false,
        });
        if (!data.error.length) {
          message.success("保存成功！");
          if (this.state.isVip == 6) {
            text == "submit" &&
              this.setState({
                isMedit: 0
              })
          } else {
            this.props.onCancel();
          }
        } else {
          message.warning(data.error[0].message);
        }
      }.bind(this)
    );
  }

  getpatentTypeList() {
    $.ajax({
      method: "get",
      dataType: "json",
      crossDomain: false,
      url: globalConfig.context + '/api/admin/orderProject/getPatentType',
      success: function (data) {
        if (data.error.length === 0) {
          this.setState({
            patentTypeList: data.data
          })
        } else {
          message.warning(data.error[0].message);
        };
      }.bind(this)
    });
  }
  // 删除子项目
  deleteMemberSonProject(id) {
    const { splitList, histYear } = this.state
    $.ajax({
      method: "POST",
      dataType: "json",
      crossDomain: false,
      url: globalConfig.context +
        this.props.type == "change"
        ? '/api/admin/orderChange/deleteMemberSonProject'
        : '/api/admin/orderProject/deleteMemberSonProject',
      data: {
        id,
      },
      success: function (data) {
        if (data.error.length === 0) {
          this.onChange()
          let splList = splitList
          let hlist = []
          for (var i = 0; i < splitList.length; i++) {
            if (id == splitList[i].id) {
              //如果是 type==1 新增  就彻底删除 否则 改为type==3
              if (splList[i].type == 0 || splList[i].type == 2) {
                splList[i].type = 3
              } else {
                splList.splice(i, 1)
              }
              // hlist.splice(i, 1)
            }
          }
          for (var j = 0; j < splList.length; j++) {
            splList[j].type != 3 && hlist.push(splList[j].serviceYear)
          }
          this.setState({
            splitList: splList,
            histYear: hlist,
          })
        } else {
          message.warning(data.error[0].message);
        };
      }.bind(this)
    });
  }
  // 恢复子项目
  updateMemberSonProject(id, taskComment) {
    const { splitList, histYear, serviceYear } = this.state
    $.ajax({
      method: "POST",
      dataType: "json",
      crossDomain: false,
      url: globalConfig.context + '/api/admin/orderChange/updateMemberSonProject',
      data: {
        id,
        taskComment,
      },
      success: function (data) {
        if (data.error.length === 0) {
          // this.onChange()
          let splList = splitList
          let histList = histYear
          for (var i = 0; i < splList.length; i++) {
            if (splList[i].id == data.data.id) {
              splList[i].type = data.data.type
              splList[i].taskComment = data.data.taskComment
            }
          }
          histList.push(serviceYear)
          this.setState({
            addFrom: false,
            splitList: splList,
            histYear: histList,
            serviceYear: undefined,
            taskComment: undefined,
            isMedit: 0,
          })
          message.success("保存成功！")
        } else {
          message.warning(data.error[0].message);
        };
      }.bind(this)
    });
  }

  handleClose(removedTag) {
    let serviceLife = this.state.serviceLife.filter(tag => { return tag !== removedTag });
    this.setState({
      serviceLife,
      commodityQuantity: serviceLife.length == 0 ? undefined : serviceLife.length,
      yearSum: serviceLife.length == 0 ? undefined : serviceLife.length.toString(),
      serviceYear: undefined
    });
  }

  aGain() {
    const { serviceLife } = this.state
    this.setState({
      serviceLife: serviceLife,
      commodityQuantity: serviceLife.length == 0 ? undefined : serviceLife.length,
      yearSum: serviceLife.length == 0 ? undefined : serviceLife.length.toString(),
    })
  }

  tagClose(tag) {
    const _this = this
    let serviceLife = this.state.serviceLife.filter(t => { return t !== tag });
    let delid = ""
    const { splitList = [], } = this.state
    if (serviceLife.length < 1) {
      Modal.error({
        title: '提示',
        content: (
          <div>
            <p style={{ color: "red" }}>会员服务年限必须保留一个</p>
          </div>
        ),
        onOk() { },
      });
      return
    }
    for (var i = 0; i < splitList.length; i++) {
      if (tag == splitList[i].serviceYear && splitList[i].type != 3) {
        delid = splitList[i].id
      }
    }
    if (delid != "") {
      confirm({
        title: '确定要删除吗',
        content: '会员子项目也会一并删除',
        okText: '确定',
        okType: 'danger',
        cancelText: '取消',
        onOk() {
          _this.setState({
            serviceLife: serviceLife,
            commodityQuantity: serviceLife.length == 0 ? undefined : serviceLife.length,
            yearSum: serviceLife.length == 0 ? undefined : serviceLife.length.toString(),
            serviceYear: undefined
          });
          _this.deleteMemberSonProject(delid)
        },
        onCancel() {
          // _this.aGain()
        },
      });
    } else {
      this.setState({
        serviceLife,
        commodityQuantity: serviceLife.length == 0 ? undefined : serviceLife.length,
        yearSum: serviceLife.length == 0 ? undefined : serviceLife.length.toString(),
        serviceYear: undefined
      }, () => {
        this.onChange()
      });
    }
  }
  // 添加会员子项目
  addMemberFirstSonProject() {
    if (!this.state.serviceYear) {
      message.warning("请选择本次派单年份！");
      return
    }
    let info = {
      tid: this.state.tid,
      serviceYear: this.state.serviceYear,
      taskComment: this.state.taskComment,
    }
    let changeInfo = {
      id: this.state.tid,
      serviceYear: this.state.serviceYear,
      taskComment: this.state.taskComment,
    }
    if (this.state.projectType == 1) {
      info.htMember = this.state.newCheck.includes(1) ? 1 : 0
      info.additionalDeduction = this.state.newCheck.includes(2) ? 1 : 0
      info.rdAwardsubsidy = this.state.newCheck.includes(3) ? 1 : 0

      changeInfo.htMember = this.state.newCheck.includes(1) ? 1 : 0
      changeInfo.additionalDeduction = this.state.newCheck.includes(2) ? 1 : 0
      changeInfo.rdAwardsubsidy = this.state.newCheck.includes(3) ? 1 : 0
    }
    if (this.state.recoveryId != "") {
      this.updateMemberSonProject(this.state.recoveryId, this.state.taskComment)
      return
    }
    this.setState({
      loading: true,
    });
    $.ajax({
      method: "POST",
      dataType: "json",
      crossDomain: false,
      url: globalConfig.context +
        this.props.type == "change"
        ? "/api/admin/orderChange/addMemberSonProject"
        : "/api/admin/orderProject/addMemberFirstSonProject",
      data: this.props.type == "change" ? changeInfo : info,
      success: function (data) {
        this.setState({
          loading: false
        });
        if (data.error.length === 0) {
          message.success("保存成功！");
          let list = this.state.splitList
          let histList = this.state.histYear
          list.push(data.data)
          histList.push(data.data.serviceYear)
          this.setState({
            addFrom: false,
            splitList: list,
            histYear: histList,
            serviceYear: undefined,
            taskComment: undefined,
            isMedit: 0,
            newCheck: [],
            checkType: this.getNewCheckType(data.data, this.state.checkType), // 临时显示
          })
        } else {
          message.warning(data.error[0].message);
        };
      }.bind(this)
    });
  }

  getNewCheckType(item, list = []) {
    let newCheckType = list
    if (item.htMember == 1) {
      newCheckType.push(1)
    }
    if (item.additionalDeduction == 1) {
      newCheckType.push(2)
    }
    if (item.rdAwardsubsidy == 1) {
      newCheckType.push(3)
    }
    return [...new Set(newCheckType)]
  }

  render() {
    let children = vipYear.map(its => (
      <Option key={its}>{its}</Option>
    ));
    let plainOptions = this.state.projectType == 3
      ? [{ label: '仅提供单变会员', value: 1 },] : this.state.projectType == 2
        ? [{ label: '仅填报表，仅咨询，不出备查资料', value: 1 }] : this.state.projectType == 1
          ? [
            { label: '高新会员', value: 1 },
            { label: '加计扣除', value: 2 },
            { label: '研发奖补', value: 3 }
          ] : []
    const { RangePicker } = DatePicker;
    const { readOnly } = this.props;
    const { isVip, histYear, isMedit } = this.state
    return (
      <Modal
        maskClosable={false}
        visible={this.props.visible}
        onOk={this.props.onCancel}
        onCancel={this.props.onCancel}
        width="900px"
        title={readOnly ? "项目任务详情" : "编辑项目任务"}
        footer=""
        className="admin-desc-content"
      >
        <Form
          layout="horizontal"
        >
          <Spin spinning={this.state.loading}>
            <div>
              <div className="clearfix">
                <FormItem
                  className="half-item"
                  {...formItemLayout}
                  label="服务名称"
                >
                  {this.state.commodityName}
                </FormItem>
                {
                  isVip != 6 &&
                  <FormItem
                    className="half-item"
                    {...formItemLayout}
                    label="服务数量"
                  >
                    {readOnly ? this.state.commodityQuantity :
                      <Input
                        placeholder="请输入服务数量"
                        disabled={isVip == 6}
                        value={this.state.commodityQuantity}
                        style={{ width: "200px" }}
                        onChange={(e) => {
                          this.setState({ commodityQuantity: e.target.value });
                        }}
                        ref="commodityQuantity"
                      />}
                    {!readOnly && <span className="mandatory">*</span>}
                  </FormItem>
                }
              </div>
              <FormItem
                className="half-item"
                {...formItemLayout}
                label="实签价格(万元)"
              >
                {readOnly ? this.state.commodityPrice :
                  <Input
                    type='number'
                    placeholder="请输入实签价格"
                    disabled={isMedit != 1}
                    value={this.state.commodityPrice}
                    style={{ width: "200px" }}
                    onChange={(e) => {
                      this.setState({ commodityPrice: e.target.value });
                    }}
                    ref="commodityPrice"
                  />}
                {!readOnly && <span className="mandatory">*</span>}
              </FormItem>
              <FormItem
                className="half-item"
                {...formItemLayout}
                label="主要业务"
              >
                {readOnly ? getboutique(this.state.main) :
                  <Select
                    placeholder="选择是否为主要业务"
                    disabled={isMedit != 1}
                    style={{ width: "200px" }}
                    value={this.state.main}
                    onChange={(e) => {
                      this.setState({ main: e });
                    }}
                  >
                    {boutique.map(function (item) {
                      return (
                        <Select.Option key={item.value}>
                          {item.key}
                        </Select.Option>
                      );
                    })}
                  </Select>}
                {!readOnly && <span className="mandatory">*</span>}
              </FormItem>
              {
                !this.state.patentTransfer &&
                <FormItem
                  className="half-item"
                  {...formItemLayout}
                  label="专利类型："
                  style={{
                    display: this.state.displayFees,
                  }}
                >
                  {readOnly ? this.state.patentTypeName :
                    <Select
                      placeholder="请选择专利类型"
                      style={{ width: "200px" }}
                      value={this.state.patentType}
                      onChange={(e) => {
                        this.setState({ patentType: e });
                        if (e !== 0 && e !== 2) {
                          this.setState({
                            costReduction: ''
                          })
                        }
                      }}
                    >
                      {this.state.patentTypeList.map(function (v, k) {
                        return (
                          <Select.Option key={k} value={v.id}>{v.name}</Select.Option>
                        );
                      })}
                    </Select>}
                  <span style={{ color: "red", marginLeft: "8px" }}>
                    *
                  </span>
                </FormItem>
              }
              {
                // 知识产权
                isVip == 8 && this.state.addProjectType != 2 &&
                <div className="clearfix">
                  <FormItem
                    className="half-item"
                    {...formItemLayout}
                    label="申请"
                  >
                    {
                      <Radio.Group
                        disabled={readOnly}
                        value={this.state.ordinaryRisk}
                        onChange={(e) => {
                          this.setState({ ordinaryRisk: e.target.value });
                        }}
                      >
                        <Radio value={0}>普通申请</Radio>
                        <Radio value={1}>风险代理</Radio>
                      </Radio.Group>
                    }
                  </FormItem>
                </div>
              }
              {
                // 软著
                this.state.addProjectType == 2 &&
                <div className="clearfix">
                  <FormItem
                    className="half-item"
                    {...formItemLayout}
                    label="天数"
                  >
                    {
                      <Radio.Group
                        disabled={readOnly}
                        value={this.state.days}
                        onChange={(e) => {
                          this.setState({ days: e.target.value });
                        }}
                      >
                        <Radio value={0}>普通</Radio>
                        <Radio value={1}>加急</Radio>
                      </Radio.Group>
                    }
                  </FormItem>
                </div>
              }
              {
                // 软著
                this.state.addProjectType == 2 &&
                <div className="clearfix">
                  <FormItem
                    className="half-item"
                    {...formItemLayout}
                    label="方案"
                  >
                    {
                      <Radio.Group
                        disabled={readOnly}
                        value={this.state.scheme}
                        onChange={(e) => {
                          this.setState({ scheme: e.target.value });
                        }}
                      >
                        <Radio value={0}>无方案</Radio>
                        <Radio value={1}>有方案</Radio>
                      </Radio.Group>
                    }
                  </FormItem>
                </div>
              }
              <div className="clearfix">
                <FormItem
                  className="half-item"
                  {...formItemLayout}
                  label="官费："
                  style={{
                    display: this.state.displayFees,
                  }}
                >
                  {readOnly
                    ? (this.state.officialCost === 1 ? '含官费' : this.state.officialCost === 0 ? '不含官费' : '')
                    : <Radio.Group
                      value={this.state.officialCost}
                      onChange={(e) => {
                        this.setState({ officialCost: e.target.value });
                        if (e.target.value === 0) {
                          this.setState({
                            costReduction: ''
                          })
                        }
                      }}
                    >
                      <Radio value={1}>含官费</Radio>
                      <Radio value={0}>不含官费</Radio>
                    </Radio.Group>}
                  <span style={{ color: "red", marginLeft: "8px" }}>
                    *
                  </span>
                </FormItem>
              </div>
              <div className="clearfix">
                {
                  readOnly ?
                    <FormItem
                      className="half-item"
                      {...formItemLayout}
                      label="费减："
                      style={{
                        display: this.state.displayFees,
                      }}
                    >
                      {this.state.costReduction === 1 ? '有费减' : this.state.costReduction === 0 ? '无费减' : ''}
                      <span style={{ color: "red", marginLeft: "8px" }}>
                        *
                      </span>
                    </FormItem>
                    :
                    (this.state.patentType === 0 || this.state.patentType === 2) &&
                    <div className="clearfix">
                      <FormItem
                        className="half-item"
                        {...formItemLayout}
                        label="费减："
                        style={{
                          display: this.state.displayFees,
                        }}
                      >
                        {/*不含官费或者专利类型不为复审或者申请时置灰*/}
                        <Radio.Group
                          disabled={this.state.patentType !== 0 && this.state.patentType !== 2}
                          value={this.state.costReduction}
                          onChange={(e) => {
                            this.setState({ costReduction: e.target.value });
                          }}
                        >
                          <Radio value={1}>有费减</Radio>
                          <Radio value={0}>无费减</Radio>
                        </Radio.Group>
                        <span style={{ color: "red", marginLeft: "8px" }}>
                          *
                        </span>
                      </FormItem>
                    </div>
                }
              </div>
              {
                //审计
                this.state.addProjectType == "3" &&
                <FormItem
                  className="half-item"
                  {...formItemLayout}
                  label="服务年限"
                >
                  {
                    readOnly ?
                      !!this.state.serviceLife ? this.state.serviceLife.toString() : "" :
                      <Select
                        mode="multiple"
                        style={{ width: '200px' }}
                        placeholder="请选择服务年限"
                        value={this.state.serviceLife}
                        onChange={(e) => {
                          this.setState({
                            serviceLife: e,
                          })
                        }}
                      >
                        {children}
                      </Select>
                  }
                  {!readOnly && <span className="mandatory">*</span>}
                </FormItem>
              }
              {
                isVip == 6 &&
                <FormItem
                  className="half-item"
                  {...formItemLayout}
                  label="会员服务年限"
                >
                  {
                    readOnly ?
                      !!this.state.serviceLife ? this.state.serviceLife.toString() : "" :
                      <div>
                        {
                          this.state.serviceLife.map((tag) =>
                            <Tag
                              key={tag}
                              // closable={!isEdit}
                              // afterClose={() => this.handleClose(tag)}
                              // onClose={() => this.tagClose(tag)}
                              onClick={() => isMedit == 1 && this.tagClose(tag)}
                            >{tag + " "}{isMedit == 1 && <Icon type="close" />}</Tag>
                          )
                        }
                        {
                          isMedit == 1 && (this.state.serviceLife.length < 10) &&
                          <Button
                            size="small"
                            type="primary"
                            onClick={() => {
                              this.setState({
                                addYears: true,
                                addyear: undefined,
                                isGive: undefined,
                              })
                            }}>
                            + 添加服务年限
                          </Button>
                        }
                      </div>
                  }
                </FormItem>
              }
              {
                isVip == 6 &&
                <FormItem
                  className="half-item"
                  {...formItemLayout}
                  label="会员总服务年限"
                >
                  {
                    !this.state.yearSum ? "" :
                      [
                        { value: "0", key: "" },
                        { value: "1", key: "一年" },
                        { value: "2", key: "二年" },
                        { value: "3", key: "三年" },
                        { value: "4", key: "四年" },
                        { value: "5", key: "五年" },
                        { value: "6", key: "六年" },
                        { value: "7", key: "七年" },
                        { value: "8", key: "八年" },
                        { value: "9", key: "九年" },
                        { value: "10", key: "十年" },
                      ][this.state.yearSum]["key"]
                  }
                </FormItem>
              }
              {
                // 会员合同期
                isVip == 6 &&
                <div className="clearfix">
                  <FormItem
                    className="half-item"
                    {...formItemLayout}
                    label={this.state.projectType == 3
                      ? '单边会员' : this.state.projectType == 2
                        ? '简单会员' : this.state.projectType == 1
                          ? '高新会员' : this.state.projectType == 0
                            ? '其他' : ' '}
                  >
                    <CheckboxGroup
                      // disabled={this.state.projectType == 3 || this.state.projectType == 2 || isMedit != 1}
                      disabled
                      style={{ width: 200 }}
                      options={plainOptions}
                      value={this.state.checkType}
                      onChange={e => {
                        this.setState({
                          checkType: e
                        })
                      }}
                    />
                  </FormItem>
                  <FormItem
                    className="half-item"
                    {...formItemLayout}
                    label="合同期"
                  >
                    {
                      readOnly ?
                        !!this.state.contractTerm ? this.state.contractTerm.toString().replace(",", "至") : "" :
                        <RangePicker
                          style={{ width: 200 }}
                          disabled={isMedit != 1}
                          value={[
                            this.state.contractTerm[0]
                              ? moment(this.state.contractTerm[0])
                              : null,
                            this.state.contractTerm[1]
                              ? moment(this.state.contractTerm[1])
                              : null,
                          ]}
                          onChange={(data, dataString) => {
                            this.setState({ contractTerm: dataString });
                          }}
                        />
                    }
                    {!readOnly && <span className="mandatory">*</span>}
                  </FormItem>
                </div>
              }
              {
                // 科技项目
                isVip == 3 &&
                <div className="clearfix">
                  <FormItem
                    labelCol={{ span: 4 }}
                    wrapperCol={{ span: 16 }}
                    label='科技项目'
                  >
                    <RadioGroup
                      disabled={readOnly}
                      onChange={e => {
                        this.setState({
                          technologyProjectType: e.target.value
                        })
                      }}
                      value={this.state.technologyProjectType}
                    >
                      <Radio value={3}>国家级</Radio>
                      <Radio value={2}>省级</Radio>
                      <Radio value={1}>市区级</Radio>
                      <Radio value={0}>简易项目</Radio>
                    </RadioGroup>
                  </FormItem>
                </div>
              }
              {
                // 审计
                this.state.addProjectType == "3" &&
                <div className="clearfix">
                  <FormItem
                    labelCol={{ span: 4 }}
                    wrapperCol={{ span: 16 }}
                    label=""
                  >
                    <span style={{ color: "red" }}>注：派单年度的上年度总资产和收入。如，当前为2022年，那么需要填写2021年的总资产和收入！</span>
                  </FormItem>
                  {
                    this.state.isYear && !readOnly &&
                    <div className="clearfix">
                      <FormItem
                        className="half-item"
                        label="企业上年度年份"
                        {...formItemLayout}
                      >
                        <Select
                          style={{ width: '200px' }}
                          placeholder="请选择年份"
                          value={this.state.lastYear}
                          onChange={e => {
                            this.setState({
                              lastYear: e,
                            })
                          }}
                        >
                          {
                            YearList.map(its => (
                              <Option key={its}>{its}</Option>
                            ))
                          }
                        </Select>
                        <span className="mandatory">*</span>
                      </FormItem>
                    </div>
                  }
                  <FormItem
                    className="half-item"
                    label="企业上年度总资产(万元)"
                    {...formItemLayout}
                  >
                    {
                      readOnly ? this.state.lastYearCapital :
                        <Input
                          type='number'
                          placeholder=""
                          value={this.state.lastYearCapital}
                          style={{ width: "200px" }}
                          onChange={(e) => {
                            this.setState({ lastYearCapital: e.target.value });
                          }}
                        />
                    }

                    {!readOnly && <span className="mandatory">*</span>}
                  </FormItem>
                  <FormItem
                    className="half-item"
                    label="企业上年度总收入(万元)"
                    {...formItemLayout}
                  >
                    {
                      readOnly ? this.state.lastYearIncome :
                        <Input
                          type='number'
                          placeholder=""
                          value={this.state.lastYearIncome}
                          style={{ width: "200px" }}
                          onChange={(e) => {
                            this.setState({ lastYearIncome: e.target.value });
                          }}
                        />
                    }
                    {!readOnly && <span className="mandatory">*</span>}
                  </FormItem>
                </div>
              }
              {
                // 普通项目说明
                isVip != 6 &&
                <div className="clearfix">
                  <FormItem
                    labelCol={{ span: 4 }}
                    wrapperCol={{ span: 16 }}
                    label="项目说明"
                  >
                    {readOnly ? this.state.taskComment :
                      <Input
                        type="textarea"
                        placeholder=""
                        autosize={{ minRows: 4 }}
                        value={this.state.taskComment}
                        onChange={(e) => {
                          this.setState({ taskComment: e.target.value });
                        }}
                      />}
                  </FormItem>
                </div>
              }
              {/*0通用 1专利 2软著 3审计 4双软 5高新 6商标*/}
              {
                this.state.addProjectType === 5 &&
                <div className="clearfix">
                  <FormItem
                    className="half-item"
                    {...formItemLayout}
                    label="企业要求申报批次"
                  >
                    {readOnly ? (
                      this.state.declarationBatch === 1 ? '第一批' :
                        this.state.declarationBatch === 2 ? '第二批' :
                          this.state.declarationBatch === 3 ? '第三批' :
                            this.state.declarationBatch === 4 ? '第四批' : '未知'
                    ) :
                      <Select
                        placeholder="请选择企业要求申报批次"
                        style={{ width: "200px" }}
                        value={this.state.declarationBatch}
                        onChange={(e) => {
                          this.setState({ declarationBatch: e });
                        }}
                      >
                        <Select.Option value={1}>
                          第一批
                        </Select.Option>
                        <Select.Option value={2}>
                          第二批
                        </Select.Option>
                        <Select.Option value={3}>
                          第三批
                        </Select.Option>
                        <Select.Option value={4}>
                          第四批
                        </Select.Option>
                      </Select>}
                    {!readOnly && <span className="mandatory">*</span>}
                  </FormItem>
                  <FormItem
                    className="half-item"
                    {...formItemLayout}
                    label="申报年份"
                  >
                    {
                      readOnly ? this.state.serviceYear :
                        <Select
                          style={{ width: '200px' }}
                          placeholder="请选择申报年份"
                          value={this.state.serviceYear}
                          onChange={e => {
                            this.setState({
                              serviceYear: e,
                            })
                          }}
                        >
                          {
                            vipYear.map(its => (
                              <Option key={its}>{its}</Option>
                            ))
                          }
                        </Select>
                    }
                    {!readOnly && <span className="mandatory">*</span>}
                  </FormItem>
                </div>
              }
              {
                this.props.isIso || this.state.isIso ?
                  <div className="clearfix">
                    <FormItem
                      className="half-item"
                      {...formItemLayout}
                      label="是否包含认证费用"
                    >
                      {readOnly ? (
                        this.state.ifCertificationFee == "1" ? '包含' :
                          this.state.ifCertificationFee == "0" ? '不包含' : '未知'
                      ) : <Select
                        placeholder="请选择是否包含认证费用"
                        style={{ width: "200px" }}
                        value={this.state.ifCertificationFee}
                        onChange={(e) => {
                          this.setState({ ifCertificationFee: e });
                        }}
                      >
                        <Select.Option value={"0"}>否</Select.Option>
                        <Select.Option value={"1"}>是</Select.Option>
                      </Select>}
                      {!readOnly && <span className="mandatory">*</span>}
                    </FormItem>
                  </div> : null
              }
              {
                isMedit == 0 && isVip == 6 &&
                <div className="clearfix">
                  <FormItem
                    wrapperCol={{ span: 12, offset: 8 }}
                    className="half-middle"
                  >
                    <Button
                      className="submitSave"
                      onClick={() => {
                        this.setState({
                          isMedit: 1
                        })
                      }}
                    >
                      重新编辑项目任务
                    </Button>
                  </FormItem>
                </div>
              }
              {
                ((!readOnly && isVip != 6) || (isVip == 6 && isMedit == 1)) &&
                <div className="clearfix">
                  <FormItem
                    wrapperCol={{ span: 12, offset: 8 }}
                    className="half-middle"
                  >
                    <Button
                      className="submitSave"
                      type="primary"
                      onClick={() => {
                        this.onChange("submit");
                      }}
                    >
                      保存
                    </Button>
                    <Button
                      className="submitSave"
                      type="ghost"
                      onClick={() => {
                        isVip == 6
                          ? this.setState({
                            isMedit: 0
                          })
                          : this.props.onCancel()
                      }}
                    >
                      取消
                    </Button>
                  </FormItem>
                </div>
              }
              {
                // 会员项目子集列表
                !!this.state.splitList && this.state.splitList.length > 0 &&
                this.state.splitList.map((item) =>
                  // 标识为 3=删 不显示
                  item.type != 3 &&
                  <div
                    key={item.id}
                    className="clearfix"
                    style={{
                      width: "100%",
                      borderTop: "1px dashed #000000",
                      padding: "10px 0"
                    }}
                  >
                    <FormItem
                      className="half-item"
                      {...formItemLayout}
                      label="本次派单"
                    >
                      {item.serviceYear}
                    </FormItem>
                    <FormItem
                      className="half-item"
                      {...formItemLayout}
                      label="服务数量"
                    >
                      {item.commodityQuantity}
                    </FormItem>
                    {
                      this.state.projectType == 1 &&
                      <FormItem
                        className="half-item"
                        {...formItemLayout}
                        label="高新会员"
                      >
                        <CheckboxGroup
                          disabled
                          style={{ width: 200 }}
                          options={[
                            { label: '高新会员', value: 1 },
                            { label: '加计扣除', value: 2 },
                            { label: '研发奖补', value: 3 }
                          ]}
                          value={this.getNewCheckType(item)}
                        />
                      </FormItem>
                    }
                    {
                      (item.memberType == "0" || item.memberType == "1" || item.memberType == "2") &&
                      <FormItem
                        className="half-item"
                        {...formItemLayout}
                        label="付款情况"
                      >
                        {item.memberType == "0"
                          ? "已付会员节点全款" : item.memberType == "1"
                            ? "已付部分期款，需特批" : item.memberType == "2"
                              ? "未付款，需特批" : ""}
                      </FormItem>
                    }
                    {
                      (item.memberType == "1" || item.memberType == "2") &&
                      <div className="clearfix">
                        <FormItem
                          labelCol={{ span: 4 }}
                          wrapperCol={{ span: 16 }}
                          label="附件"
                        >
                          {item.pictureUrl ?
                            <div>
                              <ImgList fileList={splitUrl(item.pictureUrl, ",", globalConfig.avatarHost + "/upload")} ItemWidth={'96px'} />
                            </div> : <div />}
                        </FormItem>
                      </div>
                    }
                    <div className="clearfix">
                      <FormItem
                        labelCol={{ span: 4 }}
                        wrapperCol={{ span: 16 }}
                        label="项目说明"
                      >
                        {item.taskComment}
                      </FormItem>
                    </div>
                    {/* {
                      (isMedit == 0 || isMedit == 2) &&
                      <div className="clearfix">
                        <FormItem
                          wrapperCol={{ span: 12, offset: 10 }}
                          className="half-middle"
                        >
                          <Button type="danger"
                            onClick={() => {
                              const _this = this
                              confirm({
                                title: '确定要删除吗',
                                content: '确定删除本次派单吗',
                                okText: '确定',
                                okType: 'danger',
                                cancelText: '取消',
                                onOk() {
                                  _this.deleteMemberSonProject(item.id)
                                },
                                onCancel() { },
                              });
                            }}
                          >删除</Button>
                        </FormItem>
                      </div>
                    } */}
                  </div>
                )
              }
              {
                (isMedit == 0 || isMedit == 2) &&
                this.state.splitList.filter((item) => { return item.type != 3 }).length < this.state.yearSum &&
                <div
                  className="clearfix"
                  style={{
                    width: "100%",
                    borderTop: "1px dashed #000000",
                    padding: "30px 0 10px 0"
                  }}
                >
                  {
                    !this.state.addFrom &&
                    // this.state.splitList.length < this.state.yearSum &&
                    this.state.splitList.filter((item) => { return item.type != 3 }).length < this.state.yearSum &&
                    <div className="clearfix">
                      <FormItem
                        wrapperCol={{ span: 19, offset: 8 }}
                        className="half-middle"
                      >
                        <Button
                          type="primary"
                          onClick={() => {
                            this.setState({
                              addFrom: true,
                            })
                          }}
                        >
                          + 添加本次派单
                        </Button>
                        <span style={{ color: "#61BBE2", marginLeft: 10 }}>请填写本次派单的年份，派单表示立即安排人员开始相关的工作！！！</span>
                      </FormItem>
                    </div>
                  }
                  {
                    this.state.addFrom &&
                    <div>
                      <FormItem
                        className="half-item"
                        {...formItemLayout}
                        label="本次派单"
                      >
                        <Select
                          placeholder="请选择本次派单年份"
                          style={{ width: "200px" }}
                          value={this.state.serviceYear}
                          onChange={(e) => {
                            let addId = ""
                            let addtext = ""
                            if (!!this.state.splitList) {
                              for (var i = 0; i < this.state.splitList.length; i++) {
                                if (this.state.splitList[i].serviceYear == e && this.state.splitList[i].type == 3) {
                                  addId = this.state.splitList[i].id
                                  addtext = this.state.splitList[i].taskComment
                                }
                              }
                            }
                            this.setState({
                              serviceYear: e,
                              recoveryId: addId,
                              taskComment: addtext,
                            });
                          }}
                        >
                          {this.state.serviceLife.length > 0 && this.state.serviceLife.map(function (item) {
                            return (
                              <Select.Option key={item} disabled={histYear.includes(item)}>
                                {item}
                              </Select.Option>
                            );
                          })}
                        </Select>
                        {<span className="mandatory">*</span>}
                      </FormItem>
                      <FormItem
                        className="half-item"
                        {...formItemLayout}
                        label="服务数量"
                      >
                        <Input
                          placeholder="请输入服务数量"
                          disabled={isVip == 6}
                          value={1}
                          style={{ width: "200px" }}
                          ref="commodityQuantity"
                        />
                        {<span className="mandatory">*</span>}
                      </FormItem>
                      {
                        this.state.projectType == 1 &&
                        <div className="clearfix">
                          <FormItem
                            className="half-item"
                            {...formItemLayout}
                            label={'高新会员'}
                          >
                            <CheckboxGroup
                              style={{ width: 200 }}
                              options={[
                                { label: '高新会员', value: 1 },
                                { label: '加计扣除', value: 2 },
                                { label: '研发奖补', value: 3 }
                              ]}
                              value={this.state.newCheck}
                              onChange={e => {
                                this.setState({
                                  newCheck: e
                                })
                              }}
                            />
                          </FormItem>
                        </div>
                      }
                      <div className="clearfix">
                        <FormItem
                          labelCol={{ span: 4 }}
                          wrapperCol={{ span: 16 }}
                          label="项目说明"
                        >
                          <Input
                            type="textarea"
                            placeholder=""
                            autosize={{ minRows: 2 }}
                            value={this.state.taskComment}
                            onChange={(e) => {
                              this.setState({ taskComment: e.target.value });
                            }}
                          />
                        </FormItem>
                      </div>
                      <div className="clearfix">
                        <FormItem
                          wrapperCol={{ span: 12, offset: 8 }}
                          className="half-middle"
                        >
                          <Button
                            className="submitSave"
                            type="primary"
                            onClick={() => {
                              this.addMemberFirstSonProject()
                            }}
                          >
                            保存
                          </Button>
                          <Button
                            className="submitSave"
                            type="ghost"
                            onClick={() => {
                              this.setState({
                                addFrom: false
                              })
                            }}
                          >
                            取消
                          </Button>
                        </FormItem>
                      </div>
                    </div>
                  }
                </div>
              }
            </div>
          </Spin>
        </Form>
        {
          this.state.addYears &&
          <Modal
            title="添加服务年限"
            visible={this.state.addYears}
            okText="添加"
            onOk={() => {
              if (!this.state.addyear) {
                message.warn("请选择年份！")
                return
              }
              if (this.state.isGive == undefined) {
                message.warn("请选择是否赠送！")
                return
              }
              let slist = this.state.serviceLife
              let newYear = this.state.addyear
              if (this.state.isGive == 0) {
                newYear = newYear
              } else if (this.state.isGive == 1) {
                newYear = newYear + "(赠)"
              }
              slist.push(newYear)
              this.setState({
                serviceLife: slist,
                commodityQuantity: slist.length,
                yearSum: slist.length.toString(),
                addYears: false
              }, () => {
                // let addId = ""
                // if (!!this.state.splitList) {
                //   for (var i = 0; i < this.state.splitList.length; i++) {
                //     if (this.state.splitList[i].serviceYear == newYear && this.state.splitList[i].type == 3) {
                //       addId = this.state.splitList[i].id
                //     }
                //   }
                // }
                // addId == ""
                //   ? this.onChange()
                //   : this.updateMemberSonProject(addId)
              })
            }}
            onCancel={() => {
              this.setState({
                addYears: false
              })
            }}
          >
            <Select
              style={{ width: '200px', marginRight: 50 }}
              placeholder="请选择年份"
              onChange={e => {
                this.setState({
                  addyear: e,
                })
              }}
            >
              {
                vipYear.map(its => (
                  <Option
                    key={its}
                    disabled={this.state.serviceLife.toString().includes(its)}
                  >{its}</Option>
                ))
              }
            </Select>
            <RadioGroup
              onChange={e => {
                this.setState({
                  isGive: e.target.value
                })
              }}
              value={this.state.isGive}
            >
              <Radio value={0}>非赠送</Radio>
              <Radio value={1}>赠送</Radio>
            </RadioGroup>
          </Modal>
        }
      </Modal >
    )
  }
}

export default newEditProject;
