zhongping-miniprogram/miniprogram/pages/addPhone/addPhone.ts

154 lines
2.8 KiB
TypeScript

// pages/certification/certification.ts
import { getPayInfo } from '../../apis/pay'
import { realNameAuthentication } from '../../apis/login'
const app = getApp<IAppOption>()
Page({
/**
* 页面的初始数据
*/
data: {
step: 1,
name: '',
idCard: '',
phoneNumber: '',//app.globalData.userInfo?.username,
info: {},
payShow: false,
type: ''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
// this.setData({
// phoneNumber: app.globalData.userInfo?.username
// })
this.getInfo()
// console.log(options.phoneNumber==='');
this.setData({
phoneNumber: options.phoneNumber,
idCard: options.phoneNumber==='' ? '' : app.globalData.userInfo.idCard || '',
name: options.phoneNumber==='' ? '' : app.globalData.userInfo.name || '',
type: options.phoneNumber==='' ? 'add' : 'refresh'
})
},
getInfo() {
getPayInfo({}).then((res: any) => {
this.setData({
info: res.d
})
})
},
pay() {
const { name, idCard, phoneNumber, type } = this.data
realNameAuthentication({
name, idCard, phoneNumber,
wxPayApiType: 'JSAPI',
authType: type === 'add' ? 'PHONE_ADD' : 'PHONE_REFRESH'
}).then((res: any) => {
console.log(res)
wx.requestPayment({
...res.d,
success: (res: any) => {
console.log(res)
wx.navigateTo({
url: '/pages/certificationResult/certificationResult'
})
},
fail: (err: any) => {
console.log(err)
wx.showToast({
icon: 'none',
title: '支付失败, 请稍后再试!'
})
}
})
})
},
showShadow() {
this.setData({
payShow: true
})
},
hideShadow() {
this.setData({
payShow: false
})
},
next() {
const { name, idCard } = this.data
if (!name) {
wx.showToast({
icon: 'none',
title: '请输入您的真实姓名'
})
return
}
if (!idCard) {
wx.showToast({
icon: 'none',
title: '请输入您的身份证号'
})
return
}
this.setData({
step: 2
})
},
edit() {
this.setData({
step: 1
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})