//index.js //获取应用实例 const app = getApp() //获取应用实例 var tcity = require("../../utils/citys.js"); var server = require('../../libs/config.js'); var amapFile = require('../../libs/amap-wx.js'); var myAmapFun = null; /** * 删除左右两端的空格 */ String.prototype.trim = function () { return this.replace(/(^\s*)|(\s*$)/g, ""); } Page({ data: { motto: 'Hello World', userInfo: {}, hasUserInfo: false, canIUse: wx.canIUse('button.open-type.getUserInfo'), provinces: [], province: "", citys: [], city: "", countys: [], county: '', value: [0, 0, 0], values: [0, 0, 0], condition: false, area: [], areaIndex: 0, profession: ['专业', '输电', '变电'], professionIndex: 0, locateName: '', desc: '', jd:'', wd:'', team: [], pprofession: [], saveZz: { pro: '', city: '', country: '' }, checkOk: false }, //事件处理函数 bindViewTap: function () { wx.navigateTo({ url: '../logs/logs' }) }, getUserInfo: function (e) { console.log(e) app.globalData.userInfo = e.detail.userInfo this.setData({ userInfo: e.detail.userInfo, hasUserInfo: true }) }, bindChange: function (e) { var val = e.detail.value var t = this.data.values; var cityData = this.data.cityData; if (val[0] != t[0]) { console.log('province no '); const citys = []; const countys = []; for (let i = 0; i < cityData[val[0]].sub.length; i++) { citys.push(cityData[val[0]].sub[i].name) } for (let i = 0; i < cityData[val[0]].sub[0].sub.length; i++) { countys.push(cityData[val[0]].sub[0].sub[i].name) } this.setData({ province: this.data.provinces[val[0]], city: cityData[val[0]].sub[0].name, citys: citys, county: cityData[val[0]].sub[0].sub[0].name, countys: countys, values: val, value: [val[0], 0, 0] }) return; } if (val[1] != t[1]) { console.log('city no'); const countys = []; for (let i = 0; i < cityData[val[0]].sub[val[1]].sub.length; i++) { countys.push(cityData[val[0]].sub[val[1]].sub[i].name) } this.setData({ city: this.data.citys[val[1]], county: cityData[val[0]].sub[val[1]].sub[0].name, countys: countys, values: val, value: [val[0], val[1], 0] }) console.log(this.data.city) var that = this if (this.data.city == '- -') { wx.request({ url: server.Server.url + '/api/team/getTeam?deptid=73815566BD994D1D8C06830743802084', success: function (res) { that.setData({ team: res.data }); var temp = []; for (var i = 0; i < res.data.length; i++) { temp[i] = res.data[i].teamName; } that.setData({ area: temp }); } }) } else { wx.request({ url: server.Server.url + '/api/team/getTeamByName', data: { deptName: this.data.city }, success: function (res) { that.setData({ team: res.data }); var temp = []; for (var i = 0; i < res.data.length; i++) { temp[i] = res.data[i].teamName; } that.setData({ area: temp }); } }) } return; } if (val[2] != t[2]) { console.log('county no'); this.setData({ county: this.data.countys[val[2]], values: val }) var that = this if (this.data.county == '- -' && this.data.city != '- -') { wx.request({ url: server.Server.url + '/api/team/getTeamByName', data: { deptName: this.data.city }, success: function (res) { that.setData({ team: res.data }); var temp = []; for (var i = 0; i < res.data.length; i++) { temp[i] = res.data[i].teamName; } that.setData({ area: temp }); } }) } else { wx.request({ url: server.Server.url + '/api/team/getTeamByName', data: { deptName: this.data.county }, success: function (res) { that.setData({ team: res.data }); var temp = []; for (var i = 0; i < res.data.length; i++) { temp[i] = res.data[i].teamName; } that.setData({ area: temp }); } }) } return; } }, open: function () { this.setData({ condition: !this.data.condition }) }, onLoad: function () { var key = server.Config.key; myAmapFun = new amapFile.AMapWX({ key: key }); if (app.globalData.userInfo) { this.setData({ userInfo: app.globalData.userInfo, hasUserInfo: true }) } else if (this.data.canIUse) { // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 // 所以此处加入 callback 以防止这种情况 app.userInfoReadyCallback = res => { this.setData({ userInfo: res.userInfo, hasUserInfo: true }) } } else { // 在没有 open-type=getUserInfo 版本的兼容处理 wx.getUserInfo({ success: res => { app.globalData.userInfo = res.userInfo this.setData({ userInfo: res.userInfo, hasUserInfo: true }) } }) } console.log("onLoad"); var that = this; tcity.init(that); //初始化队伍列表 ,默认查询省公司下队伍 var cityData = that.data.cityData; const provinces = []; const citys = []; const countys = []; for (let i = 0; i < cityData.length; i++) { provinces.push(cityData[i].name); } console.log('省份完成'); for (let i = 0; i < cityData[0].sub.length; i++) { citys.push(cityData[0].sub[i].name) } console.log('city完成'); for (let i = 0; i < cityData[0].sub[0].sub.length; i++) { countys.push(cityData[0].sub[0].sub[i].name) } that.setData({ 'provinces': provinces, 'citys': citys, 'countys': countys, 'province': cityData[0].name, 'city': cityData[0].sub[0].name, 'county': cityData[0].sub[0].sub[0].name }) //初始化队伍信息,默认加载广西省公司下的队伍 wx.request({ url: server.Server.url + '/api/team/getTeam?deptid=73815566BD994D1D8C06830743802084', success: function (res) { that.setData({ team: res.data }); var temp = []; for (var i = 0; i < res.data.length; i++) { temp[i] = res.data[i].teamName; } that.setData({ area: temp }); } }) // //初始化专业信息 wx.request({ url: server.Server.url + '/api/dict/get/feaf75e9-3641-49df-8e5f-f1c81ae2sad2', success: function (res) { that.setData({ pprofession: res.data }); var temp = []; for (var i = 0; i < res.data.length; i++) { temp[i] = res.data[i].typename; } that.setData({ profession: temp }); } }) console.log('初始化完成'); }, //选择队伍 onAreaChange: function (e) { this.setData({ areaIndex: e.detail.value }); }, //选择专业 onproChange: function (e) { this.setData({ professionIndex: e.detail.value }); }, check: function (e) { }, formSubmit: function (e) { if (e.detail.value.name.trim() === "") { wx.showToast({ title: "姓名不能为空" }); return; } if (e.detail.value.phone === "") { wx.showToast({ title: "请填写手机号" }); return; } if (e.detail.value.yqm === "") { wx.showToast({ title: "邀请码为空" }); return; } try{ this.data.team[e.detail.value.dw].teamId }catch(e){ wx.showToast({ title: "队伍为空" }); return; } // 2.获取并设置当前位置经纬度 wx.getLocation({ type: "gcj02", success: (res) => { this.setData({ jd: res.longitude, wd: res.latitude }); //设置经纬度对应地址 that = this; myAmapFun.getRegeo({ success: function (data) { that.setData({ locateName: data[0].name, desc: data[0].desc }) }, fail: function (info) { // wx.showModal({title:info.errMsg}) } }) } }); console.log(this.data.pprofession) //设置注册数据 this.setData({ userInformation: { zz: e.detail.value.zz, dw: this.data.team[e.detail.value.dw].teamId, name: e.detail.value.name, phone: e.detail.value.phone, zy: this.data.pprofession[e.detail.value.zy].typecode, dz: e.detail.value.dz, yqm: e.detail.value.yqm, jd:this.data.jd, wd:this.data.wd, locateName:this.data.locateName, desc:this.data.desc, code:app.globalData.code } }); console.info(this.data.userInformation); //检查邀请码 var that = this //查询邀请码是否正确 wx.request({ url: server.Server.url + '/api/user/checkCode/' + this.data.userInformation.yqm, method: 'get', // POST // header: {}, // 设置请求的 header success: function (res) { if (res.data == false) { wx.showToast({ title: '邀请码无效', }) } else { wx.showLoading({ title: "注册中", mask: true }); //请求服务进行注册 wx.request({ url: server.Server.url + '/api/user/register', // url: 'https://www.easy-mock.com/mock/59c0bb01e0dc663341af8b9f/gugnv/userInfo', data: { userInfo: that.data.userInformation }, method: 'get', // POST // header: {}, // 设置请求的 header success: function (res) { if(res.data.code=="0"){ wx.hideLoading(); wx.redirectTo({ url: '../txmap/index?userId=' + res.data.id, }) }else{ wx.hideLoading(); wx.showToast({ title: "出现异常" }); } } }) } } }) } })