// component/myInfo/myInfo.ts import { ConstsData } from "../../utils/const" import { httpUtil } from "../../utils/restful"; Component({ /** * 组件的属性列表 */ properties: { }, /** * 组件的初始数据 */ data: { regionOne: Array(), regionTwo: Array(), regionThree: Array(), regionOneIndex: 0, regionTwoIndex: 0, regionThreeIndex: 0, region: [ Array(), Array(), Array() ], regionIndex: [0, 0, 0], schoolArray: [['中国']], schoolIndex: 0, classArray: ['一年级一班', '一年级2班', '一年级3班', '一年级4班'], classIndex: 0, provinceValue: '',//省份value regionValue: '',//地区value cityValue: '', schoolData: [{ 'id': '' }], schoolId: '', classData: [{ 'id': '' }], classId: '', isShowPassWord: true, userName: "", userPwd: "" }, lifetimes: { attached: function () { // 在组件实例被从页面节点树添加时执行 this.changeOrganizeInfo() }, detached: function () { // 在组件实例被从页面节点树移除时执行 }, }, /** * 组件的方法列表 */ methods: { changeOrganizeInfo: function () { //切换地区 this.setData({ regionOne: [], regionTwo: [], regionThree: [] }) ConstsData.AppData.organizeInfo.data.children.forEach((item: { title: String; }) => { this.data.regionOne.push(item.title) }) ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children.forEach((item: { title: String; }) => { this.data.regionTwo.push(item.title) }) ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].children.forEach((item: { title: String; }) => { this.data.regionThree.push(item.title) }) this.setData({ region: [this.data.regionOne, this.data.regionTwo, this.data.regionThree], regionIndex: [this.data.regionOneIndex, this.data.regionTwoIndex, this.data.regionThreeIndex], provinceValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].value.toString(), cityValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].value.toString(), regionValue: ConstsData.AppData.organizeInfo.data.children[this.data.regionOneIndex].children[this.data.regionTwoIndex].children[this.data.regionThreeIndex].value.toString() }) //切换学校 this.changeSchool(); //切换班级 }, //查询学校 changeSchool: function () { //查询学校 let params = { city: this.data.cityValue, province: this.data.provinceValue, region: this.data.regionValue, type: 1, } httpUtil.wxGet(httpUtil.interfaces.getSchoolOrClass, params).then((res: any) => { this.setData({ schoolArray: [], schoolIndex: 0, schoolData: res.data.data, schoolId: res.data.data[0].id }) let newArray: string[] = []; res.data.data.forEach((element: { title: string; }) => { newArray.push(element.title) }); this.data.schoolArray.push(newArray) this.setData({ schoolArray: this.data.schoolArray }) this.changeClass() }).catch(res => { console.log("查询学校error:", res) }) }, //查询班级 changeClass: function () { let params = { "city": this.data.cityValue, "father": this.data.schoolId,//学校ID "province": this.data.provinceValue, "region": this.data.regionValue, "type": 2, } httpUtil.wxGet(httpUtil.interfaces.getSchoolOrClass, params).then((res: any) => { this.setData({ classArray: [], classIndex: 0 }) this.setData({ classData: res.data.data, classId: res.data.data[0].id }) res.data.data.forEach((element: { title: string; }) => { this.data.classArray.push(element.title) }); this.setData({ classArray: this.data.classArray, }) }).catch(res => { console.log("查询班级error:", res) }) }, bindMultiPickerColumnChange: function (event: any) { // switch (Number(event.detail.column)) { case 0: //代表第一列 this.setData({ regionOneIndex: event.detail.value, }) break; case 1: //代表第二列 this.setData({ regionTwoIndex: event.detail.value, }) break; case 2: //代表第三列 this.setData({ regionThreeIndex: event.detail.value }) break; } this.changeOrganizeInfo(); }, bindRegionChange: function (event: any) { this.setData({ regionIndex: event.detail.value }) }, bindSchoolPicker: function (event: any) { this.setData({ schoolIndex: event.detail.value, schoolId: this.data.schoolData[event.detail.value].id }) this.changeClass(); }, bindClssPicker: function (event: any) { this.setData({ classIndex: event.detail.value }) }, showPwdTab: function () { if (this.data.isShowPassWord) { this.setData({ isShowPassWord: false }) } else { this.setData({ isShowPassWord: true }) } }, bindUserNameInput: function (event: any) { this.setData({ userName: event.detail.value }) }, bindUserPwdInput: function (event: any) { this.setData({ userPwd: event.detail.value }) }, submitMyInfo: function () { if (!this.data.userName) { wx.showToast({ title: '请输入姓名', icon: 'none', duration: 1000 }) return; } if (!this.data.userPwd) { wx.showToast({ title: '请输入密码', icon: 'none', duration: 1000 }) return; } let params = { name: this.data.userName, address: this.data.region[0] + "--" + this.data.region[1] + "--" + this.data.region[2], school: this.data.schoolArray[this.data.schoolIndex], class: this.data.classArray[this.data.classIndex], password: this.data.userPwd } console.log("params:", params) } } })