123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- // pages/contest/contest.js
- import {
- imine
- } from '../../../api/api.js'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- showSchool:false,
- sexList: [{label:'男',value:1},{label:'女',value:2}],
- form: {schoolName:''},
- areaList: [],
- sortList: [
- {name:'actualName',title:'姓名'},
- {name:'sex',title:'性别'},
- {name:'birthday',title:'生日'},
- {name:'area',title:'区域'},
- {name:'school',title:'学校'},
- {name:'grade',title:'年级'}
- ],
- ageList: [],
- gradeList: [
- {label:'一年级',value:'一年级'},
- {label:'二年级',value:'二年级'},
- {label:'三年级',value:'三年级'},
- {label:'四年级',value:'四年级'},
- {label:'五年级',value:'五年级'},
- {label:'六年级',value:'六年级'},
- {label:'七年级',value:'七年级'},
- {label:'八年级',value:'八年级'},
- {label:'九年级',value:'九年级'},
- {label:'高一',value:'高一'},
- {label:'高二',value:'高二'},
- {label:'高三',value:'高三'}
- ],
- schoolList: [],
- jgList: [true,true,true,true,true,true],
- statusBar: 0
- },
- goHome (e) {
- wx.reLaunch({
- url: '/pages/home/home',
- })
- },
- changeInput (e) {
- const id = e.currentTarget.id;
- let value = (id === 'actualName' ? e.detail.value.replace(/[^\u4E00-\u9FA5]/g, '') : e.detail.value)
- this.setData({
- ['form.'+id]: value
- })
- },
- bindAddrChange (e) {
- const id = e.currentTarget.id;
- const value = e.detail.value
- this.setData({
- ['form.'+id]: value.join(' ')
- })
- },
- bindPickerData (e) {
- const id = e.currentTarget.id;
- const value = this.formatYMD(e.detail.value)
- this.setData({
- ['form.'+id]: value
- })
- },
- formatYMD (time) {
- let date = new Date(time)
- let y = date.getFullYear()
- let m = date.getMonth() + 1
- m = m < 10 ? '0' + m : m
- let d = date.getDate()
- d = d < 10 ? '0' + d : d
- return y + '-' + m + '-' + d
- },
- bindPicker (e) {
- const id = e.currentTarget.id;
- const list = e.currentTarget.dataset.list
- const value = e.detail.value
- this.setData({
- ['form.'+id]: this.data[list][value].value
- })
- },
- handlePickerSchool (e) {
- const id = this.data.form.area
- if (id) {
- const value = e.detail.value
- imine.querySchoolByAreaId({
- reqdata: {
- id,
- keyword: value
- }
- }, res => {
- this.setData({
- schoolList: res.list
- })
- })
- } else {
- wx.showToast({
- title: '请先选择区域',
- icon: 'none'
- })
- }
-
- // this.setData({
- // ['form.'+id]: this.data.schoolList[value].id,
- // ['form.schoolName']: this.data.schoolList[value].schoolName
- // })
- },
- handleShowSchool () {
- if (this.data.schoolList.length) {
- this.setData({
- showSchool: true
- })
- } else {
- wx.showToast({
- icon: 'none',
- title: '请先选择区域'
- })
- }
-
- },
- handleChooseSchool (e) {
- let item = e.currentTarget.dataset.item
- console.log(item)
- // @todo 给学校赋值,并且关闭输入框
- this.setData({
- showSchool:false,
- 'form.school': item.id,
- 'form.schoolName': item.schoolName
- })
- },
- bindPickerChange(e) {
- const id = e.currentTarget.id;
- const value = e.detail.value
- this.setData({
- ['form.'+id]: this.data.areaList[value].id,
- ['form.areaName']: this.data.areaList[value].areaName
- }, () => {
- imine.querySchoolByAreaId({reqdata:{
- id: this.data.form[id]
- }},r => {
- let list = r.list
- let index = list.findIndex(item=>item.schoolName.includes('其他'))
- let obj = list.splice(index,1)
- list.push(obj[0])
- this.setData({
- schoolList: list,
- ['form.school']: null,
- ['form.schoolName']: ''
- })
- })
- })
- },
- submit (e) {
- let {actualName,sex,birthday,area,grade,other,school} = this.data.form
- console.log(this.data.form);
-
- let {sortList} = this.data
- this.setData({
- jgList: sortList.map(item => !!this.data.form[item.name])
- }, () => {
- if (!sortList.every(item => this.data.form[item.name])) {
- console.log(this.data.jgList);
- return
- }
- let id = wx.getStorageSync('id')
- imine.updateUser({reqdata:{actualName,sex,birthday,area,grade,other,school,id}},r => {
- this.loadMyinformation()
- wx.showModal({
- title: '答题须知:',
- content: '1.比赛期间每人最多答题三次\n\n 2.排行榜以得分情况计算',
- confirmColor: '#ff0000',
- cancelText: '返回',
- success (res) {
- if (res.confirm) {
- wx.navigateTo({
- url: '/pages/contest/answer/answer'
- })
- } else if (res.cancel) {
- wx.reLaunch({
- url: '/pages/home/home',
- })
- }
- }
- })
- })
- })
- },
- queryAllArea () {
- imine.queryAllArea({},r => {
- this.setData({
- areaList: r.list
- })
- })
- },
- loadMyinformation() {
- let id = wx.getStorageSync('id')
- imine.loadMyinformation({reqdata: {id}},r => {
- wx.setStorageSync('user', r.object)
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.queryAllArea()
- wx.getSystemInfo({
- success: e => {
- this.setData({
- statusBar: e.statusBarHeight + 13
- })
- }
- })
- let {ageList} = this.data
- for (let index = 0; index < 100; index++) {
- // const element = array[index];
- ageList[index] = { label: index+1+'岁',value: index+1}
- }
- this.setData({
- ageList,
- endDate: new Date().format('yyyy-MM-dd')
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|