<template>
	<view>
		<view class="consult">
			<dHeader :title="$lang.lang.consult.consult"></dHeader>
		</view>
		<view class="start-bar"></view>
		<view class="consultAdd">
			<view class="consult-item">
				<view class="consult-item-label">
					<image src="../../static/img/consulta-1.png" mode=""></image>
					<text>{{$lang.lang.consult.title}}</text>
				</view>
				<view class="consult-item-put">
					<input class="consolt_title" v-model="params.title" type="text" :placeholder="$lang.lang.notices.title">
				</view>			
			</view>
			<view class="consult-item">
				<view class="consult-item-label">
					<image src="../../static/img/consulta-2.png" mode=""></image>
					<text>{{$lang.lang.consult.type}}</text>
				</view>
				<view class="consult-item-put noborder">
					<radio-group @change="typeChange">
						<label class="radio">
							<radio value="1" :checked="params.type == 1" /><text>{{$lang.lang.index.consult}}</text>
						</label>
						<label class="radio">
							<radio value="2" :checked="params.type == 2" /><text>{{$lang.lang.consult.advice}}</text>
						</label>
					</radio-group>
				</view>
			</view>
			<view class="consult-item">
				<view class="consult-item-label">
					<image src="../../static/img/consulta-3.png" mode=""></image>
					<text>{{$lang.lang.consult.name}}</text>
				</view>
				<view class="consult-item-put">
					<input v-model="params.name" disabled type="text" >
				</view>
			</view>
			<view class="consult-item">
				<view class="consult-item-label">
					<image src="../../static/img/consulta-4.png" mode=""></image>
					<text>{{$lang.lang.consult.phone}}</text>
				</view>
				<view class="consult-item-put">
					<input v-model="params.phone" disabled type="number">
				</view>
			</view>
			<view class="consult-item">
				<view class="consult-item-label">
					<image src="../../static/img/consulta-5.png" mode=""></image>
					<text>{{$lang.lang.consult.orderNo}}</text>
				</view>
				<view class="consult-item-put">
					<input class="consolt_title" v-model="params.orderCode" type="text" :placeholder="$lang.lang.notices.orderNo">
				</view>
			</view>
			<view class="consult-item-2">
				<view class="consult-item-label-2">
					<image src="../../static/img/consulta-6.png" mode=""></image>
					<text>{{$lang.lang.consult.contented}}</text>
				</view>
				<view class="consult-item-put-2">
					<textarea class="textarea" v-model="params.content" :placeholder="$lang.lang.notices.content" id="" cols="30" rows="5"></textarea>
				</view>
			</view>
		</view>
		<view class="consult-btn">
			<view class="" @click="submitForm">{{$lang.lang.consult.sumbit}}</view>
			<view class="" @click="resetForm">{{$lang.lang.consult.reset}}</view>
		</view>
	</view>
</template>

<script>
	import dHeader from '../../components/dHeader/index.vue'
	export default {
		components: {
			dHeader
		},
		data() {
			return {
				params: {
					title: '',
					type: 1,
					content: '',
					name: '',
					phone: '',
					orderCode: '',
				},
				rules: {
					title: this.$lang.lang.notices.title,
					type: this.$lang.lang.notices.type,
					content: this.$lang.lang.notices.content,
				},
				userInfo:{}
			}
		},
		onLoad() {
			this.getUserInfo()
		},
		methods: {
			typeChange (e) {
				console.log()
				this.params.type = e.detail.value
			},
			getUserInfo() {
				this.$request.get('/app-api/member/user/get').then(res => {
					if(res.code==0&&res.data){
						this.userInfo = res.data
						this.params.name = res.data.nickname
						this.params.phone = res.data.mobile
					}

				})
			},
			submitForm () {
				if(!this.$request.checkFormData(this.params, this.rules)){
					return false
				}
				this.$request.post('/app-api/ecw/message-leave/create', this.params).then(res => {
					if(res.code==0){
						uni.showToast({
							title: this.$lang.lang.notices.success,
							icon: 'success',
						})
						setTimeout(() => {
							uni.navigateBack()
						}, 1500)
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			},
			resetForm(){
				for(let i in this.params){
					this.params[i] = (i == 'type') ? 0 : ''
				}
				this.typeChange()
			}
		}
	}
</script>

<style>
	@import url("../../static/css/consult_add.css");
</style>
