列表中,不同下拉枚举使用不同参照

步骤:

1、数据建模,创建两个【文本】类型字段,一个参照ID(本例子为ziduan3),一个参照名称(本例子为canzhaoziduan)

2、页面设计,隐藏参照ID,参照名称 "cControlType"设置为 "uncertain"

3、从其他单据中获取参照编码,添加页面初始化函数

  • 代码部分

      function (event) {
        var viewModel = this;
        const gridModelInfo = viewModel.getGridModel();
          // ctrttype 下拉框枚举字段
        // canzhaoziduan 参照名称字段,uncertain字段
        // ziduan3 参照 id字段
        // ziduan4 参照带入字段
    
        //1、不确定列改为参照
        gridModelInfo.getEditRowModel().get("ctrttype").on('blur', function(data) {
            let ctrttype = gridModelInfo.getEditRowModel().get("ctrttype").getValue();
            //不确定列改为参照
            const cellConfig = {'cControlType':'refer'};
              //设置参照编码
            if (ctrttype == '1') {
              cellConfig.cRefType = 'productcenter.aa_warehouse'; //从其他单据中获取
              cellConfig.cShowCaption = '仓库档案';
    
            } else if (ctrttype == '2') {
              cellConfig.cRefType = 'productcenter.pc_mallordershopref';
              cellConfig.cShowCaption = '客户档案';
            }
            cellConfig.cRefRetId =  {"ziduan3":"id"};
            let index = gridModelInfo.getFocusedRowIndex();
            //设置行数据
            gridModelInfo.setCellValue(index,'cellConfig',cellConfig);
    
        });
    
        //2、参照设置完成,点击确定按钮赋值 
        gridModelInfo.getEditRowModel().get("canzhaoziduan").on('afterMount',function(model){
          let ctrttype = gridModelInfo.getEditRowModel().get("ctrttype").getValue();
          let index = gridModelInfo.getFocusedRowIndex();
          if(model.modelType == 'ReferModel'){
            //model.clearCache('vm');
              model.on('afterInitVm',function(args){
                let referViewModelInfo = args.vm;
                referViewModelInfo.on('afterOkClick',function(okData){
                  if (ctrttype == '1') {
                    gridModelInfo.setCellValue(index, "ziduan3", okData[0].id);
                    gridModelInfo.setCellValue(index, "canzhaoziduan", okData[0].name);
                    gridModelInfo.setCellValue(index, "ziduan4", okData[0].address);
                  } else if (ctrttype == '2') {
                    gridModelInfo.setCellValue(index, "ziduan3", okData[0].id);
                    gridModelInfo.setCellValue(index, "canzhaoziduan", okData[0].name);
                    gridModelInfo.setCellValue(index, "ziduan4", okData[0].code);
                  }
                });
              })
          }
        });
        //3、表格设置数据之前
        gridModelInfo.on('beforeSetDataSource',function(data){
          //处理JS单线程,异步问题
          if(!viewModel.getCache('isSelfExecute')){
             data.forEach((dataitem,index)=>{
                const Param ={};
                //设置参照编码、参照类型(grid\Tree\TreeList)
                if (dataitem.ctrttype == '1') {
                  Param.refCode = 'productcenter.aa_warehouse';
                  Param.dataType='grid';
                } else if (dataitem.ctrttype == '2') {
                  Param.refCode = 'productcenter.pc_mallordershopref';
                  Param.dataType='grid';
                }
                //通过参照接口,获取最新name值
                const proxy = viewModel.setProxy({
                  getRefData:{
                    url:'bill/ref/getRefData',
                    method:'POST'
                  }
                });
                const condition = {
                  isExtend: true,
                  simpleVOs: []
                };
                condition.simpleVOs.push({
                    field: 'id', 
                    op: 'eq', 
                    value1: dataitem.ziduan3
                });
                Object.assign(Param, {condition: condition});
                proxy.getRefData(Param,function(error,result){
                  if (error) {
                    console.error('getRefData:' + error.message);
                    return false;
                  }
                  if(Param.dataType == 'grid'){
                    dataitem.canzhaoziduan=result.recordList[0].name;
                  }
                  if(['Tree','TreeList'].indexOf(Param.dataType)>-1){
                    //此时可通过看返回值,赋值即可
                  }
                  if(index == (data.length-1)){
                    viewModel.setCache('isSelfExecute',true);
                    gridModelInfo.setState('dataSourceMode','local');
                    //设置表格数据
                    gridModelInfo.setDataSource(data);
                  }
                })
            })
            return false;
          }
          viewModel.clearCache('isSelfExecute');
        });
    
      }
    
Copyright © 用友 -【生态技术部】 2021 all right reserved,powered by Gitbook修订时间: 2021-12-07 19:02:02

results matching ""

    No results matching ""