<template>
  <div class="app-container">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="未完成" name="1">
        <el-table
          :header-cell-style="{ background: '#f8f8f9' }"
          v-loading="loading"
          :data="myList"
        >
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column
            label="客户名称"
            align="center"
            prop="customerName"
          />
          <el-table-column label="申请人" align="center" prop="userId" />
          <el-table-column label="部门" align="center" prop="deptName" />
          <el-table-column label="员工状态" align="center" prop="staffStatus" />
          <el-table-column label="职位" align="center" prop="postName" />
          <el-table-column label="申请时间" align="center" prop="applyTime" />
          <el-table-column
            label="审批时间"
            align="center"
            prop="taskCreateTiem"
          />
          <!-- <el-table-column
            label="流程实例定义id"
            align="center"
            prop="processDefinitionId"
          /> -->
          <!-- <el-table-column
            label="流程实例id"
            align="center"
            prop="processInstanceId"
          /> -->
          <el-table-column label="当前节点" align="center" prop="taskName" />
          <!-- <el-table-column
            label="当前节点key"
            align="center"
            prop="taskUserId"
          /> -->
          <el-table-column
            label="当前处理人"
            align="center"
            prop="taskUserId"
          />
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleManage(scope.row)"
                >处理</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleRevocation(scope.row)"
                >撤回</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleDetail(scope.row)"
                >详情</el-button
              >

              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList1"
        />
      </el-tab-pane>
      <el-tab-pane label="正在处理" name="2">
        <el-table
          :header-cell-style="{ background: '#f8f8f9' }"
          v-loading="loading"
          :data="myList"
        >
          <el-table-column
            label="客户名称"
            align="center"
            prop="customerName"
          />
          <el-table-column label="申请人" align="center" prop="userId" />
          <el-table-column label="部门" align="center" prop="deptName" />
          <el-table-column label="员工状态" align="center" prop="staffStatus" />
          <el-table-column label="职位" align="center" prop="postName" />
          <el-table-column label="申请时间" align="center" prop="applyTime" />
          <el-table-column
            label="审批时间"
            align="center"
            prop="taskCreateTiem"
          />
          <el-table-column label="状态" align="center" prop="state" />
          <!-- <el-table-column
            label="流程实例定义id"
            align="center"
            prop="processDefinitionId"
          />
          <el-table-column
            label="流程实例id"
            align="center"
            prop="processInstanceId"
          /> -->
          <el-table-column label="当前节点" align="center" prop="taskName" />
          <el-table-column
            label="当前处理人"
            align="center"
            prop="taskUserId"
          />
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleManage(scope.row)"
                >处理</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleRevocation(scope.row)"
                >撤回</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleDetail(scope.row)"
                >详情</el-button
              >

              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList2"
        />
      </el-tab-pane>
      <el-tab-pane label="已完成" name="3">
        <el-table
          :header-cell-style="{ background: '#f8f8f9' }"
          v-loading="loading"
          :data="myEndList"
        >
          <!-- "客户名称","申请人","部门" ,"员工状态","职位","申请时间",
          "结束时间", "结束原因", "操作" -->
          <el-table-column
            label="客户名称"
            align="center"
            prop="customerName"
          />
          <el-table-column label="申请人" align="center" prop="userId" />
          <el-table-column label="部门" align="center" prop="deptName" />
          <el-table-column label="员工状态" align="center" prop="staffStatus" />
          <el-table-column label="职位" align="center" prop="postName" />
          <el-table-column label="申请时间" align="center" prop="applyTime" />
          <el-table-column label="结束时间" align="center" prop="endTime" />
          <el-table-column label="结束原因" align="center" prop="status" />
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleManage(scope.row)"
                >处理</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleRevocation(scope.row)"
                >撤回</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleDetail(scope.row)"
                >详情</el-button
              >

              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList3"
        />
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
// import { listFile1,listFile2,listFile3, getFile, delFile, addFile, updateFile } from "@/api/system/file";
export default {
  name: "myTaskIndex",
  data() {
    return {
      // tab首选项
      activeName: "1",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 总条数
      total: 0,
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // tab不同状态的表格数据
      myTaskList: [],
      myList: [],
      myEndList: [],
    };
  },
  created() {
    // this.getList();
  },
  methods: {
    // tab获取列表
    getList() {
      if (this.activeName === "1") {
        this.getList1();
      } else if (this.activeName === "2") {
        this.getList2();
      } else {
        this.getList3();
      }
    },
    /** 查询未完成列表 */
    getList1() {
      this.loading = true;
      listFile1(this.queryParams).then((response) => {
        this.myTaskList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询正在处理列表 */
    getList2() {
      this.loading = true;
      listFile2(this.queryParams).then((response) => {
        this.myList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询已完成列表 */
    getList3() {
      this.loading = true;
      listFile3(this.queryParams).then((response) => {
        this.myEndList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // tab
    handleClick(tab, event) {
      this.queryParams.pageNum = 1;
      this.activeName = tab.name;
      this.getList();
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
    },
    // 处理
    handleManage(row) {
      const ids = row.id || this.ids;
    },
    // 撤回
    handleRevocation(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm("是否确认撤回该条数据?")
        .then(function () {
          // return delFile(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("撤回成功");
        })
        .catch(() => {});
    },
    // 详情
    handleDetail(row) {
      const ids = row.id || this.ids;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm("是否确认删除该条数据?")
        .then(function () {
          return delFile(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>
