<template>
  <view class="pwd-retrieve-container pwd">
    <uni-forms ref="form" :value="user" >
      <uni-forms-item name="newPassword" label="新密码">
        <uni-easyinput :inputBorder="false" type="password" v-model="user.newPassword" placeholder="请输入新密码" />
      </uni-forms-item>
      <uni-forms-item name="confirmPassword" label="确认密码">
        <uni-easyinput :inputBorder="false" type="password" v-model="user.confirmPassword" placeholder="请确认新密码" />
      </uni-forms-item>
      <view class="rbtn" @click="submit">提交</view>
    </uni-forms>
  </view>
</template>

<script>
  import { getappCheck } from "@/api/system/user"

  export default {
    data() {
      return {
		  phone:'',
		  code:'',
        user: {
          newPassword: undefined,
          confirmPassword: undefined
        },
        rules: {
          newPassword: {
            rules: [{
                required: true,
                errorMessage: '新密码不能为空',
              },
              {
                minLength: 6,
                maxLength: 20,
                errorMessage: '长度在 6 到 20 个字符'
              }
            ]
          },
          confirmPassword: {
            rules: [{
                required: true,
                errorMessage: '确认密码不能为空'
              }, {
                validateFunction: (rule, value, data) => data.newPassword === value,
                errorMessage: '两次输入的密码不一致'
              }
            ]
          }
        }
      }
    },
    onReady() {
      this.$refs.form.setRules(this.rules)
    },
	onLoad(e) {
		this.phone=e.phone;
		this.code=e.code;
	},
    methods: {
      submit() {
		var that = this;
        this.$refs.form.validate().then(res => {
			var params={
				phone:this.phone,
				code:this.code,
				password:this.user.newPassword
			}
          getappCheck(params).then(response => {
            that.$toast("重置成功")
            setTimeout(function(){
            	that.$tab.reLaunch('/pages/login') 
            },1500)
          })
        })
      }
    }
  }
</script>

<style lang="scss">
  page {
    background-color: #f5f5f5;
  }

  .pwd-retrieve-container {
    padding: 10rpx 36rpx;
  }
  .pwd .rbtn{width: 100%;height: 98rpx;background: $com-cd3;border-radius: 49rpx;text-align: center;line-height: 98rpx;font-size: 32rpx;font-weight: bold;color: #FFFEFE;margin-top: 68rpx;}
  .pwd /deep/ .uni-forms-item{height: 126rpx;background: #FFFFFF;border-radius: 18rpx;margin-top: 30rpx;padding: 0 40rpx;box-sizing: border-box;display: flex;align-items: center;margin-bottom: 0;}
  .pwd /deep/ .uni-forms-item__label{font-size: 32rpx;font-weight: 500;
color: #161616;flex: 0 0 auto;width: auto !important;}
  .pwd /deep/ .uni-easyinput{flex: 1;text-align: right;font-size: 32rpx;color: #161616;}
  .pwd /deep/ .uni-forms-item__content{display: flex;align-items: center;flex-direction: row;}
  .pwd /deep/ .uni-easyinput__placeholder-class{font-size: 30rpx;}
  .pwd /deep/ .uni-easyinput__content-input{font-size: 30rpx;}
   .pwd /deep/ .uni-forms-item__error{margin-top:20rpx;left: auto;right: 0;}
  

</style>
