app-quick-search.vue 2.2 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
<template>
    <i-input 
        class='app-quick-search' 
        search 
        @on-search="onSearch($event)"
        v-model="value" 
        :placeholder="placeholder" />
</template>

<script lang="ts">
import { IPSAppDataEntity, IPSAppDEField } from '@ibiz/dynamic-model-api';
import { Vue, Component, Prop, Model } from 'vue-property-decorator';

@Component({})
export default class AppQuickSearch extends Vue {
    /**
     * 应用实体
     *
     * @type {IPSAppDataEntity}
     * @memberof AppQuickSearch
     */
    @Prop() public appDataEntity?: IPSAppDataEntity;

    /**
     * 搜索框值
     * 
     * @memberof AppQuickSearch
     */
    @Model('valueChange', { type: String }) publicValue!: string;

    /**
     * 搜索框值
     * 
     * @memberof AppQuickSearch
     */
    get value():string {
        return this.publicValue;
    }

    /**
     * 设置搜索框值
     * 
     * @memberof AppQuickSearch
     */
    set value(value: string) {
        this.$emit('valueChange', value)
    }

    /**
     *  快速搜索栏空白填充内容
     *
     * @memberof AppQuickSearch
     */
    get placeholder (): string {
        let placeholder = '';
        let _this: any = this;
        const quickSearchFields: Array<IPSAppDEField> = this.appDataEntity?.getQuickSearchPSAppDEFields() || [];
        if (quickSearchFields.length > 0) {
            quickSearchFields.forEach((field: IPSAppDEField, index: number) => {
                const _field: IPSAppDEField | null | undefined = this.appDataEntity?.findPSAppDEField(field.codeName);
                if (_field) {
                    if(_field.quickSearchPlaceHolder){
                        placeholder += (this.$tl(_field.getQSPHPSLanguageRes()?.lanResTag, _field.quickSearchPlaceHolder) + (index === quickSearchFields.length - 1 ? '' : ', '));
                    }else{
                        placeholder += (_this.$tl(_field.getLNPSLanguageRes()?.lanResTag, _field.logicName) + (index === quickSearchFields.length - 1 ? '' : ', '));
                    }
                }
            })
        }
        return placeholder;
    }

    /**
     * 搜索事件
     *
     * @memberof AppQuickSearch
     */
    public onSearch(value: any) {
        this.$emit('search', value);
    }
}
</script>