<template>
    <div>
        <ul>
            <li v-for="item in items" :key="item.langDesc" style="display：table; text-align: center">
                <br>
                {{ item.langDesc }}:
                <Input type="text"  v-model="item.vsiValue" style="width:240px" size="small" maxlength="30"></Input>
                <br>
            </li>
        </ul>
    </div>
</template>
<script>
    export default{
        
        components:{

        },
        props: {
            vsiId: {
                type: String,
                default() {
                    return ""
                }
            },
        },
        created:function(){
            this.$emit('SetPageSize', 400);  
            this.getValueNameInfo(); 
            this.$emit("SetTitle", this.$t("module.valueSet.globalNameEdit"));
            this.$emit('SetPageActions', [
                {
                    text: this.$t("common.save"),
                    theme: "success",
                    icon: "checkmark-round",
                    handle: this.updateNameLang,
                }
            ]);
        },
        mounted:function(){
           
        },
        data(){
            return{
              items: [], 
            }
        },
        computed:{

        },
        
        beforeMount:function(){

        },
        beforeDestroy:function(){

        },
        destroyed:function(){

        },
        methods:{
            getValueNameInfo(){
                $store.dispatch("GetValueNameInfo",this.vsiId).then(response => {
                    for(const key in response){
                        this.items.push({"langCode": response[key].langCode, "langDesc": response[key].langDesc, "vsiValue": response[key].vsiValue, "version": response[key].version,})
                    }
                })
            },
            updateNameLang(){
                let data_update = [];
                for(const key in this.items){
                    data_update.push({"langCode": this.items[key].langCode, "langDesc": this.items[key].langDesc, "vsiId": this.vsiId, "vsiValue": this.items[key].vsiValue, "version": this.items[key].version, })
                }
                $store.dispatch("UpdateNameLang", data_update).then((response) => {
                    if(response.statusCode == "0"){
                        this.$Message.success({
                            content: this.$t("module.valueSet.warning.updateNameSuccessfully"),
                            duration: 3
                        });
                        this.$emit("Close", data_update || []);
                    }else{
                        this.$Message.warning({
                            content: response.msg,
                            duration: 3
                        })
                    }
                })
            }
        },
        watch:{

        },
        directives:{

        }
    }
</script>
