<template>
    <span :class="label?'input-span':''" style="position:relative">
        <i v-if="$store.state.envCfg.goldBet!=1" class="fa fa-ge" 
                :title="`该字段开启金币倍率转换,输入值为: 原值*${$store.state.envCfg.goldBet}\n输入数值必须为倍率的整数倍\n当前实际值:${realGold}`"
                style="font-size:6px;color:#66b1ff;position:absolute;left:-13px;top:-3px;"></i>
        <span v-if="label">{{$dict.tranByPubMap(label)}} :</span>
        <el-input v-model.number="gold" type="number"  v-bind="$attrs"  @change="onChange" :style="$attrs.elstyle+inputStyle" clearable @mousewheel.native.prevent></el-input>
    </span>
    
</template>


<script>

export default {
    props:["label","width","value"],
    data() {
        var gold=this.value;
        if(gold!==''){
            gold = this.tranGold(gold);
        }
        if(!gold && gold!==0) gold=""
        return {
            gold : gold,
            realGold : "",
        }
    },
    watch:{
        value(newval,oldval){
            if(newval){
                this.gold = this.tranGold(parseInt(newval));
            }else{
                this.gold = newval;
            }
            
            this.realGold = this.reTranGold(this.gold);
        }
    },

    mounted() {
    },
    computed: {
        inputStyle() {
            if(!this.$attrs.elstyle){
                if(this.width){
                    return ";width:"+this.width+"px;";
                }else {
                    return ";width:auto;";
                }
            }
        }
    },

    methods: {
        onChange(){
            var val = "";
            if(!isNaN(this.gold)) val = this.reTranGold(this.gold);
            this.gold = this.tranGold(val);
            if(val===0) this.gold = 0;
            this.realGold = val;
            this.$emit('input',val);
            this.$emit('change',val);
        }
    }
}
</script>

<style lang="less" scoped>
    .input-span{
        display: inline-block;
        margin-left: 10px;
        margin-right: 10px;
        margin-top: 5px;
        position: relative;
        >span{
            display: inline-block;
            white-space: nowrap;
            color:gray;
            font-size: 15px;
        }
    }
</style>
<style lang="less">
    .el-form-item__content .input-span{
        margin-top: 0px;
    }
</style>