<template>
	<view class="page">
		<nav-bar :title="$t('setPin.title')" bgColor="#fff"></nav-bar>
		<view style="width: 92%; margin: 10px auto; padding: 15px 10px;">
			<uni-forms label-position="top" label-width="80px" :model="model" :rules="rules" ref="model">
				<uni-forms-item :label="$t('setPin.text1')" name="password">
					<uni-easyinput type="password" :passwordIcon="true" v-model="model.password" :placeholder="$t('setPin.text2')" />
				</uni-forms-item>
				<uni-forms-item :label="$t('setPin.text3')" name="newpassword">
					<uni-easyinput type="password" :passwordIcon="true" v-model="model.newpassword" :placeholder="$t('setPin.text4')" />
				</uni-forms-item>
				<uni-forms-item :label="$t('setPin.text5')" name="renewpassword">
					<uni-easyinput type="password" :passwordIcon="true" v-model="model.renewpassword" :placeholder="$t('setPin.text6')" />
				</uni-forms-item>
			</uni-forms>
		</view>
		<view style="bottom: 0px; position: absolute; width:100vw; height: 60px;">
			<view class="cell_list">
				<button type="primary" round style="width: 100%;" @click="submit">{{$t("buttonSubmit")}}</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				model: {
				    password: '',
				    newpassword: '',
				    renewpassword: ''
				},
				rules: {
					password:{
						rules:[{required: true,errorMessage: $t('setPin.text7')},
							{minLength: 6, maxLength: 6, errorMessage: $t('setPin.text8'), }],
					},
					newpassword: {rules:[{required: true,errorMessage: $t('setPin.text9')},
							{minLength: 6, maxLength: 6, errorMessage: $t('setPin.text10'), }],
					},
					renewpassword:{rules:[{required: true,errorMessage: $t('setPin.text11')},
							{minLength: 6, maxLength: 6, errorMessage: $t('setPin.text10'), }],
					},
				}
			};
		},
		computed: {
			...mapState(['userInfo'])
		},
		//第一次加载
		onLoad(e) {
		},
		//页面显示
		onShow() {},
		//方法
		methods: {
			onPageJump(url) {
				uni.navigateTo({
					url: url
				});
			},
			onTokenJump(url) {
				this.judgeLogin(() => {
					uni.navigateTo({
						url: url
					});
				});
			},
			submit(){
				this.$refs.model.validate().then(res=>{
					if (this.model.newpassword !== this.model.renewpassword) {
						uni.showToast({
							title:$t('setPin.text12'),
							icon:'error'
						})
						return;
					}
				    this.$http.post('/api/user/change_trade_password', this.model).then(res => {
						if(res.code == 0){
							uni.showToast({
								title: res.data.mes
							});
							setTimeout(() => {
								uni.navigateBack();
							}, 1000);
						}
					});
				});
			}
		},
		//页面隐藏
		onHide() {},
		//页面卸载
		onUnload() {},
		//页面下来刷新
		onPullDownRefresh() {},
		//页面上拉触底
		onReachBottom() {},
		//用户点击分享
		onShareAppMessage(e) {
			return this.wxShare();
		}
	};
</script>
<style lang="scss" scoped>
	@import '@/style/mixin.scss';
	body{background-color: #fff;}
	.page{min-height: 95vh;position: relative;}
	.rechargeTitle{
		font-weight: 400;font-size: 16px;color: #999999;line-height: 23px; text-align: center; margin-top: 30px;
	}
	.rechargeNet{
		font-weight: 600;font-size: 20px;color: #333;line-height: 23px; text-align: center; margin-top: 20px;
	}
	.txt{
		font-size: 14px; color:#999; font-weight: 500;
	}
	.cell_right{
		font-size: 14px; color:#333; font-weight: 500;
	}
</style>