app-span.vue 5.6 KB
Newer Older
1
<template>
2
    <codelist v-if="tag" :tag="tag" :value="value" :codelistType="codelistType" :renderMode="renderMode" :valueSeparator="valueSeparator" :textSeparator="textSeparator" :data="data" :localContext="localContext" :localParam="localParam" :context="context" :viewparams="viewparams"></codelist>
3
    <app-upload-file-info v-else-if="Object.is(this.editorType,'PICTURE') || Object.is(this.editorType,'PICTURE_ONE') || Object.is(this.editorType,'FILEUPLOADER')" :value="value" :name="name"></app-upload-file-info>
4 5 6 7 8
    <span class="app-span" v-else >{{text}}</span>
</template>

<script lang="ts">
import { Vue, Component, Prop, Watch, Model } from 'vue-property-decorator';
9
import moment from "moment"; 
10
@Component({})
11
export default class AppSpan extends Vue {
12 13 14 15 16 17 18 19 20

    /**
     * 当前值
     * 
     * @type {*}
     * @memberof AppSpan
     */
    @Prop() public value?: any;

21 22 23 24 25 26 27 28 29 30 31 32 33 34
    /**
     * 数据类型
     * 
     * @type {string}
     * @memberof AppSpan
     */
    @Prop() public dataType?: string;

    /**
     * 单位名称
     * 
     * @type {string}
     * @memberof AppSpan
     */
35
    @Prop({default:''}) public unitName?: string;
36

37 38 39
    /**
     * 精度
     *
40 41
     * @type {number}
     * @memberof AppSpan
42
     */
43
    @Prop({default:'2'}) public precision?:number;
44

45 46 47 48 49 50 51 52
    /**
     * 日期值格式化
     * 
     * @type {string}
     * @memberof AppSpan
     */
    @Prop() public valueFormat?: string;

53 54 55 56 57 58 59 60
    /**
     * 当前表单项名称
     * 
     * @type {*}
     * @memberof AppSpan
     */
    @Prop() public name?: any;

61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
    /**
     * 代码表标识
     *
     * @type {string}
     * @memberof AppSpan
     */
    @Prop() public tag?: string;

    /**
     * 代码表类型
     *
     * @type {string}
     * @memberof AppSpan
     */
    @Prop() public codelistType?: string;

    /**
     * 获取或模式
     * @type {boolean}
80
     * @memberof AppSpan
81 82 83 84 85 86
     */
    @Prop({default:"STR"}) public renderMode?: string;

    /**
     * 文本分隔符
     * @type {boolean}
87
     * @memberof AppSpan
88
     */
89
    @Prop({default:'、'}) public textSeparator?: string;
90 91 92 93

    /**
     * 值分隔符
     * @type {boolean}
94
     * @memberof AppSpan
95
     */
96
    @Prop({default:','}) public valueSeparator?: string;
97

98 99 100 101 102 103 104 105 106
    /**
     * 传入表单数据
     *
     * @type {*}
     * @memberof AppSpan
     */
    @Prop() public data?: any;

    /**
107 108 109 110 111 112 113 114 115 116 117
     * 局部上下文导航参数
     * 
     * @type {any}
     * @memberof AppSpan
     */
    @Prop() public localContext!:any;

    /**
     * 局部导航参数
     * 
     * @type {any}
118 119
     * @memberof AppSpan
     */
120
    @Prop() public localParam!:any;
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137

    /**
     * 视图上下文
     *
     * @type {*}
     * @memberof AppSpan
     */
    @Prop() public context!: any;

    /**
     * 视图参数
     *
     * @type {*}
     * @memberof AppSpan
     */
    @Prop() public viewparams!: any;

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
    /**
     * 监控表单属性 data 值
     *
     * @memberof AppSpan
     */
    @Watch('value')
    onDataChange(newVal: any, oldVal: any) {
        if(newVal !== oldVal){
           this.load();
        }
    }

    /**
     * 显示值
     * @type {*}
     * @memberof AppSpan
     */
    public text:any = '';

    /**
     * 编辑器类型
     *
     * @type {string}
     * @memberof AppSpan
     */
    @Prop() public editorType?: string;

    /**
     * vue  生命周期
     *
     * @memberof AppSpan
     */
    public created() {
        this.load();
    }

    /**
     * 处理数据
     * 
     * @memberof AppSpan
     */
    public load(){
180
        if(this.tag){
181
            return;  //代码表走codelist组件
182
        }else if(this.editorType === "ADDRESSPICKUP"){
183 184 185 186 187 188 189
            if(this.$util.isEmpty(this.value)){
                this.text = '';
            }else{
                JSON.parse(this.value).forEach((item:any,index:number) => {
                  this.text += index === 0 ? item.srfmajortext : ","+item.srfmajortext;
                });
            }
190
        }else{
191 192
            if(this.$util.isEmpty(this.value)){
                this.text = '';
193
            }else if(this.dataType){
194
                this.dataFormat();
195 196 197
            }else{
                this.text = this.value;
            }
198
                
199 200 201 202
        }
    }

    /**
203
     * 数据格式化
204 205 206
     * 
     * @memberof AppSpan
     */
207 208
    public dataFormat(){
        if(this.valueFormat){
209 210
            this.dateFormat() ;
            return;
211
        }
212 213
        if(Object.is(this.dataType,"CURRENCY")){
            let number:any = Number(this.value); 
214
            this.text = Number(number.toFixed(this.precision)).toLocaleString('en-US')+ ' '+ this.unitName;   
215
        }else if(Object.is(this.dataType,"FLOAT") || Object.is(this.dataType,"DECIMAL")){
216
            let number:any = Number(this.value);
217 218
            const decimalCnt:number = this.value.toString().split('.').length > 1 ? this.value.toString().split('.')[1].length : 0;
            this.text = (Number(this.precision) === 0 && decimalCnt !== 0) ? number.toFixed(decimalCnt) : number.toFixed(this.precision);
219 220
        }else {
            this.text = this.value;
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
        }
    }

    /**
     * 日期格式化
     * 
     * @memberof AppSpan
     */
    public dateFormat(){
        if(this.valueFormat){
            if(this.valueFormat.indexOf('%1$t') !== -1){
                this.text= moment(this.data).format("YYYY-MM-DD HH:mm:ss");
            }else if(this.valueFormat.indexOf('%1$s') == -1){
                this.text= moment(this.data).format(this.valueFormat);
            }else{
                this.text= this.value;
237
            }
238
        }
239
    }    
240 241 242 243 244 245
}
</script>

<style lang='less'>
@import './app-span.less';
</style>