<template>
  <div id="eqInSp">
    <el-row>
      <el-button type="primary" @click="add">添加{{inSpaceType}}</el-button>
      <el-tooltip class="item" effect="dark" content="可前往“全部关系总览”中计算竖井内系统" placement="right">
        <el-button>按空间计算</el-button>
      </el-tooltip>
    </el-row>
    <div class="table-box">
      <el-table :data="tableData" style="width: 100%" height="100%" v-loading="loading" :header-cell-style="headerStyle">
        <el-table-column :label="`${inSpaceType}名称`" show-overflow-tooltip min-width="100">
          <template slot-scope="scope">
            <div>
              {{scope.row.SysLocalName||scope.row.SysName||''}}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="SysLocalID" :label="`${inSpaceType}本地编码`" show-overflow-tooltip min-width="100"></el-table-column>
        <el-table-column :label="`${inSpaceType}类型`" show-overflow-tooltip min-width="100">
          <template slot-scope="scope">
            <div>
              {{scope.row.CategoryNames.CategoryName}}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="action" label="操作" min-width="100">
          <template slot-scope="scope">
            <el-tooltip class="item" effect="dark" content="删除关系" placement="left">
              <el-button size="mini" @click="handleDelete(scope.$index, scope.row)" type="danger" plain icon="el-icon-delete"></el-button>
            </el-tooltip>
          </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>
    <!-- 添加设备弹窗 -->
    <addSystemDialog ref="addEqDialog" @refresh="getTableData" :type="type" :params="params"></addSystemDialog>
  </div>
</template>

<script>
import { queryCenoteTableData, syinshUnlink } from "@/api/scan/request";
import { mapGetters } from "vuex";
import addSystemDialog from "@/components/ledger/cenote/dialog/addSystemDialog"
export default {
  components: {
    addSystemDialog
  },
  computed: {
    ...mapGetters("layout", ["projectId"])
  },
  data() {
    return {
      inSpaceType: '系统',
      headerStyle: {
        backgroundColor: '#e1e4e5',
        color: '#2b2b2b',
        lineHeight: '30px'
      }, // 列表样式
      loading: false, // loading
      tableData: [] //列表数据
    };
  },
  props: {
    params: Object,
    type: String
  },
  created() {
    this.getTableData()
  },
  methods: {
    // 获取列表数据
    getTableData() {
      let params = {
        filters: `id='${this.params.ShaftID}'`,
        cascade: [
          {
            name: 'systemList',
            cascade: [{ name: 'categoryNames' }]
          }
        ]
      }
      queryCenoteTableData(params, res => {
        this.tableData = res.content[0].systemList || []
      })
    },
    // 删除关系
    handleDelete(index, row) {
      this.$confirm("确认删除该关系？", "提示", {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let params = {
          sysId: row.id,
          shaftId: this.params.ShaftID
        }
        this.deleteSyInSh(params);
      }).catch(() => {
        this.$message("取消删除")
      })
    },
    // 删除系统所在竖井关系
    deleteSyInSh(params) {
      syinshUnlink(params, res => {
        this.$message.success('删除成功')
        this.getTableData()
      })
    },
    // 改变pagesize
    handleSizeChange(pageSize) {
      this.page.pageSize = pageSize;
      this.getTableData();
    },
    // 改变pageno
    handleCurrentChange(pageNo) {
      this.page.pageNumber = pageNo;
      this.getTableData();
    },
    // 添加设备
    add() {
      this.$refs.addEqDialog.showDialog()
    }
  },
  watch: {
    type() {
      this.getTableData()
    }
  }
};
</script>
<style lang="less" scoped>
#eqInSp {
  height: 100%;
  .table-box {
    margin-top: 10px;
    height: calc(100% - 50px);
  }
}
</style>
