<template>
  <div :class="type === '2' ? 'poolAdd poolDetail' : 'poolAdd'">
    <el-form
      ref="form"
      :model="form"
      :rules="type === '2' ? rules1 : rules"
      label-width="160px"
      class="special-el-form"
    >
      <h3>项目基础信息</h3>
      <el-divider></el-divider>
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          maxlength="100"
          v-model="form.projectName"
          placeholder="请输入项目名称"
          :disabled="type === '2'"
        />
      </el-form-item>

      <el-form-item label="渠道" prop="tProjectChannel.channelName">
        <el-select
          :disabled="type === '2'"
          v-model="form.tProjectChannel.channelName"
          placeholder="请选择"
          clearable
          @change="handleChannel"
        >
          <el-option
            v-for="item in channelList"
            :key="item.id"
            :label="item.channelName"
            :value="item.id"
          />
          <el-option label="直接触达" value="1" />
          <el-option label="内部推荐" value="2" />
<!--          <el-option label="无" value="-1" />-->
        </el-select>
        <!-- <channelItem
          ref="channelItem"
          @getChannelInfo="getChannelInfo"
        ></channelItem> -->
        <!-- <el-input v-model="form.channel" placeholder="请输入渠道" /> -->
      </el-form-item>
      <el-form-item label="初次接触日期" prop="contactDate">
        <el-date-picker
          :disabled="type === '2'"
          clearable
          v-model="form.contactDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择初次接触日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="所属组别">
        <el-select
          v-model="form.tProjectChannel.channelGroup"
          disabled
          placeholder="请选择所属组别"
        >
          <el-option
            v-for="dict in dict.type.project_group"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="所属行业" prop="industry">
        <el-select
          v-model="form.industry"
          placeholder="请选择所属行业"
          :disabled="type === '2'"
        >
          <el-option
            v-for="dict in dict.type.CUSTOMER_TRADE"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="项目负责人" prop="investHead">
        <el-input
          v-if="type === '2'"
          maxlength="30"
          v-model="form.investHead"
          :disabled="type === '2'"
        />
        <div
          class="el-input__inner inputSimulation"
          @click="openSelectDept"
          v-else
        >
          {{ form.investHead ? form.investHead : "请选择项目负责人" }}
        </div>
        <selecDept
          ref="selecDepts"
          @getDeptUserInfo="getDeptUserInfo"
          :deptId="deptId"
        ></selecDept>
      </el-form-item>

      <el-form-item
        label="项目情况描述"
        prop="description"
        class="special-el-form-item"
      >
        <el-input
          :disabled="type === '2'"
          maxlength="200"
          rows="4"
          type="textarea"
          v-model="form.description"
          placeholder="请输入项目情况描述"
        />
      </el-form-item>
      <h3>项目公司信息</h3>
      <el-divider></el-divider>
      <el-form-item label="公司名称" prop="tProjectCompany.companyName">
        <el-input
          :disabled="type === '2'"
          maxlength="100"
          v-model="form.tProjectCompany.companyName"
          placeholder="请输入公司名称"
        />
      </el-form-item>
      <el-form-item label="统一社会信用代码" prop="tProjectCompany.companyCode">
        <el-input
          :disabled="type === '2'"
          maxlength="35"
          v-model="form.tProjectCompany.companyCode"
          placeholder="请输入企业统一社会信用代码"
        />
      </el-form-item>
      <el-form-item label="营业开始时间" prop="tProjectCompany.startTime">
        <el-date-picker
          :disabled="type === '2'"
          clearable
          v-model="form.tProjectCompany.startTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择营业开始时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="营业结束时间" prop="tProjectCompany.endTime">
        <el-date-picker
          :disabled="type === '2'"
          clearable
          v-model="form.tProjectCompany.endTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择营业结束时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item
        label="注册资本(万元)"
        prop="tProjectCompany.registeredCapital"
      >
        <el-input
          :disabled="type === '2'"
          maxlength="20"
          v-model="form.tProjectCompany.registeredCapital"
          @input="
            (value) =>
              (form.tProjectCompany.registeredCapital = value
                .replace(/[^0-9.]/g, '')
                .replace(/^(\-)*(\d+)\.(\d\d\d\d).*$/, '$1$2.$3')
                .replace(/-/g, ''))
          "
          placeholder="请输入注册资本"
        />
      </el-form-item>
      <el-form-item label="实缴资本(万元)" prop="tProjectCompany.paidCapital">
        <el-input
          :disabled="type === '2'"
          maxlength="20"
          v-model="form.tProjectCompany.paidCapital"
          @input="
            (value) =>
              (form.tProjectCompany.paidCapital = value
                .replace(/[^0-9.]/g, '')
                .replace(/^(\-)*(\d+)\.(\d\d\d\d).*$/, '$1$2.$3')
                .replace(/-/g, ''))
          "
          placeholder="请输入实缴资本"
        />
      </el-form-item>

      <el-form-item label="实控人" prop="tProjectCompany.actualBod">
        <el-input
          :disabled="type === '2'"
          maxlength="25"
          v-model="form.tProjectCompany.actualBod"
          placeholder="请输入实控人"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="tProjectCompany.phone">
        <el-input
          :disabled="type === '2'"
          maxlength="20"
          v-model="form.tProjectCompany.phone"
          placeholder="请输入联系电话"
        />
      </el-form-item>
      <el-form-item label="所属类型" prop="tProjectCompany.type">
        <el-input
          :disabled="type === '2'"
          maxlength="25"
          v-model="form.tProjectCompany.type"
          placeholder="请输入所属类型"
        />
      </el-form-item>
      <el-form-item label="备案时间" prop="tProjectCompany.filingTime">
        <el-date-picker
          :disabled="type === '2'"
          clearable
          v-model="form.tProjectCompany.filingTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择备案时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item
        label="注册地址"
        prop="tProjectCompany.registeredAddress"
        class="special-el-form-item"
      >
        <el-input
          :disabled="type === '2'"
          type="textarea"
          rows="4"
          maxlength="100"
          v-model="form.tProjectCompany.registeredAddress"
          placeholder="请输入注册地址"
        />
      </el-form-item>

      <el-form-item
        label="办公地址"
        prop="tProjectCompany.businessAddress"
        class="special-el-form-item"
      >
        <el-input
          :disabled="type === '2'"
          type="textarea"
          rows="4"
          maxlength="100"
          v-model="form.tProjectCompany.businessAddress"
          placeholder="请输入办公地址"
        />
      </el-form-item>
      <el-form-item
        label="公司附件"
        prop="listFile"
        class="special-el-form-item"
      >
        <fileItem
          ref="fileItem"
          :id="form.id"
          @getFileList="getFileList"
        ></fileItem>
      </el-form-item>
      <h3>项目公司联系人信息</h3>
      <el-divider></el-divider>
      <el-form-item label="联系人姓名" prop="tProjectContacts.name">
        <el-input
          :disabled="type === '2'"
          maxlength="25"
          v-model="form.tProjectContacts.name"
          placeholder="请输入联系人姓名"
        />
      </el-form-item>
      <el-form-item label="职位" prop="tProjectContacts.position">
        <el-input
          :disabled="type === '2'"
          maxlength="25"
          v-model="form.tProjectContacts.position"
          placeholder="请输入职位"
        />
      </el-form-item>
      <el-form-item label="联系电话/微信" prop="tProjectContacts.contact">
        <el-input
          :disabled="type === '2'"
          maxlength="25"
          v-model="form.tProjectContacts.contact"
          placeholder="请输入联系电话/微信"
        />
      </el-form-item>
      <h3>项目融资信息</h3>
      <el-divider></el-divider>
      <el-form-item label="项目融资阶段" prop="financingStage">
        <el-select
          :disabled="type === '2'"
          v-model="form.financingStage"
          placeholder="请选择项目融资阶段"
        >
          <el-option
            v-for="dict in dict.type.financing_stage"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="预期融资金额(万元)" prop="financingMoney">
        <el-input
          :disabled="type === '2'"
          maxlength="20"
          v-model="form.financingMoney"
          @input="
            (value) =>
              (form.financingMoney = value.replace(/\D/g, '').replace(/-/g, ''))
          "
          placeholder="请输入预期融资金额"
        />
      </el-form-item>
      <el-form-item label="投后估值(万元)" prop="investValuation">
        <el-input
          :disabled="type === '2'"
          maxlength="20"
          v-model="form.investValuation"
          @input="
            (value) =>
              (form.investValuation = value
                .replace(/[^0-9.]/g, '')
                .replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3')
                .replace(/-/g, ''))
          "
          placeholder="请输入投后估值"
        />
      </el-form-item>
      <el-form-item label="预计投资金额(万元)" prop="investMoney">
        <el-input
          :disabled="type === '2'"
          maxlength="20"
          v-model="form.investMoney"
          @input="
            (value) =>
              (form.investMoney = value.replace(/\D/g, '').replace(/-/g, ''))
          "
          placeholder="请输入预计投资金额"
        />
      </el-form-item>
      <!--  -->
      <el-form-item label="投资类型" prop="investType">
        <el-select
          v-model="form.investType"
          placeholder="请选择投资类型"
          :disabled="type === '2'"
        >
          <el-option
            v-for="dict in dict.type.invest_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="投资策略" prop="investPloy">
        <el-select
          v-model="form.investPloy"
          placeholder="请选择投资策略"
          :disabled="type === '2'"
        >
          <el-option
            v-for="dict in dict.type.invest_ploy"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="投资价值" prop="investWorth">
        <el-select
          v-model="form.investWorth"
          placeholder="请选择投资价值"
          :disabled="type === '2'"
        >
          <el-option
            v-for="dict in dict.type.invest_worth"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item
        label="历次融资"
        prop="previousFinancing"
        class="special-el-form-item"
      >
        <el-input
          :disabled="type === '2'"
          maxlength="200"
          rows="4"
          type="textarea"
          v-model="form.previousFinancing"
          placeholder="请输入历次融资"
        />
      </el-form-item>
      <el-form-item
        label="融资条件"
        prop="financingCondition"
        class="special-el-form-item"
      >
        <el-input
          :disabled="type === '2'"
          maxlength="200"
          rows="4"
          type="textarea"
          v-model="form.financingCondition"
          placeholder="请输入融资条件"
        />
      </el-form-item>
      <el-form-item
        label="投资亮点"
        prop="investSparkle"
        class="special-el-form-item"
      >
        <el-input
          :disabled="type === '2'"
          maxlength="200"
          rows="4"
          type="textarea"
          v-model="form.investSparkle"
          placeholder="请输入投资亮点"
        />
      </el-form-item>

      <el-form-item
        label="股权架构"
        prop="shareholding"
        class="special-el-form-item"
      >
        <el-input
          :disabled="type === '2'"
          maxlength="200"
          rows="4"
          type="textarea"
          v-model="form.shareholding"
          placeholder="请输入股权架构"
        />
      </el-form-item>
      <h3>其他</h3>
      <el-divider></el-divider>

      <el-form-item label="BP" prop="bpFile" class="special-el-form-item">
        <fileItem
          ref="bpFileItem"
          :id="form.id"
          @getFileList="getBPFileList"
        ></fileItem>
      </el-form-item>
      <el-form-item
        label="其他附件"
        prop="otherFile"
        class="special-el-form-item"
      >
        <fileItem
          ref="otherFileItem"
          :id="form.id"
          @getFileList="getOtherFileList"
        ></fileItem>
      </el-form-item>
      <el-form-item label="备注" prop="mark" class="special-el-form-item">
        <el-input
          :disabled="type === '2'"
          maxlength="200"
          :readonly="type === '2' ? true : false"
          rows="4"
          type="textarea"
          v-model="form.mark"
          placeholder="请输入备注"
        />
      </el-form-item>

      <el-form-item class="btnList" v-if="type === '1'">
        <el-button @click="goBack">返 回</el-button>
        <el-button
          type="warning"
          @click="submitForm(1)"
          v-preventReClick
          v-if="!form.projectState || form.projectState == '1'"
          >暂 存</el-button
        >
        <el-button type="primary" @click="submitForm(2)" v-preventReClick
          >提 交</el-button
        >
      </el-form-item>
    </el-form>
    <section v-if="isShowFlow">
      <flowBase :procInstId="form.procInstId" :id="form.id" v-if="form.procInstId"></flowBase>
    </section>
  </div>
