123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- 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'
- })
- }
- })
- }
- })
|