index.js 25 KB

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