index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. //获取应用实例
  5. var tcity = require("../../utils/citys.js");
  6. var server = require('../../libs/config.js');
  7. var amapFile = require('../../libs/amap-wx.js');
  8. var myAmapFun = null;
  9. /**
  10. * 删除左右两端的空格
  11. */
  12. String.prototype.trim = function () {
  13. return this.replace(/(^\s*)|(\s*$)/g, "");
  14. }
  15. Page({
  16. data: {
  17. motto: 'Hello World',
  18. userInfo: {},
  19. hasUserInfo: false,
  20. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  21. provinces: [],
  22. province: "",
  23. citys: [],
  24. city: "",
  25. countys: [],
  26. county: '',
  27. value: [0, 0, 0],
  28. values: [0, 0, 0],
  29. condition: false,
  30. area: [],
  31. areaIndex: 0,
  32. profession: ['专业', '输电', '变电'],
  33. professionIndex: 0,
  34. locateName: '',
  35. desc: '',
  36. jd:'',
  37. wd:'',
  38. team: [],
  39. pprofession: [],
  40. saveZz: {
  41. pro: '',
  42. city: '',
  43. country: ''
  44. },
  45. checkOk: false
  46. },
  47. //事件处理函数
  48. bindViewTap: function () {
  49. wx.navigateTo({
  50. url: '../logs/logs'
  51. })
  52. },
  53. getUserInfo: function (e) {
  54. console.log(e)
  55. app.globalData.userInfo = e.detail.userInfo
  56. this.setData({
  57. userInfo: e.detail.userInfo,
  58. hasUserInfo: true
  59. })
  60. },
  61. bindChange: function (e) {
  62. var val = e.detail.value
  63. var t = this.data.values;
  64. var cityData = this.data.cityData;
  65. if (val[0] != t[0]) {
  66. console.log('province no ');
  67. const citys = [];
  68. const countys = [];
  69. for (let i = 0; i < cityData[val[0]].sub.length; i++) {
  70. citys.push(cityData[val[0]].sub[i].name)
  71. }
  72. for (let i = 0; i < cityData[val[0]].sub[0].sub.length; i++) {
  73. countys.push(cityData[val[0]].sub[0].sub[i].name)
  74. }
  75. this.setData({
  76. province: this.data.provinces[val[0]],
  77. city: cityData[val[0]].sub[0].name,
  78. citys: citys,
  79. county: cityData[val[0]].sub[0].sub[0].name,
  80. countys: countys,
  81. values: val,
  82. value: [val[0], 0, 0]
  83. })
  84. return;
  85. }
  86. if (val[1] != t[1]) {
  87. console.log('city no');
  88. const countys = [];
  89. for (let i = 0; i < cityData[val[0]].sub[val[1]].sub.length; i++) {
  90. countys.push(cityData[val[0]].sub[val[1]].sub[i].name)
  91. }
  92. this.setData({
  93. city: this.data.citys[val[1]],
  94. county: cityData[val[0]].sub[val[1]].sub[0].name,
  95. countys: countys,
  96. values: val,
  97. value: [val[0], val[1], 0]
  98. })
  99. console.log(this.data.city)
  100. var that = this
  101. if (this.data.city == '- -') {
  102. wx.request({
  103. url: server.Server.url + '/api/team/getTeam?deptid=73815566BD994D1D8C06830743802084',
  104. success: function (res) {
  105. that.setData({
  106. team: res.data
  107. });
  108. var temp = [];
  109. for (var i = 0; i < res.data.length; i++) {
  110. temp[i] = res.data[i].teamName;
  111. }
  112. that.setData({
  113. area: temp
  114. });
  115. }
  116. })
  117. } else {
  118. wx.request({
  119. url: server.Server.url + '/api/team/getTeamByName',
  120. data: { deptName: this.data.city },
  121. success: function (res) {
  122. that.setData({
  123. team: res.data
  124. });
  125. var temp = [];
  126. for (var i = 0; i < res.data.length; i++) {
  127. temp[i] = res.data[i].teamName;
  128. }
  129. that.setData({
  130. area: temp
  131. });
  132. }
  133. })
  134. }
  135. return;
  136. }
  137. if (val[2] != t[2]) {
  138. console.log('county no');
  139. this.setData({
  140. county: this.data.countys[val[2]],
  141. values: val
  142. })
  143. var that = this
  144. if (this.data.county == '- -' && this.data.city != '- -') {
  145. wx.request({
  146. url: server.Server.url + '/api/team/getTeamByName',
  147. data: { deptName: this.data.city },
  148. success: function (res) {
  149. that.setData({
  150. team: res.data
  151. });
  152. var temp = [];
  153. for (var i = 0; i < res.data.length; i++) {
  154. temp[i] = res.data[i].teamName;
  155. }
  156. that.setData({
  157. area: temp
  158. });
  159. }
  160. })
  161. } else {
  162. wx.request({
  163. url: server.Server.url + '/api/team/getTeamByName',
  164. data: { deptName: this.data.county },
  165. success: function (res) {
  166. that.setData({
  167. team: res.data
  168. });
  169. var temp = [];
  170. for (var i = 0; i < res.data.length; i++) {
  171. temp[i] = res.data[i].teamName;
  172. }
  173. that.setData({
  174. area: temp
  175. });
  176. }
  177. })
  178. }
  179. return;
  180. }
  181. },
  182. open: function () {
  183. this.setData({
  184. condition: !this.data.condition
  185. })
  186. },
  187. onLoad: function () {
  188. var key = server.Config.key;
  189. myAmapFun = new amapFile.AMapWX({ key: key });
  190. if (app.globalData.userInfo) {
  191. this.setData({
  192. userInfo: app.globalData.userInfo,
  193. hasUserInfo: true
  194. })
  195. } else if (this.data.canIUse) {
  196. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  197. // 所以此处加入 callback 以防止这种情况
  198. app.userInfoReadyCallback = res => {
  199. this.setData({
  200. userInfo: res.userInfo,
  201. hasUserInfo: true
  202. })
  203. }
  204. } else {
  205. // 在没有 open-type=getUserInfo 版本的兼容处理
  206. wx.getUserInfo({
  207. success: res => {
  208. app.globalData.userInfo = res.userInfo
  209. this.setData({
  210. userInfo: res.userInfo,
  211. hasUserInfo: true
  212. })
  213. }
  214. })
  215. }
  216. console.log("onLoad");
  217. var that = this;
  218. tcity.init(that);
  219. //初始化队伍列表 ,默认查询省公司下队伍
  220. var cityData = that.data.cityData;
  221. const provinces = [];
  222. const citys = [];
  223. const countys = [];
  224. for (let i = 0; i < cityData.length; i++) {
  225. provinces.push(cityData[i].name);
  226. }
  227. console.log('省份完成');
  228. for (let i = 0; i < cityData[0].sub.length; i++) {
  229. citys.push(cityData[0].sub[i].name)
  230. }
  231. console.log('city完成');
  232. for (let i = 0; i < cityData[0].sub[0].sub.length; i++) {
  233. countys.push(cityData[0].sub[0].sub[i].name)
  234. }
  235. that.setData({
  236. 'provinces': provinces,
  237. 'citys': citys,
  238. 'countys': countys,
  239. 'province': cityData[0].name,
  240. 'city': cityData[0].sub[0].name,
  241. 'county': cityData[0].sub[0].sub[0].name
  242. })
  243. //初始化队伍信息,默认加载广西省公司下的队伍
  244. wx.request({
  245. url: server.Server.url + '/api/team/getTeam?deptid=73815566BD994D1D8C06830743802084',
  246. success: function (res) {
  247. that.setData({
  248. team: res.data
  249. });
  250. var temp = [];
  251. for (var i = 0; i < res.data.length; i++) {
  252. temp[i] = res.data[i].teamName;
  253. }
  254. that.setData({
  255. area: temp
  256. });
  257. }
  258. })
  259. // //初始化专业信息
  260. wx.request({
  261. url: server.Server.url + '/api/dict/get/feaf75e9-3641-49df-8e5f-f1c81ae2sad2',
  262. success: function (res) {
  263. that.setData({
  264. pprofession: res.data
  265. });
  266. var temp = [];
  267. for (var i = 0; i < res.data.length; i++) {
  268. temp[i] = res.data[i].typename;
  269. }
  270. that.setData({
  271. profession: temp
  272. });
  273. }
  274. })
  275. console.log('初始化完成');
  276. },
  277. //选择队伍
  278. onAreaChange: function (e) {
  279. this.setData({
  280. areaIndex: e.detail.value
  281. });
  282. },
  283. //选择专业
  284. onproChange: function (e) {
  285. this.setData({
  286. professionIndex: e.detail.value
  287. });
  288. },
  289. check: function (e) {
  290. },
  291. formSubmit: function (e) {
  292. if (e.detail.value.name.trim() === "") {
  293. wx.showToast({
  294. title: "姓名不能为空"
  295. });
  296. return;
  297. }
  298. if (e.detail.value.phone === "") {
  299. wx.showToast({
  300. title: "请填写手机号"
  301. });
  302. return;
  303. }
  304. if (e.detail.value.yqm === "") {
  305. wx.showToast({
  306. title: "邀请码为空"
  307. });
  308. return;
  309. }
  310. try{
  311. this.data.team[e.detail.value.dw].teamId
  312. }catch(e){
  313. wx.showToast({
  314. title: "队伍为空"
  315. });
  316. return;
  317. }
  318. // 2.获取并设置当前位置经纬度
  319. wx.getLocation({
  320. type: "gcj02",
  321. success: (res) => {
  322. this.setData({
  323. jd: res.longitude,
  324. wd: res.latitude
  325. });
  326. //设置经纬度对应地址
  327. that = this;
  328. myAmapFun.getRegeo({
  329. success: function (data) {
  330. that.setData({
  331. locateName: data[0].name,
  332. desc: data[0].desc
  333. })
  334. },
  335. fail: function (info) {
  336. // wx.showModal({title:info.errMsg})
  337. }
  338. })
  339. }
  340. });
  341. console.log(this.data.pprofession)
  342. //设置注册数据
  343. this.setData({
  344. userInformation: {
  345. zz: e.detail.value.zz,
  346. dw: this.data.team[e.detail.value.dw].teamId,
  347. name: e.detail.value.name,
  348. phone: e.detail.value.phone,
  349. zy: this.data.pprofession[e.detail.value.zy].typecode,
  350. dz: e.detail.value.dz,
  351. yqm: e.detail.value.yqm,
  352. jd:this.data.jd,
  353. wd:this.data.wd,
  354. locateName:this.data.locateName,
  355. desc:this.data.desc,
  356. code:app.globalData.code
  357. }
  358. });
  359. console.info(this.data.userInformation);
  360. //检查邀请码
  361. var that = this
  362. //查询邀请码是否正确
  363. wx.request({
  364. url: server.Server.url + '/api/user/checkCode/' + this.data.userInformation.yqm,
  365. method: 'get', // POST
  366. // header: {}, // 设置请求的 header
  367. success: function (res) {
  368. if (res.data == false) {
  369. wx.showToast({
  370. title: '邀请码无效',
  371. })
  372. } else {
  373. wx.showLoading({
  374. title: "注册中",
  375. mask: true
  376. });
  377. //请求服务进行注册
  378. wx.request({
  379. url: server.Server.url + '/api/user/register',
  380. // url: 'https://www.easy-mock.com/mock/59c0bb01e0dc663341af8b9f/gugnv/userInfo',
  381. data: {
  382. userInfo: that.data.userInformation
  383. },
  384. method: 'get', // POST
  385. // header: {}, // 设置请求的 header
  386. success: function (res) {
  387. if(res.data.code=="0"){
  388. wx.hideLoading();
  389. wx.redirectTo({
  390. url: '../txmap/index?userId=' + res.data.id,
  391. })
  392. }else{
  393. wx.hideLoading();
  394. wx.showToast({
  395. title: "出现异常"
  396. });
  397. }
  398. }
  399. })
  400. }
  401. }
  402. })
  403. }
  404. })