<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="客户编号" prop="customerCode">
        <el-input
          v-model="queryParams.customerCode"
          placeholder="请输入客户编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户名称" prop="customerName">
        <el-input
          v-model="queryParams.customerName"
          placeholder="请输入客户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <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="myTaskList"
        >
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column
            label="客户编号"
            align="center"
            prop="customerCode"
          />
          <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="流程实例定义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="taskDefinitionKey"
          /> -->
          <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
              >
              <!-- 
                v-hasPermi="['system:file:edit']" -->
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleRevocation(scope.row)"
                >撤回</el-button
              >
              <!-- 
                v-hasPermi="['system:file:revocation']" -->
              <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 type="selection" width="55" align="center" />
          <el-table-column
            label="客户编号"
            align="center"
            prop="customerCode"
          />
          <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
              >
              <!-- 
                v-hasPermi="['system:file:edit']" -->
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleRevocation(scope.row)"
                >撤回</el-button
              >
              <!-- 
                v-hasPermi="['system:file:revocation']" -->
              <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-tabs>
  </div>
</template>

<script>
// import { listFile1,listFile2, getFile, delFile, updateFile } from "@/api/system/file";

export default {
  name: "myTaskIndex",
  data() {
    return {
      // 查询表单参数
      form: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        customerCode: null,
        customerName: null,
      },
      // 总条数
      total: 0,
      // tab首选项
      activeName: "1",
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // DGT请假流程审批表格数据
      myTaskList: [],
      myList: [],
    };
  },
  created() {
    // this.getList();
  },
  methods: {
    // tab获取列表
    getList() {
      if (this.activeName === "1") {
        this.getList1();
      } else if (this.activeName === "2") {
        this.getList2();
      }
    },
    /** 查询我的代办任务列表 */
    getList1() {
      this.loading = true;
      listFile(this.queryParams).then((response) => {
        this.myTaskList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询我的单据列表 */
    getList2() {
      this.loading = true;
      listFile(this.queryParams).then((response) => {
        this.myList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //切换tab
    handleClick(tab) {
      this.queryParams.pageNum = 1;
      this.activeName = tab.name;
      this.getList();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id || this.ids;
      // getFile(id).then((response) => {
      //   this.form = response.data;
      // });
    },
    // 处理
    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>
