<template>
  <div class="box">
    <el-card class="tree-box" shadow="always" :body-style="{ padding: '5px' }" ref="cardTree">
      <div slot="header" class="clearfix">
        <span v-show="!status">选择档案门类</span>
        <el-button style="float: right; padding:  0" type="text" @click='btns'>
          <el-tooltip class="item" effect="dark" v-if="!status" content="折叠" placement="right">
            <svg-icon icon-class="leftzd" v-if="!status" />
          </el-tooltip>
          <el-tooltip class="item" effect="dark" v-if="status" content="展开" placement="left">
            <svg-icon icon-class="rightzd" v-if="status" />
          </el-tooltip>
        </el-button>
      </div>
        <el-scrollbar wrap-style="overflow-x:hidden;" style="height: calc(100vh - 160px)">
          <el-tree v-loading="treeLoading" highlight-current :data="treeData" :props="defaultProps" default-expand-all
            @node-click="handleNodeClick">
            <span slot-scope="{ node, data }" class="custom-tree-node">
              <!--可以根据情况，以数据类型来显示不同的图标或图片-->
              <svg-icon icon-class="wjj" style="margin-right: 5px; color: rgb(255, 207, 92)"
                v-if="data.classType === 'L'" class="iconfont icon-folder-open-fill" />
              <svg-icon icon-class="wj" style="margin-right: 5px; color: rgb(255, 207, 92)" v-else
                class="iconfont icon-wenjian" />
              <span>{{ node.label }}</span>
            </span>
          </el-tree>
        </el-scrollbar>
    </el-card>
    <div class="resize" title="收缩侧边栏">
      ⋮
    </div>
    <el-card class="form-box" ref='cardForm' :body-style="{ padding: ' 20px 10px' }">
      <div class="top-box">
        <span class="title">对比结果列表</span>
        <el-button @click="diaClick" size="mini" type="primary" icon="el-icon-setting">门类字段与元数据标准字段对比</el-button>
      </div>
      <table-content :tableData='tableData' />
    </el-card>

    <dia-content @handleNodeClick='handleNodeClick' @cancel='cancel' :treeRow='treeRow' :treeId='treeId'
      :diaStatus='diaStatus' :RecordList='RecordList' />
  </div>
</template>
<script>
  import {
    message,
    dragControllerDiv
  } from '@/utils/common';
  import {
    mapState
  } from "vuex";
  import diaContent from "./components/diacontent.vue"
  import tableContent from "./components/tableContent.vue"
  export default {
    data() {
      return {
        status: false,
        // 树形结构数据
        defaultProps: {
          children: "childClass",
          label: "className",
        },
        diaStatus: false,
        treeId: '',
        treeRow: {}
      }
    },
    components: {
      tableContent,
      diaContent
    },
    watch: {
      'status': {
        handler(val, oldVal) {
          const cardTree = this.$refs.cardTree.$el.style
          const cardForm = this.$refs.cardForm.$el.style
          if (val) {
            cardTree.width = '5%'
            cardForm.width = '94%'
          } else {
            cardTree.width = '22%';
            cardForm.width = '77%';
          }
        }
      }
    },
    computed: {
      ...mapState({
        treeData: (state) => state.categorySetting.treeData,
        tableData: (state) => state.categorySetting.tableData,
        RecordList: (state) => state.categorySetting.RecordList,
      }),
      treeLoading: {
        get() {
          return this.$store.state.categorySetting.treeLoading;
        },
        set(val) {
          this.$store.state.categorySetting.treeLoading = val;
        },
      },
    },
    methods: {
      btns() {
        this.status = !this.status
      },
      getTree() {
        this.treeLoading = true
        this.$store.dispatch('categorySetting/getTree',{ className: "档案" }).catch(err => {
          this.treeLoading = false
        })
      },
      handleNodeClick(data, node, ele) {
        this.treeRow = data
        this.treeId = data.id.toString()
        this.$store.dispatch('categorySetting/selectMetadataEntityByClassId', {
          classId: this.treeId
        })
      },
      diaClick() {
        if (!this.treeId) {
          message('warning', '请先选择门类', 3000)
          return
        }
        this.$store.dispatch('categorySetting/getRecordList').then(res => {
          this.diaStatus = true
        })
      },
      cancel() {
        this.diaStatus = false
      },
    },
    mounted() {
      dragControllerDiv()
    },
    created() {
      this.getTree()
    }
  }

</script>
<style lang='scss' scoped>
  .box {
    display: flex;
    justify-content: space-around;
    height: 100%;

    .tree-box {
      width: 22%;
      // height: 720px;
      background-color: #fff;
      padding: 5px 10px;


      .clearfix {
        font-weight: 600;
        font-size: 17px;
        letter-spacing: 3px;
      }
    }

    .form-box {
      width: 77%;
      height: calc(100vh - 90px);
      overflow-y: auto;

      background-color: #fff;
      padding: 5px 10px;

      .top-box {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 10px;

        .title {
          font-weight: bold;
        }
      }
    }
  }

</style>
