2025-06-06 15:07:26 +08:00

162 lines
3.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { pageOptionType } from './constant';
import { apiArr } from '../../../api/user';
import { postUrl } from '../../../utils/util';
Page({
/**
* 页面的初始数据
*/
data: {
cellPhone: null,
passWord: null,
type: '',
content:{},
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
console.log('options', options);
// 基于父页面传递参数设置页面名称
wx.setNavigationBarTitle({
title: options.title
})
// 根据父页面传递type参数映射页面渲染参数
this.setData({
content: pageOptionType[options.type],
type: options.type,
});
},
handerChangeClick(event) {
const {value} = event.detail;
const {name} = event.currentTarget.dataset;
if (name === 'phone') {
this.setData({ cellPhone: value });
};
if (name === 'pwd') {
this.setData({ passWord: value });
}
},
// 提交修改
handleSubmit() {
/**
* 参数场景说明:
* 修改登录密码页面时cellPhone 是新设密码passWord 是确认密码
* 修改支付密码页面时cellPhone 是已绑定手机号passWord 是支付密码
*/
const {cellPhone, passWord, type} = this.data;
console.log('手机号', cellPhone);
console.log('密码', passWord);
wx.showLoading({
title: '加载中',
mask: true
})
if (type === 'login') {
if (cellPhone === passWord) {
postUrl(apiArr.modifyPass, {
new_password: cellPhone,
conform_password: passWord,
}, res => {
wx.hideLoading();
wx.showToast({
title: '修改登录密码成功',
icon: 'success',
success () {
setTimeout(() => {
wx.navigateBack({
delta: 1
})
}, 2000)
}
})
})
} else {
wx.hideLoading();
wx.showToast({
title: '新密码与确认密码不一致',
icon: 'none',
duration: 2000
})
}
}
if (type === 'pay') {
postUrl(apiArr.payPass, {
mobile: cellPhone,
pay_password: passWord,
}, res => {
wx.hideLoading();
if (res.error) {
wx.showToast({
title: res.error,
icon: 'error',
})
return;
}
wx.showToast({
title: '设置支付密码成功',
icon: 'success',
success () {
setTimeout(() => {
wx.navigateBack({
delta: 1
})
}, 2000)
}
})
});
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})