C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

252 lines
5.3 KiB

  1. // pages/questionnaire/questionnaire.js
  2. const Http = require("../../utils/HttpBasics");
  3. var config = require("../../config/config.js");
  4. const util = require("../../utils/util.js");
  5. var app = getApp();
  6. const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px'
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. navigationBarHeight,
  13. id: "",
  14. question: {},
  15. userDetails: "",
  16. thenDate: "",
  17. },
  18. //设置选中项
  19. setLsit(e) {
  20. if (this.data.userDetails != "") {
  21. return
  22. }
  23. let index1 = e.currentTarget.dataset.index1
  24. let index2 = e.currentTarget.dataset.index2
  25. let tempList = this.data.question
  26. if (tempList.topicList[index1].type == 1) {
  27. tempList.topicList[index1].answers.map(item => {
  28. item.falg = false
  29. })
  30. tempList.topicList[index1].answers[index2].falg = !tempList.topicList[index1].answers[index2].falg
  31. } else {
  32. tempList.topicList[index1].answers[index2].falg = !tempList.topicList[index1].answers[index2].falg
  33. }
  34. this.setData({
  35. question: tempList
  36. })
  37. },
  38. //提交
  39. save() {
  40. let falg = false
  41. let logList = []
  42. let tmepData = this.data.question.topicList
  43. tmepData.map(item => {
  44. let tmepObj = {}
  45. let tempArr = []
  46. tmepObj.topicId = item.id
  47. item.answers.map(res => {
  48. if (res.falg) {
  49. tempArr.push(res.id)
  50. item.complete = true
  51. }
  52. })
  53. tmepObj.answer = JSON.stringify(tempArr)
  54. logList.push(tmepObj)
  55. })
  56. tmepData.map(item => {
  57. if (item.complete == null) {
  58. falg = true
  59. }
  60. })
  61. if (falg) {
  62. wx.showToast({
  63. title: "您还有未答的题目!",
  64. icon: 'none',
  65. duration: 2000,
  66. // mask: false
  67. });
  68. return true
  69. }
  70. let param = {
  71. questionId: this.data.id,
  72. logList: logList
  73. }
  74. console.log(tmepData)
  75. console.log(param, "param")
  76. Http.post({
  77. url: config.api.submitQuestin,
  78. data: param
  79. }).then(res => {
  80. let str = ""
  81. if (this.data.question.rewardCredit) {
  82. str = `感谢您的参与,
  83. ${this.data.question.rewardCredit}积分已经到账啦`
  84. } else {
  85. str = `感谢您的参与!`
  86. }
  87. wx.showToast({
  88. title: str,
  89. icon: 'none',
  90. duration: 2000,
  91. success: () => {
  92. setTimeout(() => {
  93. wx.switchTab({
  94. url: '/index/index'
  95. })
  96. }, 2000)
  97. }
  98. // mask: false
  99. });
  100. }).catch(err => {
  101. wx.showToast({
  102. title: err.errMsg,
  103. icon: 'none',
  104. duration: 2000,
  105. // mask: false
  106. });
  107. })
  108. },
  109. //是否授权手机号
  110. ifPhoneInfo() {
  111. let that = this;
  112. Http.get({
  113. url: config.api.checkPhoneStatus,
  114. data: {}
  115. }).then(res => {
  116. return
  117. }).catch(err => {
  118. wx.navigateTo({
  119. url: `/pages/getuserinfo/index?path=wj&wjId=${this.data.id}`,
  120. })
  121. })
  122. },
  123. /* 判断是否授权*/
  124. userAuthorization() {
  125. Http.get({
  126. url: config.api.checkUserStatus,
  127. data: {
  128. token: app.globalData.token
  129. }
  130. }).then(res => {
  131. this.ifPhoneInfo()
  132. }).catch(err => {
  133. wx.navigateTo({
  134. url: `/pages/getuserinfo/index?fromflag=wj&wjId=${this.data.id}`,
  135. })
  136. })
  137. },
  138. //获取问卷详情
  139. getDetail() {
  140. let param = {
  141. id: this.data.id
  142. }
  143. Http.get({
  144. url: config.api.questionnaireDetail,
  145. data: param
  146. }).then(res => {
  147. res.data.question.startDate_Sing = util.formatTime(res.data.question.startDate, "yyyy-MM-dd hh:mm")
  148. res.data.question.endDate_Sing = util.formatTime(res.data.question.endDate, "yyyy-MM-dd hh:mm")
  149. console.log(res.data.question)
  150. if (res.data.userDetails) {
  151. let temp = res.data.question.topicList
  152. temp.map((item, index) => {
  153. // res.data.userDetails
  154. item.answers.map(item2 => {
  155. let tempArr = JSON.parse(res.data.userDetails.logList[index].answer)
  156. if (tempArr.indexOf(item2.id) != -1) {
  157. item2.falg = true
  158. }
  159. })
  160. })
  161. this.setData({
  162. userDetails: res.data.userDetails
  163. })
  164. }
  165. this.setData({
  166. question: res.data.question
  167. })
  168. }).catch(err => {
  169. wx.showToast({
  170. title: err.errMsg,
  171. icon: 'none',
  172. duration: 2000,
  173. // mask: false
  174. });
  175. })
  176. },
  177. /**
  178. * 生命周期函数--监听页面加载
  179. */
  180. onLoad: function(options) {
  181. this.setData({
  182. id: options.id,
  183. })
  184. this.getDetail()
  185. },
  186. /**
  187. * 生命周期函数--监听页面初次渲染完成
  188. */
  189. onReady: function() {
  190. },
  191. /**
  192. * 生命周期函数--监听页面显示
  193. */
  194. onShow: function() {
  195. this.userAuthorization()
  196. this.setData({
  197. thenDate: new Date().getTime()
  198. })
  199. },
  200. /**
  201. * 生命周期函数--监听页面隐藏
  202. */
  203. onHide: function() {
  204. },
  205. /**
  206. * 生命周期函数--监听页面卸载
  207. */
  208. onUnload: function() {
  209. },
  210. /**
  211. * 页面相关事件处理函数--监听用户下拉动作
  212. */
  213. onPullDownRefresh: function() {
  214. },
  215. /**
  216. * 页面上拉触底事件的处理函数
  217. */
  218. onReachBottom: function() {
  219. },
  220. /**
  221. * 用户点击右上角分享
  222. */
  223. onShareAppMessage: function() {
  224. }
  225. })