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.

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