<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.Building?scope.row.Building.BuildLocalName?scope.row.Building.BuildLocalName:'':''}} -
              {{scope.row.Floor?scope.row.Floor.FloorLocalName?scope.row.Floor.FloorLocalName:'':''}}
            </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="EquipLocalName" :label="`${inSpaceType}本地编码`" show-overflow-tooltip min-width="100"></el-table-column>
        <el-table-column prop="EquipFamily.FamilyName" label="设备族" show-overflow-tooltip min-width="100"></el-table-column>
        <el-table-column prop="InstallLocation" 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.TaskState == '待验证' || scope.row.TaskState == '未找到'" title="查看详情" class="iconfont icon-xiangqing table-button" @click="handleDetail(scope.$index, scope.row)"></i>
            <i v-if="scope.row.TaskState == '未找到'" title="重新生成任务" class="iconfont icon-Update table-button" @click="handleRegenerate(scope.$index, scope.row)"></i>
            <i v-if="scope.row.TaskState == '待验证'" title="删除任务" class="iconfont icon-delete table-button" @click="handleDelete(scope.$index, scope.row)"></i>
            <i v-if="scope.row.TaskState == '未找到'" 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">
      <assets-detail :id="detailId"></assets-detail>
    </el-drawer>
  </div>
</template>

<script>
import { queryAssetsTask, deleteAssetsTask } from "@/api/data_admin/buildTaskApi"
import tools from "@/utils/tools"
import { mapGetters } from "vuex"
import assetsDetail from '../detail/assetsDetail'
export default {
  components: {
    assetsDetail
  },
  computed: {
    ...mapGetters("layout", ["projectId"])
  },
  props: {
    paramsData: Object,
  },
  data() {
    return {
      inSpaceType: '资产',
      loading: false, // loading
      drawer: false, // 详情侧弹窗
      detailId: '',
      tableData: [], //列表数据
      page: {
        pageSize: 50,
        pageSizes: [10, 20, 50, 100],
        pageNumber: 1,
        total: 0
      },
      taskTypeMap: {//待撕码,待换码
        '-5': '已撕码',
        '3': '待撕码',
        '2': '待换码',
        '0': '正常贴码'
      },
      taskStateMap: {
        '-1': '未找到',
        '0': '已完成',
        '1': '待验证'
      },
      headerStyle: {
        backgroundColor: '#e1e4e5',
        color: '#2b2b2b',
        lineHeight: '30px'
      }, // 列表样式
    };
  },
  created() {
    this.getTableData()
  },
  methods: {
    // 获取列表数据
    getTableData() {
      this.loading = true
      let params = {
        filters: `projectId='${this.projectId}';taskType in ['2']`,
        cascade: [
          {
            name: 'equipFamily'
          }, {
            name: 'building',
          }, {
            name: 'floor',
          }
        ],
        orders: "createTime desc, id asc",
        pageNumber: this.page.pageNumber,
        pageSize: this.page.pageSize
      }
      // if (this.paramsData.buildfloor[0] == "noKnow") {
      //   params.Filters += `;BuildingId isNull`
      // } else if (this.paramsData.buildfloor[0] && this.paramsData.buildfloor[0] != "all") {
      //   params.Filters += `;BuildingId='${this.paramsData.buildfloor[0]}'`
      //   if (this.paramsData.buildfloor[1] == "noKnow") {
      //     params.Filters += `;FloorId isNull`
      //   } else if (this.paramsData.buildfloor[1] && this.paramsData.buildfloor[1] != "all") {
      //     params.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}'`
      // }
      queryAssetsTask(params, res => {
        this.loading = false
        this.page.total = res.total;
        this.tableData = res.content.map(item => {
          item.taskState = this.taskStateMap[item.taskState]
          item.taskType = this.taskTypeMap[item.taskType]
          return item
        })
      })
    },
    // 删除关系
    handleDelete(index, row) {
      this.$confirm("确认删除该任务？", "提示", {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let params = [{TaskId: row.TaskId}]
        deleteAssetsTask(params, res => {
          this.$message.success('删除成功')
          this.getTableData()
        })
      }).catch(() => {
        this.$message("取消删除")
      })
    },
    //查看任务详情
    handleDetail() {
      this.drawer = true
      this.detailId = row.TaskId
    },
    // 改变pagesize
    handleSizeChange(pageSize) {
      this.page.pageNumber = 1
      this.page.pageSize = pageSize;
      this.getTableData()
    },
    // 改变pageno
    handleCurrentChange(pageNo) {
      this.page.pageNumber = pageNo;
      this.getTableData()
    }
  },
  watch: {
    paramsData: {
      handler(newName, oldName) {
        if(!tools.isSimilarly(newName, oldName)){
          this.page.pageNumber = 1
          this.getTableData()
        }
      },
      immediate: true,
      deep: true
    },
    projectId() {
      this.page.pageNumber = 1
      this.getTableData()
    }
  }
};
</script>
<style lang="less" scoped>
/deep/ .el-drawer__body {
  height: calc(100% - 80px);
  border-top: 1px solid #c9c9c9;
}
/deep/ .el-drawer__header {
  margin-bottom: 12px;
}
.table-container {
  height: 100%;
  background: #fff;
  .table-button{
    cursor: pointer;
    margin-right: 15px;
  }
}
</style>
