index.js 25 KB

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