</template>
<script>
import {
  getPool,
  addPool,
  updatePool,
} from "@/api/invest/pool";
import { listChannel } from "@/api/invest/channel";
import fileItem from "../invest/components/fileItem";
import channelItem from "../invest/components/channelItem";
import selecDept from "../invest/components/selecDept";
import { mapGetters } from "vuex";
import flowBase from "./flowBase.vue";
export default {
  props: {
    id: {
      type: String,
    },
    type: {
      type: String,
      default: "1", //1可编辑  2不可编辑
    },
    // 声明接收的 props，名称与父组件传递时一致（驼峰式在模板中用短横线）
    isShowFlow: {
      type: Boolean,
      default: false // 默认值
    },
  },
  components: {flowBase, fileItem, channelItem, selecDept },
  dicts: [
    "CUSTOMER_TRADE",
    "project_group",
    "invest_type",
    "invest_ploy",
    "invest_worth",
    "financing_stage",
  ],
  data() {
    const validateLogo = (rule, value, callback) => {
      if (this.fileListBP.length <= 0) {
        callback(new Error("请上传BP"));
      } else {
        callback();
      }
    };
    return {
      deptId: process.env.VUE_APP_DEPTID,
      title: "新增项目",
      baseUrl: process.env.VUE_APP_BASE_API,

      // 表单参数
      form: {
        id: null,
        projectName: null,
        projectGroup: "",
        industry: null,
        recordDate: null,
        projectCode: null,
        channel: "",
        contactDate: null,
        projectDate: null,
        decisionDate: null,
        tProjectCompany: {
          companyName: null,
          companyCode: null,
          startTime: null,
          endTime: null,
          registeredCapital: null,
          registeredAddress: null,
          paidCapital: null,
          businessAddress: null,
          actualBod: null,
          phone: null,
          filingTime: null,
          type: null,
        },
        tProjectContacts: {
          name: null,
          position: null,
          contact: null,
        },
        tProjectChannel: {
          channelName: "",
          channelGroup: "",
        },

        description: null,
        projectContacts: null,
        investHead: null,
        previousFinancing: null,
        financingStage: null,
        financingCondition: null,
        financingMoney: null,
        financingDate: null,
        investSparkle: null,
        investValuation: null,
        investMoney: null,
        investType: null,
        investPloy: null,
        investWorth: null,
        shareholding: null,
        projectStage: null,
        projectState: null,
        mark: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        listFile: null,
        bpFile: null,
        otherFile: null,
        procInstId:null,
      },
      fileList: [],
      fileListBP: [],
      fileListOther: [],
      // 表单校验
      rules1: {},
      rules: {
        projectName: [{ required: true, trigger: "blur", message: "请输入" }],
        // channel: [{ required: true, trigger: "blur", message: "请输入" }],
        contactDate: [{ required: true, trigger: "blur", message: "请输入" }],
        // projectGroup: [
        //   { required: true, trigger: "change", message: "请选择" },
        // ],
        industry: [{ required: true, trigger: "change", message: "请选择" }],
        investHead: [{ required: true, trigger: "blur", message: "请输入" }],
        bpFile: [{ required: true, validator: validateLogo }],
        "tProjectChannel.channelName": [
          { required: true, trigger: "change", message: "请选择" },
        ],
        // description: [{ required: true, trigger: "blur", message: "请输入" }],
        "tProjectCompany.companyName": [
          { required: true, trigger: "blur", message: "请输入" },
        ],
        "tProjectCompany.companyCode": [
          { required: true, trigger: "blur", message: "请输入" },
        ],
        "tProjectCompany.startTime": [
          { required: true, trigger: "blur", message: "请选择" },
        ],
        "tProjectCompany.endTime": [
          { required: true, trigger: "blur", message: "请选择" },
        ],
        "tProjectCompany.registeredCapital": [
          { required: true, trigger: "blur", message: "请输入" },
        ],
        "tProjectCompany.registeredAddress": [
          { required: true, trigger: "blur", message: "请输入" },
        ],
        "tProjectCompany.paidCapital": [
          { required: true, trigger: "blur", message: "请输入" },
        ],
        "tProjectCompany.businessAddress": [
          { required: true, trigger: "blur", message: "请输入" },
        ],
        "tProjectCompany.actualBod": [
          { required: true, trigger: "blur", message: "请输入" },
        ],
        "tProjectCompany.phone": [
          { required: true, trigger: "blur", message: "请输入联系电话" },
          // {
          //   pattern: /^1[3456789]\d{9}$/,
          //   message: "请输入正确的手机号",
          //   trigger: "blur",
          // },
        ],
        "tProjectCompany.filingTime": [
          { required: true, trigger: "blur", message: "请选择" },
        ],
        "tProjectCompany.type": [
          { required: true, trigger: "blur", message: "请输入" },
        ],
        // files: [{ required: true, trigger: "blur", message: "请输入" }],
        "tProjectContacts.name": [
          { required: true, trigger: "blur", message: "请输入" },
        ],
        "tProjectContacts.position": [
          { required: true, trigger: "blur", message: "请输入" },
        ],
        "tProjectContacts.contact": [
          { required: true, trigger: "blur", message: "请输入" },
        ],
        financingStage: [
          { required: true, trigger: "change", message: "请选择" },
        ],
        financingMoney: [
          { required: true, trigger: "blur", message: "请输入" },
        ],
        investValuation: [
          { required: true, trigger: "blur", message: "请输入" },
        ],
        investMoney: [{ required: true, trigger: "blur", message: "请输入" }],
        investType: [{ required: true, trigger: "change", message: "请选择" }],
        investPloy: [{ required: true, trigger: "change", message: "请选择" }],
        investWorth: [{ required: true, trigger: "change", message: "请选择" }],
        // previousFinancing: [{ required: true, trigger: "blur", message: "请输入" }],
        // financingCondition: [
        //   { required: true, trigger: "blur", message: "请输入" },
        // ],
        investSparkle: [{ required: true, trigger: "blur", message: "请输入" }],
        shareholding: [{ required: true, trigger: "blur", message: "请输入" }],
        // mark: [{ required: true, trigger: "blur", message: "请输入" }]
      },
      channelList: [],
    };
  },
  computed: {
    ...mapGetters(["user"]),
  },
  mounted() {
    new Promise((resolve, reject) => {
      listChannel({
        pageNum: 1,
        pageSize: 100,
      }).then((response) => {
        this.channelList = response.rows;
        resolve();
      });
    }).then(() => {
      if (this.id) {
        this.getPoolDetail(this.id);
      } else {
        this.reset();
      }
    });
  },
  methods: {
    // getListChannel() {
    //   // 渠道
    //   listChannel({
    //     pageNum: 1,
    //     pageSize: 100,
    //   }).then((response) => {
    //     this.channelList = response.rows;
    //   });
    // },
    // 选择部门人
    openSelectDept() {
      this.$refs.selecDepts.show(1, this.user.userId);
    },
    getDeptUserInfo(info) {
      if (info.length > 0) {
        this.form.investHead = info[0].nickName;
        this.$refs.form.clearValidate(["investHead"]);
      }
    },
    // 获取渠道信息
    getChannelInfo(info) {
      if (info.length > 0) {
        this.form.channel = info[0].id;
        this.form.tProjectChannel.channelName = info[0].channelName;
        this.form.tProjectChannel.channelGroup = info[0].channelGroup;
        this.$refs.form.clearValidate(["channel"]);
      }
    },
    // 选择渠道
    handleChannel(vId) {
      let obj = {};
      obj = this.channelList.find((item) => {
        return item.id === vId;
      });
      if (obj && obj.id) {
        this.form.channel = obj.id;
        this.form.tProjectChannel.channelName = obj.channelName;
        this.form.tProjectChannel.channelGroup = obj.channelGroup;
      } else {
        if (vId=="1") {
          this.form.channel = 1;
          this.form.tProjectChannel.channelName = "直接触达";
        }else if (vId=="2"){
          this.form.channel = 2;
          this.form.tProjectChannel.channelName = "内部推荐";
        }
        this.form.tProjectChannel.channelGroup = "";
      }
    },
    handleChannelItem() {
      this.$refs.channelItem.showChannelItem = true;
    },
    getPoolDetail(id) {
      getPool(id).then((response) => {
        this.form = response.data;
        let channeItem = this.channelList.find((item) => {
          if (this.form.channel == item.id) {
            return item;
          }
        });
        if (channeItem && channeItem.channelName) {
          this.form.tProjectChannel.channelName = channeItem.channelName;
          this.form.tProjectChannel.channelGroup = channeItem.channelGroup;
        } else {
          if(this.form.channel=="1") {
            this.form.tProjectChannel = {
              channelName: "直接触达",
              channelGroup: "",
            };
          }else if(this.form.channel=="2") {
            this.form.tProjectChannel = {
              channelName: "内部推荐",
              channelGroup: "",
            };
          }else {
            this.form.tProjectChannel = {
              channelName: "无",
              channelGroup: "",
            };
          }
        }
        setTimeout(() => {
          if (this.type == "2") {
            this.$refs.fileItem.handleButton();
            this.$refs.bpFileItem.handleButton();
            this.$refs.otherFileItem.handleButton();
          }
          this.$refs.fileItem.fileList = [];
          this.$refs.fileItem.getListFileBusinessId(
            this.form.tProjectCompany.companyId
          );
          this.$refs.bpFileItem.fileList = [];
          this.$refs.bpFileItem.getListFileBusinessId(this.form.id, "9");
          this.$refs.otherFileItem.fileList = [];
          this.$refs.otherFileItem.getListFileBusinessId(this.form.id, "0");
        }, 300);
      });
    },
    // 获取fileList
    getFileList(fileList) {
      if (fileList && fileList.length > 0) {
        this.fileList = fileList;
      } else {
        this.fileList = [];
      }
    },
    getBPFileList(fileList) {
      if (fileList && fileList.length > 0) {
        this.fileListBP = fileList;
        this.$refs.form.clearValidate(["bpFile"]);
      } else {
        this.fileList = [];
      }
    },
    getOtherFileList(fileList) {
      if (fileList && fileList.length > 0) {
        this.fileListOther = fileList;
      } else {
        this.fileList = [];
      }
    },
    /** 提交按钮 */
    submitForm(type) {
      let that = this;
      if (this.form.channel == "") {
        this.form.channel = -1;
      }
      if (type === 1) {
        // 暂存
        if (!this.form.projectName) {
          this.$modal.msgError("请输入项目名称");
          return false;
        }
        this.form.listFile = this.fileList;
        this.form.bpFile = this.fileListBP;
        this.form.otherFile = this.fileListOther;
        if (this.form.id != null) {
          updatePool(this.form).then((response) => {
            this.$modal.msgSuccess("暂存成功");
            setTimeout(() => {
              that.goBack();
            }, 1500);
          });
        } else {
          this.form.projectStage = "1";
          this.form.projectState = "1";
          this.form.projectGroup = this.form.tProjectChannel.channelGroup;
          addPool(this.form).then((response) => {
            this.$modal.msgSuccess("暂存成功");
            setTimeout(() => {
              that.goBack();
            }, 1500);
          });
        }
      } else if (type === 2) {
        // 提交
        this.$refs["form"].validate((valid, rules) => {
          if (valid) {
            this.form.listFile = this.fileList;
            this.form.bpFile = this.fileListBP;
            this.form.otherFile = this.fileListOther;
            this.form.tProjectCompany.registeredCapital =
              this.form.tProjectCompany.registeredCapital
                .replace(/[^0-9.]/g, "")
                .replace(/^(\-)*(\d+)\.(\d\d\d\d).*$/, "$1$2.$3")
                .replace(/-/g, "");
            this.form.tProjectCompany.paidCapital =
              this.form.tProjectCompany.paidCapital
                .replace(/[^0-9.]/g, "")
                .replace(/^(\-)*(\d+)\.(\d\d\d\d).*$/, "$1$2.$3")
                .replace(/-/g, "");
            this.form.investValuation = this.form.investValuation
              .replace(/[^0-9.]/g, "")
              .replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3")
              .replace(/-/g, "");
            this.form.financingMoney = this.form.financingMoney
              .replace(/\D/g, "")
              .replace(/-/g, "");
            this.form.investMoney = this.form.investMoney
              .replace(/\D/g, "")
              .replace(/-/g, "");
            if (this.form.id != null) {
              if (this.form.projectState == "1") {
                this.form.projectState = "a";
              }
              updatePool(this.form).then((response) => {
                this.$modal.msgSuccess("修改成功");
                setTimeout(() => {
                  that.goBack();
                }, 1500);
              });
            } else {
              this.form.projectStage = "1";
              this.form.projectState = "a";
              this.form.projectGroup = this.form.tProjectChannel.channelGroup;
              addPool(this.form).then((response) => {
                this.$modal.msgSuccess("新增成功");
                setTimeout(() => {
                  that.goBack();
                }, 1500);
              });
            }
          } else {
            for (var ruleName in rules) {
              let _rule = rules[ruleName];
              let message = _rule[0].message;
              this.$message.warning(message, 1);
              break;
            }
            //验证不通过回滚到不通过的第一个位置
            this.$nextTick(() => {
              let isError = document.getElementsByClassName("is-error");
              isError[0].scrollIntoView({
                block: "center",
                behavior: "smooth",
              });
            });
          }
        });
      }
    },
    goBack() {
      this.$router.go(-1);
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectName: null,
        projectGroup: "",
        industry: null,
        recordDate: null,
        projectCode: null,
        channel: "",
        contactDate: null,
        projectDate: null,
        decisionDate: null,
        tProjectCompany: {
          companyName: null,
          companyCode: null,
          startTime: null,
          endTime: null,
          registeredCapital: null,
          registeredAddress: null,
          paidCapital: null,
          businessAddress: null,
          actualBod: null,
          phone: null,
          filingTime: null,
          type: null,
        },
        tProjectContacts: {
          name: null,
          position: null,
          contact: null,
        },
        tProjectChannel: {
          channelName: "",
          channelGroup: "",
        },
        description: null,
        projectContacts: null,
        investHead: this.user.nickName,
        previousFinancing: null,
        financingStage: null,
        financingCondition: null,
        financingMoney: null,
        financingDate: null,
        investSparkle: null,
        investValuation: null,
        investMoney: null,
        investType: null,
        investPloy: null,
        investWorth: null,
        shareholding: null,
        projectStage: null,
        projectState: null,
        mark: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        listFile: null,
        bpFile: null,
        otherFile: null,
      };
      this.resetForm("form");
    },
  },
};
</script>
<style lang="scss" scoped>
.poolAdd {
  h2 {
    margin-left: 30px;
  }
  .special-el-form {
    h3 {
      width: 100%;
      margin-bottom: -10px;
      font-weight: bold;
    }
    .btnList {
      width: 100%;
      display: flex;
      justify-content: center;
      padding-bottom: 40px;
    }
  }
}
.poolDetail {
  position: relative;
  // cursor: not-allowed;
}
.poolDetail ::placeholder {
  color: #f5f7fa !important;
}
// .poolDetail::after {
//   content: "";
//   display: block;
//   position: absolute;
//   top: 0;
//   left: 0;
//   width: 100%;
//   height: 120%;
// }
</style>
