<!-- 我的任务 -->
<template>
  <div class="L-main" id="L-size-main">
    <div class="content-search" id="L-header">
      <div class="search-title">查询条件</div>
      <el-form :inline="true" :model="formInline" size="small" class="demo-form-inline">
        <el-row>
          <el-col :span="7">
            <el-form-item label="任务编号:">
              <el-input v-model="formInline.type" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="任务名称:">
              <el-input v-model="formInline.name" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="任务状态:">
              <el-select v-model="formInline.status" placeholder="请选择">
                <el-option label="item.label" value="item.value">
                </el-option>
                <!-- <el-option
                  v-for="dict in dict.type.bms_approval_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value">
                </el-option> -->
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="3" style="text-align: right;padding-right: 20px;">
            <el-form-item class="unit-form">
              <el-button size="mini" @click="resetQuery('queryFrom')">重置</el-button>
              <el-button size="mini" type="primary" @click="handleQuery('queryFrom')">查询</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <main>
      <div class="search-title">
        <span class="search-title-span">任务列表</span>
      </div>
      <section>
        <el-table v-loading="loading" :data="tableData" :height="tabHeader" :max-height="tabHeader" border>
          <el-table-column type="index" width="50" label="序号" align="center"/>
          <el-table-column label="任务编号" key="number" width="200px" prop="number" align="center" />
          <el-table-column label="任务名称" key="name" prop="name" align="center" />
          <el-table-column label="任务下发时间" key="type" prop="type" align="center">
            <!-- <template slot-scope="scope">
              <dict-tag :options="dict.type.project_middle_type" :value="scope.row.projectMiddleType"/>
            </template> -->
          </el-table-column>
          <el-table-column label="任务期限" key="unit" prop="unit" align="center" />
          <el-table-column label="任务状态" key="status" width="200px" prop="status" class-name="table-status" align="center">
            <template slot-scope="scope">
              <span  v-if="scope.row.status === 0" style="color: #F59A23;">
                待审核
              </span>
              <span v-if="scope.row.status === 1" style="color: #F43147;">
                审核驳回
              </span>
              <span v-if="scope.row.status === 2" style="color: #a4c86c;">
                已完成
              </span>
            </template>
          </el-table-column>
          <el-table-column label="操作" prop="userId" class-name="table-operation" align="center">
            <template slot-scope="scope">
              <span class="del-info" v-if="scope.row.status == 2" @click="goInfo(scope.row,3)" style="color: #192A92;margin-right: 15px;cursor: pointer;">查看</span>
              <span class="del-info" v-if="scope.row.status == 0" @click="goInfo(scope.row,1)" style="color: #192A92;margin-right: 15px;cursor: pointer;">开始核查</span>
              <span class="del-info" v-if="scope.row.status == 1" @click="goInfo(scope.row,2)" style="color: #192A92;margin-right: 15px;cursor: pointer;">重新核查</span>
            </template>
          </el-table-column>
        </el-table>
      </section>
      <my-pagination 
        id="L-pagination"
        :total="total"
        :page="pagination.current"
        :limit="pagination.size"
        @pagination="getPagination"
        :current-page.sync="pagination.current" 
      ></my-pagination>
    </main>
  </div>
</template>
<script>
import myPagination from "@/views/components/Pagination/index.vue"
// import myDialog from "@/views/components/myDialog/index.vue"
export default {
  // dicts: ['jjh_project_type', 'bms_approval_status', "project_middle_type", "project_small_type", "project_categories"],
  components:{myPagination},
  data() {
    return {
      formInline:{
        name:"",
        type:"",
        time:[],
        number:"",
        status:"",
      },
      total:0,
      pagination:{
        current:1,
        size:10,
      },
      tableData:[
        {
          number:20230001,
          name:"XXX任务",
          type:"2023-07-30 16:30:21",
          unit:"2023-07-30",
          status:0,
        },{
          number:20230001,
          name:"XXX任务",
          type:"2023-07-30 16:30:21",
          unit:"2023-07-30",
          status:1,
        },{
          number:20230001,
          name:"XXX任务",
          type:"2023-07-30 16:30:21",
          unit:"2023-07-30",
          status:2,
        }
      ],
      loading:false,
      tabHeader: undefined,
    }
  },
  mounted(){
    this.getInfo();
    this.cancalDebounce();
    window.addEventListener('resize', this.cancalDebounce);
  },
  destroyed() {
    window.removeEventListener('resize', this.cancalDebounce);
  },
  methods:{
    // 获取列表
    getInfo(){
      // this.loading = true;
      // jProject(this.pagination).then(res=>{
      //   this.loading = false;
      //   this.total = res.data.total;
      //   this.tableData = res.data.records;
      // })
    },
    // 重置
    resetQuery(){
      this.formInline = {
        name:"",
        type:"",
        time:[],
        number:"",
        status:"",
      }
      this.pagination = {
        current: 1,
        size: 10,
      }
      this.getList();
    },
    // 查询
    handleQuery(){
      this.pagination = {
        current: 1,
        size: 10
      }
      if(this.formInline.time.length > 0) {
        this.formInline.startTime = this.formInline.time[0]
        this.formInline.endTime = this.formInline.time[1]
      }
      this.pagination = { ...this.pagination,...this.formInline };
      this.getList();
    },
    // 页码获取
    getPagination(pages){
      this.pagination.current = pages.page;
      this.pagination.size = pages.limit;
      this.getList();
    },
    // 导入
    handleImport(){},
    // 导出
    handleExport(){},
    // 新增资产
    handleAdd(){

    },
    // 查看详情
    goInfo(row,id){
      if(id == 1) {
        this.$router.push({name: 'mytaskAudit',query: {
          pageType: "info",
        }})
      } else if(id == 2) {
        this.$router.push({name: 'mytaskAudit',query: {
          pageType: "info",
        }})
      } else if(id == 3) {
        this.$router.push({name: 'mytaskInfo',query: {
          pageType: "info",
        }})
      }
    },
    // 编辑
    edit(){
    },
    // 屏幕尺寸变化
    cancalDebounce(){
      const element = document.getElementById('L-size-main'); // 通过元素的 ID 获取元素
      const header = document.getElementById('L-header'); // 通过元素的 ID 获取元素
      const pagination = document.getElementById('L-pagination'); // 通过元素的 ID 获取元素
      const elementHeight = element.offsetHeight;
      const headerHeight = header.offsetHeight;
      const paginationtHeight = pagination.offsetHeight;
      this.tabHeader = elementHeight - headerHeight - paginationtHeight - 100;
    }
  },
}
</script>