index.js 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  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. wx.navigateTo({
  392. url: '/pages/index_screen/index_screen?age=' + that.data.age + '&height=' + that.data.height + '&marry=' + that.data.marry + '&idmarry=' + that.data.idmarry + '&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 + ''
  393. })
  394. },
  395. // 上拉加载更多
  396. onReachBottom() {
  397. var that = this;
  398. let _age = transformation(that.data.age) //不限以上 转换成0
  399. let _height = transformation(that.data.height) //不限以上 转换成0
  400. let _income = transformation(that.data.income) //不限以上 转换成0
  401. that.showLoading(); //提示加载中
  402. // 列表信息
  403. var home_url = 'circle/friend/home';
  404. if (that.data.inputValue) { //判断 搜索用户ID存在 只传用户ID
  405. var home_data = {
  406. page: (that.data.page++) + 1,
  407. limit: that.data.limit,
  408. number: that.data.inputValue, // 性别
  409. };
  410. // console.log('用户ID');
  411. } else { //否则 传常规选择
  412. var home_data = {
  413. page: (that.data.page++) + 1,
  414. limit: that.data.limit,
  415. age: _age, // 年龄
  416. height: _height, // 身高
  417. marry: that.data.marry, // 婚史
  418. education: that.data.education, // 学历
  419. income: _income, //收入
  420. city: that.data.city, // 市
  421. };
  422. // console.log('选择');
  423. }
  424. app.postRequest(home_url, home_data, function (res) {
  425. if (res.code == 201) {
  426. // console.log(res.data);
  427. var home = that.data.home
  428. // var moreTxt = '';
  429. // if (0 < (res.data.length < 10)) {
  430. // moreTxt = res.msg;
  431. // // console.log('无')
  432. // } else {
  433. // moreTxt = ''
  434. // // console.log('有')
  435. // }
  436. // 设置数据
  437. for (var i = 0; i < res.data.length; i++) {
  438. home.push(res.data[i]);
  439. }
  440. that.setData({
  441. home: home,
  442. morehide: true,
  443. })
  444. that.cancelLoading(); //数据加载完关闭
  445. return;
  446. }
  447. that.cancelLoading(); //数据加载完关闭
  448. that.setData({
  449. home_code: res.code,
  450. morehide: false,
  451. moreTxt: res.msg,
  452. })
  453. })
  454. },
  455. list: function () {
  456. var that = this;
  457. let _age = transformation(that.data.age) //不限以上 转换成0
  458. let _height = transformation(that.data.height) //不限以上 转换成0
  459. let _income = transformation(that.data.income) //不限以上 转换成0
  460. that.showLoading(); //提示加载中
  461. // 列表信息
  462. let home_url = 'circle/friend/home';
  463. if (that.data.inputValue) { //判断 搜索用户ID存在 只传用户ID
  464. var home_data = {
  465. page: that.data.page,
  466. limit: that.data.limit,
  467. number: that.data.inputValue, // 性别
  468. };
  469. } else { //否则 传常规选择
  470. var home_data = {
  471. page: that.data.page,
  472. limit: that.data.limit,
  473. age: _age, // 年龄
  474. height: _height, // 身高
  475. marry: that.data.marry, // 婚史
  476. education: that.data.education, // 学历
  477. income: _income, //收入
  478. city: that.data.city, // 市
  479. };
  480. }
  481. app.postRequest(home_url, home_data, function (res) {
  482. that.setData({
  483. inputValue: '',
  484. })
  485. var moreTxt = '';
  486. if (res.code == 201) {
  487. // if (res.data.length < 10) {
  488. // moreTxt = res.msg
  489. // } else {
  490. // moreTxt = ''
  491. // }
  492. // console.log(res.data);
  493. that.setData({
  494. home: res.data,
  495. morehide: true,
  496. home_code: res.code,
  497. })
  498. that.cancelLoading(); //数据加载完关闭
  499. return;
  500. }
  501. that.cancelLoading(); //数据加载完关闭
  502. that.setData({
  503. home: res.data,
  504. morehide: false,
  505. moreTxt: res.msg,
  506. })
  507. })
  508. },
  509. // 加载
  510. showLoading: function () {
  511. wx.showLoading({
  512. title: '加载中',
  513. icon: 'loading'
  514. });
  515. },
  516. // 关闭加载
  517. cancelLoading: function () {
  518. wx.hideLoading();
  519. },
  520. // 省市区三级联动 点击弹窗
  521. linkage: function (e) {
  522. var that = this;
  523. let citypid_url = 'public/citypid';
  524. let citypid_data = {};
  525. app.postRequest(citypid_url, citypid_data, function (res) { // 省市区三级联动 ajax
  526. if (res.code == 201) {
  527. that.setData({
  528. provincedata: res.data, // 省数据
  529. })
  530. // console.log(res.data)
  531. that.provinceOn();
  532. }
  533. })
  534. },
  535. // 省事件
  536. provinceOn: function (e) {
  537. var that = this;
  538. // console.log(e);
  539. if (e) {
  540. that.setData({
  541. provinceid: e.currentTarget.dataset.id, //省ID
  542. provincetext: e.currentTarget.dataset.text, //省名字
  543. })
  544. }
  545. // console.log(that.data.provinceid);
  546. // console.log(that.data.provincetext)
  547. let citypid_url = 'public/citypid';
  548. let citypid_data = {
  549. pid: that.data.provinceid,
  550. };
  551. app.postRequest(citypid_url, citypid_data, function (res) { // 省市区三级联动 ajax
  552. if (res.code == 201) {
  553. that.setData({
  554. hiddenName: false,
  555. citydata: res.data, // 市数据
  556. scrolltop: 0, //市区滚动条
  557. areadata: '', //区域数据清空
  558. cityidx: '', // idx 选中清空
  559. })
  560. // console.log(res.data)
  561. }
  562. })
  563. },
  564. // 市事件
  565. cityOn: function (e) {
  566. var that = this;
  567. var _cityidx = that.data.cityidx
  568. var cityid = e.currentTarget.dataset.id; //市ID
  569. var citytext = e.currentTarget.dataset.text; //市名字
  570. var _index = e.currentTarget.dataset.index + 1; //下标
  571. // console.log(_index);
  572. // console.log(_index*42,);
  573. // console.log(_cityidx);
  574. // console.log(cityid);
  575. that.setData({
  576. cityidx: cityid, // 市 选中
  577. citytext: citytext, // 市 选中名字
  578. areadata: '', //区域数据清空
  579. })
  580. let citypid_url = 'public/citypid';
  581. let citypid_data = {
  582. pid: cityid,
  583. };
  584. app.postRequest(citypid_url, citypid_data, function (res) { // 省市区三级联动 ajax
  585. if (res.code == 201) {
  586. if (_cityidx == cityid) {
  587. that.setData({
  588. areadata: '', // 区数据
  589. cityidx: '', // idx 选中清空
  590. })
  591. } else {
  592. that.setData({
  593. areadata: res.data, // 区数据
  594. scrolltop: _index * 42,
  595. })
  596. // console.log('执行')
  597. // console.log(_index * 42);
  598. }
  599. // console.log(res.data)
  600. }
  601. })
  602. },
  603. //区选中事件
  604. areaOn: function (e) {
  605. var that = this;
  606. var _style = e.currentTarget.dataset.style;
  607. // console.log(_style);
  608. var regionid = e.currentTarget.dataset.id; //传递地区ID
  609. // console.log(regionid);
  610. switch (_style) {
  611. case 'provinceLx':
  612. // console.log('省');
  613. that.setData({
  614. city: regionid,
  615. provinceName: that.data.provincetext, // 省名字
  616. cityName: '', // 市名字清空
  617. areaName: "", // 区名字
  618. page: 1,
  619. })
  620. break;
  621. case 'cityLx':
  622. // console.log('市');
  623. that.setData({
  624. city: regionid,
  625. provinceName: that.data.provincetext, // 省名字
  626. cityName: that.data.citytext, // 省名字
  627. areaName: "", // 区名字
  628. page: 1,
  629. })
  630. break;
  631. case 'areaLx':
  632. // console.log('区');
  633. var areatext = e.currentTarget.dataset.text; //区名字
  634. that.setData({
  635. city: regionid,
  636. provinceName: that.data.provincetext, // 省名字
  637. cityName: that.data.citytext, // 省名字
  638. areaName: areatext, // 区名字
  639. page: 1,
  640. })
  641. break;
  642. }
  643. // console.log(that.data.city)
  644. // console.log(that.data.provinceName)
  645. // console.log(that.data.cityName)
  646. // console.log(that.data.areaName)
  647. that.list(); //调用筛选
  648. that.setData({
  649. hiddenName: true,
  650. provinceid: 1,
  651. provincetext: '北京', //省 名字
  652. cityidx: 0,
  653. citytext: '',
  654. })
  655. app.globalData.Selection = 0; // 是否选中
  656. },
  657. //省市区不限
  658. regionBx: function () {
  659. var that = this;
  660. that.setData({
  661. hiddenName: true,
  662. provinceid: 1,
  663. provincetext: '北京', //省 名字
  664. cityidx: 0,
  665. citytext: '',
  666. provinceName:'', // 省名字
  667. city: 0, // 市数据清空
  668. cityName: '', // 市名字清空
  669. areaName: "", // 区名字
  670. page: 1,//当前页码
  671. })
  672. that.list(); //调用筛选
  673. },
  674. //省市区关闭
  675. Close: function () {
  676. var that = this;
  677. that.setData({
  678. hiddenName: true,
  679. provinceid: 1,
  680. provincetext: '北京', //省 名字
  681. cityidx: 0,
  682. citytext: '',
  683. })
  684. },
  685. Getlocation: function () {
  686. wx.getSetting({
  687. success: (res) => {
  688. // console.log(JSON.stringify(res))
  689. // console.log(res)
  690. // console.log(res.authSetting['scope.userLocation'])
  691. // res.authSetting['scope.userLocation'] == undefined 表示 初始化进入该页面
  692. // res.authSetting['scope.userLocation'] == false 表示 非初始化进入该页面,且未授权
  693. // res.authSetting['scope.userLocation'] == true 表示 地理位置授权
  694. if (!res.authSetting['scope.userLocation']) {
  695. wx.showModal({
  696. title: '请求授权当前位置',
  697. content: '需要获取您的地理位置,请前往授权',
  698. success: function (res) {
  699. if (res.cancel) {
  700. wx.showToast({
  701. title: '拒绝授权',
  702. icon: 'none',
  703. duration: 1000
  704. })
  705. } else if (res.confirm) {
  706. wx.getLocation({
  707. success: function (res) {
  708. // console.log(res.latitude)
  709. // console.log(res.longitude)
  710. getApp().getDistrict(res.latitude, res.longitude);
  711. },
  712. })
  713. }
  714. }
  715. })
  716. } else if (res.authSetting['scope.userLocation'] == undefined) {
  717. //调用wx.getLocation的API
  718. }
  719. else {
  720. //调用wx.getLocation的API
  721. }
  722. }
  723. })
  724. },
  725. })
  726. var data_processing = function (data, min_max, ) {
  727. for (let i = 0; i < data.length; i++) { //已选中的数据处理
  728. if (data[i] == min_max) {
  729. return i;
  730. }
  731. }
  732. }
  733. var transformation = function (resdata) {
  734. if (resdata) {
  735. let newArry = resdata.split("-"); //转成数组
  736. if (newArry[0] == '不限' || newArry[0] == undefined) {
  737. var _min = 0
  738. } else {
  739. var _min = newArry[0];
  740. }
  741. if (newArry[1] == '以上' || newArry[1] == undefined) {
  742. var _max = 0
  743. } else {
  744. var _max = newArry[1];
  745. }
  746. resdata = _min + '-' + _max
  747. }
  748. return resdata;
  749. }