kFormBuild主表中明细表分页处理

1、数据结构

data() {
            return {
                selfPaginations :[], //保存多个分页列表参数
                 recordData :{}, //主表数据
                  mydataSource: {} // 列表数据源 {records:[{data:null,name:'',pagination:{}}]} ,
                }
    }
    // ipagination : {current:1,pageSize:10,tableName:'rsExtendPost'}
     分页参数包括当前页、页大小、对应表属性名称

2、根据分页获取多个明细表数据
ipagination: 选择的某个明细表分页对象值
recordData:主表实体数据
params: 主表查询参数

//selfPaginations 数组
             getTableIds(params,recordData,ipagination){
                 const that = this
                 if(ipagination == undefined||ipagination == null ){
                     ipagination = {current:1,pageSize:10,tableName:'xasdfsdafsdfdsafweewr'}
                 } 
                 //取关联数据
                const  url = that.url.selectMainExtendTableNameByMainTable 
                // alert('主表获取n:1关联的从表信息')
                getAction(url, params).then((res) => { 
                   let tmpDataSource = [] //暂存
                   if(that.mydataSource.records){
                       tmpDataSource = that.mydataSource.records
                   }
                    that.mydataSource = {} //清空
                    if (res.success) {
                        let records  = res.result.records || res.result;
                        let recordsCount = records.length //明细列表个数
                        let count = 0								 //计步器		
                        records.forEach( (item) =>{
                            //获取其它tab列表数据
                            let  mapdata  = {};
                            mapdata[formatConversion(item.dbFieldName,1)] = recordData.id
                            let queryParam  = {tableName:item.tableName,jsonQFields:mapdata }
                            let maintablePropertyName = ipagination.tableName   
                            let tablePropertyName = formatConversion(item.tableName,1)

                            queryParam.pageNo = 1
                            queryParam.pageSize =10
                             //处理哪个分页列表,通过 it.tableName ==maintablePropertyName 表对象是否相同判断更新哪个分页数据源
                            let isUpdateDs = true //默认为更新
                            if(that.selfPaginations.length>0){
                                that.selfPaginations.forEach(it=>{
                                    //用传递的参数处理
                                    if(it.tableName == maintablePropertyName){
                                        console.log("更新:"+maintablePropertyName+' '+JSON.stringify(ipagination))
                                        queryParam.pageNo = ipagination.current
                                        queryParam.pageSize = ipagination.pageSize
                                        ipagination.current = ipagination.current
                                        isUpdateDs = true
                                          return
                                    }else if(it.tableName == tablePropertyName){
                                        console.log('不更新:'+maintablePropertyName+' '+JSON.stringify(it))
                                        ipagination = it
                                        queryParam.pageNo = ipagination.current
                                        queryParam.pageSize = ipagination.pageSize
                                        ipagination.current = 1
                                        isUpdateDs = false
                                        return
                                    }

                                })
                            }
                            //改用更新单个数据源方法
                            if(isUpdateDs){
                                //取某个关联数据对应的记录设置ds
                                 getAction(that.url.getRecordlist, queryParam).then((res) => {
                                        //console.log('取某个关联数据对应的记录设置DS '+queryParam.tableName+' '+ new Date())
                                        if (res.success) {
                                            let  tablePropertyName =    formatConversion(queryParam.tableName,1)
                                            ipagination.tableName= tablePropertyName

                                            ipagination.total = res.result.total
                                            let orecords = res.result.records || res.result;
                                            if (orecords.length > 0) {
                                                let sourceObj = {}
                                                let ds = []

                                                orecords.forEach(rec=>{
                                                    let nitem = {}
                                                    Object.keys(rec).forEach(k => (nitem[tablePropertyName+"." +k] = rec[k]))
                                                    ds.push(nitem)
                                                })
                                                //dataSource  由[]改为{}类型
                                                sourceObj['data']= ds||[]
                                                sourceObj['name'] = formatConversion(item.tableName,1)
                                                sourceObj['pagination'] = ipagination||{}
                                               // console.log('pagination:'+JSON.stringify(sourceObj['pagination']))
                                               // if(!hasIpaginations){
                                                    const tmpipagination = that.selfPaginations.filter(it=> it.tableName == tablePropertyName)
                                                    if(tmpipagination!=null){
                                                        that.selfPaginations.push({current:ipagination.current,pageSize:ipagination.pageSize,tableName:ipagination.tableName,total:ipagination.total})
                                                    }
                                               // }
                                                let dsIndex = tmpDataSource.findIndex( ({name})=> name == formatConversion(item.tableName,1))
                                                //alert('dsIndex'+dsIndex+' '+formatConversion(item.tableName,1))
                                                if(dsIndex>-1){ //更新
                                                    tmpDataSource.splice(dsIndex,1,sourceObj)
                                                }else{  //新增
                                                    tmpDataSource.push(sourceObj)
                                                }

                                            }
                                        }
                                    }).finally(()=>{
                                     count = count + 1
                                    // console.log('取某个关联数据对应的记录设置Result '+queryParam.tableName+' '+count+' '+ new Date())
                                     if(count == recordsCount){
                                         //console.log('设置数据源 '+queryParam.tableName+' '+ new Date())
                                          that.$nextTick(()=> {
                                              let result = {records: tmpDataSource}
                                              that.mydataSource = result
                                          })
                                     }

                                 })
                            }else{
                                count = count+1
                                if(count == recordsCount){
                                   // console.log('设置数据源 '+queryParam.tableName+' '+ new Date())
                                    that.$nextTick(()=> {
                                        let result = {records: tmpDataSource}
                                        that.mydataSource = result
                                    })
                                }
                                console.log('没有更新的记录设置Result '+queryParam.tableName+' '+count+' '+ new Date())
                            }
                           // console.log('count:'+count +' '+recordsCount) //异步获取count 不正确
                        })

                    }
                })
            },

3、调用
3.1)初次加载数据
queryParam : 主表名,根据主表查明细表记录 -> 根据明细表记录查明细表对应的实体数据
recordData: 主表实体数据

that.$nextTick(()=>{
                                let queryParam = {mainTable:tableRecord.tableName} //,displayMainUi:'true'
                                this.getTableIds(queryParam,recordData,null)
                            
                            })

3.2)分页处理某个列表数据

if(type == 'handleTableChange'){
                   let pageination = record
                   that.$nextTick(()=>{
                       let queryParam = {mainTable:this.tableInfo.tableName} //,displayMainUi:'true'
                       //alert(JSON.stringify(pageination))
                       this.getTableIds(queryParam,this.recordData,pageination)
                   })
                   this.$refs.dlxForminner.setData(this.recordData)
                   return
               }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值