C端小程序
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

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