08335 / hivui-platform-template
hivui平台项目模板
Newer
Older
hivui-platform-template / project / hivuiBirt / templates / pages / TabTableSave.js
/**
 * 查询方案、查询面板、工具条、网格,标准查询页面
 * @param {*} queryDataset 保存数据集,命名规范 ds_[数组下标]_[对话框id]
 * @param {*} conf 组件定义配置项
 * @returns 
 */
import { StringUtil } from "@birt/funclib/StringUtil.js";
import { $CONST } from "@birt/funclib/ConstUtil.js";
import axios from "@birt/funclib/AxiosUtil.js";
import {baseURL,projectName,requestUrl} from '@birt/config'
export function TabTableSave(conf) {
  debugger
    const dlgId = StringUtil.randomString(6);
    const hcTabsId = "HcTabs_" + dlgId;
    const hcTabDetailId = "detail_" + dlgId;
    // 设置数据集id,分页
    var queryDataset = conf.mainDataset;
    queryDataset.controlId += "_" + dlgId;
    var addDataset = conf.addDataset;
    addDataset.controlId += "_" + dlgId;
    queryDataset._infcPagging = {
        _isPagging: true,
        returnCount: true
    }
    addDataset._editState = true;
    // 查询面板
    let hcQueryPanel = false;
    if (conf.hcQueryPanel) {
        hcQueryPanel = {
            controlName: "HcQueryPanel",
            controlId: "HcQueryPanel_" + dlgId,
            dataset: queryDataset.controlId,
            children: []
        }
        // 应用查询面板个性化配置
        Object.assign(hcQueryPanel, conf.hcQueryPanel || {});
    }

    // 操作工具条
    let listFormToolbar = false;
    let addFormToolbar = false;
    if (conf.listFormToolbar) {
      listFormToolbar = {
        controlName: "HcFormToolbar",
        controlId: "listHcFormToolbar_" + dlgId,
        dataset: queryDataset.controlId,
        style: 'margin: 0 -4%;',
        class: 'text',
        children: [],
        deleteSucced:function(saveData){
          debugger
          this.store.resetPageStart()
          this.store.load()
        }
      }
      // 应用表单个性化配置
      Object.assign(listFormToolbar, conf.listFormToolbar || {});
    }
    if (conf.addFormToolbar) {
      addFormToolbar = {
        controlName: "HcFormToolbar",
        controlId: "addHcFormToolbar_" + dlgId,
        dataset: addDataset.controlId,
        style: 'margin: 0 -4%;',
        children: []
      }
      // 应用表单个性化配置
      Object.assign(addFormToolbar, conf.addFormToolbar || {});
    }
    const hcTableId = "HcTable_" + dlgId
    const hcTableAddId = "HcTableAdd_" + dlgId
    // 网格明细
    var hcTable = {
        controlName: "HcTable",
        controlId: "HcTable_" + dlgId,
        dataset: queryDataset.controlId,
        border: true,
        size: "small",
        showAddBtn: false,
        // showSummary:true,
        height: function (parentHeight) {
            return parentHeight - 160;
        },
        events: {
            // 双击跳转至详情页
            rowDblclick: function (row, column, event) {
                debugger
                let curtTabs = this.getRefCompt(hcTabsId);
                let pushParam = Object.assign(row);
                let eleNumber = this.store && this.store._getEleNumber();
                if (eleNumber) {
                    pushParam[$CONST.FLOWNUMBER] = row[eleNumber.field];
                }
                curtTabs.setActiveTabName(hcTabDetailId, pushParam);
            },
        },
        children: [],
    };
    // 网格新增
  var hcTableAdd = {
    isEdit: true,
    controlName: "HcTable",
    controlId: hcTableAddId,
    dataset: addDataset.controlId,
    highlightCurrentRow: true,
    height: function (parentHeight) {
      return parentHeight - 100;
    },
    size: "small",
    // showSummary:true,
    children: [],
    events: {
      currentChange: function (row) {
        this.store.setCurtRecord(row);
      }
    },
    style: "margin:auto;"
  };
  // 应用网格个性化配置
  Object.assign(hcTable, conf.hcTable || {});
  Object.assign(hcTableAdd, conf.hcTableAdd || {});
  // 操作列 
  let operateColumn = {
    controlName: "HcTableColumnScope",
    controlId: "HcTableColumn_operate",
    label: "操作",
    width: 150,
    headerAlign: "center",
    fixed: "right",
    slot: "scope",
    children: [{
      controlName: "HcButton",
      controlId: "HcButton_add",
      type: "primary",
      icon: "el-icon-plus",
      size: 'mini',
      style: 'padding: 5px 15px;',
      disabled: function () {
        return this.store && this.store.allowAdd && !this.store.allowAdd();
      },
      events: {
        click() {
          let newRecd = this.store.newRecord();
          this.store.add(newRecd);
        },
      },
    },
    {
      controlName: "HcButton",
      controlId: "HcButton_del",
      type: "danger",
      size: 'mini',
      style: 'padding: 5px 15px;',
      icon: "el-icon-delete",
      disabled: function () {
        return this.store && this.store.allowRemove && !this.store.allowRemove();
      },
      events: {
        click() {
          this.store.remove(this.scope.row);
        },
      },
    },
    ],
  }
  hcTableAdd.children.push(operateColumn);
  
    // 详情表单 
    var hcDetailForm = false;
    if (conf.hcDetailForm) {
        hcDetailForm = Object.assign(
            conf.hcDetailForm,
            {
                height: function (parentHeight) {
                    return parentHeight - 170;
                },
            })
    }

    // 分页工具条
    var hcPagination = {
        controlName: "HcPagination",
        controlId: "HcPagination_" + dlgId,
        pageSizes: [10, 20, 50, 100],
        layout: "total, prev, pager, next, sizes, jumper",
        dataset: queryDataset.controlId,
    };
    var hcTabs = {
      controlName: "HcTabs",
      controlId: hcTabsId,
      tabPosition: "top",
      activeTabName: "list_" + dlgId,
      tabPosition: 'right',
      // events: {
      //   click: function () {
      //     var tabs = this.getRefCompt(hcTabsId).activeTabName
      //     if (tabs.indexOf('detail') > -1) {
      //       this.getRefCompt('HcButton_set').$parent.$parent.$el.style.display = 'none'
      //     } else {
      //       this.getRefCompt('HcButton_set').$parent.$parent.$el.style.display = 'flex'
      //     }
      //   }
      // },
      children: [{
        controlName: "HcTabPane",
        controlId: "HcTabPane_list_" + dlgId,
        label: "列表",
        name: "list_" + dlgId,
        children: []
          .concat(hcQueryPanel ? hcQueryPanel : [])
          .concat(listFormToolbar ? listFormToolbar : [])
          .concat(hcTable)
          .concat(hcPagination)
        },
        {
          controlName: "HcTabPane",
          controlId: "HcTabPane_add" + dlgId,
          label: "批量新增",
          name: "add_" + dlgId,
          children: []
            .concat(addFormToolbar ? addFormToolbar : [])
            .concat(hcTableAdd)
        },
        {
          controlName: "HcTabPane",
          controlId: "HcTabPane_detail_" + dlgId,
          label: "详情",
          name: hcTabDetailId,
          children: []
            .concat(hcDetailForm ? hcDetailForm : [])
        },
      ],
    }

    // 应用报表模型
    var birtWorkBook = Object.assign({
        controlName: "BirtWorkBook",
        controlId: "BirtWorkBook_" + dlgId,
        showToolBar: false,
        totalPage: 1,
        renderType: "pages",
        height: function (parentHeight) {
            return parentHeight - 1;
        },
    }, conf.birtWorkBook || {})
    // 添加布局结构
    birtWorkBook.children = [{
    controlName: "BirtSheet",
    controlId: "BirtSheet_" + dlgId,
    name: "sheet_" + dlgId,
    pageIndex: 0,
    dataSets: [queryDataset, addDataset],
    children: [{
      controlName: "BirtFormSheet",
      controlId: "BirtFormSheet_" + dlgId,
      children: []
      .concat(hcTabs)
    }]
  }]
    return birtWorkBook
}