import { __decorate } from "tslib";
import { Component, Prop } from 'vue-property-decorator';
import { VueLifeCycleProcessing, EditorBase } from '@ibizstudio-ex/template-vue';
import { GetModelService, ModelTool, Util } from '@ibizstudio-ex/runtime';
import AppEmbedPicker from './components/app-embed-picker/app-embed-picker.vue';
/**
 * 上传实体名称嵌入视图插件类
 *
 * @export
 * @class UpdateEntitynamePicker
 * @extends {EditorBase}
 */
let UpdateEntitynamePicker = class UpdateEntitynamePicker extends EditorBase {
    /**
     * 编辑器初始化
     *
     * @memberof DataPickerEditor
     */
    async initEditor() {
        var _a, _b, _c, _d, _e, _f;
        await super.initEditor();
        await this.initModelService();
        // 加载链接视图和选择视图
        const pickupAppView = (_b = (_a = this.editorInstance) === null || _a === void 0 ? void 0 : _a.getPickupPSAppView) === null || _b === void 0 ? void 0 : _b.call(_a);
        const linkAppView = (_d = (_c = this.editorInstance) === null || _c === void 0 ? void 0 : _c.getLinkPSAppView) === null || _d === void 0 ? void 0 : _d.call(_c);
        await (pickupAppView === null || pickupAppView === void 0 ? void 0 : pickupAppView.fill(true));
        await (linkAppView === null || linkAppView === void 0 ? void 0 : linkAppView.fill(true));
        this.codeList = (_f = (_e = this.editorInstance) === null || _e === void 0 ? void 0 : _e.getPSAppCodeList) === null || _f === void 0 ? void 0 : _f.call(_e);
        const { placeHolder } = this.editorInstance;
        this.customProps.deMajorField = ModelTool.getEditorMajorName(this.editorInstance);
        this.customProps.deKeyField = ModelTool.getEditorKeyName(this.editorInstance);
        this.customProps.emptyText = placeHolder;
        this.customProps.viewModelData = pickupAppView || undefined;
        this.customProps.refreshitems = this.editorInstance.getParentPSModelObject().getResetItemNames();
    }
    /**
     * 初始化选择视图相关参数
     *
     * @memberof DataPickerEditor
     */
    initPickupViewParams() {
        var _a;
        const pickupAppView = this.editorInstance.getPickupPSAppView();
        if (pickupAppView) {
            const view = {
                viewname: 'app-view-shell',
                title: this.$tl((_a = pickupAppView.getCapPSLanguageRes()) === null || _a === void 0 ? void 0 : _a.lanResTag, pickupAppView.title),
                width: pickupAppView === null || pickupAppView === void 0 ? void 0 : pickupAppView.width,
                height: pickupAppView === null || pickupAppView === void 0 ? void 0 : pickupAppView.height,
                placement: pickupAppView === null || pickupAppView === void 0 ? void 0 : pickupAppView.openMode,
                isRedirectView: pickupAppView.hasOwnProperty('redirectView') ? pickupAppView.redirectView : false,
                viewpath: pickupAppView === null || pickupAppView === void 0 ? void 0 : pickupAppView.modelPath,
            };
            this.customProps.pickupView = view;
        }
    }
    /**
     * 初始化模型服务
     *
     * @memberof DataPickerEditor
     */
    async initModelService() {
        this.modelService = await GetModelService(this.context);
    }
    /**
     * 初始化链接视图相关参数
     *
     * @memberof DataPickerEditor
     */
    async initLinkViewParams() {
        var _a, _b, _c, _d;
        const linkAppView = this.editorInstance.getLinkPSAppView();
        await (linkAppView === null || linkAppView === void 0 ? void 0 : linkAppView.fill(true));
        if (linkAppView) {
            const view = {
                viewname: 'app-view-shell',
                title: this.$tl((_a = linkAppView.getCapPSLanguageRes()) === null || _a === void 0 ? void 0 : _a.lanResTag, linkAppView.title),
                width: linkAppView === null || linkAppView === void 0 ? void 0 : linkAppView.width,
                height: linkAppView === null || linkAppView === void 0 ? void 0 : linkAppView.height,
                placement: linkAppView === null || linkAppView === void 0 ? void 0 : linkAppView.openMode,
                deResParameters: Util.formatAppDERSPath(this.context, linkAppView.getPSAppDERSPaths()),
                isRedirectView: linkAppView.redirectView,
                viewpath: linkAppView === null || linkAppView === void 0 ? void 0 : linkAppView.modelPath,
            };
            Object.defineProperty(view, 'viewModel', { enumerable: false, writable: true, value: linkAppView });
            if (linkAppView === null || linkAppView === void 0 ? void 0 : linkAppView.getPSAppDataEntity()) {
                Object.assign(view, {
                    parameters: [
                        { pathName: Util.srfpluralize(((_b = linkAppView.getPSAppDataEntity()) === null || _b === void 0 ? void 0 : _b.codeName) || '').toLowerCase(), parameterName: (_c = linkAppView.getPSAppDataEntity()) === null || _c === void 0 ? void 0 : _c.codeName.toLowerCase() },
                        { pathName: 'views', parameterName: (_d = linkAppView.getPSDEViewCodeName()) === null || _d === void 0 ? void 0 : _d.toLowerCase() },
                    ],
                });
            }
            else {
                Object.assign(view, {
                    parameters: [{ pathName: 'views', parameterName: linkAppView.codeName.toLowerCase() }],
                });
            }
            this.customProps.linkview = view;
        }
    }
    /**
     * 初始化AC相关参数
     *
     * @memberof DataPickerEditor
     */
    initAcParams() {
        this.customProps.acParams = ModelTool.getAcParams(this.editorInstance);
        this.customProps.sort = ModelTool.getAcSort(this.editorInstance);
    }
    /**
     * 绘制嵌入视图
     *
     * @memberof DataPickerEditor
     */
    renderEmbedPicker() {
        var _a;
        return this.$createElement(this.editorComponentName, {
            props: Object.assign({ name: this.editorInstance.name, value: this.value, disabled: this.disabled, ignorefieldvaluechange: this.ignorefieldvaluechange, data: JSON.stringify(this.contextData), context: this.context, viewparams: this.viewparams, valueItem: ((_a = this.parentItem) === null || _a === void 0 ? void 0 : _a.valueItemName) || '' }, this.customProps),
            on: { formitemvaluechange: this.editorChange },
            style: this.customStyle,
        });
    }
    /**
     * 默认绘制
     *
     * @memberof DataPickerEditor
     */
    renderDefault() {
        var _a, _b, _c, _d;
        return this.$createElement(AppEmbedPicker, {
            props: Object.assign({ parentCodeName: (_a = this.parentItem) === null || _a === void 0 ? void 0 : _a.codeName, name: this.editorInstance.name, value: this.value, disabled: this.disabled, data: this.contextData, context: this.context, viewparams: this.viewparams, service: this.service, pickUpData: ((_b = this.editorInstance.editorParams) === null || _b === void 0 ? void 0 : _b['pickupdata']) ? (_c = this.editorInstance.editorParams) === null || _c === void 0 ? void 0 : _c['pickupdata'] : null, valueItem: ((_d = this.parentItem) === null || _d === void 0 ? void 0 : _d.valueItemName) || '' }, this.customProps),
            on: { formitemvaluechange: this.editorChange },
            style: this.customStyle,
        });
    }
    /**
     * 数据选择插件（地图定位）
     *
     * @memberof DataPickerEditor
     */
    renderMapPosition() {
        return this.$createElement(this.editorComponentName, {
            props: Object.assign({ name: this.editorInstance.name, value: this.value, disabled: this.disabled, data: this.contextData, context: this.context, viewparams: this.viewparams }, this.customProps),
            on: {
                change: (value) => {
                    this.editorChange({ name: this.editorInstance.name, value: value });
                },
                itemChange: (val1, val2) => {
                    this.editorChange(val1);
                    this.editorChange(val2);
                },
            },
        });
    }
    /**
     * 单位选择器
     *
     * @memberof DataPickerEditor
     */
    renderOrgSelect() {
        var _a;
        const params = this.initSelectPickerParams();
        Object.assign(params, {
            filter: ((_a = this.editorInstance.editorParams) === null || _a === void 0 ? void 0 : _a['filter']) ? this.editorInstance.editorParams['filter'] : 'srforgid',
        });
        return this.$createElement(this.editorComponentName, {
            props: params,
            on: {
                'select-change': this.editorChange.bind(this),
            },
        });
    }
    /**
     * 部门人员选择器
     *
     * @memberof DataPickerEditor
     */
    renderDepartmentPersonnel() {
        var _a, _b;
        const params = this.initSelectPickerParams();
        Object.assign(params, {
            filter: ((_a = this.editorInstance.editorParams) === null || _a === void 0 ? void 0 : _a['filter']) ? this.editorInstance.editorParams['filter'] : 'srfpdept',
        });
        if ((_b = this.editorInstance.editorParams) === null || _b === void 0 ? void 0 : _b['treeurl']) {
            Object.assign(params, {
                treeurl: this.editorInstance.editorParams['treeurl'],
            });
        }
        return this.$createElement(this.editorComponentName, {
            props: params,
            on: {
                formitemvaluechange: this.editorChange.bind(this),
            },
        });
    }
    /**
     * 单位人员选择器
     *
     * @memberof DataPickerEditor
     */
    renderGroupSelect() {
        var _a, _b, _c;
        const params = this.initSelectPickerParams();
        Object.assign(params, {
            filter: ((_a = this.editorInstance.editorParams) === null || _a === void 0 ? void 0 : _a['filter']) ? this.editorInstance.editorParams['filter'] : 'srforgid',
        });
        if ((_b = this.editorInstance.editorParams) === null || _b === void 0 ? void 0 : _b['treeurl']) {
            Object.assign(params, {
                treeurl: this.editorInstance.editorParams['treeurl'],
            });
        }
        if ((_c = this.editorInstance.editorParams) === null || _c === void 0 ? void 0 : _c['editorMode']) {
            Object.assign(params, {
                editorMode: this.editorInstance.editorParams['editorMode'],
            });
        }
        return this.$createElement(this.editorComponentName, {
            props: params,
            on: {
                formitemvaluechange: this.editorChange.bind(this),
            },
        });
    }
    /**
     * 部门选择器
     *
     * @memberof DataPickerEditor
     */
    renderDepartmentSelect() {
        var _a;
        const params = this.initSelectPickerParams();
        Object.assign(params, {
            filter: ((_a = this.editorInstance.editorParams) === null || _a === void 0 ? void 0 : _a['filter']) ? this.editorInstance.editorParams['filter'] : 'srforgid',
        });
        return this.$createElement(this.editorComponentName, {
            props: params,
            on: {
                'select-change': this.editorChange.bind(this),
            },
        });
    }
    /**
     * 单多选列表框
     *
     * @memberof DataPickerEditor
     */
    renderCommonMicrocom() {
        const params = this.initSelectPickerParams();
        Object.is(params, {
            viewparams: this.viewparams,
        });
        return this.$createElement(this.editorComponentName, {
            props: params,
            on: {
                formitemvaluechange: this.editorChange.bind(this),
            },
        });
    }
    /**
     * 组织部门人员微服务组件参数处理
     *
     * @memberof DataPickerEditor
     */
    initSelectPickerParams() {
        var _a, _b, _c, _d, _e, _f, _g, _h;
        const params = {
            name: this.editorInstance.name,
            value: this.value,
            valueitem: ((_a = this.parentItem) === null || _a === void 0 ? void 0 : _a.valueItemName) || '',
            multiple: ((_b = this.editorInstance.editorParams) === null || _b === void 0 ? void 0 : _b['multiple']) ? JSON.parse(this.editorInstance.editorParams['multiple']) : false,
            url: (_c = this.editorInstance.editorParams) === null || _c === void 0 ? void 0 : _c['url'],
            filter: (_d = this.editorInstance.editorParams) === null || _d === void 0 ? void 0 : _d['filter'],
            requestMode: (_f = (_e = this.editorInstance.editorParams) === null || _e === void 0 ? void 0 : _e['requestMode']) === null || _f === void 0 ? void 0 : _f.toLowerCase(),
            fillMap: ((_g = this.editorInstance.editorParams) === null || _g === void 0 ? void 0 : _g['fillMap'])
                ? eval('(' + this.editorInstance.editorParams['fillMap'] + ')')
                : { id: ((_h = this.parentItem) === null || _h === void 0 ? void 0 : _h.valueItemName) || '', label: this.editorInstance.name },
            disabled: this.disabled,
            data: this.contextData,
            context: this.context,
            style: this.customStyle,
            localParam: this.customProps.localParam,
            localContext: this.customProps.localContext,
        };
        if (this.codeList) {
            Object.assign(params, {
                tag: this.codeList.codeName,
                codelistType: this.codeList.codeListType,
                renderMode: this.codeList.orMode,
                valueSeparator: this.codeList.valueSeparator,
                textSeparator: this.codeList.textSeparator,
            });
        }
        return params;
    }
    /**
     * 绘制内容
     *
     * @returns {*}
     * @memberof DataPickerEditor
     */
    render() {
        if (!this.editorIsLoaded) {
            return null;
        }
        return this.renderDefault();
    }
};
__decorate([
    Prop()
], UpdateEntitynamePicker.prototype, "ignorefieldvaluechange", void 0);
UpdateEntitynamePicker = __decorate([
    Component({
        components: {
            AppEmbedPicker,
        },
    }),
    VueLifeCycleProcessing()
], UpdateEntitynamePicker);
export { UpdateEntitynamePicker };
