240 lines
6.0 KiB
JavaScript
240 lines
6.0 KiB
JavaScript
/*
|
|
* 手太欠
|
|
* 愿这世界都如故事里一样 美好而动人~
|
|
*/
|
|
|
|
Page({
|
|
data: {
|
|
barHeight : getApp().globalData.barHeight, // 状态栏高度
|
|
openId : '',
|
|
nameValue : '', // 姓名
|
|
testTitle : '',
|
|
nameStatus: false, // 姓名填写弹框
|
|
Analyze : '', // 是否交钱
|
|
disabled : false, // 支付按钮
|
|
payStatus : false, // 支付弹框
|
|
payPrice : '', // 支付金额
|
|
},
|
|
|
|
onLoad(options) {
|
|
this.setData({
|
|
openId: options.code
|
|
})
|
|
if(options) {
|
|
wx.login({
|
|
success: res => {
|
|
// 获取openid
|
|
this.openInfo(res.code)
|
|
}
|
|
})
|
|
}
|
|
},
|
|
|
|
onShow() {
|
|
// 判断是否可检测
|
|
this.ifAnalyze();
|
|
},
|
|
|
|
|
|
/**
|
|
* openid
|
|
*/
|
|
openInfo(code) {
|
|
wx.$api.auth.codeOpenid({code: code}).then(res => {
|
|
this.setData({
|
|
openId: res.data
|
|
})
|
|
}).catch(err => {})
|
|
},
|
|
|
|
/**
|
|
* 是否可检测
|
|
*/
|
|
ifAnalyze() {
|
|
wx.$api.index.analyze().then(res => {
|
|
if(res.data.is_first) {
|
|
this.setData({
|
|
testTitle: '首次免费,开始测肤'
|
|
})
|
|
} else if (res.data.is_first == false && res.data.analyze == false) {
|
|
this.setData({
|
|
testTitle: '支付' + res.data.price + '元,进行测肤'
|
|
})
|
|
} else if (res.data.is_first == false && res.data.analyze == true) {
|
|
this.setData({
|
|
testTitle: '您已付费,进行检测'
|
|
})
|
|
}
|
|
|
|
this.setData({
|
|
Analyze : res.data
|
|
})
|
|
if(!res.data.is_update) {
|
|
this.setData({
|
|
nameStatus: true
|
|
})
|
|
}
|
|
}).catch(err => {})
|
|
},
|
|
|
|
/*
|
|
姓名截取
|
|
*/
|
|
bindinput(e) {
|
|
this.setData({
|
|
nameValue: e.detail.value.substr(0,5)
|
|
})
|
|
},
|
|
|
|
/*
|
|
提交信息
|
|
*/
|
|
issueForm() {
|
|
wx.showLoading({
|
|
title: '信息提交中...',
|
|
mask : true
|
|
})
|
|
let data = {
|
|
name : this.data.nameValue
|
|
}
|
|
wx.$api.auth.userAdd(data).then(() => {
|
|
wx.hideLoading()
|
|
this.setData({
|
|
nameStatus: false
|
|
})
|
|
}).catch(err => {})
|
|
},
|
|
|
|
/**
|
|
* 开始皮肤检测
|
|
*/
|
|
goAnalyze() {
|
|
if(this.data.Analyze.is_first == false && this.data.Analyze.analyze == false) {
|
|
this.setData({
|
|
payStatus: true
|
|
})
|
|
} else {
|
|
this.uploadPhoto()
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 上传图片信息
|
|
*/
|
|
uploadPhoto() {
|
|
wx.chooseMedia({
|
|
count : 1,
|
|
sourceType: ['camera'],
|
|
camera : 'front',
|
|
success : path => {
|
|
// 获取皮肤检测接口
|
|
if(wx.cropImage){
|
|
wx.cropImage({
|
|
src: path.tempFiles[0].tempFilePath, // 图片路径
|
|
cropScale: '3:4', // 裁剪比例
|
|
success: res=> {
|
|
// 获取皮肤检测接口
|
|
this.checkEnter(res.tempFilePath);
|
|
},
|
|
complete: err => {}
|
|
})
|
|
return
|
|
}
|
|
this.checkEnter(path.tempFiles[0].tempFilePath);
|
|
}
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 皮肤检测接口
|
|
*/
|
|
checkEnter(img) {
|
|
wx.$api.index.skinEnter({}, img).then(res => {
|
|
wx.redirectTo({
|
|
url: "/pages/report/detail/detail?image_id=" + res.image_id
|
|
})
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 关闭支付弹窗
|
|
*/
|
|
cancelAnalyze() {
|
|
this.setData({
|
|
payStatus: false
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 创建订单
|
|
*/
|
|
payFound() {
|
|
wx.$api.index.skinOrder().then(res => {
|
|
this.setData({
|
|
disabled : true
|
|
})
|
|
this.payBtn(res.data.order_id)
|
|
}).catch(err => {})
|
|
},
|
|
|
|
/**
|
|
* 确认支付1元
|
|
*/
|
|
payBtn(orderid) {
|
|
wx.showLoading({
|
|
title: '支付中...',
|
|
mask : true
|
|
})
|
|
wx.$api.index.skinPay(orderid,{type: 'miniapp', openid: this.data.openId}).then(res=>{
|
|
wx.hideLoading()
|
|
let payInfo = JSON.parse(res.data.wechat)
|
|
wx.requestPayment({
|
|
timeStamp: payInfo.timeStamp,
|
|
nonceStr : payInfo.nonceStr,
|
|
package : payInfo.package,
|
|
paySign : payInfo.paySign,
|
|
signType : payInfo.signType,
|
|
success : res=>{
|
|
if(res.errMsg == "requestPayment:ok"){
|
|
wx.showToast({
|
|
title: '支付成功',
|
|
icon : 'success'
|
|
})
|
|
}
|
|
this.setData({
|
|
payStatus: false
|
|
})
|
|
this.setData({
|
|
Analyze: false
|
|
})
|
|
this.uploadPhoto()
|
|
},
|
|
fail : err=>{
|
|
wx.showToast({
|
|
title: '支付失败',
|
|
icon : 'error'
|
|
})
|
|
this.setData({
|
|
disabled : false,
|
|
payStatus: false
|
|
})
|
|
}
|
|
})
|
|
}).catch(err => {
|
|
this.setData({
|
|
disabled : false,
|
|
payStatus: false
|
|
})
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 返回上一页
|
|
*/
|
|
returnGo() {
|
|
wx.navigateBack({
|
|
delta: 1
|
|
})
|
|
},
|
|
})
|