app-mob-mdctrl-base.tsx 14.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
import { Emit, Prop, Watch } from 'vue-property-decorator';
import { Util, ViewTool } from 'ibiz-core';
import { MobMDCtrlControlBase } from '../../../widgets';
import { IPSUIAction, IPSUIActionGroupDetail } from '@ibiz/dynamic-model-api';

/**
 * 多数据部件基类
 *
 * @export
 * @class AppMobMDCtrlBase
 * @extends {MobMDCtrlControlBase}
 */
export class AppMobMDCtrlBase extends MobMDCtrlControlBase {

    /**
     * 部件动态参数
     *
     * @memberof AppMobMDCtrlBase
     */
    @Prop() public declare dynamicProps: any;

    /**
     * 部件静态参数
     *
     * @memberof AppMobMDCtrlBase
     */
    @Prop() public declare staticProps: any;

    /**
     * 监听部件动态参数变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof AppMobMDCtrlBase
     */
    @Watch('dynamicProps', {
        immediate: true,
    })
    public onDynamicPropsChange(newVal: any, oldVal: any) {
        if (newVal && !Util.isFieldsSame(newVal, oldVal)) {
            super.onDynamicPropsChange(newVal, oldVal);
        }
    }

    /**
     * 监听部件静态参数变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof AppMobMDCtrlBase
     */
    @Watch('staticProps', {
        immediate: true,
    })
    public onStaticPropsChange(newVal: any, oldVal: any) {
        if (newVal && !Util.isFieldsSame(newVal, oldVal)) {
            super.onStaticPropsChange(newVal, oldVal);
        }
    }

    /**
     * 销毁视图回调
     *
     * @memberof AppMobMDCtrlBase
     */
    public destroyed() {
        this.ctrlDestroyed();
    }

    /**
     * 部件事件
     *
     * @param {{ controlname: string; action: string; data: any }} { controlname 部件名称, action 事件名称, data 事件参数 }
     * @memberof AppMobMDCtrlBase
     */
    @Emit('ctrl-event')
    public ctrlEvent({ controlname, action, data }: { controlname: string; action: string; data: any }): void { }

    /**
     * 初始化部件的绘制参数
     *
     * @type {Array<*>}
     * @memberof ViewBase
     */
    public initRenderOptions(opts?: any) {
        this.renderOptions = {};
        const { controlType, codeName } = this.controlInstance;
        // 部件类名
        const controlClassNames: any = {
            'control-container': true,
            'multidata-container': true,
            [`app-control-${controlType.toLowerCase()}`]: true,
            [Util.srfFilePath2(codeName)]: true,
        };
        Object.assign(controlClassNames, opts);
        if (this.controlInstance?.getPSSysCss?.()?.cssName) {
            Object.assign(controlClassNames, { [this.controlInstance?.getPSSysCss()?.cssName || '']: true });
        }
        if (this.listMode) {
            Object.assign(controlClassNames, { [`app-control-${controlType.toLowerCase()}__` + this.listMode.toLowerCase()]: true });
        }
        this.$set(this.renderOptions, 'controlClassNames', controlClassNames);
    }

    /**
     * 绘制界面行为组
     *
     * @returns {*}
     * @memberof AppMobMDCtrlBase
     */
    public renderListItemAction(item: any) {
        return [
            this.controlInstance?.getPSDEUIActionGroup?.() ? this.renderActionGroup(item) : null,
            this.controlInstance?.getPSDEUIActionGroup2?.() ? this.renderActionGroup2(item) : null,
        ]
    }

    /**
     * 绘制左滑界面行为组
     *
     * @returns {*}
     * @memberof AppMobMDCtrlBase``
     */
    public renderActionGroup(item: any) {
        const details = this.controlInstance?.getPSDEUIActionGroup()?.getPSUIActionGroupDetails?.();
        if (this.controlInstance.controlStyle != 'LISTVIEW3') {
            return <ion-item-options side="start">
                {details && details?.map((detail: IPSUIActionGroupDetail) => {
                    if (detail.getPSUIAction()) {
                        const uiaction: IPSUIAction | null = detail.getPSUIAction();
                        if (uiaction && item[uiaction.codeName]?.visabled) {
                            let iconName = item[uiaction.codeName].icon ? ViewTool.setIcon(item[uiaction.codeName]?.icon) : '';
                            return <ion-item-option disabled={item[uiaction.codeName]?.disabled} color={uiaction.uIActionTag == "Remove" ? 'danger' : 'primary'} on-click={($event: any) => this.mdctrl_click($event, detail, item)}>
                                {item[uiaction.codeName]?.icon && item[uiaction.codeName]?.isShowIcon && <ion-icon name={iconName}></ion-icon>}
                                {item[uiaction.codeName]?.isShowCaption && <ion-label >{this.$tl(uiaction.getCapPSLanguageRes()?.lanResTag, uiaction.caption)}</ion-label>}
                            </ion-item-option>
                        }
                    }
                })}
            </ion-item-options>
        }
    }

