index.js 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  1. const app = getApp();
  2. const webSocket = require('../../utils/websocket.js');
  3. Page({
  4. data: {
  5. heightid: 0,
  6. heightArray: [], // 身高-数据
  7. heightindex: [0, 0], // 身高-下标
  8. Ageid: 0,
  9. AgeArray: [], // 年龄-数据
  10. AgeIndex: [0, 0], // 年龄-下标
  11. // MarriageArray: [], // 婚史-数据
  12. // Marriageindex: '', // 婚史-下标
  13. EducationArray: [], // 学历-数据
  14. Educationindex: '', // 学历-下标
  15. inputValue: '', //用户ID
  16. sex: 0, // 性别
  17. age: 0, // 年龄
  18. height: 0, // 身高
  19. education: 0, // 学历
  20. educationid: 0,
  21. // marry: 0, // 婚史
  22. // idmarry: 0,
  23. income: 0,
  24. // income: '', // 收入
  25. // occupation: '', // 职业
  26. // home: '', //列表信息
  27. // tab: [true, true, true, true],
  28. home: [], //定义列表信息数组
  29. // tabTxt: ['性别', '年龄', '婚史', '特色'],//tab文案
  30. page: 1,//当前页码
  31. limit: 10,//获取条数
  32. morehide: true, //暂无更多信息显示隐藏
  33. moreTxt: '',
  34. // 省市区
  35. city: 0, // 市 要传的数据
  36. provinceName: '', // 省 要传的数据
  37. cityName: '', // 市 要传的数据
  38. areaName: '', // 区 要传的数据
  39. provincedata: '', //省数据
  40. provinceid: 1, //省选中ID
  41. provincetext: '北京', //省 名字
  42. citydata: '', //市数据
  43. cityidx: '', //市选中ID
  44. citytext: '', //市 名字
  45. areadata: '', //区数据
  46. scrolltop: '', //市区滚动条
  47. hiddenName: true, //显示隐藏
  48. },
  49. onShow: function (options) {
  50. var that = this;
  51. // webSocket.connectSocket();
  52. var _trigger = app.globalData.trigger // 搜索或清空
  53. // console.log(_trigger);
  54. if (_trigger == true){
  55. that.onLoad();
  56. }
  57. app.globalData.trigger = false;
  58. },
  59. // 触发聊天
  60. onReady: function (options){
  61. webSocket.connectSocket();
  62. },
  63. onLoad: function (options) {
  64. var that = this;
  65. that.Getlocation(); //获取地理位置
  66. that.setData({
  67. page: 1,//当前页码
  68. })
  69. var _Selection = app.globalData.Selection // 是否选中 1选中 0没选中
  70. var _income = app.globalData.income // 收入
  71. // if (app.globalData.idmarry) {
  72. // that.setData({
  73. // idmarry: app.globalData.idmarry
  74. // })
  75. // }
  76. if (app.globalData.educationid) {
  77. that.setData({
  78. educationid: app.globalData.educationid
  79. })
  80. }
  81. if (app.globalData.inputValue) { //用户ID
  82. that.setData({
  83. inputValue: app.globalData.inputValue
  84. })
  85. }
  86. if (app.globalData.income) {
  87. that.setData({
  88. income: _income,
  89. })
  90. } else if (app.globalData.income == 0 && _Selection == 1) { //判断筛选页面 是否清空数据 同时 是否选中,而不是返回
  91. that.setData({
  92. income: _income,
  93. })
  94. }
  95. // console.log(_Selection)
  96. var _city = app.globalData.city // 市
  97. var _provincename = app.globalData.provinceName // 省 名称
  98. var _cityname = app.globalData.cityName // 市 名称
  99. var _areaname = app.globalData.areaName // 区 名称
  100. if (_provincename || _cityname && _Selection == 1) {
  101. that.setData({
  102. city: _city,
  103. provinceName: _provincename, // 省名称
  104. cityName: _cityname, // 市名称
  105. areaName: _areaname, // 区名称
  106. })
  107. console.log(_provincename)
  108. console.log(_cityname)
  109. } else if (_provincename == '' && _cityname == '' && _Selection == 1){
  110. that.setData({
  111. city: _city,
  112. provinceName: _provincename, // 省名称
  113. cityName: _cityname, // 市名称
  114. areaName: _areaname, // 区名称
  115. })
  116. }
  117. // 年龄 ajax
  118. let Age_url = 'public/paramsgather?type=age';
  119. let Age_data = {};
  120. if (app.globalData.age) { //判断 是否从筛选页面传来的参数
  121. var _age = app.globalData.age // 年龄
  122. var agenewArry = _age.split("-"); //转成数组
  123. var _age_min = agenewArry[0]
  124. var _age_max = agenewArry[1]
  125. // console.log(_age_min)
  126. // console.log(_age_max)
  127. that.setData({
  128. Ageid: 0,
  129. age: _age
  130. })
  131. } else if (app.globalData.age == 0 && _Selection == 1) { //判断筛选页面 是否清空数据 同时 是否选中,而不是返回
  132. var _age = app.globalData.age // 年龄
  133. that.setData({
  134. age: _age,
  135. Ageid: 0,
  136. AgeIndex: ['', '']
  137. })
  138. }
  139. app.postRequest(Age_url, Age_data, function (res) { // 年龄 ajax
  140. if (res.code == 201) {
  141. if (app.globalData.age) {
  142. let newarray = ['不限'];
  143. var res_data = newarray.concat(res.data); //在原有的数据上 凭借上 不限
  144. let newarray1 = ['以上'];
  145. var res_data1 = newarray1.concat(res.data); //在原有的数据上 凭借上 以上
  146. let min = data_processing(res_data, _age_min); //已选中的数据处理 min
  147. let max = data_processing(res_data1, _age_max); //已选中的数据处理 max
  148. that.setData({
  149. AgeIndex: [min, max]
  150. })
  151. }
  152. let dictObject = res.data; //对象不能直接使用 以下转成数组
  153. // 对象转成数组
  154. var createArr = []
  155. for (let i in dictObject) {
  156. createArr.push(dictObject[i] + "岁");
  157. }
  158. let bx = ['不限'];
  159. var Unlimited = bx.concat(createArr);
  160. let ys = ['以上'];
  161. var Above = ys.concat(createArr);
  162. that.setData({
  163. AgeArray: [Unlimited, Above],
  164. })
  165. // console.log(createArr);
  166. }
  167. })
  168. // 身高 ajax
  169. let height_url = 'public/paramsgather?type=height';
  170. let height_data = {
  171. pid: '0'
  172. };
  173. if (app.globalData.height) { //判断 是否从筛选页面传来的参数
  174. // console.log(app.globalData.height);
  175. var _height = app.globalData.height // 身高
  176. var heightnewArry = _height.split("-"); //转成数组
  177. var heightSmall = heightnewArry[0]
  178. var heightlarge = heightnewArry[1]
  179. // console.log(heightSmall)
  180. // console.log(heightlarge)
  181. that.setData({
  182. height: _height,
  183. heightid: 0
  184. })
  185. } else if (app.globalData.height == 0 && _Selection == 1) { //判断筛选页面 是否清空数据 同时 是否选中,而不是返回
  186. var _height = app.globalData.height // 身高
  187. that.setData({
  188. height: _height,
  189. heightid: 0,
  190. heightindex: ['', ''], // 身高-下标
  191. })
  192. }
  193. app.postRequest(height_url, height_data, function (res) { // 身高 ajax
  194. if (res.code == 201) {
  195. if (app.globalData.height) {
  196. let newarray = ['不限'];
  197. var res_data = newarray.concat(res.data); //在原有的数据上 凭借上 不限
  198. let newarray1 = ['以上'];
  199. var res_data1 = newarray1.concat(res.data); //在原有的数据上 凭借上 以上
  200. let min = data_processing(res_data, heightSmall); //已选中的数据处理 min
  201. let max = data_processing(res_data1, heightlarge); //已选中的数据处理 max
  202. that.setData({
  203. heightindex: [min, max]
  204. })
  205. }
  206. let dictObject = res.data; //对象不能直接使用 以下转成数组
  207. // 对象转成数组
  208. var createArr = []
  209. for (let i in dictObject) {
  210. createArr.push(dictObject[i] + "cm");
  211. }
  212. let bx = ['不限'];
  213. var Unlimited = bx.concat(createArr);
  214. let ys = ['以上'];
  215. var Above = ys.concat(createArr);
  216. // console.log(createArr);
  217. that.setData({
  218. heightArray: [Unlimited, Above],
  219. })
  220. }
  221. })
  222. // 婚史 ajax
  223. // let Marriage_url = 'public/paramsgather?type=marriage';
  224. // let Marriage_data = {};
  225. // if (app.globalData.marry) { //判断 是否从筛选页面传来的参数
  226. // // console.log(app.globalData.marry);
  227. // var _marry = app.globalData.marry // 婚姻
  228. // that.setData({
  229. // marry: _marry
  230. // })
  231. // } else if (app.globalData.marry == 0 && _Selection == 1) { //判断筛选页面 是否清空数据 同时 是否选中,而不是返回
  232. // var _marry = app.globalData.marry // 婚姻
  233. // that.setData({
  234. // marry: _marry,
  235. // Marriageindex: "", // 身高-下标
  236. // })
  237. // }
  238. // app.postRequest(Marriage_url, Marriage_data, function (res) { // 婚史 ajax
  239. // if (res.code == 201) {
  240. // if (app.globalData.marry) {
  241. // for (let i = 0; i < res.data.length; i++) { //已选中的数据处理
  242. // if (i == _marry) {
  243. // that.setData({
  244. // Marriageindex: i,
  245. // })
  246. // }
  247. // }
  248. // }
  249. // that.setData({
  250. // MarriageArray: res.data,
  251. // idmarry: that.data.idmarry,
  252. // })
  253. // }
  254. // })
  255. // 学历 ajax
  256. let Education_url = 'public/paramsgather?type=xueli';
  257. let Education_data = {};
  258. if (app.globalData.education) { //判断 是否从筛选页面传来的参数
  259. // console.log(app.globalData.marry);
  260. var _education = app.globalData.education // 学历
  261. that.setData({
  262. education: _education
  263. })
  264. } else if (app.globalData.education == 0 && _Selection == 1) { //判断筛选页面 是否清空数据 同时 是否选中,而不是返回
  265. var _education = app.globalData.education // 学历
  266. that.setData({
  267. education: _education,
  268. Educationindex: "", // 学历-下标
  269. })
  270. }
  271. app.postRequest(Education_url, Education_data, function (res) { // 学历 ajax
  272. if (res.code == 201) {
  273. var obj = { id: 0, education_name: '不限' };
  274. var datares = res.data;
  275. datares.unshift(obj)
  276. if (app.globalData.education) {
  277. for (let i = 0; i < datares.length; i++) { //已选中的数据处理
  278. if (datares[i].id == _education) {
  279. that.setData({
  280. Educationindex: i,
  281. })
  282. }
  283. }
  284. }
  285. that.setData({
  286. EducationArray: datares,
  287. educationid: that.data.educationid,
  288. })
  289. }
  290. })
  291. that.list();
  292. },
  293. heightEvent: function (e) { // 身高
  294. var that = this;
  295. // console.log(this);
  296. // console.log(e);
  297. // console.log(this.data.heightArray[e.detail.value]);
  298. // console.log('picker发送选择改变,携带值为', e.detail.value)
  299. var _value = e.detail.value; //发送选择改变,携带值为
  300. var heightSmall = this.data.heightArray[0][e.detail.value[0]].substring(0, 3);
  301. var heightlarge = this.data.heightArray[1][e.detail.value[1]].substring(0, 3);
  302. // console.log(heightdata)
  303. if (heightSmall > heightlarge && heightSmall != '不限' && heightlarge != '以上') { //判断 最小值 大于 最大值 数据互换
  304. // console.log('调换')
  305. var heightdata = heightlarge + '-' + heightSmall;
  306. that.Exchange(_value); // 调用数组调换
  307. } else {
  308. var heightdata = heightSmall + '-' + heightlarge;
  309. }
  310. that.setData({
  311. heightindex: _value,
  312. height: heightdata,
  313. heightid: 1,
  314. })
  315. that.list();
  316. app.globalData.Selection = 0; // 是否选中
  317. app.globalData.height = 0; // 身高
  318. },
  319. // 年龄双选
  320. AgeEvent: function (e) {
  321. var that = this;
  322. var _value = e.detail.value; //发送选择改变,携带值为
  323. // console.log('picker发送选择改变,携带值为', e.detail.value)
  324. var Small = this.data.AgeArray[0][e.detail.value[0]].substring(0, 2);
  325. var large = this.data.AgeArray[1][e.detail.value[1]].substring(0, 2);
  326. // console.log(Agedata);
  327. if (Small > large && Small != '不限' && large != '以上') { //判断 最小值 大于 最大值 数据互换
  328. // console.log('调换')
  329. var Agedata = large + '-' + Small;
  330. that.Exchange(_value); // 调用数组调换
  331. } else {
  332. var Agedata = Small + '-' + large; //否则正常选中
  333. }
  334. that.setData({
  335. AgeIndex: _value,
  336. age: Agedata,
  337. Ageid: 1,
  338. page: 1,
  339. })
  340. that.list(); //调用筛选
  341. app.globalData.Selection = 0; // 是否选中
  342. app.globalData.age = 0; // 年龄
  343. },
  344. // 数组数据调换
  345. Exchange: function (data) {
  346. for (var i = 0; i < data.length / 2; i++) {
  347. var data_i = data[i];
  348. data[i] = data[data.length - 1 - i];
  349. data[data.length - 1 - i] = data_i;
  350. }
  351. return;
  352. },
  353. // MarriageEvent: function (e) { // 婚史 单项选择器
  354. // var that = this;
  355. // // console.log(this);
  356. // // console.log(e);
  357. // // console.log(this.data.MarriageArray[e.detail.value]);
  358. // // console.log('picker发送选择改变,携带值为', e.detail.value)
  359. // this.setData({
  360. // Marriageindex: e.detail.value,
  361. // marry: e.detail.value,
  362. // page: 1,
  363. // idmarry: 1,
  364. // })
  365. // that.list(); //调用筛选
  366. // app.globalData.Selection = 0; // 是否选中
  367. // app.globalData.marry = 0 // 婚史
  368. // },
  369. EducationEvent: function (e) { // 学历 单项选择器
  370. var that = this;
  371. // console.log(this);
  372. // console.log(e);
  373. // console.log(this.data.EducationArray[e.detail.value].id);
  374. // console.log('picker发送选择改变,携带值为', e.detail.value)
  375. this.setData({
  376. Educationindex: e.detail.value,
  377. education: this.data.EducationArray[e.detail.value].id,
  378. page: 1,
  379. educationid: 1,
  380. })
  381. that.list(); //调用筛选
  382. app.globalData.Selection = 0; // 是否选中
  383. app.globalData.education = 0 // 学历
  384. },
  385. More: function () {
  386. var that = this;
  387. // console.log(that.data.age);
  388. // console.log(that.data.provinceName);
  389. // console.log(that.data.cityName);
  390. // console.log(that.data.areaName);
  391. // '&marry=' + that.data.marry + '&idmarry=' + that.data.idmarry +
  392. wx.navigateTo({
  393. url: '/pages/index_screen/index_screen?age=' + that.data.age + '&height=' + that.data.height + '&education=' + that.data.education + '&income=' + that.data.income + '&educationid=' + that.data.educationid +'&city=' + that.data.city + '&provinceName=' + that.data.provinceName + '&cityName=' + that.data.cityName + '&areaName=' + that.data.areaName + ''
  394. })
  395. },
  396. // 上拉加载更多
  397. onReachBottom() {
  398. var that = this;
  399. let _age = transformation(that.data.age) //不限以上 转换成0
  400. let _height = transformation(that.data.height) //不限以上 转换成0
  401. let _income = transformation(that.data.income) //不限以上 转换成0
  402. that.showLoading(); //提示加载中
  403. // 列表信息
  404. var home_url = 'circle/friend/home';
  405. if (that.data.inputValue) { //判断 搜索用户ID存在 只传用户ID
  406. var home_data = {
  407. page: (that.data.page++) + 1,
  408. limit: that.data.limit,
  409. number: that.data.inputValue, // 性别
  410. };
  411. // console.log('用户ID');
  412. } else { //否则 传常规选择
  413. var home_data = {
  414. page: (that.data.page++) + 1,
  415. limit: that.data.limit,
  416. age: _age, // 年龄
  417. height: _height, // 身高
  418. // marry: that.data.marry, // 婚史
  419. education: that.data.education, // 学历
  420. income: _income, //收入
  421. city: that.data.city, // 市
  422. };
  423. // console.log('选择');
  424. }
  425. app.postRequest(home_url, home_data, function (res) {
  426. if (res.code == 201) {
  427. // console.log(res.data);
  428. var home = that.data.home
  429. // var moreTxt = '';
  430. // if (0 < (res.data.length < 10)) {
  431. // moreTxt = res.msg;
  432. // // console.log('无')
  433. // } else {
  434. // moreTxt = ''
  435. // // console.log('有')
  436. // }
  437. // 设置数据
  438. for (var i = 0; i < res.data.length; i++) {
  439. home.push(res.data[i]);
  440. }
  441. that.setData({
  442. home: home,
  443. morehide: true,
  444. })
  445. that.cancelLoading(); //数据加载完关闭
  446. return;
  447. }
  448. that.cancelLoading(); //数据加载完关闭
  449. that.setData({
  450. home_code: res.code,
  451. morehide: false,
  452. moreTxt: res.msg,
  453. })
  454. })
  455. },
  456. list: function () {
  457. var that = this;
  458. let _age = transformation(that.data.age) //不限以上 转换成0
  459. let _height = transformation(that.data.height) //不限以上 转换成0
  460. let _income = transformation(that.data.income) //不限以上 转换成0
  461. that.showLoading(); //提示加载中
  462. // 列表信息
  463. let home_url = 'circle/friend/home';
  464. if (that.data.inputValue) { //判断 搜索用户ID存在 只传用户ID
  465. var home_data = {
  466. page: that.data.page,
  467. limit: that.data.limit,
  468. number: that.data.inputValue, // 性别
  469. };
  470. } else { //否则 传常规选择
  471. var home_data = {
  472. page: that.data.page,
  473. limit: that.data.limit,
  474. age: _age, // 年龄
  475. height: _height, // 身高
  476. // marry: that.data.marry, // 婚史
  477. education: that.data.education, // 学历
  478. income: _income, //收入
  479. city: that.data.city, // 市
  480. };
  481. }
  482. app.postRequest(home_url, home_data, function (res) {
  483. that.setData({
  484. inputValue: '',
  485. })
  486. var moreTxt = '';
  487. if (res.code == 201) {
  488. // if (res.data.length < 10) {
  489. // moreTxt = res.msg
  490. // } else {
  491. // moreTxt = ''
  492. // }
  493. // console.log(res.data);
  494. that.setData({
  495. home: res.data,
  496. morehide: true,
  497. home_code: res.code,
  498. })
  499. that.cancelLoading(); //数据加载完关闭
  500. return;
  501. }
  502. that.cancelLoading(); //数据加载完关闭
  503. that.setData({
  504. home: res.data,
  505. morehide: false,
  506. moreTxt: res.msg,
  507. })
  508. })
  509. },
  510. // 加载
  511. showLoading: function () {
  512. wx.showLoading({
  513. title: '加载中',
  514. icon: 'loading'
  515. });
  516. },
  517. // 关闭加载
  518. cancelLoading: function () {
  519. wx.hideLoading();
  520. },
  521. // 省市区三级联动 点击弹窗
  522. linkage: function (e) {
  523. var that = this;
  524. let citypid_url = 'public/citypid';
  525. let citypid_data = {};
  526. app.postRequest(citypid_url, citypid_data, function (res) { // 省市区三级联动 ajax
  527. if (res.code == 201) {
  528. that.setData({
  529. provincedata: res.data, // 省数据
  530. })
  531. // console.log(res.data)
  532. that.provinceOn();
  533. }
  534. })
  535. },
  536. // 省事件
  537. provinceOn: function (e) {
  538. var that = this;
  539. // console.log(e);
  540. if (e) {
  541. that.setData({
  542. provinceid: e.currentTarget.dataset.id, //省ID
  543. provincetext: e.currentTarget.dataset.text, //省名字
  544. })
  545. }
  546. // console.log(that.data.provinceid);
  547. // console.log(that.data.provincetext)
  548. let citypid_url = 'public/citypid';
  549. let citypid_data = {
  550. pid: that.data.provinceid,
  551. };
  552. app.postRequest(citypid_url, citypid_data, function (res) { // 省市区三级联动 ajax
  553. if (res.code == 201) {
  554. that.setData({
  555. hiddenName: false,
  556. citydata: res.data, // 市数据
  557. scrolltop: 0, //市区滚动条
  558. areadata: '', //区域数据清空
  559. cityidx: '', // idx 选中清空
  560. })
  561. // console.log(res.data)
  562. }
  563. })
  564. },
  565. // 市事件
  566. cityOn: function (e) {
  567. var that = this;
  568. var _cityidx = that.data.cityidx
  569. var cityid = e.currentTarget.dataset.id; //市ID
  570. var citytext = e.currentTarget.dataset.text; //市名字
  571. var _index = e.currentTarget.dataset.index + 1; //下标
  572. // console.log(_index);
  573. // console.log(_index*42,);
  574. // console.log(_cityidx);
  575. // console.log(cityid);
  576. that.setData({
  577. cityidx: cityid, // 市 选中
  578. citytext: citytext, // 市 选中名字
  579. areadata: '', //区域数据清空
  580. })
  581. let citypid_url = 'public/citypid';
  582. let citypid_data = {
  583. pid: cityid,
  584. };
  585. app.postRequest(citypid_url, citypid_data, function (res) { // 省市区三级联动 ajax
  586. if (res.code == 201) {
  587. if (_cityidx == cityid) {
  588. that.setData({
  589. areadata: '', // 区数据
  590. cityidx: '', // idx 选中清空
  591. })
  592. } else {
  593. that.setData({
  594. areadata: res.data, // 区数据
  595. scrolltop: _index * 42,
  596. })
  597. // console.log('执行')
  598. // console.log(_index * 42);
  599. }
  600. // console.log(res.data)
  601. }
  602. })
  603. },
  604. //区选中事件
  605. areaOn: function (e) {
  606. var that = this;
  607. var _style = e.currentTarget.dataset.style;
  608. // console.log(_style);
  609. var regionid = e.currentTarget.dataset.id; //传递地区ID
  610. // console.log(regionid);
  611. switch (_style) {
  612. case 'provinceLx':
  613. // console.log('省');
  614. that.setData({
  615. city: regionid,
  616. provinceName: that.data.provincetext, // 省名字
  617. cityName: '', // 市名字清空
  618. areaName: "", // 区名字
  619. page: 1,
  620. })
  621. break;
  622. case 'cityLx':
  623. // console.log('市');
  624. that.setData({
  625. city: regionid,
  626. provinceName: that.data.provincetext, // 省名字
  627. cityName: that.data.citytext, // 省名字
  628. areaName: "", // 区名字
  629. page: 1,
  630. })
  631. break;
  632. case 'areaLx':
  633. // console.log('区');
  634. var areatext = e.currentTarget.dataset.text; //区名字
  635. that.setData({
  636. city: regionid,
  637. provinceName: that.data.provincetext, // 省名字
  638. cityName: that.data.citytext, // 省名字
  639. areaName: areatext, // 区名字
  640. page: 1,
  641. })
  642. break;
  643. }
  644. // console.log(that.data.city)
  645. // console.log(that.data.provinceName)
  646. // console.log(that.data.cityName)
  647. // console.log(that.data.areaName)
  648. that.list(); //调用筛选
  649. that.setData({
  650. hiddenName: true,
  651. provinceid: 1,
  652. provincetext: '北京', //省 名字
  653. cityidx: 0,
  654. citytext: '',
  655. })
  656. app.globalData.Selection = 0; // 是否选中
  657. },
  658. //省市区不限
  659. regionBx: function () {
  660. var that = this;
  661. that.setData({
  662. hiddenName: true,
  663. provinceid: 1,
  664. provincetext: '北京', //省 名字
  665. cityidx: 0,
  666. citytext: '',
  667. provinceName:'', // 省名字
  668. city: 0, // 市数据清空
  669. cityName: '', // 市名字清空
  670. areaName: "", // 区名字
  671. page: 1,//当前页码
  672. })
  673. that.list(); //调用筛选
  674. },
  675. //省市区关闭
  676. Close: function () {
  677. var that = this;
  678. that.setData({
  679. hiddenName: true,
  680. provinceid: 1,
  681. provincetext: '北京', //省 名字
  682. cityidx: 0,
  683. citytext: '',
  684. })
  685. },
  686. Getlocation: function () {
  687. wx.getSetting({
  688. success: (res) => {
  689. // console.log(JSON.stringify(res))
  690. // console.log(res)
  691. // console.log(res.authSetting['scope.userLocation'])
  692. // res.authSetting['scope.userLocation'] == undefined 表示 初始化进入该页面
  693. // res.authSetting['scope.userLocation'] == false 表示 非初始化进入该页面,且未授权
  694. // res.authSetting['scope.userLocation'] == true 表示 地理位置授权
  695. if (!res.authSetting['scope.userLocation']) {
  696. wx.showModal({
  697. title: '请求授权当前位置',
  698. content: '需要获取您的地理位置,请前往授权',
  699. success: function (res) {
  700. if (res.cancel) {
  701. wx.showToast({
  702. title: '拒绝授权',
  703. icon: 'none',
  704. duration: 1000
  705. })
  706. } else if (res.confirm) {
  707. wx.getLocation({
  708. success: function (res) {
  709. // console.log(res.latitude)
  710. // console.log(res.longitude)
  711. getApp().getDistrict(res.latitude, res.longitude);
  712. },
  713. })
  714. }
  715. }
  716. })
  717. } else if (res.authSetting['scope.userLocation'] == undefined) {
  718. //调用wx.getLocation的API
  719. }
  720. else {
  721. //调用wx.getLocation的API
  722. }
  723. }
  724. })
  725. },
  726. })
  727. var data_processing = function (data, min_max, ) {
  728. for (let i = 0; i < data.length; i++) { //已选中的数据处理
  729. if (data[i] == min_max) {
  730. return i;
  731. }
  732. }
  733. }
  734. var transformation = function (resdata) {
  735. if (resdata) {
  736. let newArry = resdata.split("-"); //转成数组
  737. if (newArry[0] == '不限' || newArry[0] == undefined) {
  738. var _min = 0
  739. } else {
  740. var _min = newArry[0];
  741. }
  742. if (newArry[1] == '以上' || newArry[1] == undefined) {
  743. var _max = 0
  744. } else {
  745. var _max = newArry[1];
  746. }
  747. resdata = _min + '-' + _max
  748. }
  749. return resdata;
  750. }