<template>
  <a-layout>
    <a-layout-content>
      <p class="content_title">
        <span>督查类别</span>
        <a-select
          v-model:value="orgName"
          @change="handleChange"
          :filter-option="filterOption"
          placeholder="请选择"
          style="width: 200px"
          show-search>
          <a-select-option v-for="item in supervisionObjlist" :key="item.id" :value="item.name">{{ item.name }}</a-select-option>
        </a-select>
        <span class="hrs"></span>
      </p>
      <a-row :gutter="10">
        <a-col :span="leftWidth">
          <tree-group :orgType="orgType" @sendCurrentNodeinfo="sendCurrentNodeinfo"></tree-group>
        </a-col>
        <a-col :span="rightWidth" style="position: relative;">
          <plan-content ref="planContentRef" :duChaType="duChaType" :currentNodeinfo="currentNodeinfo"></plan-content>
          <div class="open_board">
            <a-icon type="left" v-if="isOpen" @click="closeLeft"/>
            <a-icon type="right" v-else @click="openLeft"/>
          </div>
        </a-col>
      </a-row>
    </a-layout-content>
  </a-layout>
</template>

<script>
import { getPersPlanType } from '../../api/duChaPlan';
import planContent from './planManageProvinceNew/planContent.vue';
import treeGroup from './planManageProvinceNew/treeGroup.vue';
export default {
  name: 'Sljd',
  emits: [],
  data() {
    return {
      supervisionObjlist: [], // 督查类型列表
      orgType: '',
      orgName: '', // 默认为数据第一个
      currentNodeinfo: {}, // 当前选择树节点的信息，从子组件接收过来传给另一个子组件
      leftWidth: 5,
      rightWidth: 19,
      isOpen: true,
    };
  },
  computed: {
    persId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '';
      // return localStorage.getItem('persId') ? localStorage.getItem('persId') : ''
    },
    duChaType() {
      return this.orgType ? this.orgType.replace(/\b(0+)/gi, '') : '';
    },
  },
  components: {
    'tree-group': treeGroup,
    'plan-content': planContent,
  },
  created() {
    this.getSupervisionObjlist();
  },
  methods: {
    closeLeft() {
      this.isOpen = false;
      this.leftWidth = 0;
      this.rightWidth = 24;
    },
    openLeft() {
      this.isOpen = true;
      this.leftWidth = 5;
      this.rightWidth = 19;
    },
    getSupervisionObjlist() {
      // 获取督查类型
      const { persId } = this;
      getPersPlanType(persId)
        .then((res) => {
          if (res.success && res.data.length) {
            this.supervisionObjlist = res.data;
            this.orgType = this.supervisionObjlist[0].id;
            this.orgName = this.supervisionObjlist[0].name;
          } else {
            this.$message.warning('暂未分配督查类别');
          }
        })
        .catch(() => {
          this.$message.warning('系统异常');
        });
    },
    handleChange(value, option) {
      // 点击选择器选择督查类型
      this.orgType = option.key;
    },
    filterOption(input, option) {
      // 筛选条件
      return (
        option.componentOptions.children[0].text
          .toLowerCase()
          .indexOf(input.toLowerCase()) >= 0
      );
    },
    sendCurrentNodeinfo(data) {
      this.currentNodeinfo = { ...data };
      this.$nextTick(() => {
        const pc = this.$refs.planContentRef;
        if (pc) {
          const current = pc.activeContent;
          pc.activeContent = current === 'first' ? 'second' : 'first';
          pc.$nextTick(() => {
            pc.activeContent = current;
          });
        }
      });
    },
  },
};
</script>

<style lang='less' scoped>
.content_title {
  span {
    padding: 0 10px;
    font-size: 16px;
  }
  .hrs{
    display: inline-block;
    width: calc(100% - 40px);
    margin-left:10px;
    height: 1px;
    vertical-align: middle;
    background-color: #ddd;
  }
}
.open_board {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 24px;
  height: 30px;
  line-height: 30px;
  border: solid 1px #ddd;
  border-top-right-radius: 5px;
  border-bottom-right-radius: 5px;
  text-align: center;
  background-color: #bbebff;
  cursor: pointer;
}
</style>