    /**
     * 绘制右滑界面行为组
     *
     * @returns {*}
     * @memberof AppMobMDCtrlBase
     */
    public renderActionGroup2(item: any) {
        const details = this.controlInstance?.getPSDEUIActionGroup2()?.getPSUIActionGroupDetails?.();
        if (this.controlInstance.controlStyle != 'LISTVIEW3') {
            return <ion-item-options side="end">
                {details?.map((detail: IPSUIActionGroupDetail) => {
                    if (detail.getPSUIAction()) {
                        const uiaction: IPSUIAction | null = detail.getPSUIAction();
                        if (uiaction && item[uiaction.codeName]?.visabled) {
                            let iconName = item[uiaction.codeName].icon ? ViewTool.setIcon(item[uiaction.codeName]?.icon) : '';
                            return <ion-item-option disabled={item[uiaction.codeName]?.disabled} color={uiaction.uIActionTag == "Remove" ? 'danger' : 'primary'} on-click={($event: any) => this.mdctrl_click($event, detail, item)}>
                                {item[uiaction.codeName]?.icon && item[uiaction.codeName]?.isShowIcon && <ion-icon name={iconName}></ion-icon>}
                                {item[uiaction.codeName]?.isShowCaption && <ion-label >{this.$tl(uiaction.getCapPSLanguageRes()?.lanResTag, uiaction.caption)}</ion-label>}
                            </ion-item-option>
                        }
                    }
                })}
            </ion-item-options>
        }
    }
    /**
     * 绘制导航列表
     *
     * @returns {*}
     * @memberof AppMobMDCtrlBase
     */
    public renderListExpBar() {
        return <van-sidebar
            v-model={this.sidebarValue}
            on-change={this.switchView.bind(this)}>
            {this.items.length>0?this.items.map((item: any, index: number) => {
                return <van-sidebar-item class={{ 'list__sidebar__item': true, 'list__sidebar__item--active': this.sidebarValue === index }} key={item?.srfkey} >
                    <div slot="title">
                        {this.controlInstance?.getItemPSLayoutPanel() ? this.renderItemPSLayoutPanel(item) : <ion-label>{item?.srfmajortext}</ion-label>}
                    </div>
                </van-sidebar-item>
            }):<div class="control-content--nodata">{this.$t('app.commonWords.noData')}</div>}
        </van-sidebar>
    }

    /**
     * 绘制列表项插件
     *
     * @returns {*}
     * @memberof AppMobMDCtrlBase
     */
    public renderPluginItem(item: any) {
        const plugin = this.controlInstance.getPSSysPFPlugin()
        if (plugin) {
            const pluginInstance: any = this.PluginFactory.getPluginInstance("CONTROLITEM", plugin.pluginCode);
            if (pluginInstance) {
                return pluginInstance.renderCtrlItem(this.$createElement, item, this, null);
            }
        }
    }

    /**
     * 绘制列表主体
     *
     * @returns {*}
     * @memberof AppMobMDCtrlBase
     */
    public renderMainMDCtrl() {
        return this.items.length > 0
            ? <ion-list class="app-control-mobmdctrl__content__list" ref="ionlist">
                {this.controlInstance.enableGroup ? this.renderHaveGroup() : this.renderNoGroup()}
            </ion-list>
            : !this.isFirstLoad ? <div class="control-content--nodata">{this.$t('app.commonWords.noData')}</div> : null
    }

    /**
     * 绘制触底加载
     *
     * @returns {*}
     * @memberof AppMobMDCtrlBase
     */
    public renderBottomRefresh() {
        if (this.loadStatus && !this.allLoaded) {
            return <div class="loadding">
                <span >{this.$t('app.loadding') ? this.$t('app.loadding') : "加载中"}</span>
                <ion-spinner name="dots"></ion-spinner>
            </div>
        }
    }

    /**
     * 绘制分组
     *
     * @returns {*}
     * @memberof AppMobMDCtrlBase
     */
    public renderHaveGroup() {
        return this.groupParam.group_data.map((obj: any) => {
            return <div class="item-grouped">
                <van-collapse v-model={this.activeName} on-change={($event: any) => { this.activeName = $event; }}>
                    {obj.items && obj.items.length > 0 &&
                        <van-collapse-item name={obj.text}>
                            <template slot="title">
                                <div>{obj.text}(<label>{obj.items.length}</label>)</div>
                            </template>
                            {obj.items.map((item: any, index: any) => {
                                return <ion-item-sliding ref={item?.srfkey} class="list__sliding__item" on-click={() => this.item_click(item)}>
                                    {this.renderListItemAction(item)}
                                    {
                                        this.controlInstance?.getPSSysPFPlugin()?.pluginType === 'LIST_ITEMRENDER' ? this.renderPluginItem(item) : this.controlInstance?.getItemPSLayoutPanel() ? this.renderItemPSLayoutPanel(item) : this.renderListContent(item, index)
                                    }
                                </ion-item-sliding>
                            })}
                        </van-collapse-item>}
                </van-collapse>
            </div>
        })

    }

