// pages/my/myStudy/myStudy.js const App = getApp(); var util = require("../../../utils/util.js"); let CityArray0 = []; let CityArray1 = []; let CityArray2 = []; let g1 = []; let g2 = []; Page({ /** * 页面的初始数据 */ data: { facultyName: "", professionalTitle: "", appAssetsUrl2: App.appAssetsUrl2, userName: "", areaList: [], schoolList: [], bottomLeft: App.bottomLeft, schoolIndex: 0, sexIndex: null, sexArray: App.sexList, userphoto: "", region: [], multiArray: [0, 0, 0], multiIndex: [0, 0, 0], u: [], allData: {}, load: true, identityNumber: "", college: null, sexCode: null, disabled: false, disabled1: true, obj: { auditStatus: null, }, index0: null, index1: null, schoolPopup: false, pickMove: false, sname: "", searchName: "", tipHeight: 0, consultingTeacher: "", inviteTeacher: "", }, facultyInput(e) { this.setData({ facultyName: e.detail.value, }); }, proInput(e) { this.setData({ professionalTitle: e.detail.value, }); }, messageInput(e) { this.setData({ consultingTeacher: e.detail.value, }); }, guidanceInput(e) { this.setData({ inviteTeacher: e.detail.value, }); }, schoolInput(e) { this.setData({ searchName: e.detail.value, }); this.searchSchool(); console.log(e.detail.value); }, userNameInput(e) { this.setData({ userName: e.detail.value, }); }, idInput(e) { this.setData({ identityNumber: e.detail.value, }); }, //搜索学校 searchSchool() { App._get( "areainfo/selectSchoolInfoByParams/", { region: this.data.allData.region, schoolName: this.data.searchName, }, (res) => { if (res.code === 0) { console.log(res); console.log(this.data.searchName, "this.data.searchName"); this.setData({ schoolList: res.dictList, }); if (res.dictList.length == 0) { App.showError("暂无相关学校!"); } // this.data.schoolList.forEach((v,k) => { // if(v.itemcode == res.data.college) { // return this.setData({ // schoolIndex: k // }) // } // }) } } ); }, submit() { // return this.popup2.showPopup() if (!this.data.allData.region) { return App.showError("请选择地址!"); } if (this.data.college === null) { return App.showError("请选择学校!"); } console.log(this.data.facultyName); if (this.data.facultyName === "") { return App.showError("请输入所属院系!"); } if (this.data.professionalTitle === "") { return App.showError("请输入所学专业!"); } if (this.data.consultingTeacher === "") { return App.showError("请输入邀约老师!"); } if (this.data.inviteTeacher === "") { return App.showError("请输入指导老师!"); } if (this.data.userName === "") { return App.showError("请输入真实姓名!"); } if (this.data.sexIndex === null) { return App.showError("请选择性别!"); } if (this.data.identityNumber === "") { return App.showError("请输入身份证号!"); } if (this.data.identityNumber) { let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; if (!reg.test(this.data.identityNumber)) { return App.showError("请输入正确身份证号!"); } } let that = this; if (that.data.obj.auditStatus == 2) { App._put_form( "studentstatus/update", "", { city: this.data.allData.region, college: this.data.college, faculty: this.data.facultyName, identityNumber: this.data.identityNumber, proofOfQualifications: this.data.userphoto, province: this.data.allData.province, realName: this.data.userName, sex: this.data.sexCode, specialized: this.data.professionalTitle, consultingTeacher: this.data.consultingTeacher, inviteTeacher: this.data.inviteTeacher, memberId: util.getUserId(), id: that.data.obj.id, auditId: that.data.obj.auditId, }, (res) => { if (res.code === 0) { that.popup2.showPopup(); } } ); } else { App._post_form( "studentstatus/save", "", { city: this.data.allData.region, college: this.data.college, faculty: this.data.facultyName, identityNumber: this.data.identityNumber, proofOfQualifications: this.data.userphoto, province: this.data.allData.province, realName: this.data.userName, sex: this.data.sexCode, specialized: this.data.professionalTitle, consultingTeacher: this.data.consultingTeacher, inviteTeacher: this.data.inviteTeacher, memberId: util.getUserId(), }, function (res) { if (res.code == 0) { // wx.navigateTo({ // url: '/expert/success/success' // }) that.popup2.showPopup(); } }, function (res) {} ); } }, getInfo() { let that = this; App._get(`studentstatus/info/${util.getUserId()}`, {}, (res) => { if (res.code === 0) { this.setData({ ["allData.region"]: res.data.city, ["allData.province"]: res.data.province, ["u.province"]: res.data.province, ["u.region"]: res.data.city, college: res.data.college, facultyName: res.data.faculty, identityNumber: res.data.identityNumber, userphoto: res.data.proofOfQualifications, userName: res.data.realName, sexCode: res.data.sex, professionalTitle: res.data.specialized, obj: res.data, sname: res.data.schoolName, consultingTeacher: res.data.consultingTeacher, inviteTeacher: res.data.inviteTeacher, }); console.log(res); this.searchProvince(); if (res.data.city) { App._get("areainfo/Schoolinfo/" + res.data.city, {}, (res2) => { if (res2.code === 0) { this.setData({ schoolList: res2.dictList, }); this.data.schoolList.forEach((v, k) => { if (v.itemcode == res.data.college) { return this.setData({ schoolIndex: k, }); } }); console.log(this.data.schoolIndex, "schoolIndex"); } }); } this.data.sexArray.forEach((v, k) => { if (v.itemcode == res.data.sex) { return this.setData({ sexIndex: k, }); } }); if (res.data.auditStatus == 0 || res.data.auditStatus == 1) { this.setData({ disabled: true, disabled1: true, }); } console.log("省市:", this.data.multiArray); let query = wx.createSelectorQuery(); query .select("#bot-box") .boundingClientRect((rect) => { let height = rect.height; that.setData({ tipHeight: height, }); }) .exec(); } else { let query = wx.createSelectorQuery(); query .select("#bot-box") .boundingClientRect((rect) => { let height = rect.height; that.setData({ tipHeight: height, }); }) .exec(); this.searchProvince(); } }); }, _error() { console.log("返回"); this.popup2.hidePopup(); wx.navigateBack({ delta: 1, }); }, _success() { console.log("查看"); this.popup2.hidePopup(); this.getInfo(); }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { // this.getSchool() this.setData({ sexArray: App.sexList, }); this.getInfo(); }, // 上传学籍 upImg() { if (this.data.disabled) { return; } let _this = this; var tempFile; wx.showActionSheet({ itemList: ["拍照上传", "从相册中选择"], success(res) { if (res.tapIndex === 0) { wx.chooseImage({ count: 1, sizeType: ["original", "compressed"], sourceType: ["camera"], success(res) { const tempFilePaths = res.tempFilePaths; wx.uploadFile({ url: App.apiRoot + "file/upload", filePath: tempFilePaths[0], name: "file", success: function (res) { if (res.errMsg === "uploadFile:ok") { wx.showToast({ title: "上传成功", image: "", duration: 1500, mask: false, }); let data = JSON.parse(res.data); _this.setData({ userphoto: data.data, }); } }, function() { wx.showToast({ title: "上传失败", icon: "none", image: "", duration: 1500, mask: false, }); }, }); }, }); } else if (res.tapIndex === 1) { wx.chooseImage({ count: 1, sizeType: ["original", "compressed"], sourceType: ["album"], success(res) { const tempFilePaths = res.tempFilePaths; wx.uploadFile({ url: App.apiRoot + "file/upload", filePath: tempFilePaths[0], name: "file", success: function (res) { if (res.errMsg === "uploadFile:ok") { wx.showToast({ title: "上传成功", image: "", duration: 1500, mask: false, }); let data = JSON.parse(res.data); _this.setData({ userphoto: data.data, }); } }, function() { wx.showToast({ title: "上传失败", icon: "none", image: "", duration: 1500, mask: false, success: (result) => {}, fail: () => {}, complete: () => {}, }); }, }); }, }); } }, fail(res) {}, }); }, /** * 加载省份 */ searchProvince() { let _this = this; let proId = ""; let prov = ""; // let prov = this.data.allData.province; App._post_form("areainfo/province", "", null, function (res) { if (res.code === 0) { let provice = res.list; _this.data.multiArray[0] = provice; CityArray0 = provice; console.log("数组:", _this.data.u.province); if (_this.data.u.region) { prov = _this.data.u.province; // debugger if (CityArray0.length) { for (let i = 0; i < CityArray0.length; i++) { if (CityArray0[i].areaid == prov) { // _this.data.multiIndex[0] = i; _this.setData({ ["multiIndex[0]"]: i, }); break; } } } } if (prov && _this.data.load === true) { proId = prov; } else { //根据默认省,获取默认市 if (_this.data.multiArray[0].length) { proId = _this.data.multiArray[0][0].areaid; } } _this.loadCity(proId); } }); }, //获取市级 loadCity(cid) { let _this = this; App._post_form("areainfo/city/" + cid, "", null, function (res) { if (res.code === 0) { let city = res.list; _this.data.multiArray[1] = city; CityArray1 = city; if (_this.data.u.region) { let region = _this.data.u.region; if (CityArray1.length) { for (let i = 0; i < CityArray1.length; i++) { if (CityArray1[i].areaid === region) { _this.data.multiIndex[1] = i; break; } } } let cityId = ""; if (region && _this.data.load === true) { cityId = region; } else { if (_this.data.multiArray[1].length) { cityId = _this.data.multiArray[1][0].areaid; } } // _this.loadSchool(cityId) _this.getSchool(_this.data.allData.region); } _this.setData({ multiArray: _this.data.multiArray, multiIndex: _this.data.multiIndex, }); } }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { this.popup2 = this.selectComponent("#popup2"); }, /** * 生命周期函数--监听页面显示 */ onShow() {}, // 获取学校列表 getSchool(id) { App._get("areainfo/Schoolinfo/" + id, {}, (res) => { if (res.code === 0) { this.setData({ schoolList: res.dictList, }); } }); }, schoolChange(e) { let that = this; this.setData({ schoolIndex: e.detail.value, college: that.data.schoolList[e.detail.value]["itemcode"], }); console.log(this.data.college); }, //学校change bindChangeSchool(e) { console.log(e); this.setData({ schoolIndex: e.detail.value, // college: that.data.schoolList[e.detail.value]['itemcode'] }); console.log(this.data.schoolIndex, "mmmmm"); }, pickstart() { this.setData({ pickMove: true, }); }, pickend() { this.setData({ pickMove: false, }); }, confirmSchool() { if (this.data.pickMove) { return; } if (this.data.schoolList.length == 0) { return App.showError("请选择学校!"); } this.setData({ schoolPopup: false, college: this.data.schoolList[this.data.schoolIndex]["itemcode"], }); this.data.schoolList.map((v) => { if (v.itemcode == this.data.college) { this.setData({ sname: v.itemname, }); } }); console.log(this.data.college, "college"); }, // 性别change sexChange(e) { let that = this; this.setData({ sexIndex: e.detail.value, sexCode: that.data.sexArray[e.detail.value]["itemcode"], }); }, // 地区change areaChange(e) { this.data.load = false; let _this = this; _this.data.multiIndex[0] = e.detail.value[0]; _this.data.multiIndex[1] = e.detail.value[1]; _this.setData({ multiIndex: _this.data.multiIndex, ["allData.province"]: CityArray0[_this.data.multiIndex[0]].areaid, ["allData.region"]: CityArray1[_this.data.multiIndex[1]].areaid, }); // _this.loadSchool(_this.data.allData.region) _this.getSchool(_this.data.allData.region); console.log(this.data.allData); console.log("fdjkdfjkjjkjk"); console.log(e); }, //绑定选择器滑动事件 地区 MultiPickerAreaChange: function (e) { this.data.load = false; let _this = this; if (e.detail.column === 0) { let pid = CityArray0[e.detail.value].areaid; _this.data.multiIndex[0] = e.detail.value; _this.loadCity(pid); _this.setData({ index0: e.detail.value, }); } else if (e.detail.column === 1) { _this.data.multiIndex[1] = e.detail.value; _this.setData({ multiIndex: _this.data.multiIndex, }); // _this.setData({ // index1: e.detail.value // }) } console.log(1111111111111); console.log(e); }, schoolName() { if (this.data.disabled) { return; } if (!this.data.allData.region) { return App.showError("请选择学校地址!"); } else { this.setData({ // disabled1: false schoolPopup: true, // schoolIndex: [this.data.schoolIndex], schoolIndex: [0], searchName: "", }); this.getSchool(this.data.allData.region); } console.log(this.data.allData.region, "0000000"); console.log(this.data.schoolIndex, "ffff"); }, hiddenAddress() { this.setData({ schoolPopup: false, }); console.log(11111111111); }, /** * 生命周期函数--监听页面隐藏 */ onHide() {}, /** * 生命周期函数--监听页面卸载 */ onUnload() {}, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() {}, /** * 页面上拉触底事件的处理函数 */ onReachBottom() {}, /** * 用户点击右上角分享 */ onShareAppMessage() {}, });