<template>
  <!-- 项目立项申请 -->
  <div class="projectApplication" v-loading="loading">
    <div class="pAHeader">
      <div class="pAHeader1">项目立项管理</div>
    </div>
    <hr />

    <!-- 搜索框开始 -->
    <div class="selectInp">
      <div class="manageSelects">
        <div class="selectsBlock">
          <div class="selectLabel">项目筛选</div>
          <el-select
            v-model="selectInp.filter"
            @change="getData"
            placeholder="我的项目"
          >
            <el-option label="所有项目" value=""></el-option>
            <el-option
              v-for="item in options.projectFilter"
              :key="item.courseId"
              :label="item.title"
              :value="item.courseId"
            >
            </el-option>
          </el-select>
        </div>

        <div class="selectsBlock">
          <div class="selectLabel">部门</div>
          <el-select
            v-model="selectInp.department"
            @change="getData"
            placeholder="请选择"
          >
            <el-option label="所有部门" value=""></el-option>
            <el-option
              v-for="item in options.department"
              :key="item.classid"
              :label="item.name"
              :value="item.classid"
            >
            </el-option>
          </el-select>
        </div>

        <div class="selectsBlock">
          <div class="selectLabel">分类</div>
          <el-select
            v-model="selectInp.sort"
            @change="getData"
            placeholder="请选择"
          >
            <el-option label="所有分类" value=""></el-option>
            <el-option
              v-for="item in options.sort"
              :key="item.typeid"
              :label="item.name"
              :value="item.typeid"
            >
            </el-option>
          </el-select>
        </div>
        <div class="selectsBlock">
          <div class="selectLabel">负责人</div>
          <el-select
            v-model="selectInp.person"
            @change="getData"
            placeholder="请选择"
          >
            <el-option label="所有负责人" value=""></el-option>
            <el-option
              v-for="(item, index) in options.person"
              :key="index"
              :label="item.pro_leader"
              :value="item.pro_leader"
            >
            </el-option>
          </el-select>
        </div>

        <div class="selectsBlock">
          <div class="selectLabel">状态</div>
          <el-select
            v-model="selectInp.state"
            @change="getData"
            placeholder="请选择"
          >
            <el-option label="所有状态" value="" />
            <el-option
              v-for="(item, index) in classType"
              :key="item.index"
              :label="item.title"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
        <div class="selectsBlock">
          <span class="selectLabel">年份</span>
          <el-select
            v-model="selectInp.year"
            @change="getData"
            placeholder="请选择"
          >
            <el-option label="所有年份" value="" />
            <el-option
              v-for="item in options.year"
              :key="item.time"
              :label="item.time + '年'"
              :value="item.time"
            >
            </el-option>
          </el-select>
        </div>
      </div>
      <div class="ProjectManagementQuery">
        <el-input
          v-model="input"
          placeholder="输入项目名称/负责人/老师"
        ></el-input>
        <el-button type="primary" class="btn" size="mini" @click="getData"
          >查询</el-button
        >
      </div>
      <div
        class="ProjectManagementQuery"
        style="margin-top: 60px"
        v-if="$store.state.userInfo.type == 0"
      >
        <el-button type="primary" class="btn" @click.stop="exportExcel"
          >导出EXCEL</el-button
        >
      </div>
    </div>

    <!-- 搜索框结束 -->
    <!-- 表格开始 -->
    <div>
      <div>
        <el-button style="font-size: 16px;"  v-if="$store.state.userInfo.type == 0 || $store.state.userInfo.type == 3" size="mini" :type="!isPromotion?'primary':''" @click="selectAll">全部</el-button>
        <el-button style="font-size: 16px;" v-if="$store.state.userInfo.type == 0 || $store.state.userInfo.type == 3" size="mini" :type="isPromotion?'primary':''" @click="selectPromotion">2024年立项项目</el-button>
        <span style="font-size: 12px; margin-left: 10px"
          >共 {{ table.total }} 条</span
        >
      </div>

      <el-table
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        stripe
        class="fontSize"
        :header-cell-style="{ background: '#f2f2f2', color: '#000' }"
        @selection-change="handleSelectionChange"
        @cell-click="cellProjectClick"
      >
        <!-- selection-change批量选择功能后续可能用到 -->
        <!-- 
        <el-table-column
          type="selection"
          width="25"
          >

        </el-table-column> -->
        <el-table-column
          prop="ProjectNo"
          label="项目编号"
          align="center"
          min-width="20%"
        >
        </el-table-column>
        <el-table-column
          prop="title"
          label="项目名称"
          align="center"
          min-width="35%"
        >
        </el-table-column>
        <el-table-column
          prop="pro_leader"
          align="center"
          label="项目负责人"
          min-width="15%"
        >
        </el-table-column>

        <el-table-column
          prop="name"
          align="center"
          label="所在部门"
          min-width="20%"
        >
        </el-table-column>
        <el-table-column
          prop="sort"
          align="center"
          label="分类"
          min-width="20%"
        >
        </el-table-column>
        <el-table-column
          prop="fund"
          label="预算(万)"
          align="center"
          min-width="10%"
        >
          <template #default="scope">
            <div>
              {{ scope.row.fund / 10000 }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="createTime"
          align="center"
          label="创建时间"
          min-width="25%"
        >
          <template #default="scope">
            <div>
              {{ scope.row.createTime.split(" ")[0] }}<br />{{
                scope.row.createTime.split(" ")[1]
              }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="phone"
          align="center"
          label="联系电话"
          min-width="20%"
        >
          <template #default="scope">
            <div>
              {{
                scope.row.phone != null || scope.row.phone == ""
                  ? scope.row.phone
                  : "-"
              }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="state"
          label="状态"
          align="center"
          min-width="20%"
        >
          <template #default="scope">
            <div>
              <!-- {{ scope.row.isupload+"-"+scope.row.isReturn }} -->
              <span v-if="scope.row.isReturn != 0">{{
                isReturnType[scope.row.isReturn]
              }}</span>
              <!-- {{scope.row.name + (scope.row.status==0?"":"(已屏蔽)")}} -->
              <!-- {{ (scope.row.isupload==0?"未审核": scope.row.data==1?"正在审核":"已审核")  }} -->
              <span v-else>{{
                classType.find((i) => i.value == scope.row.isupload)["title"]
              }}</span>

              <!-- <span v-if="scope.row.isupload == 0">未审核</span>
              <span v-if="scope.row.isupload == 1">审核中</span>
              <span v-if="scope.row.isupload == 2">进行中</span>
              <span v-if="scope.row.isupload == 3">待结项</span>
              <span v-if="scope.row.isupload == 4">已结项</span> -->
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="operation"
          width="370"
          align="center"
          label="操作"
        >
          <template #default="scope">
            <div class="operations">
              <!-- {{ scope.row.isupload }} -->
              <el-button
                type="primary"
                size="mini"
                @click.stop="lookDetail(scope.row.courseId, scope.row.typeid)"
                class="btnClass"
                >查看详情</el-button
              >

              <el-button
                type="primary"
                v-if="scope.row.isupload == 0"
                @click.stop="audit(scope.row, 0)"
                class="btnClass"
                >提交</el-button
              >
              <!--0申请人审核 -->
              <el-button
                type="primary"
                v-if="scope.row.isupload == 1"
                class="disa btnClass"
                >已提交</el-button
              >
              <el-button
                type="primary"
                v-if="
                  [5, 6, 7].includes(scope.row.isupload) &&
                  ![0, 3].includes($store.state.userInfo.type)
                "
                class="disa btnClass"
                size="mini"
                >审核中</el-button
              >
              <el-button
                type="primary"
                v-if="
                  scope.row.isupload == 2 &&
                  ![0, 3].includes($store.state.userInfo.type)
                "
                class="disa btnClass"
                size="mini"
                >待结项</el-button
              >
              <el-button
                type="primary"
                v-if="
                  scope.row.isupload == 3 &&
                  ![0, 3].includes($store.state.userInfo.type)
                "
                class="disa btnClass"
                size="mini"
                >结项中</el-button
              >
              <el-button
                type="primary"
                v-if="
                  scope.row.isupload == 4 &&
                  ![0, 3].includes($store.state.userInfo.type)
                "
                class="disa btnClass"
                size="mini"
                >已结项</el-button
              >

              <!--1管理员审核与院长 -->
              <el-button
                type="primary"
                v-if="
                  scope.row.isupload > 1 &&
                  [0, 3].includes($store.state.userInfo.type)
                "
                class="disa btnClass"
                >已提交</el-button
              >
              <el-button
                v-if="
                  scope.row.isupload == 0 &&
                  [0, 3].includes($store.state.userInfo.type)
                "
                type="primary"
                class="disa btnClass"
                size="mini"
                >审核</el-button
              >

              <el-button
                v-if="
                  scope.row.isupload == 1 &&
                  [0, 3].includes($store.state.userInfo.type)
                "
                type="primary"
                size="mini"
                class="btnClass"
                @click.stop="audit(scope.row, 1)"
                >审核</el-button
              >

              <el-button
                v-if="
                  [3, 5, 6, 7].includes(scope.row.isupload) &&
                  [0, 3].includes($store.state.userInfo.type)
                "
                type="primary"
                class="disa btnClass"
                size="mini"
                >审核中</el-button
              >
              <el-button
                v-if="
                  scope.row.isupload == 2 &&
                  [0, 3].includes($store.state.userInfo.type)
                "
                type="primary"
                class="disa btnClass"
                size="mini"
                >待结项</el-button
              >
              <el-button
                v-if="
                  [4].includes(scope.row.isupload) &&
                  [0, 3].includes($store.state.userInfo.type)
                "
                type="primary"
                class="disa btnClass"
                size="mini"
                >已结项</el-button
              >

              <!-- <el-button type="primary"  size="mini" @click="appTable(scope.row.typeid,scope.row.courseId)" >申请表</el-button> -->

              <el-button
                type="primary"
                class="btnClass"
                size="mini"
                @click.stop="del(scope.row)"
                >删除</el-button
              >
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 表格结束 -->
    <!-- 分页 -->
    <el-pagination
      @current-change="handleCurrentChange"
      :current-page="table.currentPage"
      :page-size="table.packageSize"
      layout=" prev, pager, next"
      background
      class="paginations"
      :total="table.total"
    >
    </el-pagination>
    <!-- 分页结束 -->

    <!-- 立项审核对话框开始 -->
    <el-dialog
      title="立项审核"
      :visible.sync="dialogVisible"
      class="pageSubmitData"
      width="700px"
      :before-close="init"
    >
      <div class="diaTit">
        <div class="spans">项目名称：</div>
        <div class="spanCon">{{ auditDialog.projectName }}</div>
        <div class="spans">项目负责人：</div>
        <div class="spanCon">{{ auditDialog.person }}</div>
      </div>

      <div class="diaTit1">
        <div class="spans1">所在部门</div>
        <div class="inp">
          <el-input
            disabled
            v-model="auditDialog.department"
            placeholder="所在部门"
          ></el-input>
        </div>
      </div>

      <div class="diaTit1">
        <div class="spans1">预算总经费</div>
        <div class="inp">
          <el-input
            disabled
            v-model="auditDialog.fund"
            placeholder="预算总经费"
          ></el-input>
        </div>
      </div>

      <div class="diaTit1">
        <div class="spans1">联系电话</div>
        <div class="inp">
          <el-input
            disabled
            v-model="auditDialog.tel"
            placeholder="联系电话"
          ></el-input>
        </div>
      </div>
      <!-- <div class="diaTit1" v-if="isManager == 1">
        <div class="spans1" style="position: relative; top: -24px">
          驳回意见
        </div>
        <div class="inp">
          <el-input
            type="textarea"
            :rows="5"
            resize="none"
            placeholder="请输入修改建议等..."
            v-model="rejectApplyText"
          >
          </el-input>
        </div>
      </div> -->
      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          v-if="isManager == 0"
          @click="ApplyPersonCommit"
          class="AllDialogBtn"
          >确定</el-button
        >

        <el-button
          type="primary"
          v-if="isManager == 1"
          @click="ManagerCommit"
          class="AllDialogBtn"
          >立项通过</el-button
        >

        <el-tooltip
          v-if="isManager == 1"
          effect="light"
          content="(直接进入学校终审状态)"
          placement="top"
        >
          <el-button
            type="primary"
            @click="ManagerCommit2"
            class="AllDialogBtn"
          >
            二次审核通过
          </el-button>
        </el-tooltip>

        <el-button
          type="primary"
          v-if="isManager == 1"
          @click="rejectApply"
          class="AllDialogBtn"
          >撤回</el-button
        >
        <el-button @click="init" class="AllDialogBtn">取消</el-button>
      </div>
    </el-dialog>
    <!-- 立项审核对话框结束 -->

    <!-- 删除通知开始 -->
    <el-dialog
      title="删除项目"
      :visible.sync="dialogVisible2"
      width="600px"
      class="pageSubmitData"
    >
      <div class="deleteContent">确定删除项目?</div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogDel" class="AllDialogBtn"
          >确认</el-button
        >
        <el-button @click="init" class="AllDialogBtn">取消</el-button>
      </span>
    </el-dialog>
    <!-- 删除通知结束-->
  </div>
</template>

<script>
// import XLSX from "xlsx";
// import {MakerSpaceWord,MakerStudentWord,getWord} from '@/components/tool/getWord.js'
// import MakerSpaceWordPreview from '@/components/MakerSpaceWordPreview.vue';
// import studentMakerProjectPreview from '@/components/studentMakerProjectPreview.vue'
export default {
  // components:{MakerSpaceWordPreview,studentMakerProjectPreview},
  data() {
    return {
      isPromotion: '',
      iid: "",
      loading: false,
      textarea: "",
      input: "",
      dialogVisible: false, //立项审核
      dialogVisible1: false, //立项撤回提交
      dialogVisible2: false, //删除
      WordPreview: false, //文档预览
      downloadWord: false, //申请表下载
      PreviewTid: "", //预览分类ID
      PreviewData: "", //预览数据
      rejectApplyText: "", //撤回-修改建议
      isManager: 0, //0申请人审核科-----  1管理员审核框
      // 分页数据
      table: {
        total: 0,
        packageSize: 7,
        currentPage: 1,
      },
      tableData: [], //列表数据
      classType: [
        { index: 0, value: "0", title: "未提交" },
        { index: 1, value: "1", title: "已提交" },
        { index: 2, value: "5", title: "所在学院/部门审核中" },
        { index: 3, value: "6", title: "双创学院审核中" },
        { index: 4, value: "7", title: "学校终审中" },
        { index: 5, value: "2", title: "待结项" },
        { index: 6, value: "3", title: "提交结项中" },
        { index: 7, value: "4", title: "已结项" },
      ],
      // "0":'未提交',
      // '1':"已提交",
      // '5':'所在学院/部门审核中',
      // '6':'双创学院审核中',
      // '7':'学校终审中',
      // '2':"待结项",
      // '3':"提交结项中",
      // '4':'已结项',
      isReturnType: {
        5: "所在学院/部门审核驳回",
        6: "双创学院审核驳回",
        7: "学校终审驳回",
      },

      selectInp: {
        // 头部搜索框的内容
        filter: "",
        department: "",
        sort: "",
        person: "",
        state: "",
        year: "",
      },
      options: {
        //头部搜索框下拉框数据
        projectFilter: [], //项目筛选
        department: [], //部门
        sort: [], //分类
        person: [], //负责人
        state: [
          //状态
          // {
          //   value: "",
          //   label: "全部",
          // },
          // {
          //   value: 0,
          //   label: "未提交",
          // },
          // {
          //   value: 1,
          //   label: "已提交",
          // },
          // {
          //   value: 2,
          //   label: "进行中",
          // },
          // {
          //   value: 3,
          //   label: "待结项",
          // },
          // {
          //   value: 4,
          //   label: "已结项",
          // },
        ],
        year: [],
      },
      auditDialog: {
        //审核对话框数据
        projectName: "",
        person: "",
        department: "",
        fund: "",
        tel: "",
        // cid:''
      },
    };
  },
  methods: {
    selectAll() {
      console.log("所有");
      this.isPromotion = '';
      this.getData()
    },
    selectPromotion() {
      console.log("晋级");
      this.isPromotion = 1;
      this.getData()
    },

    init() {
      this.dialogVisible = false;
      this.dialogVisible1 = false;
      this.dialogVisible2 = false;
    },
    audit(val, num) {
      //审核按钮
      this.isManager = num;
      this.iid = val; //储存id给对话框
      // if (val.isupload==0) {
      this.dialogVisible = true;
      // console.log(val);
      this.auditDialog.projectName = val.title;
      this.auditDialog.person = val.pro_leader;
      this.auditDialog.department = val.name;
      this.auditDialog.fund = val.fund;
      this.auditDialog.tel = val.phone || "-";
      // this.auditDialog.cid=courseId
      // }
    },
    appTable(tid, pid) {
      //查看申请表
      // console.log();
      if (tid == "5e21b204-c206-11ed-a4cd-509a4c5b67cf") {
        // downloadFile('/file/附件2：2023年学生创客项目申报书模板(2).docx',"2023年学生创客项目申报书模板.docx",(_b)=>this.loading = _b);
        this.ajax
          .get(this.$store.state.api + "/SelectProjectWordMakerStudent", {
            uid: this.$store.state.userInfo.userid,
            pid: pid,
          })
          .then((res) => {
            // console.log(res['data']);
            let data = res["data"];
            this.downloadWord = true;
            // this.downWord(data)
            // this.PreviewData = [res['data'][0][0],res['data'][1]];

            // return console.log(this.PreviewData);
            // this.WordPreview = true;
            // this.PreviewTid = tid;
          })
          .catch((err) => {
            console.log(err);
          });
      } else if (tid == "5f7a66d5-c206-11ed-a4cd-509a4c5b67cf") {
        this.ajax
          .get(this.$store.state.api + "/SelectProjectWordMakerSpace", {
            uid: this.$store.state.userInfo.userid,
            pid: pid,
          })
          .then((res) => {
            this.PreviewData = [res["data"][0][0], res["data"][1]];
            this.WordPreview = true;
            this.PreviewTid = tid;
            // MakerSpaceWord(res['data'][0][0],res['data'][1]);
          })
          .catch((err) => {
            console.log(err);
          });
      } else {
        this.$message.error("错误");
      }
    },
    downWord(data) {
      if (this.PreviewTid == "5f7a66d5-c206-11ed-a4cd-509a4c5b67cf") {
        MakerSpaceWord(this.PreviewData[0], this.PreviewData[1]);
      } else {
        getWord(data[0][0]);
      }
    },
    ManagerCommit() {
      //先判断项目有没有被驳回
      let param = {
        pid: this.iid.courseId,
      };
      // return console.log(param);
      // console.log(param)
      this.ajax.get(this.$store.state.api + "/selectSign", param).then(
        (res) => {
          let isAgree =
            res.data[0].length > 0
              ? Math.max(...res.data[0].map((obj) => obj.isAgree))
              : 1;
          if (isAgree == 2) {
            let text = "项目已被驳回，原因为:";
            for (var i = 0; i < res.data[0].length; i++) {
              if (res.data[0][i].isAgree == 2) {
                text += res.data[0][i].text;
              }
            }
            this.$message.warning(text);
            return;
          } else {
            //立项审核对话框里面的管理员通过按钮
            // console.log(this.iid);
            let param = {
              uid: this.$store.state.userInfo.userid,
              pid: this.iid.courseId,
              num: 5,
            };
            this.ajax
              // .post(this.$store.state.api+"/ApproveProject",param)
              .post(this.$store.state.api + "/updateIsupload", param)
              .then(
                (res) => {
                  // console.log(res);
                  this.dialogVisible = false;
                  this.$message.success("已通过");
                  this.getData();
                },
                (err) => {
                  console.log(err);
                }
              );
          }
        },
        (err) => {
          console.log(err);
        }
      );
    },
    ManagerCommit2() {
      //先判断项目有没有被驳回
      // let param = {
      //   pid: this.iid.courseId,
      // };
      // return console.log(param);
      // console.log(param)
      // this.ajax.get(this.$store.state.api + "/selectSign", param).then(
      //   (res) => {
      //     let isAgree =
      //       res.data[0].length > 0
      //         ? Math.max(...res.data[0].map((obj) => obj.isAgree))
      //         : 1;
      //     if (isAgree == 2) {
      //       let text = "项目已被驳回，原因为:";
      //       for (var i = 0; i < res.data[0].length; i++) {
      //         if (res.data[0][i].isAgree == 2) {
      //           text += res.data[0][i].text;
      //         }
      //       }
      //       this.$message.warning(text);
      //       return;
      //     } else {
      //立项审核对话框里面的管理员通过按钮
      // console.log(this.iid);
      let param = {
        uid: this.$store.state.userInfo.userid,
        pid: this.iid.courseId,
        num: 7,
      };
      this.ajax
        // .post(this.$store.state.api+"/ApproveProject",param)
        .post(this.$store.state.api + "/updateIsupload", param)
        .then(
          (res) => {
            // console.log(res);
            this.dialogVisible = false;
            this.$message.success("已通过");
            this.getData();
          },
          (err) => {
            console.log(err);
          }
        );
      // }
      //   },
      //   (err) => {
      //     console.log(err);
      //   }
      // );
    },
    ApplyPersonCommit() {
      //先判断项目有没有被驳回
      let param = {
        pid: this.iid.courseId,
      };
      // return console.log(param);
      // console.log(param)
      this.ajax.get(this.$store.state.api + "/selectSign", param).then(
        (res) => {
          let isAgree =
            res.data[0].length > 0
              ? Math.max(...res.data[0].map((obj) => obj.isAgree))
              : 1;
          if (isAgree == 2) {
            let text = "项目已被驳回，原因为:";
            for (var i = 0; i < res.data[0].length; i++) {
              if (res.data[0][i].isAgree == 2) {
                text += res.data[0][i].text;
              }
            }
            this.$message.warning(text);
            return;
          } else {
            //申请人审核按钮
            let param = {
              uid: this.$store.state.userInfo.userid,
              pid: this.iid.courseId,
              num: 1,
            };
            this.ajax
              .post(this.$store.state.api + "/updateIsupload", param) //updateIsupload
              .then((res) => {
                this.dialogVisible = false;
                this.$message.success("已提交");
                this.getData();
              });
          }
        },
        (err) => {
          console.log(err);
        }
      );
    },
    rejectApply() {
      //立项审核对话框里面的驳回申请
      let param = {
        uid: this.$store.state.userInfo.userid,
        pid: this.iid.courseId,
        num: 0,
      };
      this.ajax
        .post(this.$store.state.api + "/updateIsupload", param)
        .then((res) => {
          this.dialogVisible = false;
          this.$message.success("已撤回项目申请");
          this.getData();
        });
    },

    commit2(val) {
      //立项撤回对话框里面的确定撤回按钮
      this.dialogVisible1 = false;
      this.status--;
    },

    handleSelectionChange(val) {
      //批量选择功能后续可能用到
      // console.log(val);
      this.multipleSelection = val;
    },
    // 单元格被点击
    cellProjectClick(row, column, cell, event) {
      if (column.property != "operation") {
        this.lookDetail(row.courseId, row.typeid);
      }
    },

    lookDetail(val, tid) {
      this.$router.push(`/projectApplicationDetailMain?tid=${tid}&pid=${val}`);
    },
    // apply(){     //项目立项申请按钮
    //   this.$router.push('/projectApplicationApplyMain')
    // },
    getData() {
      if (this.loading) return;
      //获取表格数据
      this.loading = true;
      let param = {
        uid: this.$store.state.userInfo.userid,
        pid: this.selectInp.filter, //筛选
        did: this.selectInp.department, //部门
        tid: this.selectInp.sort, //分类
        leader: this.selectInp.person, //负责人
        st: this.selectInp.state, //审核状态
        year: this.selectInp.year,
        textInp: encodeURIComponent(this.input),
        promotion: this.isPromotion,
        page: this.table.currentPage, //当前页
        lim: this.table.packageSize, //限制获取几条数据
      };
      // return console.log(param);
      // console.log(param)
      this.tableData = [];
      this.ajax.get(this.$store.state.api + "/SelectAllProject", param).then(
        (res) => {
          let data = res.data;
          console.log(data);
          if (data[0].length == 0 && data[5][0]["total"] != 0) {
            this.table.currentPage = 1;
            this.loading = false;
            return this.getData();
          }
          let a = this.options;
          this.tableData = data[0];
          a.projectFilter = data[1];
          a.department = data[2];
          a.sort = data[3];
          a.person = data[4];
          a.year = data[6];
          if (
            a.year.filter(
              (item) => item["time"] == new Date().getFullYear().toString()
            ).length == 0
          ) {
            a.year.push({ time: new Date().getFullYear().toString() });
          }
          this.table.total = data[5][0].total;
          // this.tableData.forEach(item=>{
          //   if(item['time']!=null&&item['time']!=''){
          //     item['time']=JSON.parse(item['time'])
          //   }else{
          //     item['time'] = []
          //   }
          // })
          this.loading = false;

          // console.log(this.tableData)
        },
        (err) => {
          console.log(err);
        }
      );
    },
    del(val) {
      //表格删除按钮，点击显示删除对话框
      // console.log(val);
      this.dialogVisible2 = true;
      this.iid = val; //将要删除的id进行存储供删除对话框使用
    },
    dialogDel() {
      //确定删除这个项目
      // if (this.iid.userid == this.$store.state.userInfo.userid) {
      let param = {
        uid: this.$store.state.userInfo.userid,
        pid: this.iid.courseId,
      };
      this.ajax.post(this.$store.state.api + "/DeleteProject", param).then(
        (res) => {
          console.log(res);
          if (res.data) {
            this.$message.success("删除成功");
            this.getData();
            this.dialogVisible2 = false;
            return;
          } else {
            this.$message.error("删除失败");
          }
        },
        (err) => {
          console.log(err);
        }
      );
      // }
    },
    handleCurrentChange(val) {
      //当页数发生改变的时候调用获取列表数据请求
      // console.log(`当前页: ${val}`);
      this.table.currentPage = val;
      this.getData();
    },
    // 导出Excel表格
    exportExcel() {
      this.$confirm("是否导出Excel?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      })
        .then(() => {
          this.loading = true;
          let param = {
            uid: this.$store.state.userInfo.userid,
            pid: this.selectInp.filter, //筛选
            did: this.selectInp.department, //部门
            tid: this.selectInp.sort, //分类
            leader: this.selectInp.person, //负责人
            st: this.selectInp.state, //审核状态
            year: this.selectInp.year,
            textInp: encodeURIComponent(this.input),
						promotion: this.isPromotion,
            page: 1, //当前页
            lim: 99999999, //限制获取几条数据
          };
          this.ajax
            .get(this.$store.state.api + "/SelectAllProject", param)
            .then((res) => {
              let _data = res.data[0];
              let _array = [];

              _data.forEach((item, index) => {
                let _json = {};
                let teacher = item.course_teacher
                  ? JSON.parse(item.course_teacher)
                  : [];
                let student = item.course_student
                  ? JSON.parse(item.course_student)
                  : [];
                let money = item.money ? JSON.parse(item.money) : {};
                // _json["项目编号"] = item.ProjectNo;
                _json["项目名称"] = item.title;
                _json["项目负责人"] = item.pro_leader;
                _json["小型仪器设备费"] = money["device"]
                  ? money["device"]
                  : "0";
                _json["材料费"] = money["Material"] ? money["Material"] : "0";
                _json["测试化验加工费"] = money["processing"]
                  ? money["processing"]
                  : "0";
                _json["项目协作费"] = money["Collaboration"]
                  ? money["Collaboration"]
                  : "0";
                _json["项目成果鉴定费"] = money["APPRAISAL"]
                  ? money["APPRAISAL"]
                  : "0";
                _json["参展参赛费"] = money["entery"] ? money["entery"] : "0";
                _json["创客交流活动费"] = money["activities"]
                  ? money["activities"]
                  : "0";
                _json["知识产权事务费"] = money["Transaction"]
                  ? money["Transaction"]
                  : "0";

                // _json["所在部门"] = item.name;
                // _json["分类"] = item.sort;
                // _json["预算（万）"] = item.fund / 10000;
                // _json["创建时间"] = item.createTime;
                // _json["联系电话"] = item.phone;
                // _json["项目状态"] =
                //   item.isReturn == 0
                //     ? this.classType.find((i) => i.value == item.isupload)[
                //         "title"
                //       ]
                //     : this.isReturnType[item.isReturn];
                // for (let i = 0; i < student.length; i++) {
                //   _json["学生成员" + (i + 1)] = student[i].name;
                // 	_json["学生班级" + (i + 1)] = student[i].collage;
                // }
                // for (let i = 0; i < teacher.length; i++) {
                //   _json["指导老师" + (i + 1)] = teacher[i].name;
                // }

                _array.push(_json);
              });

              let XLSX = require("xlsx");
              const workbook = XLSX.utils.book_new(); //创建一个新的工作簿对象
              let ws = XLSX.utils.json_to_sheet(_array); //将json对象数组转化成工作表
              ws["!cols"] = [
                //设置每一列的宽度
                { wch: 50 },
                { wch: 20 },
                { wch: 20 },
                { wch: 20 },
                { wch: 20 },
                { wch: 20 },
                { wch: 20 },
                { wch: 20 },
                { wch: 20 },
                { wch: 20 },
                { wch: 20 },
                { wch: 20 },
                { wch: 20 },
                { wch: 20 },
                { wch: 20 },
                { wch: 20 },
                { wch: 20 },
                { wch: 20 },
                { wch: 10 },
                { wch: 10 },
                { wch: 10 },
                { wch: 10 },
                { wch: 10 },
                { wch: 10 },
                { wch: 10 },
              ];
              XLSX.utils.book_append_sheet(workbook, ws, "sheet1"); //把sheet添加到workbook里，第三个参数是sheet名
              XLSX.writeFile(workbook, "项目列表.xlsx");

              this.loading = false;
              console.log(_data);
            });
        })
        .catch(() => {});
    },
    // getUser() {
    //   var request = new XMLHttpRequest();
    //   request.open("get", "http://10.16.30.130/sso/api", true);
    //   request.setRequestHeader(
    //     "Content-Type",
    //     "application/x-www-form-urlencoded"
    //   );
    //   request.send("");
    //   console.log(request);
    // },
  },
  watch: {
    //监视选择框的变化，实施刷新表格数据
    // options:{
    //   handler(){
    //     immediate:true
    //     deep:true
    //     this.getData()
    //   }
    // }
  },
  mounted() {
    // 默认选择当前年份
    this.selectInp.year = new Date().getFullYear().toString();
    //跳转到此页面立刻获取数据
    // this.getData(); //获取表格数据
    // this.getUser();
    // console.log(this.$store.state.userInfo.type);
  },
  activated() {
    this.getData();
  },
};
</script>

<style lang="less" scoped>
.projectApplication {
  // .el-table::before{
  //   height: 0;
  // }

  .btnClass {
    width: 70px !important;
    max-width: 70px;
    min-width: 70px;
  }
  /deep/.el-table__row {
    .el-table__cell {
      cursor: pointer;
    }
    .el-table__cell:nth-last-child(1) {
      cursor: default;
    }
  }
  .btnCss{
    color: #409EFF;
    border-color: #c6e2ff;
    background-color: #ecf5ff;
  }
}
</style>
