testpromotion.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. const app = getApp()
  2. const util = require('../../utils/util.js')
  3. Page({
  4. data: {
  5. questions:[],
  6. step:0,
  7. answers:[],
  8. userScore:0,
  9. loaddisplay: true,
  10. prx_id: null,
  11. pd_title: null,
  12. pd_imgurl: null
  13. },
  14. onLoad: function (options) {
  15. //记录促销渠道log
  16. var that = this
  17. this.setData({
  18. loaddisplay: true,
  19. prx_id: options.id
  20. })
  21. if (options.phone != null && options.phone != "" ){
  22. if (options.phone.substr(0, 2) === 'P_') {
  23. wx.request({
  24. url: app.globalData.url + '/insertPromotionChannelLog',
  25. method: 'post',
  26. header: { "Content-Type": "application/x-www-form-urlencoded" },
  27. data: {
  28. prx_id: options.id,
  29. pcl_date: 1,
  30. pcl_openid: app.globalData.openid,
  31. pcl_channel_code: options.phone
  32. },
  33. success: function (res) {
  34. }
  35. })
  36. }
  37. }
  38. // 增加促销ID
  39. wx.request({
  40. url: app.globalData.url + '/getPromotionTestUserScoreByOpenID',
  41. method: 'post',
  42. header: { "Content-Type": "application/x-www-form-urlencoded" },
  43. data: {
  44. pc_openid: app.globalData.openid,
  45. pc_prx_id: options.id
  46. },
  47. success: function (res) {
  48. if (res.data != null && res.data != '') {
  49. wx.navigateTo({
  50. url: '/pages/testpromotion/testresult/testresult?score=' + res.data.pc_score + '&prx_id=' + that.data.prx_id
  51. })
  52. }
  53. }
  54. })
  55. },
  56. /**
  57. * 生命周期函数--监听页面初次渲染完成
  58. */
  59. onReady: function () {
  60. },
  61. /**
  62. * 生命周期函数--监听页面显示
  63. */
  64. onShow: function () {
  65. var that = this
  66. this.setData({
  67. step: 0,
  68. userScore: 0,
  69. loaddisplay: true
  70. })
  71. wx.request({
  72. url: app.globalData.url + '/getPromotionDCByID',
  73. method: 'get',
  74. data: {
  75. id: this.data.prx_id
  76. },
  77. success: function (res) {
  78. that.setData({
  79. pd_title: res.data.pd_title,
  80. pd_imgurl: res.data.pd_imgurl
  81. })
  82. wx.setNavigationBarTitle({
  83. title: res.data.pd_title,
  84. success: function (res) {
  85. // success
  86. }
  87. })
  88. }
  89. })
  90. //获取题目
  91. wx.request({
  92. url: app.globalData.url + '/getPromotionTestByPrxID',
  93. method: 'get',
  94. data: {
  95. prx_id: this.data.prx_id
  96. },
  97. success: function (resq) {
  98. that.setData({
  99. questions: resq.data
  100. })
  101. that.changQuestion(resq.data[0].id)
  102. }
  103. })
  104. },
  105. /**
  106. * 生命周期函数--监听页面隐藏
  107. */
  108. onHide: function () {
  109. },
  110. /**
  111. * 生命周期函数--监听页面卸载
  112. */
  113. onUnload: function () {
  114. },
  115. /**
  116. * 页面相关事件处理函数--监听用户下拉动作
  117. */
  118. onPullDownRefresh: function () {
  119. },
  120. /**
  121. * 页面上拉触底事件的处理函数
  122. */
  123. onReachBottom: function () {
  124. },
  125. /**
  126. * 用户点击右上角分享
  127. */
  128. onShareAppMessage: function () {
  129. return {
  130. title: this.data.pd_title,
  131. path: '/pages/index/index?share=promotion&url=/pages/testpromotion/testpromotion&id=' + this.data.prx_id+'',
  132. // path: '/pages/testpromotion/testpromotion?id=' + this.data.prx_id,
  133. imageUrl: this.data.pd_imgurl
  134. }
  135. },
  136. reply: function (e) {
  137. var that = this
  138. this.setData({
  139. userScore: this.data.userScore + e.currentTarget.dataset.score
  140. })
  141. if (this.data.questions.length-1 === this.data.step) {
  142. //保存结果
  143. wx.request({
  144. url: app.globalData.url + '/insertPromotionTestUserScore',
  145. method: 'post',
  146. header: { "Content-Type": "application/x-www-form-urlencoded" },
  147. data: {
  148. pc_openid: app.globalData.openid,
  149. pc_score: this.data.userScore,
  150. pc_prx_id: this.data.prx_id
  151. },
  152. success: function (res) {
  153. that.setData({
  154. loaddisplay: 'none'
  155. })
  156. wx.navigateTo({
  157. url: '/pages/testpromotion/testresult/testresult?score=' + that.data.userScore + '&prx_id=' + that.data.prx_id
  158. })
  159. }
  160. })
  161. } else {
  162. this.setData({
  163. step: this.data.step +1
  164. })
  165. this.changQuestion(this.data.questions[this.data.step].id)
  166. }
  167. },
  168. changQuestion: function (setp) {
  169. this.setData({
  170. loaddisplay: true
  171. })
  172. var that = this
  173. wx.request({
  174. url: app.globalData.url + '/getPromotionTestResultByPtID',
  175. method: 'get',
  176. data: {
  177. pt_id: Number(setp)
  178. },
  179. success: function (resa) {
  180. that.setData({
  181. answers: resa.data
  182. })
  183. that.setData({
  184. loaddisplay: 'none'
  185. })
  186. }
  187. })
  188. }
  189. })