<template>
  <!-- 挖掘任务 -->
  <div class="excavateTask">
    <el-container>
      <el-header style="display: flex;justify-content: space-between;align-items: center;">
        <div>
          <mySearch :SearchFields="searchFiled" @search="search" :searchValue="searchOption"></mySearch>
        </div>
        <div style="display:flex;margin-right:10px">
          <el-button type="primary" size="small" @click="createTask">创建任务</el-button>
        </div>
      </el-header>
      <el-main>
        <el-table :data="tableData" style="width: 100%;" border header-row-class-name="custom-table-header">
          <el-table-column label="#" align="center" width="80px">
            <template slot-scope="scope">
              <div>
                {{ (queryParams.current - 1) * queryParams.size + scope.$index + 1 }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="name" label="任务名称" align="center"></el-table-column>
          <el-table-column prop="taskType" label="任务类型" align="center">
            <template slot-scope="scope">
              <div>
                {{ taskType[scope.row.taskType] }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="createPerson" label="发起人" align="center"></el-table-column>
          <el-table-column prop="handlePerson" label="处理人" align="center"></el-table-column>
          <el-table-column prop="createTime" label="创建时间" align="center"></el-table-column>
          <el-table-column prop="endTime" label="截止时间" align="center"></el-table-column>
          <el-table-column prop="status" label="状态" align="center"></el-table-column>
          <el-table-column label="操作" align="center" width="180px">
            <template slot-scope="scope">
              <div>
                <el-dropdown split-button type="primary" size="small" @command="handleCommand($event, scope.row)"
                  @click="handleTask(scope.row)">
                  <p v-if="scope.row.status == '已完成' || scope.row.handlePerson != userInfo.name">查 看</p>
                  <p v-else>处 理</p>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item command="1">查看审核记录</el-dropdown-item>
                    <el-dropdown-item command="2" style="color: red;text-align: center;">删除</el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </el-main>
      <el-footer>
        <div>
          <el-pagination background layout="total, prev, pager, next, jumper" :current-page.sync="queryParams.current"
            :page-size.sync="queryParams.size" @current-change="handleCurrentChange" :total="queryParams.total">
          </el-pagination>
        </div>
      </el-footer>
    </el-container>

    <createTask ref="createTaskDialog"></createTask>
    <handleTask1 ref="handleTask1Dialog"></handleTask1>
    <!-- <handleTask2 ref="handleTask2Dialog"></handleTask2> -->
    <handleTask2 ref="handleTask2Dialog"></handleTask2>
    <auditRecords ref="auditRecords"></auditRecords>
  </div>
</template>

<script>
import createTask from '../dialog/createTask.vue'
import handleTask1 from '../dialog/handleTask1.vue'
import handleTask2 from '../dialog/handleTask2.vue'
import auditRecords from '../dialog/auditRecords.vue'
export default {
  components: {
    createTask,
    handleTask1,
    handleTask2,
    auditRecords,
  },
  data() {
    return {
      tableData: [
        {
          name: '加热器专利挖掘1',
          taskType: '1',
          createPerson: '朱豪',
          handlePerson: '张三',
          createTime: '2023-9-28 13:52',
          endTime: '2023-9-28 18:02',
          status: '未完成'
        },
        {
          name: '加热器专利挖掘2',
          taskType: '1',
          createPerson: '朱豪',
          handlePerson: '朱豪',
          createTime: '2023-9-28 13:52',
          endTime: '2023-9-28 18:02',
          status: '未完成'
        },
        {
          name: '加热器专利挖掘3',
          taskType: '2',
          createPerson: '张三',
          handlePerson: '朱豪',
          createTime: '2023-9-28 13:52',
          endTime: '2023-9-28 18:02',
          status: '未完成'
        },
        {
          name: '加热器专利挖掘4',
          taskType: '3',
          createPerson: '朱豪',
          handlePerson: '朱豪',
          createTime: '2023-9-28 13:52',
          endTime: '2023-9-28 18:02',
          status: '未完成',
          taskPath: '创新点梳理',
          endTime: '2023-10-10',
        },
        {
          name: '加热器专利挖掘5',
          taskType: '1',
          createPerson: '张三',
          handlePerson: '朱豪',
          createTime: '2023-9-28 13:52',
          endTime: '2023-9-28 18:02',
          status: '已完成'
        },
        {
          name: '加热器专利挖掘6',
          taskType: '1',
          createPerson: '朱豪',
          handlePerson: '张三',
          createTime: '2023-9-28 13:52',
          endTime: '2023-9-28 18:02',
          status: '已完成'
        },
      ],
      taskType: {
        1: '项目审核任务',
        2: '文件分配任务',
        3: '文件审核任务',
      },
      queryParams: {
        current: 1,
        size: 10,
        total: 0,
      },
      searchFiled: [
        {
          label: '任务名称',
          value: 'taskName',
          type: 1,
          placeholder: '请输入任务名称'
        },
        {
          label: '创建人',
          value: 'createPerson',
          type: 1,
          placeholder: '请输入创建人名称'
        },
      ],
      searchOption: {}
    }
  },
  computed: {
    userInfo() {
      return this.$store.state.user.userinfo
    },
  },
  mounted() {
    // this.getList()
  },
  methods: {
    //处理任务 
    handleTask(row) {
      if (row.status == '已完成' || row.handlePerson != this.userInfo.name) {
        if (row.taskType == '1') {
          this.$refs.handleTask1Dialog.open(row,false)
        } else if (row.taskType == '2') {
          this.$refs.handleTask2Dialog.open(row,false)
        }
      } else {
        if (row.taskType == '1') {
          this.$refs.handleTask1Dialog.open(row,true)
        } else if (row.taskType == '2') {
          this.$refs.handleTask2Dialog.open(row,true)
        } else {
          let router = this.$router.resolve({
            path: '/handleExamine',
            query: {
              row: JSON.stringify(row)
            }
          })
          window.open(router.href, '_blank')
        }
      }
    },
    handleCommand(ev, row) {
      switch (ev) {
        case '1'://查看审核记录
          this.$refs.auditRecords.open()
          break;
        case '2'://删除任务

          break;

        default:
          break;
      }
    },
    // 左侧搜索
    search() {

    },
    // 创建任务事件
    createTask() {
      this.$refs.createTaskDialog.open({})
    },
    // 初始化请求数据
    getList() { },
    // 分页
    handleCurrentChange(val) {
      // this.queryParams.current = val
      // this.getList()
    },
  },
}
</script>

<style lang="scss" scoped>
.excavateTask {}
</style>