<template>
  <div class="detailWrapper">
    <section class="section1 public-flex">
      <div class="public-margin-r-20">
        <h4>
          投资项目
          <span class="alreadyStop" v-if="detailInfo.delFlag === '1'"
            >已终止</span
          >
        </h4>
        <p class="projectNameTit">{{ detailInfo.projectName }}</p>
      </div>
    </section>
    <el-divider></el-divider>
    <section>
      <!-- :space="200" -->
      <el-divider></el-divider>
      <div
        class="public-flex-between basicsInfo"
        v-if="detailInfo.projectState != '1'"
      >
        <div class="public-flex-center-column">
          <div>项目公司名称</div>
          <p
            style="width: 250px; text-align: center"
            class="yichu1"
            v-if="
              detailInfo.tProjectCompany &&
              detailInfo.tProjectCompany.companyName
            "
          >
            {{ detailInfo.tProjectCompany.companyName }}
          </p>
        </div>
        <div class="public-flex-center-column">
          <div>渠道</div>
          <p
            v-if="
              detailInfo.tProjectChannel &&
              detailInfo.tProjectChannel.channelName
            "
          >
            {{ detailInfo.tProjectChannel.channelName }}
          </p>
          <p v-else-if="scope.row.channel=='1'" >
            直接触达
          </p>
          <p v-else="scope.row.channel=='2'" >
            内部推荐
          </p>
        </div>
        <div class="public-flex-center-column">
          <div>项目负责人</div>
          <p>{{ detailInfo.investHead }}</p>
        </div>
        <div class="public-flex-center-column" v-if="detailInfo.projectDate">
          <div>立项通过日期</div>
          <p>{{ detailInfo.projectDate }}</p>
        </div>
        <div class="public-flex-center-column" v-if="detailInfo.decisionDate">
          <div>投决通过日期</div>
          <p>{{ detailInfo.decisionDate }}</p>
        </div>
        <div class="public-flex-center-column">
          <div>投前估值（万元）</div>
          <p>{{ detailInfo.investValuation }}</p>
        </div>
        <div class="public-flex-center-column">
          <div>预计投资金额（万元）</div>
          <p>{{ detailInfo.investMoney }}</p>
        </div>
      </div>
    </section>
    <section class="section3">
      <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
        <el-tab-pane label="投决信息" name="0"></el-tab-pane>
        <el-tab-pane label="项目基本信息" name="1"></el-tab-pane>
      </el-tabs>
      <section>
        <div v-if="activeName === '0'" class="public-padded-20 detail-meeting">
          <el-tabs type="border-card" style="border: 1px solid #DCDFE6;">
            <el-tab-pane label="项目投决申请表">
              <el-form
                v-if="formTJApply.id"
                class="special-el-form public-padded-t-20"
                ref="formTJApply"
                :model="formTJApply"
                :rules="rulesTJApply"
                label-width="120px"
              >
                <el-form-item
                  label="股权/其他合作商务条款"
                  prop="provision"
                  class="special-el-form-item"
                >
                  <el-input
                    rows="4"
                    type="textarea"
                    maxlength="200"
                    v-model="formTJApply.provision"
                  />
                </el-form-item>
                <el-form-item
                  label="投决资料"
                  prop="listFile"
                  class="special-el-form-item"
                >
                  <fileItem
                    ref="fileItemTJApply"
                    :id="formTJApply.id"
                    @getFileList="getFileListTJApply"
                  ></fileItem>
                </el-form-item>
                <el-form-item label="其他附件" prop="otherFile" class="special-el-form-item">
                  <fileItem ref="otherFileItem" :id="formTJApply.id" @getFileList="getOtherFileListTJApply"></fileItem>
                </el-form-item>
<!--                <el-form-item
                  label="通知名单"
                  prop="participants"
                  class="special-el-form-item"
                >
                  <el-input
                    rows="4"
                    type="textarea"
                    v-model="formTJApply.participants"
                    disabled
                  />
                </el-form-item>-->
              </el-form>
              <div
                v-else
                class="public-flex-center public-padded-20"
                style="color: #909399"
              >
                暂无数据
              </div>
            </el-tab-pane>
