<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="formZZApply.id"
                class="special-el-form public-padded-t-20"
                ref="formZZApply"
                :model="formZZApply"
                label-width="120px"
              >
                <el-form-item
                  label="终止原因"
                  prop="reason"
                  class="special-el-form-item"
                >
                  <el-input
                    rows="4"
                    type="textarea"
                    maxlength="200"
                    v-model="formZZApply.reason"
                    disabled
                  />
                </el-form-item>
              </el-form>
              <div
                v-else
                class="public-flex-center public-padded-20"
                style="color: #909399"
              >
                暂无数据
              </div>
            </el-tab-pane>
          </el-tabs>
        </div>
        <div v-show="activeName === '1'" class="public-padded-20">
          <poolForm :type="type" :id="id"></poolForm>
        </div>
      </section>
    </section>
    <section>
      <flowBase :procInstId="formZZApply.procInstId" :id="id" v-if="formZZApply.procInstId "></flowBase>
    </section>
    <section>
      <el-form
        ref="flowBaseInfo"
        :model="flowBaseInfo"
        label-width="120px"
      >
        <el-form-item label="审批意见" prop="comment">
          <el-input
            maxlength="1000"
            rows="4"
            type="textarea"
            v-model="flowBaseInfo.comment"
            placeholder="请填写审批意见"
          >
          </el-input>
        </el-form-item>
        <el-form-item class="btnList">
          <!--          <div class="btn-group">-->
          <el-button @click="goBack">返 回</el-button>
          <el-button type="success" class="editButton" @click="handleComplete(true)">同意</el-button>
          <el-button type="warning" @click="handleComplete(false)">驳回</el-button>
          <!--          </div>-->
        </el-form-item>
      </el-form>
    </section>
  </div>
</template>
<script>
import poolForm from "../../invest/components/poolForm";
import flowBase from "../flowBase.vue";

import {getPool} from "@/api/invest/pool";
import{
  terminationComplete,
  getTerminationInfo,
} from "@/api/project/termination/pool"

import { mapGetters } from "vuex";

export default {
  name: "decisionAudit",
  props: {
    readonly: {
      type: Boolean,
    },
  },
  dicts: ["meeting_type", "project_stage", "project_group"],
  components: {
    flowBase,
    poolForm,
  },
  data() {
    return {
      type: "2",
      id: "",
      active: 0,
      detailInfo: {
        projectName: "",
      },
      activeName: "0",
      formType:3,
      formZZApply: {
        id: null,
        procInstId:null,
        projectPoolId: null,
        projectName: null,
        reason: null,
        taskDefKey:null,
      },
      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.getDetail();
    this.getlistProjectPoolIdNewTermination();
    if (this.$route.query.activeName) {
      this.activeName = this.$route.query.activeName;
    }
  },
  methods: {

    handleClick(tab, event) {
      let that = this;
      if (this.activeName === "0") {
        // 项目投决
        this.getlistProjectPoolIdNewDecision();
      } else if (this.activeName === "1") {
        // 项目报备
        this.getDetail();
      }
    },

    // 获取投决申请
    getlistProjectPoolIdNewTermination() {
      let that = this;
      getTerminationInfo(this.$route.query.pInstId).then((response) => {
        if (response && response.data) {
          that.formZZApply = response.data;
          /*setTimeout(() => {
            that.$refs.fileItemTJApply.handleButton();
            that.$refs.fileItemTJApply.fileList = [];
            that.$refs.fileItemTJApply.getListFileBusinessId(
              that.formTJApply.id
            );
          }, 300);*/
        }
      });
    },
    //项目报备
    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) {
      if (!flag&&!this.flowBaseInfo.comment) {
        this.$modal.msgError("请输入审批意见!");
        return;
      }
      //会议人
      this.formZZApply.flag=flag;
      const params={
        projectTermination: this.formZZApply,  // 拆分明确字段
        flowBaseInfo: this.flowBaseInfo
      }
      try{
        terminationComplete(params).then(response => {
          this.$modal.msgSuccess(response.msg);
          this.$store.dispatch("getMyTaskTerminationNumber"); //更新代办数量
          this.goMyTask();
        });
      } catch (err) {
        // 捕获重复提交错误
        this.$message.error(err.message);
      }
    },
    /*返回*/
    goBack() {
      this.$router.go(-1);
    },
    //跳转到我的任务
    goMyTask(){
      //this.$router.push({ path: "/myTask/project/termination/myTask"});
      // 关闭当前标签页并返回指定页面
      const obj = { path: "/myTask/project/termination/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 {
    border: 1px solid #DCDFE6;
    margin-top: 40px;
  }
  .btnList {
    display: flex;
    justify-content: flex-end;
    /* 让内部元素（按钮）整体靠右 */
    gap: 10px; /* 替代 margin，给按钮之间加间距，可选 */
  }
}
.projectNameTit {
}
.alreadyStop {
  font-weight: normal;
  font-size: 12px;
  background: #ff0000;
  color: #fff;
  border-radius: 5px;
  padding: 5px 10px;
  margin-left: 10px;
}
/*表格样式开始*/
.ss_scoreTable {
  padding-bottom: 50px;
  ::v-deep .el-input.is-disabled .el-input__inner {
    background-color: #fff !important;
    color: #606266;
  }
  ::v-deep .el-input__inner {
    border: 1px solid transparent;
    text-align: center;
  }
  ::v-deep.el-textarea__inner {
    border: none;
    height: 50px;
    resize: none;
  }
  ::v-deep .el-textarea.is-disabled .el-textarea__inner {
    background-color: #fff !important;
  }
  textarea:disabled,
  input:disabled {
    background-color: #fff !important;
  }
  // ::v-deep .el-textarea__inner {
  //   // border: 1px solid transparent!important;
  // }
  table {
    // width:80%;
    // width: 600px;
    margin: 0 30px;
    -moz-user-select: none;
    -webkit-user-select: none;
    -ms-user-select: none;
    -khtml-user-selece: none;
    /*上面都是兼容性问题，具体看浏览器版本或什么浏览器*/
    user-select: none; /*内容禁止选中*/
  }
  tbody td {
    font-size: 14px;
  }
  thead th,
  .big-font {
    font-size: 16px !important;
    font-weight: bold;
  }
  .public-pedded-0 {
    padding: 0;
  }
  .text-center {
    text-align: center;
  }
  .text-left {
    text-align: left;
  }
  .table-textarea {
    width: 100%;
    // width: 180px;
    border: none;
    height: 50px;
    resize: none;
  }
  .table-input {
    width: 100%;
    // width: 100%;
    // height: 80px;
    border: none;
    font-size: 20px;
    font-weight: bold;
    text-align: center;
    margin-top: 20px;
  }
  .bg-blue,
  .specificTr > th:nth-child(2n-1) {
    background-color: #9bc2e6;
  }
  .specificTr > th:nth-child(2n-1) {
    white-space: nowrap;
    padding: 0 15px;
  }
  .specificTr .table-textarea {
    padding-top: 16px;
    background-color: #fff;
  }
  tr > th {
    height: 50px;
  }
  input:disabled {
    // background-color: #fff !important;
  }
  .btnList {
    width: 100%;
    display: flex;
    justify-content: center;
    padding-bottom: 40px;
    margin-top: 30px;
  }
}
</style>
