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.

questionnaire.js 6.4 KiB

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