<template>
  <div class="L-task-info">
    <el-row>
      <el-col :span="20">
        <div class="info-left" id="L-size-main">
          <div class="content-info" id="L-header">
            <div class="info-title">任务详情</div>
            <div class="top-info">
              <el-row class="top-row">
                <el-col :span="8">
                  任务编号：<span>20240101001</span>
                </el-col>
                <el-col :span="8">
                  任务名称：<span>XXXXX资产核查任务</span>
                </el-col>
                <el-col :span="8">
                  任务状态：<span>待审核</span>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="8">
                  任务期限：<span>2024-11-11 09:00:00</span>
                </el-col>
                <el-col :span="8">
                  任务下发时间：<span>2024-11-11 09:00:00</span>
                </el-col>
              </el-row>
            </div>
          </div>
          <div class="info-cut-off-rule" id="L-tab">
            <div class="left-tab" :class="index == 1 ? 'active-tab':''" @click="activeTab(1)">资产核查信息</div>
            <div :class="index == 2 ? 'active-tab':''" @click="activeTab(2)">核查单位信息</div>
          </div>
          <div class="info-bottom-box">
            <el-form :inline="true" :model="formInline" size="small" class="demo-form-inline" v-if="index == 1">
              <el-row>
                <el-col :span="7">
                  <el-form-item label="核查单位：">
                    <el-select v-model="formInline.unit" 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="7">
                  <el-form-item label="资产类型：">
                    <el-select v-model="formInline.type" placeholder="请选择">
                      <el-option label="item.label" value="item.value">
                      </el-option>
                    </el-select>
                  </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-select>
                  </el-form-item>
                </el-col>
                <el-col :span="3">
                  <el-form-item>
                    <el-button size="mini" type="primary" @click="handleQuery()">查询</el-button>
                    <el-button size="mini" @click="resetQuery()">重置</el-button>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
            <el-form :inline="true" :model="formInlineTwo" size="small" class="demo-form-inline" v-if="index == 2">
              <el-row>
                <el-col :span="7">
                  <el-form-item label="单位名称：">
                    <el-input v-model="formInlineTwo.unitName" placeholder="请输入"></el-input>
                    <!-- <el-select v-model="formInline.unit" placeholder="请选择"> -->
                      <!-- <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">
                  <el-form-item>
                    <el-button size="mini" type="primary" @click="handleQuery()">查询</el-button>
                    <el-button size="mini" @click="resetQuery()">重置</el-button>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
            <section v-if="index == 1">
              <el-table v-loading="loading" :data="tableData" :height="tabHeader" :max-height="tabHeader" :row-class-name="tableRowClassName">
                <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: #C51717;">
                      已报废
                    </span>
                  </template>
                </el-table-column>
                <el-table-column label="操作" prop="userId" class-name="table-operation" align="center">
                  <template slot-scope="scope">
                    <span class="look-info" @click="goInfo(scope.row)" style="color: #192A92;cursor: pointer;">查看</span>
                  </template>
                </el-table-column>
              </el-table>
            </section>
            <section v-if="index == 2">
              <el-table v-loading="loading" :data="tableDataTwo" :height="tabHeader" :max-height="tabHeader" :row-class-name="tableRowClassName">
                <el-table-column type="index" width="50" label="序号" align="center"/>
                <el-table-column label="单位名称" key="unitName" width="200px" prop="unitName" align="center" />
                <el-table-column label="核查资产数量" key="hczcsl" prop="hczcsl" align="center" />
                <el-table-column label="完成数量" key="wcsl" prop="wcsl" 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="wwcsl" prop="wwcsl" align="center" />
                <el-table-column label="未完成比例" key="wwcbl" width="200px" prop="wwcbl" align="center">
                  <template slot-scope="scope">
                    <span style="color: #192A92;">{{ scope.row.wwcbl }}</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>
          </div>
        </div>
      </el-col>
      <el-col :span="4">
        <div class="info-right">
          <div class="info-title">任务详情</div>
          <div class="timeline">
            <el-timeline>
              <el-timeline-item
                v-for="(activity, index) in activities"
                :key="index"
                :timestamp="activity.timestamp">
                {{activity.content}}
              </el-timeline-item>
            </el-timeline>
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import myPagination from "@/views/components/Pagination/index.vue"
export default {
  components:{myPagination},
  data() {
    return {
      index:1,
      formInline:{
        unit:"",
        type:"",
        status:"",
      },
      formInlineTwo:{
        unitName:"",
      },
      total:0,
      pagination:{
        current:1,
        size:10,
      },
      tableData:[
        {
          number:20230001,
          name:"XXX资产",
          type:"1类资产",
          unit:"太仓市XXX局",
          status:0,
        },{
          number:20230001,
          name:"XXX资产",
          type:"1类资产",
          unit:"太仓市XXX局",
          status:1,
        },{
          number:20230001,
          name:"XXX资产",
          type:"1类资产",
          unit:"太仓市XXX局",
          status:2,
        },
      ],
      tableDataTwo:[
        {
          unitName:"太仓市XXX局",
          hczcsl:"100",
          wcsl:"80",
          wwcsl:"20",
          wwcbl:"20%"
        },{
          unitName:"太仓市XXX局",
          hczcsl:"100",
          wcsl:"80",
          wwcsl:"20",
          wwcbl:"20%"
        },{
          unitName:"太仓市XXX局",
          hczcsl:"100",
          wcsl:"80",
          wwcsl:"20",
          wwcbl:"20%"
        },
      ],
      loading:false,
      tabHeader: undefined,
      activities: [{
        content: '管理员任务下发',
        timestamp: '2024-11-11 17:00:00'
      }, {
        content: '单位核查完成提交',
        timestamp: '2024-11-11 17:00:00'
      }, {
        content: '管理员审核驳回',
        timestamp: '2024-11-11 17:00:00'
      }, {
        content: '单位重新审核提交',
        timestamp: '2024-11-11 17:00:00'
      }, {
        content: '管理员审核通过',
        timestamp: '2024-11-11 17:00:00'
      }]
    }
  },
  mounted(){
    this.getList();
    this.cancalDebounce();
    window.addEventListener('resize', this.cancalDebounce);
  },
  destroyed() {
    window.removeEventListener('resize', this.cancalDebounce);
  },
  methods:{
    // 重置
    resetQuery(){
      this.pagination = {
        current: 1,
        size: 10,
      }
      if(this.index == 1) {
        this.formInline = {
          unit:"",
          type:"",
          status:"",
        }
        this.getList();
      } else if(this.index == 2) {
        this.formInlineTwo = {
          unitName:"",
        }
        this.getListTwo();
      }
    },
    // 查询
    handleQuery(){
      this.pagination = {
        current: 1,
        size: 10,
      }
      if(this.index == 1) {
        this.pagination = { ...this.pagination,...this.formInline };
        this.getList();
      } else if(this.index == 2) {
        this.getListTwo();
      }
    },
    // 获取页码
    getPagination(){
      this.pagination.current = pages.page;
      this.pagination.size = pages.limit;
      if(this.index == 1) {
        this.getList();
      } else if(this.index == 2) {
        this.getListTwo();
      }
    },
    // 切换tab
    activeTab(id){
      this.index = id
      if(id == 1) {
        this.formInline = {
          unit:"",
          type:"",
          status:"",
        }
        this.getList();
      } else {
        this.formInlineTwo = {
          unitName:"",
        }
        this.getList();
      }
    },
    getList(){},
    getListTwo(){},
    // 修改table背景色
    tableRowClassName({row, rowIndex}){
      if (rowIndex % 2 !== 0) {
        return 'evenNumber-row';
      }
      return '';
    },
    // 屏幕尺寸变化
    cancalDebounce(){
      const element = document.getElementById('L-size-main'); // 通过元素的 ID 获取元素
      const header = document.getElementById('L-header'); // 通过元素的 ID 获取元素
      const tab = document.getElementById('L-tab'); // 通过元素的 ID 获取元素
      const pagination = document.getElementById('L-pagination'); // 通过元素的 ID 获取元素
      const elementHeight = element.offsetHeight;
      const headerHeight = header.offsetHeight;
      const paginationtHeight = pagination.offsetHeight;
      const tabHeight = tab.offsetHeight;
      this.tabHeader = elementHeight - headerHeight - paginationtHeight - tabHeight - 140;
    }
  },
}
</script>
