info.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. // pages/contest/contest.js
  2. import {
  3. imine
  4. } from '../../../api/api.js'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. showSchool:false,
  11. sexList: [{label:'男',value:1},{label:'女',value:2}],
  12. form: {schoolName:''},
  13. areaList: [],
  14. sortList: [
  15. {name:'actualName',title:'姓名'},
  16. {name:'sex',title:'性别'},
  17. {name:'birthday',title:'生日'},
  18. {name:'area',title:'区域'},
  19. {name:'school',title:'学校'},
  20. {name:'grade',title:'年级'}
  21. ],
  22. ageList: [],
  23. gradeList: [
  24. {label:'一年级',value:'一年级'},
  25. {label:'二年级',value:'二年级'},
  26. {label:'三年级',value:'三年级'},
  27. {label:'四年级',value:'四年级'},
  28. {label:'五年级',value:'五年级'},
  29. {label:'六年级',value:'六年级'},
  30. {label:'七年级',value:'七年级'},
  31. {label:'八年级',value:'八年级'},
  32. {label:'九年级',value:'九年级'},
  33. {label:'高一',value:'高一'},
  34. {label:'高二',value:'高二'},
  35. {label:'高三',value:'高三'}
  36. ],
  37. schoolList: [],
  38. jgList: [true,true,true,true,true,true],
  39. statusBar: 0
  40. },
  41. goHome (e) {
  42. wx.reLaunch({
  43. url: '/pages/home/home',
  44. })
  45. },
  46. changeInput (e) {
  47. const id = e.currentTarget.id;
  48. let value = (id === 'actualName' ? e.detail.value.replace(/[^\u4E00-\u9FA5]/g, '') : e.detail.value)
  49. this.setData({
  50. ['form.'+id]: value
  51. })
  52. },
  53. bindAddrChange (e) {
  54. const id = e.currentTarget.id;
  55. const value = e.detail.value
  56. this.setData({
  57. ['form.'+id]: value.join(' ')
  58. })
  59. },
  60. bindPickerData (e) {
  61. const id = e.currentTarget.id;
  62. const value = this.formatYMD(e.detail.value)
  63. this.setData({
  64. ['form.'+id]: value
  65. })
  66. },
  67. formatYMD (time) {
  68. let date = new Date(time)
  69. let y = date.getFullYear()
  70. let m = date.getMonth() + 1
  71. m = m < 10 ? '0' + m : m
  72. let d = date.getDate()
  73. d = d < 10 ? '0' + d : d
  74. return y + '-' + m + '-' + d
  75. },
  76. bindPicker (e) {
  77. const id = e.currentTarget.id;
  78. const list = e.currentTarget.dataset.list
  79. const value = e.detail.value
  80. this.setData({
  81. ['form.'+id]: this.data[list][value].value
  82. })
  83. },
  84. handlePickerSchool (e) {
  85. const id = this.data.form.area
  86. if (id) {
  87. const value = e.detail.value
  88. imine.querySchoolByAreaId({
  89. reqdata: {
  90. id,
  91. keyword: value
  92. }
  93. }, res => {
  94. this.setData({
  95. schoolList: res.list
  96. })
  97. })
  98. } else {
  99. wx.showToast({
  100. title: '请先选择区域',
  101. icon: 'none'
  102. })
  103. }
  104. // this.setData({
  105. // ['form.'+id]: this.data.schoolList[value].id,
  106. // ['form.schoolName']: this.data.schoolList[value].schoolName
  107. // })
  108. },
  109. handleShowSchool () {
  110. if (this.data.schoolList.length) {
  111. this.setData({
  112. showSchool: true
  113. })
  114. } else {
  115. wx.showToast({
  116. icon: 'none',
  117. title: '请先选择区域'
  118. })
  119. }
  120. },
  121. handleChooseSchool (e) {
  122. let item = e.currentTarget.dataset.item
  123. console.log(item)
  124. // @todo 给学校赋值,并且关闭输入框
  125. this.setData({
  126. showSchool:false,
  127. 'form.school': item.id,
  128. 'form.schoolName': item.schoolName
  129. })
  130. },
  131. bindPickerChange(e) {
  132. const id = e.currentTarget.id;
  133. const value = e.detail.value
  134. this.setData({
  135. ['form.'+id]: this.data.areaList[value].id,
  136. ['form.areaName']: this.data.areaList[value].areaName
  137. }, () => {
  138. imine.querySchoolByAreaId({reqdata:{
  139. id: this.data.form[id]
  140. }},r => {
  141. let list = r.list
  142. let index = list.findIndex(item=>item.schoolName.includes('其他'))
  143. let obj = list.splice(index,1)
  144. list.push(obj[0])
  145. this.setData({
  146. schoolList: list,
  147. ['form.school']: null,
  148. ['form.schoolName']: ''
  149. })
  150. })
  151. })
  152. },
  153. submit (e) {
  154. let {actualName,sex,birthday,area,grade,other,school} = this.data.form
  155. console.log(this.data.form);
  156. let {sortList} = this.data
  157. this.setData({
  158. jgList: sortList.map(item => !!this.data.form[item.name])
  159. }, () => {
  160. if (!sortList.every(item => this.data.form[item.name])) {
  161. console.log(this.data.jgList);
  162. return
  163. }
  164. let id = wx.getStorageSync('id')
  165. imine.updateUser({reqdata:{actualName,sex,birthday,area,grade,other,school,id}},r => {
  166. this.loadMyinformation()
  167. wx.showModal({
  168. title: '答题须知:',
  169. content: '1.比赛期间每人最多答题三次\n\n 2.排行榜以得分情况计算',
  170. confirmColor: '#ff0000',
  171. cancelText: '返回',
  172. success (res) {
  173. if (res.confirm) {
  174. wx.navigateTo({
  175. url: '/pages/contest/answer/answer'
  176. })
  177. } else if (res.cancel) {
  178. wx.reLaunch({
  179. url: '/pages/home/home',
  180. })
  181. }
  182. }
  183. })
  184. })
  185. })
  186. },
  187. queryAllArea () {
  188. imine.queryAllArea({},r => {
  189. this.setData({
  190. areaList: r.list
  191. })
  192. })
  193. },
  194. loadMyinformation() {
  195. let id = wx.getStorageSync('id')
  196. imine.loadMyinformation({reqdata: {id}},r => {
  197. wx.setStorageSync('user', r.object)
  198. })
  199. },
  200. /**
  201. * 生命周期函数--监听页面加载
  202. */
  203. onLoad: function (options) {
  204. this.queryAllArea()
  205. wx.getSystemInfo({
  206. success: e => {
  207. this.setData({
  208. statusBar: e.statusBarHeight + 13
  209. })
  210. }
  211. })
  212. let {ageList} = this.data
  213. for (let index = 0; index < 100; index++) {
  214. // const element = array[index];
  215. ageList[index] = { label: index+1+'岁',value: index+1}
  216. }
  217. this.setData({
  218. ageList,
  219. endDate: new Date().format('yyyy-MM-dd')
  220. })
  221. },
  222. /**
  223. * 生命周期函数--监听页面初次渲染完成
  224. */
  225. onReady: function () {
  226. },
  227. /**
  228. * 生命周期函数--监听页面显示
  229. */
  230. onShow: function () {
  231. },
  232. /**
  233. * 生命周期函数--监听页面隐藏
  234. */
  235. onHide: function () {
  236. },
  237. /**
  238. * 生命周期函数--监听页面卸载
  239. */
  240. onUnload: function () {
  241. },
  242. /**
  243. * 页面相关事件处理函数--监听用户下拉动作
  244. */
  245. onPullDownRefresh: function () {
  246. },
  247. /**
  248. * 页面上拉触底事件的处理函数
  249. */
  250. onReachBottom: function () {
  251. },
  252. /**
  253. * 用户点击右上角分享
  254. */
  255. onShareAppMessage: function () {
  256. }
  257. })