import { ViewTool, Util, LogUtil, throttle } from '@ibizstudio/runtime';
import { MDControlBase } from './md-control-base';
import { AppDataViewService } from '../ctrl-service';
import { AppViewLogicService } from '../app-service';
import { notNilEmpty } from 'qx-util';
/**
 * 数据视图部件基类
 *
 * @export
 * @class DataViewControlBase
 * @extends {MDControlBase}
 */
export class DataViewControlBase extends MDControlBase {
    constructor() {
        super(...arguments);
        /**
         * 分组属性
         *
         * @type {string}
         * @memberof DataViewControlBase
         */
        this.groupAppField = '';
        /**
         * 分组属性代码表标识
         *
         * @type {string}
         * @memberof DataViewControlBase
         */
        this.groupAppFieldCodelistTag = '';
        /**
         * 分组属性是否配置代码表
         *
         * @type {string}
         * @memberof DataViewControlBase
         */
        this.groupFieldCodelist = false;
        /**
         * 分组属性代码表类型
         *
         * @type {string}
         * @memberof DataViewControlBase
         */
        this.groupAppFieldCodelistType = '';
        /**
         * 分组代码表标识
         *
         * @type {string}
         * @memberof DataViewControlBase
         */
        this.codelistTag = '';
        /**
         * 分组代码表类型
         *
         * @type {string}
         * @memberof DataViewControlBase
         */
        this.codelistType = '';
        /**
         * 分组数据
         *
         * @type {*}
         * @memberof DataViewControlBase
         */
        this.groupData = [];
        /**
         * 分组模式
         *
         * @type {string}
         * @memberof DataViewControlBase
         */
        this.groupMode = '';
        /**
         * 加载的数据是否附加在items之后
         *
         * @type {boolean}
         * @memberof DataViewControlBase
         */
        this.isAddBehind = false;
        /**
         * 是否启用分组
         *
         * @type {boolean}
         * @memberof DataViewControlBase
         */
        this.isEnableGroup = false;
        /**
         * 排序字段
         *
         * @type {string}
         * @memberof DataViewControlBase
         */
        this.sortField = '';
        /**
         * 排序模型数据集
         *
         * @type {string}
         * @memberof DataViewControlBase
         */
        this.sortModel = [];
        /**
         * 排序方向
         *
         * @type {string}
         * @memberof DataViewControlBase
         */
        this.sortDir = '';
        /**
         * 默认隐藏批量操作工具栏
         *
         * @type {boolean}
         * @memberof DataViewControlBase
         */
        this.flag = false;
        /**
         * 是否显示排序栏
         *
         * @type {boolean}
         * @memberof DataViewControlBase
         */
        this.hasSortBar = false;
        /**
         * this引用
         *
         * @type {number}
         * @memberof DataViewControlBase
         */
        this.thisRef = this;
        /**
         * 拖拽标识
         *
         * @type {boolean}
         * @memberof DataViewControlBase
         */
        this.dragflag = false;
        /**
         * 为拖拽不是点击
         *
         * @type {boolean}
         * @memberof DataViewControlBase
         */
        this.moveflag = false;
    }
    /**
     * 监听静态参数变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof DataViewControlBase
     */
    onStaticPropsChange(newVal, oldVal) {
        this.isSingleSelect = newVal.isSingleSelect !== false;
        this.isSelectFirstDefault = newVal.isSelectFirstDefault;
        super.onStaticPropsChange(newVal, oldVal);
    }
    /**
     * 部件模型初始化
     *
     * @memberof DataViewControlBase
     */
    async ctrlModelInit() {
        var _a, _b, _c, _d, _e;
        super.ctrlModelInit();
        if (!(this.Environment && this.Environment.isPreviewMode)) {
            this.service = new AppDataViewService(this.controlInstance, this.context);
            await this.service.loaded();
        }
        this.initSortModel();
        const m = this.controlInstance;
        this.sortField = (_b = (_a = m.getMinorSortPSAppDEField()) === null || _a === void 0 ? void 0 : _a.codeName) === null || _b === void 0 ? void 0 : _b.toLowerCase();
        this.sortDir = (_c = m.minorSortDir) === null || _c === void 0 ? void 0 : _c.toLowerCase();
        this.isEnableGroup = m.enableGroup ? true : false;
        this.groupMode = m.groupMode;
        this.groupAppField = ((_d = m.getGroupPSAppDEField()) === null || _d === void 0 ? void 0 : _d.codeName.toLowerCase()) || '';
        // 代码表参数
        const codeList = m.getGroupPSCodeList();
        if (codeList) {
            this.groupCodeListParams = {
                type: codeList.codeListType,
                tag: codeList.codeName,
                context: this.context,
                viewparam: this.viewparams,
            };
        }
        // 计算是否显示排序栏
        const dataViewItems = this.controlInstance.getPSDEDataViewDataItems() || [];
        if (dataViewItems.length > 0) {
            this.hasSortBar = dataViewItems.some((dataItem) => {
                var _a;
                return dataItem.getPSAppDEField() && !((_a = dataItem.getPSAppDEField()) === null || _a === void 0 ? void 0 : _a.keyField);
            });
        }
        this.limit = ((_e = this.controlInstance) === null || _e === void 0 ? void 0 : _e.pagingSize) || this.limit;
    }
    /**
     * 初始化排序模型数据
     *
     * @memberof DataViewControlBase
     */
    initSortModel() {
        var _a;
        this.sortModel = [];
        (_a = this.controlInstance.getPSDEDataViewItems()) === null || _a === void 0 ? void 0 : _a.forEach((cardViewItem) => {
            var _a;
            if (cardViewItem.enableSort) {
                const data = {
                    id: cardViewItem.dataItemName,
                    caption: this.$tl((_a = cardViewItem.getCapPSLanguageRes()) === null || _a === void 0 ? void 0 : _a.lanResTag, cardViewItem.caption)
                };
                this.sortModel.push(data);
            }
        });
    }
    /**
     * 初始化数据映射
     *
     * @memberof ListControlBase
     */
    initDataMap() {
        const dataItems = this.controlInstance.getPSDEDataViewDataItems();
        if (dataItems && dataItems.length > 0) {
            dataItems.forEach((dataItem) => {
                this.dataMap.set(dataItem.name, { customCode: dataItem.customCode ? true : false });
            });
        }
    }
    /**
     * 数据视图部件初始化
     *
     * @memberof DataViewControlBase
     */
    ctrlInit() {
        super.ctrlInit();
        // 绑定this
        this.transformData = this.transformData.bind(this);
        this.remove = this.remove.bind(this);
        this.refresh = this.refresh.bind(this);
    }
    viewStateAction(tag, action, data) {
        if (!Object.is(tag, this.name)) {
            return;
        }
        super.viewStateAction(tag, action, data);
        if (Object.is(action, 'load')) {
            this.refresh(data);
        }
        if (Object.is(action, 'filter')) {
            this.refresh(data);
        }
        if (Object.is(action, 'save')) {
            this.save(data);
        }
    }
    /**
     * 初始化界面行为模型
     *
     * @type {*}
     * @memberof DataViewControlBase
     */
    initCtrlActionModel() {
        var _a;
        let cardViewItems = this.controlInstance.getPSDEDataViewItems() || [];
        if ((cardViewItems === null || cardViewItems === void 0 ? void 0 : cardViewItems.length) > 0) {
            for (let cardItem of cardViewItems) {
                let groupDetails = ((_a = cardItem.getPSDEUIActionGroup()) === null || _a === void 0 ? void 0 : _a.getPSUIActionGroupDetails()) || [];
                if ((groupDetails === null || groupDetails === void 0 ? void 0 : groupDetails.length) > 0) {
                    for (let uiActionDetail of groupDetails) {
                        if (uiActionDetail === null || uiActionDetail === void 0 ? void 0 : uiActionDetail.getPSUIAction()) {
                            const appUIAction = Util.deepCopy(uiActionDetail.getPSUIAction());
                            this.actionModel[appUIAction.uIActionTag] = Object.assign(appUIAction, {
                                disabled: false,
                                visabled: true,
                                getNoPrivDisplayMode: appUIAction.noPrivDisplayMode ? appUIAction.noPrivDisplayMode : 6,
                            });
                        }
                    }
                }
            }
        }
    }
    /**
     * 数据加载
     *
     * @param {*} [opt={}] 额外参数
     * @param {boolean} [isReset=false] 是否重置数据，默认加载到的数据附加在已有的之后
     * @return {*}
     * @memberof DataViewControlBase
     */
    load(opt = {}, isReset = false) {
        return new Promise((resolve, reject) => {
            if (!this.fetchAction) {
                this.$throw(`${this.controlInstance.codeName}` + this.$t('app.list.notconfig.fetchaction'), 'load');
                reject();
                return;
            }
            const arg = {};
            const page = {};
            if (this.isEnablePagingBar) {
                Object.assign(page, { page: this.curPage - 1, size: this.limit });
            }
            // 设置排序
            if (!this.isNoSort && !Object.is(this.sortDir, '') && !Object.is(this.sortField, '')) {
                const sort = this.sortField + ',' + this.sortDir;
                Object.assign(page, { sort: sort });
            }
            Object.assign(arg, page);
            const parentdata = {};
            this.$emit('ctrl-event', { controlname: this.controlInstance.name, action: 'beforeload', data: parentdata });
            Object.assign(arg, parentdata);
            let tempViewParams = parentdata.viewparams ? parentdata.viewparams : opt ? opt : {};
            Object.assign(tempViewParams, Util.deepCopy(this.viewparams));
            Object.assign(arg, { viewparams: tempViewParams }, opt);
            if (this.service) {
                let tempContext = Util.deepCopy(this.context);
                this.onControlRequset('load', tempContext, arg);
                const post = this.service.search(this.fetchAction, tempContext, arg, this.showBusyIndicator);
                post.then((response) => {
                    this.onControlResponse('load', response);
                    if (!response || response.status !== 200) {
                        this.$throw(response, 'load');
                        return;
                    }
                    const data = response.data;
                    if (!this.isAddBehind) {
                        this.items = [];
                    }
                    if (Object.keys(data).length > 0) {
                        let datas = Util.deepCopy(data);
                        datas.map((item) => {
                            if (!item.srfchecked) {
                                Object.assign(item, { srfchecked: 0 });
                            }
                        });
                        this.totalRecord = response.total;
                        if (isReset) {
                            this.items = datas;
                        }
                        else {
                            this.items.push(...datas);
                        }
                    }
                    this.isAddBehind = false;
                    this.items.forEach((item) => {
                        Object.assign(item, this.getActionState(item));
                    });
                    this.$emit('ctrl-event', {
                        controlname: this.controlInstance.name,
                        action: 'load',
                        data: this.items,
                    });
                    //在导航视图中，如已有选中数据，则右侧展开已选中数据的视图，如无选中数据则默认选中第一条
                    if (this.isSelectFirstDefault) {
                        if (this.selections && this.selections.length > 0) {
                            this.selections.forEach((select) => {
                                const index = this.items.findIndex((item) => Object.is(item.srfkey, select.srfkey));
                                if (index != -1) {
                                    this.handleClick(this.items[index]);
                                }
                            });
                        }
                        else {
                            this.handleClick(this.items[0]);
                        }
                    }
                    if (this.isEnableGroup) {
                        this.group();
                    }
                    resolve(response);
                }, (response) => {
                    this.onControlResponse('load', response);
                    this.$throw(response, 'load');
                    reject(response);
                });
            }
        });
    }
    /**
     * 删除
     *
     * @param {any[]} datas 删除数据
     * @returns {Promise<any>}
     * @memberof DataViewControlBase
     */
    async remove(datas) {
        if (!this.removeAction) {
            this.$throw(`${this.controlInstance.codeName}` + this.$t('app.grid.notconfig.removeaction'), 'remove');
            return;
        }
        let _datas = [];
        datas.forEach((record, index) => {
            if (Object.is(record.srfuf, '0')) {
                this.items.some((val, num) => {
                    if (JSON.stringify(val) == JSON.stringify(record)) {
                        this.items.splice(num, 1);
                        return true;
                    }
                });
            }
            else {
                _datas.push(datas[index]);
            }
        });
        if (_datas.length === 0) {
            return;
        }
        let dataInfo = '';
        _datas.forEach((record, index) => {
            let srfmajortext = record.srfmajortext;
            if (index < 5) {
                if (!Object.is(dataInfo, '')) {
                    dataInfo += '、';
                }
                dataInfo += srfmajortext;
            }
            else {
                return false;
            }
        });
        if (_datas.length < 5) {
            dataInfo = dataInfo + ' ' + this.$t('app.dataview.sum') + _datas.length + this.$t('app.dataview.data');
        }
        else {
            dataInfo = dataInfo + '...' + ' ' + this.$t('app.dataview.sum') + _datas.length + this.$t('app.dataview.data');
        }
        const removeData = () => {
            let keys = [];
            _datas.forEach((data) => {
                keys.push(data.srfkey);
            });
            let _removeAction = keys.length > 1 ? 'removeBatch' : this.removeAction;
            const tempContext = Util.deepCopy(this.context);
            const appDeCodeName = this.appDeCodeName.toLowerCase();
            Object.assign(tempContext, { [appDeCodeName]: keys.join(';') });
            const arg = { [appDeCodeName]: keys.join(';') };
            Object.assign(arg, { viewparams: this.viewparams }), this.onControlRequset('remove', tempContext, arg);
            const post = this.service.delete(_removeAction, tempContext, arg, this.showBusyIndicator);
            return new Promise((resolve, reject) => {
                post
                    .then((response) => {
                    this.onControlResponse('remove', response);
                    if (!response || response.status !== 200) {
                        this.$throw(response, 'remove');
                        return;
                    }
                    else {
                        this.$success(this.$t('app.commonwords.deletesuccess'), 'remove');
                    }
                    //删除items中已删除的项
                    _datas.forEach((data) => {
                        this.items.some((item, index) => {
                            if (Object.is(item.srfkey, data.srfkey)) {
                                this.items.splice(index, 1);
                                // <#if ctrl.isEnableGroup?? && ctrl.isEnableGroup()>
                                // this.group();
                                // </#if>
                                return true;
                            }
                        });
                    });
                    this.$emit('ctrl-event', { controlname: this.controlInstance.name, action: 'remove', data: {} });
                    this.selections = [];
                    resolve(response);
                })
                    .catch((response) => {
                    this.onControlResponse('remove', response);
                    this.$throw(response, 'remove');
                    reject(response);
                });
            });
        };
        dataInfo = dataInfo
            .replace(/[null]/g, '')
            .replace(/[undefined]/g, '')
            .replace(/[ ]/g, '');
        this.$Modal.confirm({
            title: this.$t('app.commonwords.warning'),
            content: this.$t('app.grid.confirmdel') + ' ' + dataInfo + '，' + this.$t('app.grid.notrecoverable'),
            onOk: () => {
                removeData();
            },
            onCancel: () => { },
        });
        return removeData;
    }
    /**
     * 保存
     *
     * @param {any[]} args 额外参数
     * @return {*}
     * @memberof DataViewControlBase
     */
    async save(args) {
        var _a, _b, _c;
        let _this = this;
        let successItems = [];
        let errorItems = [];
        let errorMessage = [];
        for (const item of _this.items) {
            try {
                if (Object.is(item.rowDataState, 'create')) {
                    if (!this.createAction) {
                        this.$throw(`${this.controlInstance.codeName}` + this.$t('app.list.notconfig.createaction'), 'save');
                    }
                    else {
                        Object.assign(item, { viewparams: this.viewparams });
                        let tempContext = Util.deepCopy(this.context);
                        this.onControlRequset('create', tempContext, item);
                        let response = await this.service.add(this.createAction, tempContext, item, this.showBusyIndicator);
                        this.onControlResponse('create', response);
                        successItems.push(Util.deepCopy(response.data));
                    }
                }
                else if (Object.is(item.rowDataState, 'update')) {
                    if (!this.updateAction) {
                        this.$throw(`${this.controlInstance.codeName}` + this.$t('app.list.notconfig.updateaction'), 'save');
                    }
                    else {
                        Object.assign(item, { viewparams: this.viewparams });
                        if (item[(_a = this.appDeCodeName) === null || _a === void 0 ? void 0 : _a.toLowerCase()]) {
                            Object.assign(this.context, { [(_b = this.appDeCodeName) === null || _b === void 0 ? void 0 : _b.toLowerCase()]: item[(_c = this.appDeCodeName) === null || _c === void 0 ? void 0 : _c.toLowerCase()] });
                        }
                        let tempContext = Util.deepCopy(this.context);
                        this.onControlRequset('update', tempContext, item);
                        let response = await this.service.add(this.updateAction, tempContext, item, this.showBusyIndicator);
                        this.onControlResponse('update', response);
                        successItems.push(Util.deepCopy(response.data));
                    }
                }
            }
            catch (error) {
                this.onControlResponse('save', error);
                errorItems.push(Util.deepCopy(item));
                errorMessage.push(error);
            }
        }
        this.$emit('ctrl-event', { controlname: this.controlInstance.name, action: 'save', data: successItems });
        this.refresh();
        if (errorItems.length === 0) {
            if ((args === null || args === void 0 ? void 0 : args.showResultInfo) || (args && !args.hasOwnProperty('showResultInfo'))) {
                this.$success(this.$t('app.commonwords.savesuccess'), 'save');
            }
        }
        else {
            errorItems.forEach((item, index) => {
                this.$throw(item.majorentityname + this.$t('app.commonwords.savefailed') + '!', 'save');
            });
        }
        return successItems;
    }
    /**
     * 刷新
     *
     * @param {*} [args={}] 额外参数
     * @memberof DataViewControlBase
     */
    async refresh(args) {
        this.curPage = 1;
        return this.load(args, true);
    }
    /**
     * 加载更多
     *
     * @memberof DataViewControlBase
     */
    async loadMore() {
        if (this.totalRecord > this.items.length) {
            this.curPage = ++this.curPage;
            this.isAddBehind = true;
            return this.load({});
        }
    }
    /**
     * 单击事件
     *
     * @param {*} args 数据
     * @memberof DataViewControlBase
     */
    handleClick(args) {
        if (this.mDCtrlActiveMode === 1) {
            this.ctrlEvent({ controlname: this.controlInstance.name, action: 'rowclick', data: args });
            return;
        }
        args.srfchecked = Number(!args.srfchecked);
        if (this.isSingleSelect) {
            this.items.forEach((item) => {
                if (item.srfkey !== args.srfkey) {
                    item.srfchecked = 0;
                }
            });
        }
        this.selectchange();
    }
    /**
     * 触发事件
     *
     * @memberof DataViewControlBase
     */
    selectchange() {
        this.selections = [];
        this.items.map((item) => {
            if (item.srfchecked === 1) {
                this.selections.push(item);
            }
        });
        this.$emit('ctrl-event', {
            controlname: this.controlInstance.name,
            action: 'selectionchange',
            data: this.selections,
        });
    }
    /**
     * 面板数据变化处理事件
     * @param {any} item 当前卡片数据
     * @param {any} $event 面板事件数据
     *
     * @memberof DataViewControlBase
     */
    onPanelDataChange(item, $event) {
        Object.assign(item, $event, { rowDataState: 'update' });
    }
    /**
     * 双击事件
     *
     * @param {*} args 数据
     * @memberof DataViewControlBase
     */
    handleDblClick(args) {
        if (this.mDCtrlActiveMode !== 0) {
            this.$emit('ctrl-event', { controlname: this.controlInstance.name, action: 'rowdblclick', data: args });
        }
    }
    /**
     * 处理操作列点击
     *
     * @param {*} data 数据
     * @param {*} event 事件源
     * @param {*} item 数据视图项模型
     * @param {*} detail 操作列模型
     * @memberof DataViewControlBase
     */
    handleActionClick(data, event, item, detail) {
        AppViewLogicService.getInstance().executeViewLogic(this.getViewLogicTag('dataviewexpbar_dataview', item.dataItemName, detail.name), event, this, data, this.controlInstance.getPSAppViewLogics());
    }
    /**
     * 排序点击事件
     * @param {string} field 属性名
     *
     * @memberof DataViewControlBase
     */
    sortClick(field) {
        if (this.sortField !== field) {
            this.sortField = field;
            this.sortDir = 'asc';
        }
        else if (this.sortDir === 'asc') {
            this.sortDir = 'desc';
        }
        else if (this.sortDir === 'desc') {
            this.sortDir = '';
        }
        else {
            this.sortDir = 'asc';
        }
        this.refresh();
    }
    /**
     * 分组方法
     *
     * @memberof DataViewControlBase
     */
    group() {
        if (Object.is(this.groupMode, 'AUTO')) {
            this.drawGroup();
        }
        else if (Object.is(this.groupMode, 'CODELIST')) {
            this.drawCodeListGroup();
        }
    }
    /**
     * 部件事件
     *
     * @param {string} controlname 部件名
     * @param {string} action 事件名
     * @param {*} data 数据
     * @memberof DataViewControlBase
     */
    onCtrlEvent(controlname, action, data) {
        super.onCtrlEvent(controlname, action, data);
        if (action == 'panelDataChange') {
            this.onPanelDataChange(data.item, data.data);
        }
    }
    /**
     * 计算卡片视图部件所需参数
     *
     * @param {*} controlInstance 部件模型对象
     * @param {*} item 单条卡片数据
     * @returns
     * @memberof DataViewControlBase
     */
    computeTargetCtrlData(controlInstance, item) {
        const { targetCtrlName, targetCtrlParam, targetCtrlEvent } = super.computeTargetCtrlData(controlInstance);
        Object.assign(targetCtrlParam.dynamicProps, {
            navdatas: [item],
        });
        Object.assign(targetCtrlParam.staticProps, {
            transformData: this.transformData,
            opendata: this.opendata,
            newdata: this.newdata,
            remove: this.remove,
            refresh: this.refresh,
            dataMap: this.dataMap,
        });
        targetCtrlEvent['ctrl-event'] = ({ controlname, action, data }) => {
            this.onCtrlEvent(controlname, action, { item: item, data: data });
        };
        return { targetCtrlName, targetCtrlParam, targetCtrlEvent };
    }
    /**
     * 绘制数据视图内容
     *
     * @memberof DataViewControlBase
     */
    renderDataViewContent(h) {
        if (!this.isEnableGroup) {
            return this.items.map((item, index) => {
                let cardViewItems = this.controlInstance.getPSDEDataViewItems() || [];
                let dataViewItem = cardViewItems[index] ? cardViewItems[index] : null;
                return (<a href={item.starturl}>
            <i-col style='margin-bottom: 10px'>{this.renderCard(h, item, dataViewItem)}</i-col>
          </a>);
            });
        }
        else {
            return <el-collapse>{this.renderGroup(h)}</el-collapse>;
        }
    }
    /**
     * 批操作工具栏
     *
     * @memberof DataViewControlBase
     */
    renderBatchToolbar() {
        if (this.batchToolbarInstance) {
            return (<div class='drag-filed' on-mousedown={($event) => this.down($event)}>
          <row class='dataview-pagination'>
            <div v-show={this.flag}>{super.renderBatchToolbar()}</div>
            <div class='dataview-pagination-icon'>
              <icon type='md-code-working' on-click={($event) => throttle(this.onClick, [$event], this)}/>
            </div>
          </row>
        </div>);
        }
    }
    /**
     * 更改批量操作工具栏显示状态
     *
     * @param $event 时间源
     * @memberof DataViewControlBase
     */
    onClick($event) {
        if (!this.moveflag) {
            this.flag = !this.flag;
        }
        this.moveflag = false;
    }
    /**
     * 绘制加载数据提示信息
     *
     * @memberof DataViewControlBase
     */
    renderLoadDataTip() {
        return (<div v-show={this.items.length == 0} class='app-data-empty' style={{ height: this.hasSortBar ? 'calc(100% - 42px)' : '100%' }}>
        {super.renderLoadDataTip()}
      </div>);
    }
    /**
     * 绘制无数据提示信息
     *
     * @memberof DataViewControlBase
     */
    renderEmptyDataTip() {
        return (<div v-show={this.items.length == 0} class='app-data-empty' style={{ height: this.hasSortBar ? 'calc(100% - 42px)' : '100%' }}>
        {super.renderEmptyDataTip()}
      </div>);
    }
    /**
     * 分组
     *
     */
    renderGroup(h) {
        return this.groupData.map((group, index) => {
            let cardViewItems = this.controlInstance.getPSDEDataViewItems() || [];
            let dataViewItem = cardViewItems[index] ? cardViewItems[index] : null;
            return (<el-collapse-item>
          <template slot='title'>
            <div style='margin: 0 0 0 12px;'>
              <b>{group.group}</b>
            </div>
          </template>
          {this.hasChildrenRender(h, group, dataViewItem)}
        </el-collapse-item>);
        });
    }
    /**
     * 绘制有子成员的项
     *
     */
    hasChildrenRender(h, group, dataViewItem) {
        if (group.children.length > 0) {
            return group.children.map((groupChild, index) => {
                return (<a href={groupChild.starturl}>
            <i-col style='min-height: 170px;margin-bottom: 10px;'>{this.renderCard(h, groupChild, dataViewItem)}</i-col>
          </a>);
            });
        }
        else {
            return (<div v-else class='item-nodata'>
          {this.$t('app.commonwords.nodata')}
        </div>);
        }
    }
    /**
     * 绘制卡片
     *
     * @memberof DataViewControlBase
     */
    renderCard(h, args, dataViewItem) {
        const style = {
            width: this.controlInstance.cardWidth > 0 ? `${this.controlInstance.cardWidth}px` : false,
            height: this.controlInstance.cardHeight > 0 ? `${this.controlInstance.cardHeight}px` : false,
        };
        return (<el-card shadow='always' body-style={style} class={[args.srfchecked === 1 ? 'isselected' : false, 'single-card-data']} nativeOnClick={() => throttle(this.handleClick, [args], this)} nativeOnDblclick={() => throttle(this.handleDblClick, [args], this)}>
        {this.controlInstance.getItemPSLayoutPanel() ? this.renderItemPSLayoutPanel(args) : this.renderDataViewItem(h, args, dataViewItem)}
      </el-card>);
    }
    /**
     * 绘制DataViewItem
     *
     * @memberof DataViewControlBase
     */
    renderDataViewItem(h, item, dataViewItem) {
        if (this.controlInstance.getItemPSSysPFPlugin()) {
            const pluginInstance = this.PluginFactory.getPluginInstance('CONTROLITEM', this.controlInstance.getItemPSSysPFPlugin().pluginCode);
            if (pluginInstance) {
                return pluginInstance.renderCtrlItem(this.$createElement, dataViewItem, this, item);
            }
        }
        else {
            return [
                <div class='data-view-item'>
          <div class='single-card-default'>
            <div calss='item-title'>
              {dataViewItem.getPSCodeList() ? (<codelist codeList={dataViewItem.getPSCodeList()} value={item.srfmajortext} data={item} context={this.context} viewparams={this.viewparams}></codelist>) : (<tooltip>
                  <p v-format={dataViewItem.valueFormat}>{item.srfmajortext}</p>
                  <p slot='content' v-format={dataViewItem.valueFormat}>
                    {item.srfmajortext}
                  </p>
                </tooltip>)}
            </div>
            {item.content && <div class='item-content'>{item.content}</div>}
          </div>
        </div>,
                <div class='data-view-item-action'>{dataViewItem ? this.renderDataViewItemAction(h, item, dataViewItem) : ''}</div>,
            ];
        }
    }
    /**
     * 绘制卡片视图项布局面板部件
     *
     * @returns {*}
     * @memberof DataViewControlBase
     */
    renderItemPSLayoutPanel(item) {
        var _a;
        let { targetCtrlName, targetCtrlParam, targetCtrlEvent } = this.computeTargetCtrlData(this.controlInstance.getItemPSLayoutPanel(), item);
        return this.$createElement(targetCtrlName, {
            props: targetCtrlParam,
            ref: (_a = this.controlInstance.getItemPSLayoutPanel()) === null || _a === void 0 ? void 0 : _a.name,
            on: targetCtrlEvent,
        });
    }
    /**
     * 绘制列表项行为
     * @param item
     * @param dataViewItem
     * @memberof DataViewControlBase
     */
    renderDataViewItemAction(h, args, dataViewItem) {
        const UIActionGroup = dataViewItem.getPSDEUIActionGroup();
        return (UIActionGroup &&
            UIActionGroup.getPSUIActionGroupDetails().map((uiactionDetail, index) => {
                var _a, _b;
                const uiaction = uiactionDetail.getPSUIAction();
                if (args[uiaction.uIActionTag].visabled) {
                    return (<button type='info' disabled={args[uiaction.uIActionTag].disabled} on-click={($event) => {
                            throttle(this.handleActionClick, [args, $event, dataViewItem, uiactionDetail], this);
                        }}>
              {uiactionDetail.showIcon ? <i class={(_a = uiaction === null || uiaction === void 0 ? void 0 : uiaction.getPSSysImage()) === null || _a === void 0 ? void 0 : _a.cssClass} style='margin-right:2px;'></i> : ''}
              <span>{uiactionDetail.showCaption ? this.$tl((_b = uiaction.getCapPSLanguageRes()) === null || _b === void 0 ? void 0 : _b.lanResTag, (uiaction === null || uiaction === void 0 ? void 0 : uiaction.caption) ? uiaction.caption : '') : ''}</span>
            </button>);
                }
            }));
    }
    /**
     * 绘制排序栏
     *
     * @memberof DataViewControlBase
     */
    renderSortBar(h) {
        const appDataEntity = this.controlInstance.getPSAppDataEntity();
        if (this.hasSortBar) {
            return (<app-sort-bar sortModel={this.sortModel} sortField={this.sortField} sortDir={this.sortDir} entityName={appDataEntity === null || appDataEntity === void 0 ? void 0 : appDataEntity.codeName} on-clickSort={(val) => throttle(this.sortClick, [val], this)}></app-sort-bar>);
        }
    }
    /**
     * 根据分组代码表绘制分组列表
     *
     * @memberof DataViewControlBase
     */
    async drawCodeListGroup() {
        let groups = [];
        const groupTree = [];
        const data = [...this.items];
        if (this.groupCodeListParams) {
            let groupCodelist = await this.codeListService.getDataItems(this.groupCodeListParams);
            groups = Util.deepCopy(groupCodelist);
        }
        if (groups.length == 0) {
            LogUtil.warn(this.$t('app.dataview.useless'));
        }
        const map = new Map();
        data.forEach(item => {
            const tag = item[this.groupAppField];
            if (notNilEmpty(tag)) {
                if (!map.has(tag)) {
                    map.set(tag, []);
                }
                const arr = map.get(tag);
                arr.push(item);
            }
        });
        groups.forEach((group) => {
            const children = [];
            if (this.groupFieldCodelist && map.has(group.label)) {
                children.push(...map.get(group.label));
            }
            else if (map.has(group.value)) {
                children.push(...map.get(group.value));
            }
            const item = {
                label: group.label,
                group: group.label,
                data: group,
                children,
            };
            groupTree.push(item);
        });
        const child = [];
        data.forEach((item) => {
            let i = 0;
            if (this.groupFieldCodelist) {
                i = groups.findIndex((group) => Object.is(group.label, item[this.groupAppField]));
            }
            else {
                i = groups.findIndex((group) => Object.is(group.value, item[this.groupAppField]));
            }
            if (i < 0) {
                child.push(item);
            }
        });
        const Tree = {
            label: this.$t('app.commonwords.other'),
            group: this.$t('app.commonwords.other'),
            children: child,
        };
        if (child && child.length > 0) {
            groupTree.push(Tree);
        }
        this.groupData = groupTree;
    }
    /**
     * 绘制分组列表
     *
     * @memberof DataViewControlBase
     */
    async drawGroup() {
        const data = [...this.items];
        let groups = [];
        data.forEach((item) => {
            if (item.hasOwnProperty(this.groupAppField)) {
                groups.push(item[this.groupAppField]);
            }
        });
        groups = [...new Set(groups)];
        if (groups.length == 0) {
            LogUtil.warn(this.$t('app.dataview.useless'));
        }
        const groupTree = [];
        groups.forEach((group, i) => {
            const children = [];
            data.forEach((item, j) => {
                if (Object.is(group, item[this.groupAppField])) {
                    children.push(item);
                }
            });
            group = group ? group : this.$t('app.commonwords.other');
            const tree = {
                label: group,
                group: group,
                children: children,
            };
            groupTree.push(tree);
        });
        this.groupData = groupTree;
    }
    /**
     * 排序class变更
     * @param {string} field 属性名
     *
     * @memberof DataViewControlBase
     */
    getsortClass(field) {
        if (this.sortField !== field || this.sortDir === '') {
            return '';
        }
        else if (this.sortDir === 'asc') {
            return 'sort-ascending';
        }
        else if (this.sortDir === 'desc') {
            return 'sort-descending';
        }
    }
    /**
     * 鼠标移动+放下
     *
     * @memberof DataViewControlBase
     */
    mouseEvent() {
        if (typeof this.$el.getElementsByClassName == 'function') {
            this.dragEle = this.$el.getElementsByClassName('drag-filed')[0];
        }
        document.onmousemove = (e) => {
            if (this.dragflag) {
                this.dragEle.style.left = e.clientX - this.leftP + 'px';
                this.dragEle.style.top = e.clientY - this.topP + 'px';
                this.moveflag = true;
            }
        };
        document.onmouseup = (e) => {
            this.dragflag = false;
        };
    }
    /**
     * mousedown事件
     *
     * @param e 事件源
     * @memberof DataViewControlBase
     */
    down(e) {
        this.leftP = e.clientX - this.dragEle.offsetLeft;
        this.topP = e.clientY - this.dragEle.offsetTop;
        this.dragflag = true;
    }
    /**
     * 获取界面行为权限状态
     *
     * @param {*} data 当前列表行数据
     * @memberof DataViewControlBase
     */
    getActionState(data) {
        let tempActionModel = Util.deepCopy(this.actionModel);
        let targetData = this.transformData(data);
        ViewTool.calcActionItemAuthState(targetData, tempActionModel, this.appUIService);
        return tempActionModel;
    }
}
