/* * 手太欠 * 愿这世界都如故事里一样 美好而动人~ */ Page({ data: { barHeight : getApp().globalData.barHeight, // 状态栏高度 nameValue : '', // 姓名 nameStatus: false, // 姓名填写弹框 Analyze : '', // 是否交钱 disabled : false, // 支付按钮 payStatus : false, // 支付弹框 payPrice : '', // 支付金额 }, onLoad(options) { }, onShow() { // 判断是否可检测 this.ifAnalyze(); }, /** * 是否可检测 */ ifAnalyze() { wx.$api.index.analyze().then(res => { this.setData({ Analyze : res.data.analyze, payPrice : res.data.price }) 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) { this.uploadPhoto() return } this.setData({ payStatus: true }) }, /** * 上传图片信息 */ uploadPhoto() { wx.chooseMedia({ count : 1, mediaType: ['image'], sourceType: ['camera'], camera : 'front', success : path => { // 获取皮肤检测接口 wx.cropImage({ src: path.tempFiles[0].tempFilePath, // 图片路径 cropScale: '3:4', // 裁剪比例 success: res=> { // 获取皮肤检测接口 this.checkEnter(res.tempFilePath); }, complete: err => {} }) } }) }, /** * 皮肤检测接口 */ 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.uploadPhoto() }, fail : err=>{ wx.showToast({ title: '支付失败', icon : 'error' }) this.setData({ disabled : false, payStatus: false }) } }) }).catch(err => {}); }, /** * 返回上一页 */ returnGo() { wx.navigateBack({ delta: 1 }) }, })