control-state-formula.js 2.23 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

export default {
    data() {
        return {
          state:"",
          controlDisplay:true
        }
    },
    methods: {
        addControlStateListener(){
            this.controlState = this.context.bill.addControlStateListener(this.define.name,{
                display:function(type){
                    if(type){
                        this.controlDisplay = true;
                    }else{
                        this.controlDisplay = false;
                    }
                }.bind(this),
                editable:function(nv){
                    this.state = nv;
                }.bind(this),
                enable:function(){

                }.bind(this),
                confirm:function(msg){
                    /**
                     * 主动调用
                     */
                    // if(msg){
                    //     this.showTipMessage(msg);
                    //     return false;
                    // }
                }.bind(this)
            });
        },
        getControlState(config){
            if(config&&config.formulas){
                for (const key in config.formulas) {
                    if(config.formulas[key] === "false"){
                        this[`setControl${key}`]&&this[`setControl${key}`]();
                    }else{
                        this.context.bill.getControlState(key,this.define.name);
                    }
                }
            }
        },
        setControldisplay(){
            this.controlDisplay = false;
        },
        setControleditable(){
            this.state = 'readOnly';
        },
        showTipMessage(message){
            this.$Modal.confirm({
                title: '提示',
                content: message,
                onOk: () => {
                    
                },
                onCancel: () => {
                    if(this.context.dataObject){
                        this.context.dataObject.resetFieldValue();
                    }
                    return ;
                }
            })
        }
    },
    mounted() {
        this.getControlState(this.define.config);
    },
    created(){
        this.addControlStateListener();
    },
    beforeDestroy() {
        this.controlState&&this.controlState();
    }
}