123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480 |
- //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: "出现异常"
- });
- }
-
- }
- })
- }
- }
- })
- }
- })
|