<template>
	<view class="change">
		<u-form label-width='150'>
			<u-form-item label="新密码">
				<u-input v-model="password"  type="password"/>
			</u-form-item>
			<u-form-item label="确认密码">
				<u-input v-model="sure_password" type="password"/>
			</u-form-item>
		</u-form>
		<view class="submit" @click="submit">
			确认修改
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				password: '',
				sure_password: ''
			}
		},
		methods: {
			submit() {
				if (!this.password) {
					uni.showToast({
						title: '请输入新密码',
						icon: 'none'
					})
					return
				}
				if (!this.sure_password) {
					uni.showToast({
						title: '请输入确认密码',
						icon: 'none'
					})
					return
				}
				if (this.password != this.sure_password) {
					uni.showToast({
						title: '您两次输入的密码不一致',
						icon: 'none'
					})
					return
				}
				this.$u.post('/base/admin-update-password', {
					password: this.password,
					password_confirmation: this.sure_password
				}).then(res => {
					this.$u.vuex('vuex_token', '');
					this.$u.vuex('vuex_user', '');
					console.log(res)
					uni.showToast({
						title: '修改成功，请重新登录',
						icon: 'none'
					})
					setTimeout(function() {
						uni.reLaunch({
							url: '../login/index'
						})
					}, 2000)

				})

			}
		}
	}
</script>

<style scoped lang="scss">
	.change {
		padding: 0 20px;
		margin-top: 10px;
		background-color: #fff;
		.submit {
			height: 45px;
			width: 60%;
			line-height: 45px;
			margin: 0 auto;
			margin-top: 100px;
			background-color: #D12727;
			text-align: center;
			color: #fff;
			border-radius: 22px;
			font-size: 16px;
		}
	}
</style>
