123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- <template>
- <view class="forget-wrap">
- <form class="login-form" @submit="formSubmit">
- <view v-show="state == 0">
- <view class="form-item">
- <input v-model="form.phone" class="item-inp" name="phone" type="number" maxlength="11" placeholder="请输入登录手机号" />
- </view>
- <view class="form-item">
- <input v-model="form.verifyCode" class="item-inp" name="verifyCode" type="number" maxlength="6" placeholder="请输入短信验证码" />
- <button class="getcode-btn" :style="{background: $config('primaryColors')}" :disabled="isDisable" @click="getCodeValidate">{{nowVal}}</button>
- </view>
- <view class="form-btn-con">
- <button class="form-btn" :style="{background: $config('buttonColors')}" @click="goStep">下一步</button>
- </view>
- </view>
- <view v-show="state == 1">
- <view class="form-item">
- <input v-model="form.password" class="item-inp" name="password" password type="text" maxlength="12" placeholder="请输入新密码" />
- </view>
- <view class="form-item">
- <input v-model="form.passwords" class="item-inp" name="passwords" password type="text" maxlength="12" placeholder="请再次输入新密码" />
- </view>
- <view class="form-btn-con">
- <button class="form-btn" :style="{background: $config('buttonColors')}" form-type="submit">提交</button>
- </view>
- </view>
- </form>
-
- <uni-popup ref="imageTxtPopup" type="center">
- <popup-con type="forgetImageTxt" title="图文验证码" :popBtn="popBtn" :changeImg="changeImg" @captchaImg="captchaImg"></popup-con>
- </uni-popup>
- </view>
- </template>
- <script>
- import { isvalidPhone } from '@/libs/tools.js'
- import uniPopup from '@/components/uni-popup/uni-popup.vue'
- import popupCon from '@/components/uni-popup/popup-con.vue'
- import { memberVerifyCode, memberChangePwd, memberValidateVerifyCode, memberGetByMobile } from '@/api/user.js'
- import { clzConfirm } from '@/libs/tools.js'
- export default{
- components: {
- uniPopup,
- popupCon
- },
- data(){
- return{
- state: 0,
- form: {
- phone: '',
- verifyCode: '',
- password: '',
- passwords: ''
- },
- nowVal: '获取验证码',
- count: '',
- timer: null,
- isDisable: false,
- popBtn: [],
- changeImg: false,
- randomCode: '',
- }
- },
- onLoad(opts) {
- if(opts.username){
- this.form.phone = opts.username
- }
- },
- methods: {
-
- goStep(){
- const _this = this
-
- if(this.form.phone == ''){
- uni.showToast({icon: 'none',title: '请输入登录手机号'})
- return
- }
- if(!isvalidPhone(this.form.phone)){
- uni.showToast({icon: 'none',title: '请输入正确的手机号码'})
- return
- }
- if(this.form.verifyCode == ''){
- uni.showToast({icon: 'none',title: '请输入验证码'})
- return
- }
-
- const obj = {}
- obj.phone = _this.form.phone,
- obj.random = _this.randomCode,
- obj.verifyCode = _this.form.verifyCode
- memberValidateVerifyCode(obj).then(res => {
- if(res.status == 200){
- _this.state = 1
- }else{
- uni.showToast({icon: 'none',title: res.message})
- }
- })
- },
-
- formSubmit(){
- const _this = this
- if(this.form.password == ''){
- uni.showToast({icon: 'none',title: '请输入新密码'})
- return
- }
- if(this.form.password.length < 6 || this.form.password.length > 12){
- uni.showToast({icon: 'none',title: '请输入6-12位新密码'})
- return
- }
- if(this.form.passwords == ''){
- uni.showToast({icon: 'none',title: '请再次输入新密码'})
- return
- }
- if(this.form.password != this.form.passwords){
- uni.showToast({icon: 'none',title: '两次密码输入不一致'})
- return
- }
- const obj = {}
- obj.phone = _this.form.phone,
- obj.random = _this.randomCode,
- obj.verifyCode = _this.form.verifyCode,
- obj.password = _this.form.password
- memberChangePwd(obj).then(res => {
- if(res.status == 200){
-
- _this.$u.vuex('vuex_user.account', _this.form.phone)
- _this.$u.vuex('vuex_user.password', '')
- clzConfirm({
- title: '提示',
- content: '修改成功',
- confirmText: '去登录',
- showCancel: false,
- success: function (ret) {
- if (ret.confirm||ret.index==0) {
- uni.reLaunch({
- url: '/pages/login/login'
- })
- }
- }
- })
- }
- })
- },
-
- getCodeValidate(){
- if(this.form.phone){
- if(!isvalidPhone(this.form.phone)){
- uni.showToast({icon: 'none',title: '请输入正确的手机号码'})
- return
- }else{
-
- memberGetByMobile({phone: this.form.phone}).then(res => {
- if(res.status == 200){
-
- this.$refs.imageTxtPopup.open()
- }else{
- uni.showToast({icon: 'none',title: res.message})
- }
- })
- }
- }else{
- uni.showToast({icon: 'none',title: '请先输入手机号'})
- }
- },
-
- getCodeFun(){
- const TIME_COUNT = 60
- if (!this.timer) {
- this.count = TIME_COUNT
- this.timer = setInterval(() => {
- if (this.count > 0 && this.count <= TIME_COUNT) {
- this.count--
- this.nowVal = this.count + 's后重发'
- this.isDisable = true
- } else {
- this.nowVal = '重新获取验证码'
- clearInterval(this.timer)
- this.timer = null
- this.isDisable = false
- }
- }, 1000)
- }
- },
-
- captchaImg(code, nowRandomCode){
- this.captchaVerify(code, nowRandomCode)
- },
-
- captchaVerify(code, nowRandomCode){
- const _this = this
- let obj = {}
- obj.phone = this.form.phone
- obj.random = nowRandomCode
- obj.captcha = code
-
- memberVerifyCode(obj).then(res => {
- console.log(JSON.stringify(res))
- if(res.status == 200){
- _this.randomCode = nowRandomCode
-
- _this.$refs.imageTxtPopup.close()
-
- this.getCodeFun()
- uni.showToast({icon: 'none',title: '验证码发送成功'})
- }else {
- _this.randomCode = ''
-
- _this.changeImg = false
- _this.$nextTick(function(){
- _this.changeImg = true
- })
- uni.showToast({icon: 'none',title: res.message})
- }
- })
- },
- }
- }
- </script>
- <style scoped lang="scss">
- @import './login.scss';
- .forget-wrap .login-form{
- padding-top: 300upx;
- }
- .getcode-btn {
- color: #fff !important;
- border: none !important;
- }
- </style>
|