<template>
    <div class="accountEdit_page">
		<div class="accountEdit_page_body">
			<div class="accountEdit_page_body_item">
				<div class="accountEdit_page_body_item_name">{{$t('account.Name')}}:</div>
				<div class="accountEdit_page_body_item_inut" style="display: flex;justify-content: space-between;">
					<a-select
						class="gallerySelect"
						v-model:value="selectSex"
						size="large"
						optionFilterProp="label"
						style="width: 30%;"
						:options="sexList"
						:placeholder="$t('account.plaseSelectSex')"
						allowClear
						show-search
					></a-select>
					<input class="login_form_input" style="width: 30%;" :class="{active:!!userDetail.occupation}" type="text" :placeholder="$t('account.plaseFirst')" v-model="surname">
					<input class="login_form_input" style="width: 30%;" :class="{active:!!userDetail.occupation}" type="text" :placeholder="$t('account.plaseLast')" v-model="givenName">
				</div>
			</div>
			<div class="accountEdit_page_body_item">
				<div class="accountEdit_page_body_item_name">{{$t('account.Country')}}:</div>
				<div class="accountEdit_page_body_item_inut">
					<a-select
                        v-model:value="Country"
                        size="large"
                        optionFilterProp="label"
                        :options="countryList"
                        placeholder="Please select"
                        allowClear
                        show-search
                    ></a-select>
				</div>
			</div>
			<div class="accountEdit_page_body_item">
				<div class="accountEdit_page_body_item_name">{{$t('account.CompanyName')}}:</div>
				<div class="accountEdit_page_body_item_inut">
					<input type="text"  v-model="CompanyName">
				</div>
			</div>
			<div class="accountEdit_page_body_item">
				<div class="gallery_btn" @click="setSubmit">
					{{$t('account.Submit')}}
				</div>
			</div>
		</div>
		<div class="mark_loading" v-show="loadingShow">
            <a-spin size="large" />
        </div>
    </div>
</template>
<script lang="ts">
import { defineComponent,computed,ref,reactive,nextTick,toRefs,createVNode, onMounted} from 'vue'
import { Https } from "@/tool/https";
import { Modal,message } from 'ant-design-vue';
import { useStore } from "vuex";
import { country } from "@/tool/country";
import { useI18n } from 'vue-i18n'
export default defineComponent({
    components:{
    },
    setup() {
        const store = useStore();
        const {t} = useI18n();
		let userDetail:any= computed(()=>{
			return store.state.UserHabit.userDetail
		})
		let accountHomeData:any = reactive({
			Country:'',
			CompanyName:'',
			loadingShow:false,
			countryList:country,
			sexList:computed(()=>{
			  	return[
				 	{label:t('account.Mr'),value:'Mr'},
					{label:t('account.Ms'),value:'Ms'},
					{label:t('account.Miss'),value:'Miss'},
				]  
			}),
			selectSex:null,
			surname:'',
			givenName:'',
		})
		let setSubmit = ()=>{
			let data = {
				country:accountHomeData.Country,
				occupation:accountHomeData.CompanyName,
				title:accountHomeData.selectSex,
				surname:accountHomeData.surname,
				givenName:accountHomeData.givenName,
			}
			if (!data.occupation) {
				message.info(t('account.jsContent7'));
				return;
			}
			if (!data.country) {
				message.info(t('account.jsContent8'));
				return;
			}
			if (!data.title) {
				message.info(t('account.jsContent9'));
				return;
			}
			if (!data.surname) {
				message.info(t('account.jsContent10'));
				return;
			}
			if (!data.givenName) {
				message.info(t('account.jsContent11'));
				return;
			}
			accountHomeData.loadingShow = true
			Https.axiosPost(Https.httpUrls.updateUserInfo,data).
				then((rv:any)=>{
					let value = {
						country:accountHomeData.Country,
						title:accountHomeData.selectSex,
						userName:accountHomeData.editUserName,
						surname:accountHomeData.surname,
						givenName:accountHomeData.givenName,
					}
					store.commit('upUserDetail',value)
					accountHomeData.loadingShow = false
					message.success(t('exportModel.jsContent7'))
				}).catch((err:any)=>{
					accountHomeData.loadingShow = false
				})
		}
		onMounted(()=>{
			let country = userDetail.value.country
			let CompanyName = userDetail.value.occupation
			let title = userDetail.value.title
			let surname = userDetail.value.surname
			let givenName = userDetail.value.givenName
			accountHomeData.Country = country
			accountHomeData.CompanyName = CompanyName
			accountHomeData.selectSex = title
			accountHomeData.surname = surname
			accountHomeData.givenName = givenName
		})
        return{
           ...toRefs(accountHomeData),
		   userDetail,
		   setSubmit,
        }
    },
    data(){
        return{
            
        }
    },
})
</script>
<style lang="less" scoped>
.accountEdit_page{
	height: 100%;
	overflow-y: auto;
	padding-bottom: 2rem;
	.accountEdit_page_body{
		width: 100%;
		// width: 85rem;
		.accountEdit_page_body_item{
			display: flex;
			margin-bottom: 20px;
			flex-direction: column;
			width: 100%;
			.gallery_btn{
				margin-left: auto;
			}
			.gallerySelect{
				box-sizing: border-box;
				height: 40px;
				:deep(.ant-select-selector){
					height: 40px;
					border: 2px solid #D0D0D0;
					border-radius: 1.6rem;
					align-items: center;
				}
				:deep(.ant-select-selector):hover{
					border: 2px solid #000;
				}
			}
			input,textarea{
				padding-left: 11px;
				border-radius: 1.6rem;
				border: 2px solid #D0D0D0;
				width: 100%;
				font-size: 2rem;
			}
			input{
				height: 40px;
			}
			.accountEdit_page_body_item_name{
				color: #000;
				text-align: left;
				font-size: 2rem;
			}
			.accountEdit_page_body_item_inut{
				margin-top: 1.5rem;
				flex: 1;
				.ant-select-lg{
					font-size: 2rem;
				}
				.ant-select{
					width: 100%;
					border-radius: 1.6rem;
					border: 2px solid #D0D0D0;
					overflow: hidden;
					.ant-select-selector{
						border-radius: 1.6rem;
					}
					:deep(.ant-select-selector ){
						border: none !important;
					}
				}
				
			}
		}
		.accountEdit_page_body_item:last-child{
			justify-content: center;
		}
	}
}
</style>
