<template>
  <div class="page">
    <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>
      <div class="treeClass">
        <el-scrollbar wrap-style="overflow-x:hidden;" style="height: calc(100vh - 165px)">
        <el-tree v-loading="treeLoading" highlight-current :data="treeData" :props="defaultProps"
          :expand-on-click-node="false" @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.childs && data.childs.length > 0" 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>
      </div>
    </el-card>
    <el-card class="form-box" ref='cardForm'>
      <div>
        <el-form :model="search" ref="headerForm" label-width="100px" size="mini">
          <el-form-item label="登记日期：" style="width:300px">
            <el-input v-model="search.gatherTime" placeholder="请选择" clearable></el-input>
          </el-form-item>
          <div class="btn">
            <el-button :disabled="JSON.stringify(treeRow)==='{}'" type="primary" size="mini" @click="searchClick"><i
                class="iconfont icon-sousuo"></i>查询
            </el-button>
            <el-button :disabled="JSON.stringify(treeRow)==='{}'" type="primary" size="mini" @click="searchClick"><i
                class="iconfont icon-sousuo"></i>手工录入
            </el-button>
          </div>
        </el-form>
      </div>
      <content-box :tableData='tableData' :tableLoading='tableLoading' :pagination='pagination'
        @refreshTable='getData' />
    </el-card>
  </div>
</template>
<script>
  import {
    mapState
  } from "vuex";
  import contentBox from "./components/contentTable";
  export default {
    data() {
      return {
        status: false,
        defaultProps: {
          children: 'childs',
          label: 'gathername'
        },
        search: {
          gatherTime: ""
        },
        params: {},
        treeRow: {}
      }
    },
    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%';
          }
        }
      }
    },
    components: {
      contentBox
    },
    computed: {
      ...mapState({
        treeData: (state) => state.thRegistration.treeData,
        tableData: (state) => state.thRegistration.tableData,
        pagination: (state) => state.thRegistration.pagination,
      }),
      treeLoading: {
        get() {
          return this.$store.state.thRegistration.treeLoading;
        },
        set(val) {
          this.$store.state.thRegistration.treeLoading = val;
        },
      },
      tableLoading: {
        get() {
          return this.$store.state.thRegistration.tableLoading;
        },
        set(val) {
          this.$store.state.thRegistration.tableLoading = val;
        },
      },
    },
    methods: {
      btns() {
        this.status = !this.status
      },
      getTree() {
        this.treeLoading = true
        this.$store.dispatch('thRegistration/getPointTree', {}).catch(err => {
          this.treeLoading = false
        })
      },
      handleNodeClick(node) {
        this.treeRow = node
        this.getData()
      },
      getData() {
        this.tableLoading = true
        this.params = {
          gatherTime: this.search.gatherTime,
          id: this.treeRow.id,
          page: this.pagination.pageNum,
          limit: this.pagination.pageSize,
        }
        this.$store.dispatch('thRegistration/getData', this.params).catch(err => {
          this.treeLoading = false
        })
      },
      searchClick() {
    
        this.getData()
      }
    },
    created() {
      this.getTree()
    }

  }

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

    .tree-box {
      width: 22%;
      // height: 720px;
      // overflow-y: auto;

      .treeClass {
        padding: 0 10px
      }

      .el-tree {
        width: 100%;
        margin-top: 10px;
      }

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

    }

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


      .el-form {
        display: flex;
        flex-wrap: wrap;
      }
    }
  }

</style>