    /**
     * 绘制无分组
     *
     * @returns {*}
     * @memberof AppMobMDCtrlBase
     */
    public renderNoGroup() {
        return this.items.length > 0
            ? this.items.map((item: any, index) => {
                return <ion-item-sliding ref={item?.srfkey} class="list__sliding" on-click={() => this.item_click(item)}>
                    {this.renderListItemAction(item)}
                    {
                        this.controlInstance.getPSSysPFPlugin()?.pluginType === 'LIST_ITEMRENDER' ? this.renderPluginItem(item) : this.controlInstance.getItemPSLayoutPanel() ? this.renderItemPSLayoutPanel(item) : this.renderListContent(item, index)
                    }
                </ion-item-sliding>
            })
            : null
    }

    /**
     * 绘制面板部件
     *
     * @returns {*}
     * @memberof AppMobMDCtrlBase
     */
    public renderItemPSLayoutPanel(item: any) {
        if (!this.controlInstance.getItemPSLayoutPanel()) {
            return null
        }
        let { targetCtrlName, targetCtrlParam, targetCtrlEvent }: { targetCtrlName: string, targetCtrlParam: any, targetCtrlEvent: any } = this.computeTargetCtrlData(this.controlInstance.getItemPSLayoutPanel(), item);
        Object.assign(targetCtrlParam.dynamicProps, { inputData: item });
        return <div style="width:100%;">
            <ion-item class="list__sliding__item">
                {/* {this.listMode == 'SELECT' ? <ion-checkbox slot="start" class="iconcheck" value={item.srfkey} on-ionChange={($event: any) => { this.selectionchange($event) }}></ion-checkbox> : null} */}
                {this.$createElement(targetCtrlName, { props: targetCtrlParam, ref: this.controlInstance.getItemPSLayoutPanel()?.name, on: targetCtrlEvent })}
            </ion-item>
        </div>
    }


    /**
     * 绘制列表项集合
     * @return {*} 
     * @memberof AppDefaultMobMDCtrlBase
     */
    public renderListContent(item: any, index: any) {
        return <ion-item class="list__sliding__item">
            <app-list-index-text item={item} index={index}></app-list-index-text>
        </ion-item>
    }


    /**
     * 绘制选择列表
     *
     * @returns {*}
     * @memberof AppMobMDCtrlBase
     */
    public renderSelectMDCtrl() {
        return this.items.length > 0
            ? (!this.isSingleSelect ?
                <ion-list>
                    {this.items.map((item: any) => {
                        return <ion-item class="list__sliding__item">
                            <ion-checkbox color="secondary" checked={item.checked} value={item.srfkey} on-ionChange={($event: any) => { this.selectionchange($event) }} slot="end"></ion-checkbox>
                            {this.controlInstance?.getItemPSLayoutPanel() ? this.renderItemPSLayoutPanel(item) : <ion-label>{item.srfmajortext}</ion-label>}
                        </ion-item>
                    })}
                </ion-list>
                : <ion-radio-group value={this.selectedValue} >
                    {this.items.map((item: any) => {
                        return <ion-item class="list__sliding__item" on-click={() => { this.onSimpleSelChange(item) }}>
                            {this.controlInstance?.getItemPSLayoutPanel() ? this.renderItemPSLayoutPanel(item) : <ion-label>{item.srfmajortext}</ion-label>}
                            <ion-radio checked={item.checked} slot="end" value={item.srfkey}></ion-radio>
                        </ion-item>
                    })}
                </ion-radio-group>
            )
            : (!this.isFirstLoad ? <div class="no-data">{this.$t('app.commonWords.noData')}</div> : null)
    }


    /**
     * 绘制列表
     *
     * @returns {*}
     * @memberof AppMobMDCtrlBase
     */
    public render() {
        const { controlClassNames } = this.renderOptions;
        if (!this.controlIsLoaded) {
            return null;
        }
        return (
            <div class={controlClassNames}>
                <div class="control-content app-control-mobmdctrl__content">
                    <van-pull-refresh class="app-control-mobmdctrl__content__refresh" value={this.isLoadding}  on-refresh={() => { this.pullDownToRefresh() }} disabled={!this.enablePullDownRefresh}>
                        {this.listMode == "LISTEXPBAR" ?
                            this.renderListExpBar() :
                            this.listMode == "SELECT" ?
                                this.renderSelectMDCtrl() :
                                [this.renderMainMDCtrl(), this.renderBottomRefresh()]}
                    </van-pull-refresh>
                </div>
            </div>
        );
    }
}