// pages/my/myData/myData.js var App = getApp() const util = require('../../../utils/util'); let CityArray0 = []; let CityArray1 = []; let CityArray2 = []; let g1 = []; let g2 = []; Page({ /** * 页面的初始数据 */ data: { bottomLeft: App.bottomLeft, load: true, nodata: util.nodata(), u: [], hiddenmodalput: true, sexArray: [], sexIndex: 0, maskShow: false, inputValue: '', multiArray: [0, 0], multiIndex: [0, 0], schoolItem: [], schIndex: 0, isHealthy: [], isHealthyIndex: 0, birthday: util.getNowDate(), birthdayIndex: 0, nowTime: util.getNowDate(), gradeIndex: [0, 0], gradeItem: [], weightItem: [], weightIndex: 0, userphoto: App.appAssetsUrl + '/images/tx.png', checkTimeItems: [], checkskillItems: [], checkboxValue: [], checkboxTxt: '', checkboxText: '', nolink: true, selectShow: false, vague: [], inputSch: '', graduationDate: '', /** * 所有需要提交的数据 */ allData: { college: '', province: null, graduationDate: '' }, isDev: true //开发环境隐藏"编辑资料"页面的部分数据项 }, /** * 防止穿透 */ preventTouchMove() {}, //绑定选择器滑动事件 地区 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); } else if (e.detail.column === 1) { _this.data.multiIndex[1] = e.detail.value; _this.setData({ multiIndex: _this.data.multiIndex }) } }, //点击完成修改后 地区 PickerAreaChange: function(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) }, // 学校选择事件 bindSchChange: function(e) { this.data.load = false; this.setData({ schIndex: e.detail.value }) if (this.data.schoolItem.length > 0) { this.data.allData.college = this.data.schoolItem[e.detail.value].itemcode } }, /** * 年级 完成 */ pickerSchChange: function(e) { this.data.load = false; this.data.gradeIndex[0] = e.detail.value[0] this.data.gradeIndex[1] = e.detail.value[1] this.setData({ gradeIndex: this.data.gradeIndex }) if (this.data.gradeItem) { this.setData({ ['allData.rank']: this.data.gradeItem[1][e.detail.value[1]].id, ['allData.grade']: this.data.gradeItem[0][e.detail.value[0]].id }) } }, /** * 体重滑轨完成 */ bindWeightChange: function(e) { this.data.load = false; this.setData({ weightIndex: e.detail.value }) if (this.data.weightItem) { if (this.data.weightItem[e.detail.value].itemcode) { this.data.allData.weighttype = this.data.weightItem[e.detail.value].itemcode } } }, /** * 年级滑轨后 */ MultiPickerSchChange: function(e) { this.data.load = false; if (e.detail.column === 0) { let pid = g1[e.detail.value].id; let newg2List = []; for (let i = 0; i < g2.length; i++) { if (pid === g2[i].pid) { newg2List.push(g2[i]) } } this.data.gradeItem[1] = newg2List this.setData({ gradeItem: this.data.gradeItem }) } }, /** * 性别滑轨完成 */ bindSexChange: function(e) { this.setData({ sexIndex: e.detail.value }) this.data.load = false; if (this.data.sexArray) { if (this.data.sexArray[e.detail.value].itemcode) { this.data.allData.sex = this.data.sexArray[e.detail.value].itemcode } } }, //生日 bindTimeChange: function(e) { if (e.detail.value) { this.setData({ birthday: e.detail.value }) this.data.allData.birthday = e.detail.value } }, //毕业时间 bindTimeChange2: function(e) { if (e.detail.value) { this.setData({ graduationDate: e.detail.value }) this.data.allData.graduationDate = e.detail.value } console.log(e.detail.value) }, //健康 bindhisChange: function(e) { this.setData({ isHealthyIndex: e.detail.value }) this.data.load = false; if (this.data.isHealthy) { this.data.allData.ishealth = this.data.isHealthy[e.detail.value].itemcode } }, /** * 绑定用户信息展示在页面上(普通文本) */ loadUser() { // let uinfo = util.getUser(); // console.log(uinfo) let _this = this; let id = util.getUserId(); let parm = { id } App._post_form('member/apiSelectMeberInfo', 'application/json', JSON.stringify(parm), function(res) { if (res.code === 0) { wx.setStorageSync("USER", res.member); let uinfo = res.member; _this.setData({ u: uinfo, birthday: uinfo.birthday === "" || uinfo.birthday === null ? '' : uinfo.birthday, userphoto: uinfo.memberphoto === '' || uinfo.memberphoto === null ? '{{appAssetsUrl}}/images/tx.png' : uinfo.memberphoto, ['allData.college']: uinfo.college, ['allData.collegeName']: uinfo.collegeName, ['allData.province']: uinfo.province, ['allData.region']: uinfo.region, ['allData.rank']: uinfo.rank, ['allData.grade']: uinfo.grade, graduationDate: uinfo.graduationDate, ['allData.graduationDate']:uinfo.graduationDate }) } }) this.loadDictionary(); this.searchProvince(); g1 = [{ id: '11', name: '研究生' }, { id: '12', name: '大学' }, { id: '13', name: '高中' }, { id: '14', name: '初中' }] g2 = [{ id: "1101", name: '研一', pid: '11' }, { id: "1102", name: '研二', pid: '11' }, { id: "1103", name: '研三', pid: '11' }, { id: "1201", name: '大一', pid: '12' }, { id: "1202", name: '大二', pid: '12' }, { id: "1203", name: '大三', pid: '12' }, { id: "1204", name: '大四', pid: '12' }, { id: "1301", name: '高一', pid: '13' }, { id: "1302", name: '高二', pid: '13' }, { id: "1303", name: '高三', pid: '13' }, { id: "1401", name: '初一', pid: '14' }, { id: "1402", name: '初二', pid: '14' }, { id: "1403", name: '初三', pid: '14' }] this.data.gradeItem.push(g1); let newg2List = []; let gra = this.data.u.rank; let rank = ""; rank = this.data.u.grade; if (rank) { for (let i = 0; i < g1.length; i++) { if (g1[i].id === rank) { this.data.gradeIndex[0] = i; break; } } } else { rank = g1[0].id } for (let i = 0; i < g2.length; i++) { if (rank === g2[i].pid) { newg2List.push(g2[i]) } } if (gra) { for (let i = 0; i < newg2List.length; i++) { if (newg2List[i].id === gra) { this.data.gradeIndex[1] = i; break; } } } this.data.gradeItem[1] = newg2List; this.setData({ gradeItem: this.data.gradeItem, gradeIndex: this.data.gradeIndex }) wx.hideLoading(); }, changeAvatar() { 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 + 'member/addPhoto/' + util .getUserId(), filePath: tempFilePaths[0], name: 'file', success: function(res) { if (res.errMsg === "uploadFile:ok") { wx.showToast({ title: '修改成功', image: '', duration: 1500, mask: false }); _this.setData({ userphoto: tempFilePaths[0] }) } }, 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 + 'member/addPhoto/' + util .getUserId(), filePath: tempFilePaths[0], name: 'file', success: function(res) { if (res.errMsg === "uploadFile:ok") { wx.showToast({ title: '修改成功', image: '', duration: 1500, mask: false }); _this.setData({ userphoto: tempFilePaths[0] }) } }, function() { wx.showToast({ title: '修改失败', icon: 'none', image: '', duration: 1500, mask: false, success: (result) => {}, fail: () => {}, complete: () => {} }); } }) } }) } }, fail(res) {} }) }, /** * 查询字典项,渲染页面下拉框数据 */ loadDictionary() { let _this = this; /** * 性别 */ App._post_form('bizcatelog/apiSelectBizcatelog/gender', '', null, function(res) { if (res.code === 0) { let gender = res.dictList let all = { itemcode: "", itemname: "全部" } gender.unshift(all) let sexI = 0; if (_this.data.u.sex) { let sex = _this.data.u.sex; if (gender.length) { for (let i = 0; i < gender.length; i++) { if (gender[i].itemcode === sex) { sexI = i; } } } } _this.setData({ sexArray: gender, sexIndex: sexI }) } }) /** * 体重 */ App._post_form('bizcatelog/apiSelectBizcatelog/WEIGHTTYPE', '', null, function(res) { if (res.code === 0) { let weight = res.dictList let all = { itemcode: "", itemname: "全部" } weight.unshift(all) if (_this.data.u.weighttype) { if (weight.length) { for (let i = 0; i < weight.length; i++) { if (_this.data.u.weighttype === weight[i].itemcode) { _this.data.weightIndex = i; break; } } } } _this.setData({ weightItem: weight, weightIndex: _this.data.weightIndex }) } }) /** * 健康证 */ App._post_form('bizcatelog/apiSelectBizcatelog/YF', '', null, function(res) { if (res.code === 0) { let healthy = res.dictList if (_this.data.u.ishealth) { let health = _this.data.u.ishealth; if (healthy.length) { for (let i = 0; i < healthy.length; i++) { if (healthy[i].itemcode === health) { _this.data.isHealthyIndex = i; break; } } } } _this.setData({ isHealthy: healthy, isHealthyIndex: _this.data.isHealthyIndex }) } }) /***空闲时间*/ App._post_form('bizcatelog/apiSelectBizcatelog/FREETIME', '', null, function(res) { if (res.code === 0) { let FREETIME = res.dictList if (FREETIME.length) { _this.data.checkTimeItems = FREETIME; if (_this.data.u.freetime) { _this.changeTxt(_this.data.checkTimeItems, _this.data.u.freetime, "freetime") } } } }) /*** 技能 */ App._post_form('bizcatelog/apiSelectBizcatelog/skill', '', null, function(res) { if (res.code === 0) { let skill = res.dictList if (skill.length) { _this.data.checkskillItems = skill; //加载技能 if (_this.data.u.skill) { _this.changeTxt(_this.data.checkskillItems, _this.data.u.skill, "skill") } } } }) }, /** * 加载省份 */ searchProvince() { let _this = this; let proId = ''; let prov = ''; App._post_form('areainfo/province', '', null, function(res) { if (res.code === 0) { let provice = res.list _this.data.multiArray[0] = provice; CityArray0 = provice; if (_this.data.u.region) { prov = _this.data.u.province; if (CityArray0.length) { for (let i = 0; i < CityArray0.length; i++) { if (CityArray0[i].areaid === prov) { _this.data.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.setData({ multiArray: _this.data.multiArray, multiIndex: _this.data.multiIndex }) } }) }, //获取学校 loadSchool(cityId) { let _this = this; App._post_form('areainfo/Schoolinfo/' + cityId, '', null, function(res) { if (res.code === 0) { let school = [] if (res.dictList.length <= 0) { school = [] } else { let college = _this.data.u.college; school = res.dictList CityArray2 = school; if (college && _this.data.load === true) { for (let i = 0; i < CityArray2.length; i++) { if (college === CityArray2[i].itemcode) { _this.data.schIndex = i; break; } } } } _this.setData({ schoolItem: school //schoolName: _this.data.schoolName?_this.data.schoolName:school[_this.data.schIndex].itemname //schIndex: _this.data.schIndex }) } }) }, /** * 更新用户数据根据id */ PushVipInfo() { wx.showLoading({ title: '加载中...', }) let _this = this; let id = util.getUserId(); let parm = { id } App._post_form('member/apiSelectMeberInfo', 'application/json', JSON.stringify(parm), function(res) { if (res.code === 0) { wx.setStorageSync("USER", res.member); _this.loadUser(); _this.loadSchool(res.member.region) } }) }, maskClose(e) { if (e.currentTarget.dataset) { let value = e.currentTarget.dataset.type; if (this.data.inputValue || this.data.checkboxValue.length) { if (value === "vipname") { this.setData({ "u.vipname": this.data.inputValue }) this.data.allData.vipname = this.data.inputValue } else if (value === "name") { this.setData({ "u.name": this.data.inputValue }) this.data.allData.name = this.data.inputValue } else if (value === "email") { let regex = /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/; if (!regex.test(this.data.inputValue)) { wx.showToast({ title: '请填写正确的邮箱!', icon: 'none' }) return; } this.setData({ "u.email": this.data.inputValue }) this.data.allData.email = this.data.inputValue } else if (value === "height") { this.setData({ "u.height": this.data.inputValue }) this.data.allData.height = this.data.inputValue } else if (value === "dormitoryno") { this.setData({ "u.dormitoryno": this.data.inputValue }) this.data.allData.dormitoryno = this.data.inputValue } else if (value === "idcard") { let regex = /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|[xX])$/; if (!regex.test(this.data.inputValue)) { wx.showToast({ title: '请填写正确的身份证!', icon: 'none' }) return; } this.setData({ "u.idcard": this.data.inputValue }) this.data.allData.idcard = this.data.inputValue } else if (value === "remarks") { this.setData({ "u.remarks": this.data.inputValue }) this.data.allData.remarks = this.data.inputValue } else if (value === "major") { this.setData({ "u.major": this.data.inputValue }) this.data.allData.major = this.data.inputValue } else if (value === "freetime") { if (this.data.checkboxValue.length) { let item = ""; for (let i = 0; i < this.data.checkboxValue.length; i++) { item += this.data.checkboxValue[i] + "," } item = item.substring(0, item.length - 1); this.data.allData.freetime = item; this.changeTxt(this.data.checkTimeItems, this.data.allData.freetime, "freetime") } } else if (value === "skill") { if (this.data.checkboxValue.length) { let item = ""; for (let i = 0; i < this.data.checkboxValue.length; i++) { item += this.data.checkboxValue[i] + "," } item = item.substring(0, item.length - 1); this.data.allData.skill = item; this.changeTxt(this.data.checkskillItems, this.data.allData.skill, "skill") } } } } this.setData({ maskShow: false, }) }, checkboxChange: function(e) { this.data.checkboxValue = e.detail.value }, bindKeyInput(e) { this.data.inputValue = e.detail.value; }, updateInfo(e) { let _this = this; _this.data.checkboxValue = []; if (e.currentTarget.dataset) { let value = e.currentTarget.dataset; if (value.mode === "checkbox") { if (value.type === "freetime") { _this.setData({ checkboxItems: _this.data.checkTimeItems }) } else if (value.type === "skill") { _this.setData({ checkboxItems: _this.data.checkskillItems }) } } _this.setData({ maskShow: true, maskTitle: value.title, maskInputPla: '输入' + value.title, maskInputMode: value.mode, type: value.type, inputValue: '' }) } }, changeTxt(valueItem, item, type) { item = item.split(","); if (item.length) { let v = ""; for (let i = 0; i < item.length; i++) { for (let j = 0; j < valueItem.length; j++) { if (valueItem[j].itemcode == item[i]) { v += valueItem[j].itemname + "," } } } v = v.substring(0, v.length - 1); if (type === "freetime") { this.setData({ checkboxTxt: v }) } else if (type === "skill") { this.setData({ checkboxText: v }) } } }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { let _this = this; if (Object.keys(options).length > 0) { if (options.type === "no") { _this.data.nolink = false; } else { _this.data.nolink = true; } } else { _this.data.nolink = true; } if (util.UserLoginStatus()) { _this.loadUser(); } this.loadVipSel(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() { wx.setNavigationBarTitle({ title: '个人资料', }) }, /** * 生命周期函数--监听页面显示 */ onShow: function() { this.data.load = true; this.data.allData = {}; }, /** * 生命周期函数--监听页面隐藏 */ onHide: function() {}, btnUpUserInfo() { let that = this; //必填校验 if (that.data.u.name == null) { wx.showToast({ title: '请填写真实姓名', icon: 'none' }) return; } if (that.data.sexIndex == 0) { wx.showToast({ title: '请选择性别', icon: 'none' }) return; } // if (that.data.u.email == '') { // wx.showToast({ // title: '请填写邮箱', // icon: 'none' // }) // return; // } if (Object.keys(this.data.allData).length > 0) { this.data.allData.id = this.data.u.id; wx.showModal({ title: '请注意', content: '您已修改资料,是否保存?', success: function(res) { if (res.confirm) { that.updateUserInfo() } } }) } else { wx.showToast({ title: '没有修改数据!', icon: 'none' }) } }, /** * 生命周期函数--监听页面卸载 */ onUnload: function() { }, updateUserInfo() { let _this = this; App._post_form('member/apiUpdateMeberInfo', 'application/json', JSON.stringify(_this.data.allData), function(res) { if (res.code === 0) { // wx.showLoading({ // title: '保存中...', // duration: 1000 // }) wx.showToast({ title: '修改成功!', icon: 'none' }) setTimeout(() =>{ _this.PushVipInfo(); if (_this.data.nolink === true) { wx.switchTab({ url: '/pages/my/index/index' }) } else if (_this.data.nolink === false) { wx.navigateBack({ delta: 1 }) } },2000) } }) }, chooseSch() { const _this = this; _this.openSel(); }, schoolPickerChange(e) { this.setData({ ['allData.college']: this.data.schoolItem[e.detail.value].itemcode, ['allData.collegeName']: this.data.schoolItem[e.detail.value].itemname }) }, /** * 打开下拉框 */ openSel() { this.setData({ selectShow: true, }) }, /** * 关闭下拉框 */ closeSel() { this.setData({ selectShow: false, vague: [], inputSch: '' }) }, ok() { this.closeSel(); }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { }, schoolInput(e) { this.setData({ ['allData.college']: e.detail.value }) }, loadVipSel() { let _this = this; App._post_form('wgfillinfo/apiSelectwgfillinfo', 'application/json', null, function(res) { if (res.code === 0) { _this.setData({ isDev: res.wgFillInfo.isDev }) } } ) } })