<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.menuName" style="width:240px" size="small" maxlength="30"></Input>
                <br>
            </li>
        </ul>
    </div>
</template>
<script>
    export default{
        
        components:{

        },
        props: {
            menuId: {
                type: String,
                default() {
                    return ""
                }
            },
        },
        created:function(){
            console.log(this.$t('module.menu.modifyMenuName'));
            
            this.$emit('SetPageSize', 400);  
            this.getMenuLang(); 
            this.$emit("SetTitle", this.$t('module.menu.modifyMenuName'));
            this.$emit('SetPageActions', [
                {
                    text: this.$t('common.save'),
                    theme: "primary",
                    icon: "md-create",
                    action: "SetManuLAng",
                    handle: this.updateMenuLang,
                }
            ]);
        },
        mounted:function(){
           
        },
        data(){
            return{
              items: [], 
            }
        },
        computed:{

        },
        
        beforeMount:function(){

        },
        beforeDestroy:function(){

        },
        destroyed:function(){

        },
        methods:{
            getMenuLang(){
                $store.dispatch("GetMenuLang",this.menuId).then(response => {
                    for(const key in response){
                        this.items.push({"langCode": response[key].langCode, "langDesc": response[key].langDesc, "menuName": response[key].menuName, "version": response[key].version,})
                    }
                })
            },
            updateMenuLang(){
                // 文本框输入格式校验
                // for(const key in this.items){
                //     if(this.items[key].langCode == "zh-CN"){
                //         let reg=/^[\u2E80-\u9FFF]+$/;//Unicode编码中的汉字范围
                //         if(!reg.test(this.items[key].menuName)){
                //             this.$Message.warning({
                //                 content: "简体中文名称只能输入简体中文",
                //                 duration: 3
                //             })
                //             return ;
                //         }
                    // }else if(items[key] == "zh-TW"){

                    // }else if(items[key] == "en-US"){

                    // }else{
                    //}
                //      }
                // }
                let data_update = [];
                for(const key in this.items){
                    data_update.push({"langCode": this.items[key].langCode, "langDesc": this.items[key].langDesc, "menuId": this.menuId, "menuName": this.items[key].menuName, "version": this.items[key].version, })
                }
                $store.dispatch("SetManuAndLang", data_update).then(response => {
                    if(response.statusCode == "0"){
                        this.$Message.success({
                            content: this.$t('module.menu.modifyMenuNameSuccess'),
                            duration: 3
                        })
                    }else{
                        this.$Message.warning({
                            content: response.msg,
                            duration: 3
                        })
                    }
                })
                this.$emit("Close", data_update || []);
            }
        },
        watch:{

        },
        directives:{

        }
    }
</script>
