set_info.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. // pages/set_info/set_info.js
  2. const { throttle } = require('../../utils/util.js')
  3. const app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. statusBar: app.globalData.statusBar,
  10. isSex:0,
  11. ageList:[
  12. {
  13. ageNum:'3岁~5岁',
  14. status:''
  15. },
  16. {
  17. ageNum: '5岁~10岁',
  18. status: ''
  19. },
  20. {
  21. ageNum: '10岁~18岁',
  22. status: ''
  23. },
  24. {
  25. ageNum: '18岁以上',
  26. status: ''
  27. },
  28. ],
  29. sexList:[
  30. {
  31. sexNum: '男',
  32. img:'../../image/man.png',
  33. status: ''
  34. },
  35. {
  36. sexNum: '女',
  37. img: '../../image/women.png',
  38. status: ''
  39. },
  40. ]
  41. },
  42. /**
  43. * 生命周期函数--监听页面加载
  44. */
  45. onLoad: function (options) {
  46. this.setData(options)
  47. },
  48. /**
  49. * 生命周期函数--监听页面初次渲染完成
  50. */
  51. onReady: function () {
  52. },
  53. /**
  54. * 生命周期函数--监听页面显示
  55. */
  56. onShow: function () {
  57. },
  58. /**
  59. * 生命周期函数--监听页面隐藏
  60. */
  61. onHide: function () {
  62. },
  63. /**
  64. * 生命周期函数--监听页面卸载
  65. */
  66. onUnload: function () {
  67. },
  68. /**
  69. * 页面相关事件处理函数--监听用户下拉动作
  70. */
  71. onPullDownRefresh: function () {
  72. },
  73. /**
  74. * 页面上拉触底事件的处理函数
  75. */
  76. onReachBottom: function () {
  77. },
  78. /**
  79. * 用户点击右上角分享
  80. */
  81. onShareAppMessage: function () {
  82. if (app.sharePageDefaultCtl) {
  83. return app.sharePageDefaultCtl()
  84. }
  85. },
  86. /**
  87. * 底部导航跳转
  88. */
  89. redirectCtl: app.redirectCtl,
  90. /**
  91. * 路由跳转
  92. */
  93. navigateCtl: app.navigateCtl,
  94. /**
  95. * 返回上一级页面
  96. */
  97. blockCtl: function () {
  98. this.redirectCtl({ url: 'me', method: {} }, true)
  99. },
  100. /**
  101. * 选择年龄
  102. */
  103. selectSex:function(){
  104. const {isSex}=this.data
  105. this.setData({ isSex:!isSex})
  106. },
  107. /**
  108. * input
  109. */
  110. inputCtl: function (e) {
  111. const mobileExp = /^1[0-9]{10}$/;
  112. const { temp = {}, type } = e.currentTarget.dataset
  113. const { value } = e.detail
  114. temp[type] = value;
  115. const { phone, name,age,school} = temp;
  116. if (type == 'phone') {
  117. this.setData({ phone })
  118. } else if (type == 'name') {
  119. return this.setData({ name })
  120. } else if (type == 'age') {
  121. return this.setData({ age })
  122. } else if (type == 'school') {
  123. return this.setData({school})
  124. }
  125. },
  126. /**
  127. * 选择性别
  128. */
  129. setSex: function (e) {
  130. const { sidx, sex } = e.currentTarget.dataset;
  131. const {isSex}=this.data
  132. this.setData({ sex, sexIdx: sidx,isSex:!isSex })
  133. },
  134. /**
  135. * 选择年龄
  136. */
  137. setAge:function(e){
  138. const { idx, age } = e.currentTarget.dataset;
  139. this.setData({ age, ageIdx:idx})
  140. const { ageList}=this.data;
  141. var temp={};
  142. temp[`ageList[${idx}].status`] = ageList[idx].status == '' ? 'active' : ''
  143. this.setData(temp);
  144. },
  145. /**
  146. * 开始测试
  147. */
  148. setInfo:throttle(function(){
  149. const mobileExp = /^1[0-9]{10}$/;
  150. const postData = { fn: this.setInfo, param: { ...arguments } }
  151. const {sexIdx, age,name,phone,sex,school}=this.data;
  152. var that=this;
  153. console.log('dianji')
  154. if (!name) {
  155. wx.showToast({
  156. title: '请输入姓名',
  157. icon: 'none'
  158. })
  159. return
  160. }
  161. if (age>150) {
  162. wx.showToast({
  163. title: '年龄不能大于150',
  164. icon: 'none'
  165. })
  166. return
  167. }
  168. if (!age) {
  169. wx.showToast({
  170. title: '请输入年龄',
  171. icon: 'none'
  172. })
  173. return
  174. }
  175. if (!sex) {
  176. wx.showToast({
  177. title: '请选择性别',
  178. icon: 'none'
  179. })
  180. return
  181. }
  182. if (!school) {
  183. wx.showToast({
  184. title: '请输入学校',
  185. icon: 'none'
  186. })
  187. return
  188. }
  189. if (!phone) {
  190. wx.showToast({
  191. title: '手机号码不能为空',
  192. icon: 'none'
  193. })
  194. return
  195. } else if (!mobileExp.test(phone)) {
  196. wx.showToast({
  197. title: '手机号码位数不对',
  198. icon: 'none',
  199. duration: 1000
  200. })
  201. return
  202. }
  203. app.post('/api/game/v2/saveRespondentInfo', { sex:sexIdx+1, age,name,phone,school}, 0, postData).then(res => {
  204. const{gameRespondentId}=res.data
  205. that.redirectCtl({ url: 'tu_xing_tui_li', method: { level: 0, ageGroup:age,gameRespondentId } }, true)
  206. })
  207. },1000)
  208. })