<template>
  <div class="table-container">
    <div class="table-list" :style="tableData && tableData.length?'height:calc(100% - 50px);':'height:100%;'">
      <el-table :data="tableData" style="width: 100%" height="100%" v-loading="loading" :header-cell-style="headerStyle">
        <el-table-column label="所属建筑楼层" show-overflow-tooltip min-width="100">
          <template slot-scope="scope">
            <div>{{scope.row.build}}-{{scope.row.floor}}</div>
          </template>
        </el-table-column>
        <el-table-column :label="`${inSpaceType}本地名称`" show-overflow-tooltip min-width="100">
          <template slot-scope="scope">
            <div>
              {{scope.row.EquipLocalName}}
              <el-badge :value="scope.row.partsNum" class="item" type="warning"></el-badge>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="EquipLocalID" :label="`${inSpaceType}本地编码`" show-overflow-tooltip min-width="100"></el-table-column>
        <el-table-column prop="EquipCategory.EquipName" :label="`${inSpaceType}类型`" show-overflow-tooltip min-width="100"></el-table-column>
        <el-table-column prop="CADID" label="安装位置" show-overflow-tooltip min-width="100"></el-table-column>
        <el-table-column prop="taskType" label="任务执行情况" show-overflow-tooltip min-width="100"></el-table-column>
        <el-table-column prop="action" label="操作" min-width="100">
          <template slot-scope="scope">
            <i v-if="scope.row.taskType == '待验证' || scope.row.taskType == '未找到'" title="查看详情" class="iconfont icon-xiangqing table-button" @click="handleDetail(scope.$index, scope.row)"></i>
            <i v-if="scope.row.taskType == '未找到'" title="重新生成任务" class="iconfont icon-Update table-button" @click="handleRegenerate(scope.$index, scope.row)"></i>
            <i v-if="scope.row.taskType == '待验证'" title="删除任务" class="iconfont icon-delete table-button" @click="handleDelete(scope.$index, scope.row)"></i>
            <i v-if="scope.row.taskType == '未找到'" title="认可此任务执行情况" class="iconfont icon-lijiqueren table-button" @click="handleConfirm(scope.$index, scope.row)"></i>
          </template>
        </el-table-column>
        <template slot="empty">
          <div style="height: 60%;transform: translateY(50%);">
            <i class="icon-wushuju iconfont"></i>
            数据暂无
          </div>
        </template>
      </el-table>
    </div>
    <el-pagination class="right" v-show="tableData && tableData.length" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page.pageNumber"
     :page-sizes="page.pageSizes" :page-size="page.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="page.total">
    </el-pagination>
    <el-drawer title="任务详情" :visible.sync="drawer" direction="rtl" size="600px">
      <span>我来啦!</span>
    </el-drawer>
  </div>
</template>

<script>
import {  } from "@/api/scan/request";
import { mapGetters } from "vuex";
export default {
  components: {
    
  },
  computed: {
    ...mapGetters("layout", ["projectId"])
  },
  props: {
    paramsData: Object,
  },
  data() {
    return {
      inSpaceType: '设备',
      loading: false, // loading
      drawer: false, // 详情侧弹窗
      page: {
        pageSize: 50,
        pageSizes: [10, 20, 50, 100],
        pageNumber: 1,
        total: 0
      },
      tableData: [{
        build: 'A栋',
        floor: '3F',
        EquipLocalName: '风机',
        partsNum: 8,
        EquipLocalID: 'AS123124343',
        EquipCategory: {
          EquipName: '风机'
        },
        CADID: '6486416846184879',
        taskType: '未找到'
      }], //列表数据
      headerStyle: {
        backgroundColor: '#e1e4e5',
        color: '#2b2b2b',
        lineHeight: '30px'
      }, // 列表样式
    };
  },
  created() {
    // this.getTableData()
  },
  methods: {
    // 获取列表数据
    getTableData() {
      let params = {
        Filters: `ProjectId='${this.projectId}'`,
        Cascade: [
          {
            Name: 'equipmentList',
            Cascade: [{ Name: 'equipCategory' }]
          }
        ],
        Orders: "createTime desc, EquipID asc",
        PageNumber: this.page.pageNumber,
        PageSize: this.page.pageSize
      }
      if (this.paramsData.buildfloor[0] == "noKnow") {
        param.Filters += `buildingId isNull`
      } else if (this.paramsData.buildfloor[0] && this.paramsData.buildfloor[0] != "all") {
        param.Filters += `buildingId='${this.paramsData.buildfloor[0]}'`
        if (this.paramsData.buildfloor[1] == "noKnow") {
          param.Filters += `;floorId isNull`
        } else if (this.paramsData.buildfloor[1] && this.paramsData.buildfloor[1] != "all") {
          param.Filters += `;floorId='${this.paramsData.buildfloor[1]}'`
        }
      }
      if(this.paramsData.taskState){
        params.Filters += `;TaskState='${this.paramsData.taskState}'`
      }
      if(this.paramsData.family){
        params.Filters += `;Family='${this.paramsData.family}'`
      }
      queryCenoteTableData(params, res => {
        this.tableData = res.Content[0].EquipmentList || []
      })
    },
    // 删除关系
    handleDelete(index, row) {
      this.$confirm("确认删除该任务？", "提示", {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // let params = {
        //   EquipId: row.EquipID,
        //   ShaftId: this.params.ShaftID
        // }
        // this.deleteEqInSh(params);
      }).catch(() => {
        this.$message("取消删除")
      })
    },
    // 删除设备所在竖井关系
    deleteEqInSh(params) {
      // eqinshUnlink(params, res => {
      //   this.$message.success('删除成功')
      //   this.getTableData()
      // })
    },
    //查看任务详情
    handleDetail() {
      this.drawer = true
    },
    // 改变pagesize
    handleSizeChange(pageSize) {
      this.page.pageSize = pageSize;
      this.getTableData()
    },
    // 改变pageno
    handleCurrentChange(pageNo) {
      this.page.pageNumber = pageNo;
      this.getTableData()
    }
  },
  watch: {
    paramsData: {
      handler(newName, oldName) {
        this.page.pageNumber = 1
        this.getTableData()
      },
      immediate: true,
      deep: true
    }
  }
};
</script>
<style lang="less" scoped>
.table-container {
  height: 100%;
  background: #fff;
  .table-button{
    cursor: pointer;
    margin-right: 15px;
  }
}
</style>