merchantTree.vue 4.58 KB
<!--
 * @Description: 选择层级的树结构
 * @Author: huyue
 * @Date: 2022-04-28 10:15:34
 * @LastEditors: huyue
 * @LastEditTime: 2022-07-19 17:54:58
-->

<template>
  <div>
    <GLDialog class="tree-dialog" :visible="visible" @close="handleClose" :title="dialogTitle" :showClose="true">
      <div>
        <div class="el-breadcrumb">
          <span class="el-breadcrumb__item">
            <span class="el-breadcrumb__inner" style="cursor: context-menu">{{ $globalState.session.merchantName }}</span>
            <i class="el-breadcrumb__separator el-icon-arrow-right"></i>
          </span>
          <span class="el-breadcrumb__item" v-for="item in selectLevel" :key="item.merchantId" @click="backLevel(item)">
            <span class="el-breadcrumb__inner">{{ item.merchantName }}</span>
            <i class="el-breadcrumb__separator el-icon-arrow-right"></i>
          </span>
          <span class="el-breadcrumb__item last-level" v-if="lastLevel">
            <span class="el-breadcrumb__inner">请选择下级组织结构</span>
            <i class="el-breadcrumb__separator el-icon-arrow-right"></i>
          </span>
        </div>
        <div>
          <div class="tree-list" :style="{ height: listHeight + 'px' }">
            <el-radio-group v-model="checkObj.first" @change="selectChange">
              <div class="tree-item" v-for="item in merchantList" :key="item.merchantId" @click.self="toNext(item, $event)">
                <el-radio :label="item" :disabled="item.childrenNms || item.entmicroName">{{ item.merchantName }}</el-radio>
                <i v-show="item.childrenNms" class="el-icon-arrow-right"></i>
              </div>
            </el-radio-group>
          </div>
        </div>
      </div>
      <div slot="footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="submit">提交</el-button>
      </div>
    </GLDialog>
  </div>
</template>
<script>
export default {
  name: 'MerchantTree',
  data() {
    return {
      loading: false,
      visible: false,
      dialogTitle: '选择商户账户',
      listHeight: 220,
      merchantList: [],
      checkObj: {
        first: ''
      },
      // 选中的用来展示面包屑
      selectLevel: [],
      lastLevel: true, // 是否显示请选择下一级
      merchantId: this.$globalState.session.merchantId
    }
  },
  methods: {
    // 获取商户账户数据
    getMerchantList(depth, id) {
      this.loading = true
      var params = {}
      params.merchantId = id ? id : this.merchantId
      params.depth = depth ? depth : 0
      this.$apis.baseInfo.getMerchantTree(params).then(res => {
        this.$nextTick(() => {
          this.merchantList = res
          this.loading = false
        })
      })
    },
    handleClose() {
      console.log(3232)
      this.visible = false
      this.selectLevel = []
      this.checkObj.first = ''
      this.lastLevel = true
    },
    submit() {
      if (!this.checkObj.first) {
        this.$message({
          message: '请选择商户账户',
          type: 'warning'
        })
        return
      }
      this.$emit('selectMerchant', this.checkObj)
      this.visible = false
      this.selectLevel = []
      this.checkObj.first = ''
      this.lastLevel = true
    },
    // 选中时触发
    selectChange(val) {
      this.$set(this.selectLevel, val.depth - 1, val)
      this.lastLevel = val.childrenNms ? true : false
    },
    // 跳转下一级,需判断是否有下一级
    toNext(item, event) {
      if (item.childrenNms) {
        this.checkObj.first = ''
        this.lastLevel = true
        this.getMerchantList(item.depth, item.merchantNo)
        this.selectLevel[item.depth - 1] = item
      }
    },
    // 点击页签,返回
    backLevel(item) {
      this.checkObj.first = ''
      this.lastLevel = item.childrenNms ? true : false
      this.selectLevel = this.selectLevel.slice(0, item.depth - 1)
      this.getMerchantList(item.depth - 1)
    }
  }
}
</script>

<style lang="scss" scoped>
.el-breadcrumb {
  line-height: 28px;
}
.el-radio__label {
  color: #333;
}
.tree-dialog {
  /deep/ {
    .last-level {
      .el-breadcrumb__inner {
        color: #5850ff;
      }
    }
    .el-breadcrumb__inner {
      font-weight: normal;
      cursor: pointer;
    }
    .el-dialog__body {
      padding: 20px;
    }
  }
}
.tree {
  &-list {
    margin-top: 10px;
    overflow: auto;
    .el-radio-group {
      width: 100%;
    }
  }
  &-item {
    padding: 15px 0 11px;
    border-top: 1px solid #e6e6e6;
    width: 100%;
    display: flex;
    justify-content: space-between;
    i {
      font-size: 12px;
    }
  }
}
</style>