<!--            <el-tab-pane label="项目投决评估评审汇总表">
              <tableForm
                :formType="4"
                ref="voteTableForm"
                :readonly="true"
                :showBack="false"
              ></tableForm>
            </el-tab-pane>-->
          </el-tabs>
        </div>
        <div v-show="activeName === '1'">
          <poolForm :type="type" :id="id"></poolForm>
        </div>
      </section>
    </section>
    <section class="approveBtn">
      <el-form
        ref="flowBaseInfo"
        :model="flowBaseInfo"
        :rules="rulesFlow"
        label-width="120px"
      >
        <el-form-item class="btnList">
          <el-button @click="goBack">返 回</el-button>
          <el-button type="primary" @click="handleComplete(true)">提交</el-button>
          <el-button type="warning" @click="handleComplete(false)">关闭</el-button>
        </el-form-item>
      </el-form>
    </section>
  </div>
</template>
<script>
import poolForm from "../../invest/components/poolForm";
import fileItem from "../../invest/components/fileItem";

import {
  getPool
} from "@/api/invest/pool";
import {
  listMeeting,
  listProjectPoolIdNewDecision,
} from "@/api/invest/meeting";
import{
  decisionComplete
} from "@/api/project/decision/pool"

import { mapGetters } from "vuex";

export default {
  name: "investPoolDetail",
  components: {
    poolForm,
    fileItem,
  },
  data() {
    const validateLogo = (rule, value, callback) => {
      if (this.fileListTJApply.length <= 0) {
        callback(new Error("请上传文件"));
      } else {
        callback();
      }
    };
    return {
      showDueApply: false,
      meetingId: "0",
      type: "2",
      id: "",
      active: 0,
      detailInfo: {
        projectName: "",
      },
      activeName: "0",
      formTJApply: {
        id: null,
        projectPoolId: null,
        projectName: null,
        provision: null,
        listFile: null,
        participants: null,
        participantsId: null,
        flag:null,
        otherFile:null,
      },
      fileListTJApply: [],
      otherFileListTJApply: [],
      rulesTJApply: {
        provision: [{ required: true, trigger: "blur", message: "请输入" }],
        listFile: [{ required: true, validator: validateLogo }],
      },
      flowBaseInfo:{
        comment:null,
        taskId:null
      },
      rulesFlow:{
        comment: [{ required: true, trigger: "blur", message: "请输入" }],
      }
    };
  },
  computed: {
    ...mapGetters(["user"]),
  },
  created() {
    this.id = this.$route.query.id;
    this.flowBaseInfo.taskId=this.$route.query.taskId;
    this.getlistProjectPoolIdNewDecision();
    this.getDetail();
    if (this.$route.query.activeName) {
      this.activeName = this.$route.query.activeName;
    }
  },
  methods: {

    getMettingId(type) {
      let queryParams = {
        pageNum: 1,
        pageSize: 10,
        meetingType: type,
        orderByColumn: "createTime",
        isAsc: "desc",
        projectPoolId: this.id,
      };
      listMeeting(queryParams).then((response) => {
        let meetingList = response.rows;
        if (meetingList.length > 0) {
          let meetingId = meetingList[0].id;
          if (type === "LX") {
            this.$refs.approvalTableForm.initialize(meetingId);
          } else if (type === "TJ") {
            this.$refs.voteTableForm.initialize(meetingId);
          }
        } else {
          if (type === "LX") {
            this.$refs.approvalTableForm.showNodata();
          } else if (type === "TJ") {
            this.$refs.voteTableForm.showNodata();
          }
        }
      });
    },
    handleClick(tab, event) {
      let that = this;
      if (this.activeName === "0") {
        // 项目投决
        this.getMettingId("TJ");
        this.getlistProjectPoolIdNewDecision();
      } else if (this.activeName === "1") {
        // 项目报备
        this.getDetail();
      }
    },

    // 获取投决申请
    getlistProjectPoolIdNewDecision() {
      let that = this;
      listProjectPoolIdNewDecision(this.id).then((response) => {
        if (response && response.data) {
          that.formTJApply = response.data;
          setTimeout(() => {
            //that.$refs.fileItemTJApply.handleButton();
            // that.$refs.fileItemTJApply.fileList = [];
            // that.$refs.fileItemTJApply.getListFileBusinessId(
            //   that.formTJApply.id
            // );
            //项目投决附件
            //this.$refs.fileItemTJApply.handleButton();
            this.$refs.fileItemTJApply.fileList = [];
            this.$refs.fileItemTJApply.getListFileBusinessId(that.formTJApply.id,"11");
            //其他附件
            //this.$refs.otherFileItem.handleButton();
            this.$refs.otherFileItem.fileList = [];
            this.$refs.otherFileItem.getListFileBusinessId(that.formTJApply.id, "0");
          }, 300);
        }
      });
    },
    // 投决申请附件回显
    getFileListTJApply(fileList) {
      this.fileListTJApply = fileList;
      if (fileList && fileList.length > 0) {
        this.$refs.formTJApply.clearValidate(["listFile"]);
      } else {
        this.fileListTJApply = [];
      }
    },
    //投决其他附件
    getOtherFileListTJApply(fileList) {
      if (fileList && fileList.length > 0) {
        this.otherFileListTJApply = fileList;
        this.$refs.formTJApply.clearValidate(["otherFile"]);
      } else {
        this.otherFileListTJApply = [];
      }
    },
    //项目报备
    getDetail() {
      getPool(this.id).then((response) => {
        this.detailInfo = response.data;
        // 项目退出完成n
        if (response.data.projectState === "n") {
          this.active = parseInt(response.data.projectStage);
        } else {
          this.active = parseInt(response.data.projectStage) - 1;
        }
      });
    },
    /** 加载审批任务弹框 */
    handleComplete(flag) {
      this.taskComplete(flag);
    },
    /** 用户审批任务 */
    taskComplete(flag) {
      this.formTJApply.flag=flag;
      this.formTJApply.listFile = this.fileListTJApply;
      this.formTJApply.otherFile = this.otherFileListTJApply;
      const params={
        projectDecision:this.formTJApply,
        flowBaseInfo: this.flowBaseInfo
      }
      this.$refs["formTJApply"].validate((valid) => {
        if (valid) {
          try{
            decisionComplete(params).then(response => {
              this.$modal.msgSuccess(response.msg);
              this.$store.dispatch("getMyTaskDecisionNumber"); //更新代办数量
              this.goMyTask();
            });
          } catch (err) {
            // 捕获重复提交错误
            this.$message.error(err.message);
          }
        }
      })
    },
    /*返回*/
    goBack() {
      this.$router.go(-1);
    },
    //跳转到我的任务
    goMyTask(){
      //this.$router.push({ path: "/myTask/project/decision/myTask"});
      // 关闭当前标签页并返回指定页面
      const obj = { path: "/myTask/project/decision/myTask", query: { t: Date.now()} };
      this.$tab.closeOpenPage(obj);
    },
  },
};
</script>
<style lang="scss" scoped>
.detailWrapper {
  padding: 20px 0;
  width: 92%;
  margin: 0 auto;
  .section1 {
    p {
      font-size: 24px;
      font-weight: bold;
      margin: 0;
    }
    > div:first-child {
      // width: calc(100% - 700px);
      width: 100%;
    }
    .btnList {
      width: 700px;
      display: flex;
      justify-content: flex-end;
    }
  }
  .basicsInfo {
    font-size: 14px;
    background: #f1f1f1;
    margin-top: -24px;
    width: 100%;
    padding: 30px 20px 10px;
    div {
      color: #7e7d7d;
    }
    p {
      font-size: 16px;
      color: #333;
      font-weight: bold;
    }
  }
  .section3 {
    margin-top: 40px;
  }
  .approveBtn {
    margin-top: 30px;
    .btnList {
      display: flex;
      justify-content: flex-end;
      /* 让内部元素（按钮）整体靠右 */
      gap: 10px; /* 替代 margin，给按钮之间加间距，可选 */
      padding-right: 50px;
    }
  }
}
.projectNameTit {
}
.alreadyStop {
  font-weight: normal;
  font-size: 12px;
  background: #ff0000;
  color: #fff;
  border-radius: 5px;
  padding: 5px 10px;
  margin-left: 10px;
}

</style>
