<template>
  <div class="mod-monitor">
    <el-form
      :inline="true"
      :model="dataForm"
      @keyup.enter.native="getDataList()"
    >
      <el-form-item label="任务标题">
        <el-input
          v-model="dataForm.monitorTitle"
          placeholder="任务标题"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="任务完成状态">
        <el-select
          v-model="dataForm.monitorState"
          placeholder="请选择任务完成状态"
        >
          <el-option label="请选择" value=""></el-option>
          <el-option label="未完成" value="0"></el-option>
          <el-option label="已完成" value="1"></el-option>
          <el-option label="超时" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button v-if="isAuth('project:monitor:add')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
        <!-- <el-button
          v-if="isAuth('project:monitor:batch')"
          type="danger"
          @click="deleteHandle()"
          :disabled="dataListSelections.length <= 0"
          >批量删除</el-button
        > -->
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%"
    >
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50"
      >
      </el-table-column>
      <!-- <el-table-column
        prop="monitorId"
        header-align="center"
        align="center"
        width="80"
        label="ID">
      </el-table-column> -->
      <el-table-column
        prop="monitorTitle"
        header-align="center"
        width="180"
        align="center"
        label="任务标题"
      >
      </el-table-column>
      <!-- <el-table-column
        prop="monitorTask"
        header-align="center"
        align="center"
        width="180"
        label="监督任务"
      >
      </el-table-column> -->
      <el-table-column
        prop="monitorState"
        header-align="center"
        align="center"
        label="任务状态"
      >
       <template slot-scope="scope">
          <el-tag v-if="scope.row.monitorState === '0'" size="small">未完成</el-tag>
          <el-tag v-else-if="scope.row.monitorState === '1'" size="small">已完成</el-tag>
          <el-tag v-else size="small" type="danger">超时</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="deptName"
        header-align="center"
        align="center"
        width="180"
        label="下发部门"
      >
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        width="180"
        label="创建时间"
      >
      </el-table-column>
      <el-table-column
        prop="finishTime"
        header-align="center"
        align="center"
        width="180"
        label="完成时间"
      >
      </el-table-column>
      <el-table-column
        prop="finishStaffName"
        header-align="center"
        align="center"
        width="100"
        label="完成任务人"
      >
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        width="150"
        label="操作"
      >
        <template slot-scope="scope">
          <el-button
            v-if="isAuth('project:monitor:detail')"
            type="text"
            size="small"
            @click="lookMonitor(scope.row.monitorId)"
            >查看详情</el-button
          >
          <el-button
          v-if="isAuth('project:monitor:del')"
            type="text"
            size="small"
            @click="deleteHandle(scope.row.monitorId)"
            >删除</el-button
          >
          <el-button
            v-if="isAuth('project:monitor:feedback')"
            type="text"
            size="small"
            @click="feddBackHandle(scope.row.monitorId)"
            >任务反馈</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dataForm: {
        monitorTitle: "",
        monitorState: "",
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
    };
  },
  components: {},
  activated() {
    this.getDataList();
  },
  methods: {
    // 获取数据列表
    getDataList() {
      this.$http({
        url: this.$http.adornUrl("/project/monitor/list"),
        method: "post",
        data: this.$http.adornData({
          page: this.pageIndex,
          limit: this.pageSize,
          monitorTitle: this.dataForm.monitorTitle,
          monitorState: this.dataForm.monitorState,
        }),
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list;
          this.totalPage = data.page.totalCount;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val;
    },
    // 新增 
    addOrUpdateHandle() {
      this.$router.push({ name: "checkAdd" });
    },
    //查看详情
    lookMonitor(id){
      this.$router.push({ name: "monitorTask", query: { monitorId: id }});
    },
    // 删除
    deleteHandle(id) {},
    feddBackHandle(id){
      this.$router.push({ name: "feedBack" , query: { monitorId: id }});
    }
  },
};
</script>
