/**
 * 编辑网格带添加，删除操作列
 * @param {*} dlgId 对话框随机id,防止id冲突与数据集id统一命名引用
 * @param {*} dsId 绑定过滤数据集ID
 * @param {*} conf 扩展配置
 * @returns 
 */
import { $HCBIRT } from "@birt/funclib/HCBIRT";

export function editTable(dlgId, dsId, conf) {
    debugger
    // 表单网格明细
    var hcTable = {
        controlName: "HcTable",
        controlId: "HcTable_" + dlgId,
        dataset: dsId,
        highlightCurrentRow: true,
        width: $HCBIRT.formWidth,
        height: 260,
        size: "small",
        // showSummary:true,
        children: [],
        style: "margin:auto;"
    };
    // 应用网格个性化配置
    Object.assign(hcTable, conf.hcTable || {});
    // 编辑网格，操作列 
    if (hcTable.isEdit) {
        let operateColumn = {
            controlName: "HcTableColumnScope",
            controlId: "HcTableColumn_operate",
            label: "操作",
            width: 100,
            headerAlign: "center",
            fixed: "right",
            slot: "scope",
            children: [
                {
                    controlName: "HcButton",
                    controlId: "HcButton_add",
                    type: "primary",
                    circle: true,
                    icon: "el-icon-plus",
                    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",
                    circle: true,
                    icon: "el-icon-delete",
                    disabled: function () {
                        
                        return this.store && this.store.allowRemove && !this.store.allowRemove();
                    },
                    events: {
                        click() {
                            this.store.remove(this.scope.row);
                        },
                    },
                },
            ],
        }
        hcTable.children.push(operateColumn);
    }
    return hcTable
}