config.vue 6.41 KB
<!-- 配置管理 -->
<template>
  <div class="config-employee config-config">
    <div class="container">
      <div class="MsgWrap powerlimt">
        <span class="content-title">产品功能权限</span>

        <div class="powerTreeWrap role-border">
          <div class="mainTitleWrap role-border-b">
            <div class="mainTitle" :class="{ activeMainTitle: currentIndex == index }" v-for="(item, index) in powerDataArray" :key="index" @click="powerTabClick(index)">
              {{ item.accounttypeName || 'null' }}
              <div class="tab_line" v-show="currentIndex == index"></div>
            </div>
          </div>
          <div class="content">
            <div class="subTitleWrap" v-if="products.length > 0">
              <div class="subTitle role-border" :class="{ acitveSubTitle: subCurrentIndex == sindex }" v-for="(ele, sindex) in products" :key="sindex" @click="powerSubTabClick(sindex)">
                {{ ele.productName }}
              </div>
            </div>
            <div class="contentTree role-border">
              <template v-if="merchantProTreeResponses.length > 0">
                <el-tree default-expand-all :data="merchantProTreeResponses" :render-content="renderContent" :props="defaultProps"></el-tree>
              </template>
              <div v-else class="noDataContent">
                <img src="../../../assets/img/empty.png" alt="" />
                <div>暂无数据</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'config',
  data() {
    return {
      powerDataArray: [],
      merchantProTreeResponses: [],
      currentIndex: 0, //功能权限主标题的索引
      subCurrentIndex: 0,
      defaultProps: {
        children: 'children',
        label: 'label'
      }
    }
  },

  props: {
    id: {
      type: String,
      default: ''
    }
  },

  computed: {
    products() {
      if (!this.powerDataArray.length) {
        return []
      }
      return this.powerDataArray[this.currentIndex].products
    }
    //功能树的数据
    // merchantProTreeResponses() {
    //   if (!this.powerDataArray.length) {
    //     return []
    //   } else if (this.powerDataArray.length > 0 && this.powerDataArray[this.currentIndex].products.length == 0) {
    //     return []
    //   }
    //   this.$nextTick(() => {
    //     this.addStyle()
    //   })
    //   return this.powerDataArray[this.currentIndex].products[this.subCurrentIndex].merchantProTreeResponses
    // }
  },

  mounted() {
    this.getInfo()
  },

  methods: {
    getInfo() {
      this.$apis.employee.getDetailInfoApi({ id: this.id }).then(res => {
        this.powerDataArray = res.accountTypeTreeResponseList || []
        this.changeMerchantProTree()
      })
    },
    changeMerchantProTree() {
      if (!this.powerDataArray.length) {
        return []
      } else if (this.powerDataArray.length > 0 && this.powerDataArray[this.currentIndex].products.length == 0) {
        return []
      }
      this.merchantProTreeResponses = this.powerDataArray[this.currentIndex].products[this.subCurrentIndex].merchantProTreeResponses
      this.$nextTick(() => {
        this.addStyle()
      })
    },
    // 渲染树结构
    renderContent(h, v) {
      if (v.data.logo == 'functionValue') {
        return (
          <div class="custom-tree-node fun-tree-node">
            <span>{v.node.label}</span>
          </div>
        )
      } else {
        return (
          <div class="custom-tree-node">
            <span>{v.node.label}</span>
          </div>
        )
      }
    },
    addStyle() {
      const nodes = document.getElementsByClassName('fun-tree-node')
      for (let i = 0; i < nodes.length; i++) {
        const parentNode = nodes[i].parentNode.parentNode
        parentNode.style.float = 'left'
      }
    },
    powerTabClick(index) {
      this.currentIndex = index
      //每次切换将subCurrentIndex置为0
      this.subCurrentIndex = 0
      this.changeMerchantProTree()
    },
    powerSubTabClick(index) {
      this.subCurrentIndex = index
      this.changeMerchantProTree()
    },
    handleClose() {
      this.$router.push({
        name: 'Account2EmployeeIndex'
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.tab_line {
  width: 100%;
  height: 2px;
  background: #5850ff;
  border-radius: 4px;
  position: absolute;
  left: 50%;
  top: 48px;
  transform: translate(-50%, 0);
}
.config-employee {
  margin-bottom: 64px;
}
.config-employee.config-config .container {
  background: #ffffff;
  padding: 0 20px;
  .content-title {
    display: inline-block;
    position: relative;
    height: 48px;
    background-color: #fff;
    font-size: 16px;
    font-weight: 600;
    color: #333333;
    line-height: 48px;
    // padding-left: 20px;
  }
  .powerlimt {
    padding-bottom: 30px;
    .powerTreeWrap {
      border-radius: 4px;
      min-height: 300px;
      padding-top: 2px;
      padding-left: 2px;
      padding-bottom: 10px;
      .mainTitleWrap {
        // height: 32px;
        display: flex;
        flex-wrap: wrap;

        .mainTitle {
          height: 48px;
          line-height: 48px;
          text-align: center;
          border-radius: 2px;
          position: relative;
          margin: 0 20px;
          cursor: pointer;
        }
        .activeMainTitle {
          background-color: #fff;
          color: #5850ff;
        }
      }
      .content {
        background-color: #fff;

        margin: 20px 10px 0;
        .subTitleWrap {
          // height: 40px;
          display: flex;
          flex-wrap: wrap;
          .subTitle {
            background-color: #fafafa;
            height: 40px;
            width: 180px;
            font-size: 14px;
            line-height: 40px;
            text-align: center;
            border-bottom: none;
            border-radius: 2px;
          }
          .acitveSubTitle {
            background-color: #fff !important;
            color: #5850ff;
          }
        }
        .contentTree {
          padding: 20px;
          min-height: 250px;
          height: 250px;
          position: relative;
          overflow: auto;

          .noDataContent {
            width: 64px;
            height: 64px;
            position: absolute;
            left: 50%;
            top: 50%;
            margin-top: -32px;
            margin-left: -32px;
            div {
              margin-top: 12px;
            }
          }
        }
      }
    }
  }
}
</style>