抖音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 lines
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 + 50) + '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. tt.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. tt.showToast({
  88. title: str,
  89. icon: 'none',
  90. duration: 2000,
  91. success: () => {
  92. setTimeout(() => {
  93. tt.reLaunch({
  94. url: '/index/index'
  95. })
  96. }, 2000)
  97. }
  98. // mask: false
  99. });
  100. }).catch(err => {
  101. tt.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. app.globalData.skip = 'navigateBack'
  119. tt.navigateTo({
  120. url: `/pages/getPhone/getPhone?skipUrl=1`,
  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. console.log(this.data.id,"this.data.id");
  135. console.log(`/pages/getuserinfo/getuserinfo?fromflag=wj&wjId=${this.data.id}`);
  136. tt.navigateTo({
  137. url: `/pages/getuserinfo/getuserinfo?fromflag=wj&wjId=${this.data.id}`,
  138. })
  139. })
  140. },
  141. //获取问卷详情
  142. getDetail() {
  143. let param = {
  144. id: this.data.id
  145. }
  146. Http.get({
  147. url: config.api.questionnaireDetail,
  148. data: param
  149. }).then(res => {
  150. res.data.question.startDate_Sing = util.formatTime(res.data.question.startDate, "yyyy-MM-dd hh:mm")
  151. res.data.question.endDate_Sing = util.formatTime(res.data.question.endDate, "yyyy-MM-dd hh:mm")
  152. console.log(res.data.question)
  153. if (res.data.userDetails) {
  154. let temp = res.data.question.topicList
  155. temp.map((item, index) => {
  156. // res.data.userDetails
  157. item.answers.map(item2 => {
  158. let tempArr = JSON.parse(res.data.userDetails.logList[index].answer)
  159. if (tempArr.indexOf(item2.id) != -1) {
  160. item2.falg = true
  161. }
  162. })
  163. })
  164. this.setData({
  165. userDetails: res.data.userDetails
  166. })
  167. }
  168. this.setData({
  169. question: res.data.question
  170. })
  171. }).catch(err => {
  172. tt.showToast({
  173. title: err.errMsg,
  174. icon: 'none',
  175. duration: 2000,
  176. // mask: false
  177. });
  178. })
  179. },
  180. /**
  181. * 生命周期函数--监听页面加载
  182. */
  183. onLoad: function(options) {
  184. console.log(options);
  185. this.setData({
  186. id: options.id,
  187. })
  188. },
  189. /**
  190. * 生命周期函数--监听页面初次渲染完成
  191. */
  192. onReady: function() {
  193. },
  194. /**
  195. * 生命周期函数--监听页面显示
  196. */
  197. onShow: function() {
  198. this.userAuthorization()
  199. this.setData({
  200. thenDate: new Date().getTime()
  201. })
  202. this.getDetail()
  203. },
  204. /**
  205. * 生命周期函数--监听页面隐藏
  206. */
  207. onHide: function() {
  208. },
  209. /**
  210. * 生命周期函数--监听页面卸载
  211. */
  212. onUnload: function() {
  213. },
  214. /**
  215. * 页面相关事件处理函数--监听用户下拉动作
  216. */
  217. onPullDownRefresh: function() {
  218. },
  219. /**
  220. * 页面上拉触底事件的处理函数
  221. */
  222. onReachBottom: function() {
  223. },
  224. /**
  225. * 用户点击右上角分享
  226. */
  227. onShareAppMessage: function() {
  228. var that = this;
  229. var shareObj = {
  230. title: "问卷详情",
  231. path: `/pages/main/index?id=${that.data.id}&type=wj`,
  232. success: function (res) {
  233. if (res.errMsg == 'shareAppMessage:ok') { }
  234. },
  235. fail: function (error) {
  236. if (res.errMsg == 'shareAppMessage:fail cancel') { } else if (res.errMsg == 'shareAppMessage:fail') { }
  237. }
  238. };
  239. console.log(shareObj)
  240. // 返回shareObj
  241. return shareObj;
  242. }
  243. })