vue 报表下钻功能开发

拿到areaCode初始值,下钻的时候把点击获取到的areaCode赋值上去就可以实现下钻功能

let data = {
         areaType: this.areaType, // 后台默认是1
         areaCode: this.reqData.areaCode,
       }
       ceApi.getcqData(data).then(res => {
         if (res.success) {
           this.loading = false
           this.reportData = res.data
           this.type = 0
         } else {
         }
       })

click点击拿到areaCode

<el-table-column
        prop=""
        label="区域名称"
       >
        <template slot-scope="scope">
          <div class="active" v-html="type==0?scope.row.areaName:scope.row.officeName" @click="doDrillDown(scope.row.areaCode,scope.row.areaType,scope.row.officeType,scope.row.officeCode)"></div>
        </template>
      </el-table-column>

形参接收 拿到areaCode值

doDrillDown(code,areaType,type,officeCode){
      this.reqData.areaCode = code;
 }

下钻后点返回 返回上一层

在点击下钻的时候,把每次获取到的areaCode push到一个数组里,点击返回的时候,删除数组的最后一个元素,重新赋值给获取数据的参数,再调一次接口

doDrillDown(code,areaType,type,officeCode){
   // 把获取到的code  push到空数组里
   this.drillDownIdArray.push(code);
}
 /**
     * 下钻后返回
     */
    doDrillDownBack(){
      this.drillDownIdArray.pop();
      let nowCode = this.drillDownIdArray[this.drillDownIdArray.length - 1];
      this.reqData.areaCode = nowCode;
      this.getData();
    },

补充优化:
这个下钻和返回都是覆盖掉之前的参数,然后重新调接口,如果数据很多的话,加载就会很慢很慢,那就可以吧下钻拿到的值存起来,返回的时候重新展示到页面就可以。
例如:[表名]-[一级]-[数据] 、 [表名]-[一级]-[数据类型]:机构|部门 (推荐-用下划线)

// 拿到数据后保存
sessionStorage.setItem("zh021_"+this.backStep+"_data",JSON.stringify(res.data))
sessionStorage.setItem("zh021_"+this.backStep+"_type",JSON.stringify(this.request)) // 不同的接口
this.backStep++; //  等级数(也可以用areaType值,自己定)
// 返回让步数减一
 this.backStep-=1
 this.request = sessionStorage.getItem(`zh021_${this.backStep-1}_type`)
 this.reportData = JSON.parse(sessionStorage.getItem(`zh021_${this.backStep-1}_data`))
  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

屿-·

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值