<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.ShaftLocalName||scope.row.ShaftName||''}}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="ShaftLocalID" :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.StructureInfo.ShaftFuncType}}
            </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>
    <!-- 添加设备弹窗 -->
    <addCenoteDialog ref="addCenoteDialog" @refresh="getTableData" :type="type" :params="params"></addCenoteDialog>
  </div>
</template>

<script>
import { queryLinkSys, queryShaftType, syinshUnlink } from "@/api/scan/request";
import { mapGetters } from "vuex";
import addCenoteDialog from "@/components/ledger/system/dialog/addCenoteDialog"
export default {
  components: {
    addCenoteDialog
  },
  computed: {
    ...mapGetters("layout", ["projectId"])
  },
  data() {
    return {
      inSpaceType: '竖井',
      headerStyle: {
        backgroundColor: '#e1e4e5',
        color: '#2b2b2b',
        lineHeight: '30px'
      }, // 列表样式
      loading: false, // loading
      tableData: [], //列表数据
      shaftType: {} //竖井类型
    };
  },
  props: {
    params: Object,
    type: String
  },
  created() {
    queryShaftType(res => {
      res.Content.forEach(item => {
        this.shaftType[item.Code] = item.Name
      })
      this.getTableData()
    })
  },
  methods: {
    // 获取列表数据
    getTableData() {
      let params = {
        Filters: `SysID='${this.params.SysID}'`,
        Cascade: [
          {
            Name: 'shaftList',
          }
        ]
      }
      queryLinkSys(params, res => {
        this.tableData = res.Content[0].Shaft || []
        this.tableData.forEach(item => {
          if (item.StructureInfo && item.StructureInfo.ShaftFuncType) {
            item.StructureInfo.ShaftFuncType = this.shaftType[item.StructureInfo.ShaftFuncType]
          }
        })
      })
    },
    // 删除关系
    handleDelete(index, row) {
      let sysId = this.$route.query.SysID
      this.$confirm("确认删除该关系？", "提示", {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let params = {
          ShaftId: row.ShaftID,
          SysId: sysId
        }
        this.deleteShThroughSh(params);
      }).catch(() => {
        this.$message("取消删除")
      })
    },
    // 删除设备所在空间关系
    deleteShThroughSh(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.addCenoteDialog.showDialog()
    }
  },
  watch: {
    type() {
      // this.getTableData()
    }
  }
};
</script>
<style lang="less" scoped>
#eqInSp {
  height: 100%;
  .table-box {
    margin-top: 10px;
    height: calc(100% - 50px);
  }
}
</style>