/* * 手太欠 * 愿这世界都如故事里一样 美好而动人~ */ Page({ data: { barHeight : getApp().globalData.barHeight, // 状态栏高度 nameValue : '', // 姓名 testTitle : '', nameStatus : false, // 姓名填写弹框 Analyze : '', // 是否交钱 disabled : false, // 支付按钮 payStatus : false, // 支付弹框 payPrice : '', // 支付金额 refertoType: 0, }, onLoad(options) { // 体验官 type=1或者type=2 直接面检,不用交钱 this.setData({ refertoType: options.type || 0 }) }, onShow() { if(this.data.refertoType == '1' || this.data.refertoType == '2') { this.setData({ testTitle: '请您开始测肤' }) return } // 判断是否可检测 this.ifAnalyze(); }, /** * 是否可检测 */ 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, mediaType: ['image'], 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({type: this.data.refertoType}, img).then(res => { wx.redirectTo({ url: "/pages/report/detail/detail?image_id=" + res.image_id + "&type=" + this.data.refertoType }) }) }, /** * 关闭支付弹窗 */ cancelAnalyze() { this.setData({ payStatus: false }) }, /** * 创建订单 */ payFound() { this.setData({ disabled : true }) wx.$api.index.skinOrder().then(res => { this.payBtn(res.data.order_id) }).catch(err => { this.setData({ disabled: false }) }) }, /** * 确认支付1元 */ payBtn(orderid) { wx.showLoading({ title: '支付中...', mask : true }) wx.$api.index.skinPay(orderid,{type: 'miniapp', openid: wx.getStorageSync("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({ disabled : false, 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 }) }, })