const app = getApp() const util = require('../../utils/util.js') Page({ data: { questions:[], step:0, answers:[], userScore:0, loaddisplay: true, prx_id: null, pd_title: null, pd_imgurl: null }, onLoad: function (options) { //记录促销渠道log var that = this this.setData({ loaddisplay: true, prx_id: options.id }) if (options.phone != null && options.phone != "" ){ if (options.phone.substr(0, 2) === 'P_') { wx.request({ url: app.globalData.url + '/insertPromotionChannelLog', method: 'post', header: { "Content-Type": "application/x-www-form-urlencoded" }, data: { prx_id: options.id, pcl_date: 1, pcl_openid: app.globalData.openid, pcl_channel_code: options.phone }, success: function (res) { } }) } } // 增加促销ID wx.request({ url: app.globalData.url + '/getPromotionTestUserScoreByOpenID', method: 'post', header: { "Content-Type": "application/x-www-form-urlencoded" }, data: { pc_openid: app.globalData.openid, pc_prx_id: options.id }, success: function (res) { if (res.data != null && res.data != '') { wx.navigateTo({ url: '/pages/testpromotion/testresult/testresult?score=' + res.data.pc_score + '&prx_id=' + that.data.prx_id }) } } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { var that = this this.setData({ step: 0, userScore: 0, loaddisplay: true }) wx.request({ url: app.globalData.url + '/getPromotionDCByID', method: 'get', data: { id: this.data.prx_id }, success: function (res) { that.setData({ pd_title: res.data.pd_title, pd_imgurl: res.data.pd_imgurl }) wx.setNavigationBarTitle({ title: res.data.pd_title, success: function (res) { // success } }) } }) //获取题目 wx.request({ url: app.globalData.url + '/getPromotionTestByPrxID', method: 'get', data: { prx_id: this.data.prx_id }, success: function (resq) { that.setData({ questions: resq.data }) that.changQuestion(resq.data[0].id) } }) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { return { title: this.data.pd_title, path: '/pages/index/index?share=promotion&url=/pages/testpromotion/testpromotion&id=' + this.data.prx_id+'', // path: '/pages/testpromotion/testpromotion?id=' + this.data.prx_id, imageUrl: this.data.pd_imgurl } }, reply: function (e) { var that = this this.setData({ userScore: this.data.userScore + e.currentTarget.dataset.score }) if (this.data.questions.length-1 === this.data.step) { //保存结果 wx.request({ url: app.globalData.url + '/insertPromotionTestUserScore', method: 'post', header: { "Content-Type": "application/x-www-form-urlencoded" }, data: { pc_openid: app.globalData.openid, pc_score: this.data.userScore, pc_prx_id: this.data.prx_id }, success: function (res) { that.setData({ loaddisplay: 'none' }) wx.navigateTo({ url: '/pages/testpromotion/testresult/testresult?score=' + that.data.userScore + '&prx_id=' + that.data.prx_id }) } }) } else { this.setData({ step: this.data.step +1 }) this.changQuestion(this.data.questions[this.data.step].id) } }, changQuestion: function (setp) { this.setData({ loaddisplay: true }) var that = this wx.request({ url: app.globalData.url + '/getPromotionTestResultByPtID', method: 'get', data: { pt_id: Number(setp) }, success: function (resa) { that.setData({ answers: resa.data }) that.setData({ loaddisplay: 'none' }) } }) } })