index.js 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139
  1. const app = getApp();
  2. const webSocket = require('../../utils/websocket.js');
  3. Page({
  4. data: {
  5. multiArray: [], // 地址-数据
  6. step: 0, // 地址
  7. multiIndex: [0, 0, 0], // 地址-下标
  8. CityRecord: '', //城市记录
  9. areaRecord: '', //区域记录
  10. CityRecordid: [], //下标记录
  11. UsedRecord: false, //是否初次
  12. provincename:'', // 省
  13. cityname: '', // 市
  14. areaname: '', // 区
  15. heightid: 0,
  16. heightArray: [], // 身高-数据
  17. heightindex: [0, 0], // 身高-下标
  18. Ageid: 0,
  19. AgeArray: [], // 年龄-数据
  20. AgeIndex: [0, 0], // 年龄-下标
  21. MarriageArray: [], // 婚史-数据
  22. Marriageindex: '', // 婚史-下标
  23. EducationArray: [], // 学历-数据
  24. Educationindex: '', // 学历-下标
  25. nickname: '',//ID
  26. sex: 0, // 性别
  27. age: 0, // 年龄
  28. agezx:0,
  29. height: 0, // 身高
  30. heightzx:0,
  31. province: 0, // 省
  32. city: 0, // 市
  33. area: 0, // 区
  34. education: 0, // 学历
  35. educationid:0,
  36. marry: 0, // 婚史
  37. idmarry:0,
  38. income:0,
  39. // income: '', // 收入
  40. // occupation: '', // 职业
  41. // home: '', //列表信息
  42. // tab: [true, true, true, true],
  43. home: [], //定义列表信息数组
  44. // tabTxt: ['性别', '年龄', '婚史', '特色'],//tab文案
  45. page: 1,//当前页码
  46. limit: 10,//获取条数
  47. morehide: false, //暂无更多信息显示隐藏
  48. moreTxt: '',
  49. code:'', //分享ID
  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. // console.log(app.globalData.height);
  61. // console.log(app.globalData.marry);
  62. // console.log(app.globalData.education);
  63. // console.log(app.globalData.income);
  64. var _Selection = app.globalData.Selection // 是否选中 1选中 0没选中
  65. var _income = app.globalData.income // 收入
  66. if (app.globalData.idmarry ){
  67. that.setData({
  68. idmarry: app.globalData.idmarry
  69. })
  70. }
  71. if (app.globalData.educationid) {
  72. that.setData({
  73. educationid: app.globalData.educationid
  74. })
  75. }
  76. that.setData({
  77. UsedRecord: false,
  78. CityRecord: '',
  79. areaRecord:'',
  80. multiIndex: [0, 0, 0], // 地址-下标
  81. step: 0,
  82. })
  83. if (app.globalData.income){
  84. that.setData({
  85. income: _income,
  86. })
  87. } else if (app.globalData.income == 0 && _Selection == 1) { //判断筛选页面 是否清空数据 同时 是否选中,而不是返回
  88. that.setData({
  89. income: _income,
  90. })
  91. }
  92. // console.log(that.data.provincename);
  93. // console.log(that.data.cityname);
  94. // console.log(that.data.areaname);
  95. var _province = app.globalData.province // 省
  96. var _city = app.globalData.city // 市
  97. var _area = app.globalData.area // 区
  98. if (_province && _city && _area) {
  99. that.setData({
  100. province: _province,
  101. city: _city,
  102. area: _area,
  103. })
  104. // console.log(_province);
  105. // console.log(_city);
  106. // console.log(_area);
  107. } else if (_city == 0 && _Selection == 1) { //判断筛选页面 是否清空数据 同时 是否选中,而不是返回
  108. that.setData({
  109. province: _province,
  110. city: _city,
  111. area: _area,
  112. })
  113. }
  114. var _provincename = app.globalData.provincename // 省
  115. var _cityname = app.globalData.cityname // 市
  116. var _areaname = app.globalData.areaname // 区
  117. if (_provincename && _cityname && _areaname) {
  118. that.setData({
  119. provincename: _provincename,
  120. cityname: _cityname,
  121. areaname: _areaname,
  122. step : 0,
  123. })
  124. // console.log(_provincename);
  125. // console.log(_cityname);
  126. // console.log(_areaname);
  127. } else if (_cityname == 0 && _Selection == 1) { //判断筛选页面 是否清空数据 同时 是否选中,而不是返回
  128. that.setData({
  129. provincename: _provincename,
  130. cityname: _cityname,
  131. areaname: _areaname,
  132. step: 0,
  133. })
  134. }
  135. // that.setData({
  136. // // nickname: that.options.nickname, //姓名
  137. // age: that.options.age, // 年龄
  138. // height: that.options.height, // 身高
  139. // // province: that.options.province, // 市
  140. // // city: that.options.city, // 市
  141. // // area: that.options.area, // 区
  142. // education: that.options.education, // 学历
  143. // income: that.options.income, // 收入
  144. // });
  145. // 年龄 ajax
  146. let Age_url = 'public/paramsgather?type=age';
  147. let Age_data = {};
  148. if (app.globalData.age){ //判断 是否从筛选页面传来的参数
  149. // console.log(app.globalData.age);
  150. var _age = app.globalData.age // 年龄
  151. var _agezx = app.globalData.agezx // 年龄
  152. if (_agezx == 0) {
  153. var agenewArry = _age.split("-"); //转成数组
  154. var _age_min = agenewArry[0]
  155. var _age_max = agenewArry[1]
  156. } else {
  157. var agenewArry = _agezx.split("-"); //转成数组
  158. var _age_min = agenewArry[0]
  159. var _age_max = agenewArry[1]
  160. }
  161. // console.log(_age_min)
  162. // console.log(_age_max)
  163. that.setData({
  164. Ageid: 0,
  165. age: _age,
  166. agezx: _agezx,
  167. })
  168. } else if (app.globalData.age == 0 && _Selection == 1) { //判断筛选页面 是否清空数据 同时 是否选中,而不是返回
  169. var _age = app.globalData.age // 年龄
  170. that.setData({
  171. age: _age,
  172. Ageid :0,
  173. AgeIndex: ['', '']
  174. })
  175. }
  176. app.postRequest(Age_url, Age_data, function (res) { // 年龄 ajax
  177. if (res.code == 201) {
  178. if (app.globalData.age){
  179. let createArr1 = res.data;
  180. let newarray1 = ['不限'];
  181. createArr1 = newarray1.concat(createArr1);
  182. for (let i = 0; i < createArr1.length; i++) { //已选中的数据处理
  183. if (createArr1[i] == _age_min) { var _min = i; }
  184. if (createArr1[i] == _age_max) { var _max = i; }
  185. that.setData({
  186. AgeIndex: [_min, _max]
  187. })
  188. }
  189. }
  190. let dictObject = res.data; //对象不能直接使用 以下转成数组
  191. // 对象转成数组
  192. var createArr = []
  193. for (let i in dictObject) {
  194. createArr.push(dictObject[i] + "岁");
  195. }
  196. // console.log(createArr);
  197. //使用concat()来把两个数组合拼起来
  198. let newarray = ['不限'];
  199. createArr = newarray.concat(createArr);
  200. // console.log(createArr);
  201. that.setData({
  202. AgeArray: [createArr, createArr],
  203. })
  204. // console.log(createArr);
  205. }
  206. })
  207. // 身高 ajax
  208. let height_url = 'public/paramsgather?type=height';
  209. let height_data = {
  210. pid: '0'
  211. };
  212. if (app.globalData.height) { //判断 是否从筛选页面传来的参数
  213. // console.log(app.globalData.height);
  214. var _height = app.globalData.height // 身高
  215. var _heightzx = app.globalData.heightzx // 年龄
  216. if (_heightzx == 0) {
  217. var heightnewArry = _height.split("-"); //转成数组
  218. var heightSmall = heightnewArry[0]
  219. var heightlarge = heightnewArry[1]
  220. } else {
  221. var heightnewArry = _heightzx.split("-"); //转成数组
  222. var heightSmall = heightnewArry[0]
  223. var heightlarge = heightnewArry[1]
  224. }
  225. // console.log(heightSmall)
  226. // console.log(heightlarge)
  227. that.setData({
  228. height: _height,
  229. heightid:0,
  230. heightzx: _heightzx,
  231. })
  232. } else if (app.globalData.height == 0 && _Selection == 1) { //判断筛选页面 是否清空数据 同时 是否选中,而不是返回
  233. var _height = app.globalData.height // 身高
  234. that.setData({
  235. height: _height,
  236. heightid: 0,
  237. heightindex: ['', ''], // 身高-下标
  238. })
  239. }
  240. app.postRequest(height_url, height_data, function (res) { // 身高 ajax
  241. if (res.code == 201) {
  242. if (app.globalData.height) {
  243. let createArr1 = res.data;
  244. let newarray1 = ['不限'];
  245. createArr1 = newarray1.concat(createArr1);
  246. for (let i = 0; i < createArr1.length; i++) { //已选中的数据处理
  247. // console.log(res.data[i])
  248. if (createArr1[i] == heightSmall) { var _min = i; }
  249. if (createArr1[i] == heightlarge) { var _max = i; }
  250. that.setData({
  251. heightindex: [_min, _max]
  252. })
  253. }
  254. }
  255. let dictObject = res.data; //对象不能直接使用 以下转成数组
  256. // 对象转成数组
  257. var createArr = []
  258. for (let i in dictObject) {
  259. createArr.push(dictObject[i] + "cm");
  260. }
  261. let newarray = ['不限'];
  262. createArr = newarray.concat(createArr);
  263. // console.log(createArr);
  264. that.setData({
  265. heightArray: [createArr, createArr],
  266. })
  267. }
  268. })
  269. // 婚史 ajax
  270. let Marriage_url = 'public/paramsgather?type=marriage';
  271. let Marriage_data = {};
  272. if (app.globalData.marry) { //判断 是否从筛选页面传来的参数
  273. // console.log(app.globalData.marry);
  274. var _marry = app.globalData.marry // 婚姻
  275. that.setData({
  276. marry: _marry
  277. })
  278. } else if (app.globalData.marry == 0 && _Selection == 1) { //判断筛选页面 是否清空数据 同时 是否选中,而不是返回
  279. var _marry = app.globalData.marry // 婚姻
  280. that.setData({
  281. marry: _marry,
  282. Marriageindex: "", // 婚姻-下标
  283. })
  284. }
  285. app.postRequest(Marriage_url, Marriage_data, function (res) { // 婚史 ajax
  286. if (res.code == 201) {
  287. if (app.globalData.marry) {
  288. let createArr1 = res.data;
  289. let newarray1 = ['不限'];
  290. createArr1 = newarray1.concat(createArr1);
  291. for (let i = 0; i < createArr1.length; i++) { //已选中的数据处理
  292. if (i == _marry) {
  293. that.setData({
  294. Marriageindex: i,
  295. })
  296. }
  297. }
  298. }
  299. let createArr = res.data;
  300. let newarray = ['不限'];
  301. createArr = newarray.concat(createArr);
  302. that.setData({
  303. MarriageArray: createArr,
  304. idmarry: that.data.idmarry,
  305. })
  306. }
  307. })
  308. // 学历 ajax
  309. let Education_url = 'public/paramsgather?type=xueli';
  310. let Education_data = {};
  311. if (app.globalData.education) { //判断 是否从筛选页面传来的参数
  312. console.log('执行');
  313. var _education = app.globalData.education // 学历
  314. that.setData({
  315. education: _education
  316. })
  317. } else if (app.globalData.education == 0 && _Selection == 1) { //判断筛选页面 是否清空数据 同时 是否选中,而不是返回
  318. var _education = app.globalData.education // 学历
  319. that.setData({
  320. education: _education,
  321. Educationindex: "", // 学历-下标
  322. })
  323. }
  324. app.postRequest(Education_url, Education_data, function (res) { // 学历 ajax
  325. if (res.code == 201) {
  326. var obj = { id: 0, name: '不限' };
  327. var datares = res.data;
  328. datares.unshift(obj)
  329. if (app.globalData.education) {
  330. for (let i = 0; i < datares.length; i++) { //已选中的数据处理
  331. if (datares[i].id == _education) {
  332. that.setData({
  333. Educationindex: i,
  334. })
  335. }
  336. }
  337. }
  338. that.setData({
  339. EducationArray: datares,
  340. educationid: that.data.educationid,
  341. })
  342. }
  343. })
  344. that.getProvince(); //地址 ajax
  345. that.list();
  346. },
  347. // 会员编码
  348. getPhone: function (e) {
  349. var nickname = e.detail.value;
  350. console.log(nickname);
  351. this.setData({
  352. nickname: nickname
  353. });
  354. },
  355. // 会员编码查询
  356. Code: function (e) {
  357. var that = this;
  358. // 判断会员编码是否存在
  359. if (that.data.nickname){
  360. that.showLoading(); //提示加载中
  361. // 列表信息
  362. let home_url = 'circle/friend/home';
  363. let home_data = {
  364. page: that.data.page,
  365. limit: that.data.limit,
  366. number: that.data.nickname, // 性别
  367. };
  368. app.postRequest(home_url, home_data, function (res) {
  369. if (res.code == 201) {
  370. // console.log(res.data);
  371. that.setData({
  372. home: res.data,
  373. })
  374. that.cancelLoading(); //数据加载完关闭
  375. return;
  376. }
  377. that.cancelLoading(); //数据加载完关闭
  378. that.setData({
  379. home_code: res.code,
  380. morehide: true,
  381. moreTxt: '暂无更多数据。'
  382. })
  383. })
  384. }else{
  385. var fail = '请输入会员编号' //调用提示框
  386. getApp().Tips(fail)
  387. }
  388. },
  389. heightEvent: function (e) { // 身高
  390. var that = this;
  391. // console.log(this);
  392. // console.log(e);
  393. // console.log(this.data.heightArray[e.detail.value]);
  394. // console.log('picker发送选择改变,携带值为', e.detail.value)
  395. var _value = e.detail.value; //发送选择改变,携带值为
  396. var heightSmall = this.data.heightArray[0][e.detail.value[0]].substring(0, 3); //最小值
  397. var heightlarge = this.data.heightArray[1][e.detail.value[1]].substring(0, 3); //最大值
  398. // console.log(heightdata)
  399. if (heightSmall > heightlarge && heightSmall != '不限' && heightlarge != '不限') { //判断 最小值 大于 最大值 数据互换
  400. // console.log('调换')
  401. var heightdata = heightlarge + '-' + heightSmall;
  402. that.Exchange(_value); // 调用数组调换
  403. that.setData({
  404. heightzx: 0,
  405. })
  406. } else if (heightSmall == '不限' && heightlarge != '不限') { //判断 最小值 = 不限 输出 最大的值以下
  407. // console.log('以下')
  408. var heightdata = heightlarge + '以下';
  409. var heightdatazx = '不限' + '-' + heightlarge;
  410. that.setData({
  411. heightzx: heightdatazx,
  412. })
  413. } else if (heightlarge == '不限' && heightSmall != '不限') { //判断 最大值 = 不限 输出 最小的值以上
  414. // console.log('以上')
  415. var heightdata = heightSmall + '以上';
  416. var heightdatazx = heightSmall + '-' + '不限';
  417. that.setData({
  418. heightzx: heightdatazx,
  419. })
  420. } else if (heightSmall == '不限' && heightlarge == '不限') { //判断 大小值 = 不限 输出 不限
  421. // console.log('不限')
  422. var heightdata = '不限';
  423. var heightdatazx = '不限' + '-' + '不限';
  424. that.setData({
  425. heightzx: heightdatazx,
  426. })
  427. } else {
  428. var heightdata = heightSmall + '-' + heightlarge; //否则正常选中
  429. that.setData({
  430. heightzx: 0,
  431. })
  432. }
  433. that.setData({
  434. heightindex: _value,
  435. height: heightdata,
  436. heightid: 1,
  437. })
  438. that.list();
  439. },
  440. // 年龄双选
  441. AgeEvent: function (e) {
  442. var that = this;
  443. // console.log('picker发送选择改变,携带值为', e.detail.value)
  444. var _value = e.detail.value; //发送选择改变,携带值为
  445. var Small = this.data.AgeArray[0][e.detail.value[0]].substring(0, 2); //小
  446. var large = this.data.AgeArray[1][e.detail.value[1]].substring(0, 2); //大
  447. // console.log(Small);
  448. // console.log(large);
  449. if (Small > large && Small != '不限' && large != '不限'){ //判断 最小值 大于 最大值 数据互换
  450. // console.log('调换')
  451. var Agedata = large + '-' + Small;
  452. that.Exchange(_value); // 调用数组调换
  453. that.setData({
  454. agezx: 0,
  455. })
  456. } else if (Small == '不限' && large != '不限') { //判断 最小值 = 不限 输出 最大的值以下
  457. // console.log('以下')
  458. var Agedata = large + '以下';
  459. var Agedataxz = '不限' + '-' + large;
  460. that.setData({
  461. agezx: Agedataxz,
  462. })
  463. } else if (large == '不限' && Small != '不限') { //判断 最大值 = 不限 输出 最小的值以上
  464. // console.log('以上')
  465. var Agedata = Small + '以上';
  466. var Agedataxz = Small + '-' + '不限';
  467. that.setData({
  468. agezx: Agedataxz,
  469. })
  470. } else if (Small == '不限' && large == '不限') { //判断 大小值 = 不限 输出 不限
  471. // console.log('不限')
  472. var Agedata = '不限';
  473. var Agedataxz = '不限' + '-' + '不限';
  474. that.setData({
  475. agezx: Agedataxz,
  476. })
  477. }else {
  478. var Agedata = Small + '-' + large; //否则正常选中
  479. that.setData({
  480. agezx: 0,
  481. })
  482. }
  483. // console.log(_value);
  484. that.setData({
  485. AgeIndex: _value,
  486. age: Agedata,
  487. Ageid: 1,
  488. page:1,
  489. })
  490. that.list(); //调用筛选
  491. },
  492. // 数组数据调换
  493. Exchange: function (data) {
  494. for (var i = 0; i < data.length / 2; i++) {
  495. var data_i = data[i];
  496. data[i] = data[data.length - 1 - i];
  497. data[data.length - 1 - i] = data_i;
  498. }
  499. return;
  500. },
  501. MarriageEvent: function (e) { // 婚史 单项选择器
  502. var that = this;
  503. // console.log(this);
  504. // console.log(e);
  505. // console.log(this.data.MarriageArray[e.detail.value]);
  506. // console.log('picker发送选择改变,携带值为', e.detail.value)
  507. this.setData({
  508. Marriageindex: e.detail.value,
  509. marry: e.detail.value,
  510. page: 1,
  511. idmarry:1,
  512. })
  513. that.list(); //调用筛选
  514. },
  515. EducationEvent: function (e) { // 学历 单项选择器
  516. var that = this;
  517. // console.log(this);
  518. // console.log(e);
  519. // console.log(this.data.EducationArray[e.detail.value].id);
  520. // console.log('picker发送选择改变,携带值为', e.detail.value)
  521. this.setData({
  522. Educationindex: e.detail.value,
  523. education: this.data.EducationArray[e.detail.value].id,
  524. page: 1,
  525. educationid:1,
  526. })
  527. that.list(); //调用筛选
  528. },
  529. // 列表切换
  530. // filterTab: function (e) {
  531. // var data = [true, true, true, true], qhid = e.currentTarget.dataset.qhid;
  532. // // console.log(e.currentTarget.dataset.qhid);
  533. // data[qhid] = !this.data.tab[qhid];
  534. // // console.log(!this.data.tab[qhid]);
  535. // this.setData({
  536. // tab: data,
  537. // })
  538. // },
  539. getProvince() { // 多项选择器
  540. let _this = this;
  541. let d_url = 'public/citypid';
  542. app.postRequest(d_url, { pid: '0' }, function (res) {
  543. if (res.code == '201') {
  544. var provinceList = res.data;
  545. var provinceArr = [];
  546. provinceArr = _this.mapArray(res.data);
  547. _this.setData({
  548. multiArray: [provinceArr, [], []],
  549. provinceList,
  550. provinceArr,
  551. })
  552. // console.log(provinceList);
  553. // console.log(provinceArr);
  554. // console.log(_this.data.CityRecord)
  555. // 方便取消事件调用 getProvince 判断 如果选择过城市 传选择过的城市
  556. if (_this.data.CityRecord) {
  557. // console.log('有');
  558. var defaultCode = _this.data.CityRecord
  559. if (defaultCode) {
  560. _this.setData({
  561. currnetProvinceKey: defaultCode
  562. })
  563. _this.getCity(defaultCode)
  564. }
  565. } else { //如果没有选择过 , 传第一个城市
  566. // console.log('无');
  567. var defaultCode = provinceList[0]['area_id']
  568. if (defaultCode) {
  569. _this.setData({
  570. currnetProvinceKey: defaultCode
  571. })
  572. _this.getCity(defaultCode)
  573. }
  574. }
  575. }
  576. })
  577. },
  578. getCity(codes) {
  579. // 多项选择
  580. let _this = this;
  581. let d_url = 'public/citypid';
  582. app.postRequest(d_url, { pid: codes }, function (res) {
  583. var cityList = res.data;
  584. var cityArr = [];
  585. if (res.code == '201') {
  586. cityArr = _this.mapArray(res.data);
  587. _this.setData({
  588. multiArray: [_this.data.provinceArr, cityArr, []],
  589. cityArr,
  590. cityList
  591. })
  592. // 方便取消事件调用 getProvince 判断 如果选择过城市 传选择过的城市
  593. if (_this.data.areaRecord && _this.data.cancelID == false) {
  594. // console.log('有');
  595. var defaultCode = _this.data.areaRecord
  596. // console.log(_this.data.areaRecord);
  597. if (defaultCode) {
  598. _this.setData({
  599. currnetProvinceKey: defaultCode
  600. })
  601. _this.getArea(defaultCode)
  602. }
  603. } else { //如果没有选择过 , 传第一个城市
  604. // console.log('无');
  605. var defaultCode = cityList[0]['area_id']
  606. // console.log(defaultCode);
  607. if (defaultCode) {
  608. _this.setData({
  609. currnetProvinceKey: defaultCode
  610. })
  611. _this.getArea(defaultCode)
  612. }
  613. }
  614. }
  615. })
  616. },
  617. getArea(codes) {
  618. // 多项选择
  619. let _this = this;
  620. let d_url = 'public/citypid';
  621. app.postRequest(d_url, { pid: codes }, function (res) {
  622. var areaList = res.data;
  623. var areaArr = [];
  624. if (res.code == '201') {
  625. areaArr = _this.mapArray(res.data);
  626. }
  627. // console.log(areaList);
  628. // console.log(areaArr);
  629. _this.setData({
  630. multiArray: [_this.data.provinceArr, _this.data.cityArr, areaArr],
  631. areaList,
  632. areaArr,
  633. })
  634. _this.setData({
  635. cancelID: true,
  636. })
  637. })
  638. },
  639. mapArray: function (data) {
  640. let cityArray = []
  641. if (data) {
  642. for (let i = 0; i < data.length; i++) {
  643. if (data[i].area_name) {
  644. cityArray[i] = data[i].area_name;
  645. }
  646. }
  647. }
  648. return cityArray;
  649. },
  650. columnchange(e) { // 滚动选择器 触发的事件
  651. var column = e.detail.column // 当前改变的列
  652. // console.log(column);
  653. // console.log(this.data.multiIndex);
  654. // console.log(JSON.parse(JSON.stringify(this.data.multiIndex)));
  655. var data = {
  656. multiIndex: this.data.multiIndex,
  657. multiArray: this.data.multiArray
  658. }
  659. data.multiIndex[column] = e.detail.value; // 第几列改变了就是对应multiIndex的第几个,更新它
  660. switch (column) { // 处理不同的逻辑
  661. case 0: // 第一列更改 就是省级的更改
  662. var currentProvinceKey = this.data.provinceList[e.detail.value].area_id
  663. if (currentProvinceKey != this.data.currnetProvinceKey) { // 判断当前的key是不是真正的更新了
  664. this.getCity(currentProvinceKey) // 获取当前key下面的市级数据
  665. }
  666. data.multiIndex[1] = 0 // 将市默认选择第一个
  667. break;
  668. case 1: // 市发生变化
  669. var currentCitykey = this.data.cityList[e.detail.value].area_id
  670. if (currentCitykey != this.data.currnetCityKey) { // 同样判断
  671. this.getArea(currentCitykey) // 获取门店
  672. }
  673. data.multiIndex[2] = 0
  674. break;
  675. }
  676. this.setData(data) // 更新数据
  677. // console.log(this.data.step)
  678. },
  679. pickchange(e) {
  680. var that =this;
  681. // console.log(that.data.multiIndex);
  682. // console.log(that.data.provinceList[e.detail.value[0]].area_id);
  683. // console.log(that.data.cityList[e.detail.value[1]].area_id);
  684. // console.log(that.data.areaList[e.detail.value[2]].area_id);
  685. that.setData({
  686. step: 1, // 更新,用来选择用户选中的门店
  687. multiIndex: e.detail.value, // 更新下标字段
  688. province: that.data.provinceList[e.detail.value[0]].area_id, // 市
  689. city: that.data.cityList[e.detail.value[1]].area_id, // 市
  690. area: that.data.areaList[e.detail.value[2]].area_id, // 区
  691. provincename: that.data.provinceList[e.detail.value[0]].area_name, // 市
  692. cityname: that.data.cityList[e.detail.value[1]].area_name, // 市
  693. areaname: that.data.areaList[e.detail.value[2]].area_name, // 区
  694. CityRecord: that.data.provinceList[e.detail.value[0]].area_id, // 省
  695. areaRecord: that.data.cityList[e.detail.value[1]].area_id, // 市
  696. CityRecordid: that.data.multiIndex,
  697. UsedRecord: true, //已使用过
  698. })
  699. that.list();
  700. },
  701. // 城市取消
  702. cancel: function (e) {
  703. var _this = this;
  704. if (_this.data.UsedRecord == true) {
  705. _this.setData({
  706. multiIndex: _this.data.CityRecordid,
  707. cancelID: false
  708. })
  709. // console.log(_this.data.CityRecordid);
  710. _this.getProvince(); //地址 ajax
  711. }
  712. },
  713. // 上拉加载更多
  714. onReachBottom() {
  715. var that = this;
  716. that.showLoading(); //提示加载中
  717. // 列表信息
  718. let home_url = 'circle/friend/home';
  719. let home_data = {
  720. page: (that.data.page++) + 1,
  721. limit: that.data.limit,
  722. height: that.data.height, // 身高
  723. age: that.data.age, // 年龄
  724. marry: that.data.marry, // 婚史
  725. education: that.data.education, // 学历
  726. // province: that.data.province, // 市
  727. city: that.data.city, // 市
  728. // area: that.data.area, // 区
  729. };
  730. app.postRequest(home_url, home_data, function (res) {
  731. if (res.code == 201) {
  732. // console.log(res.data);
  733. var home = that.data.home
  734. var moreTxt = '';
  735. if (0 < (res.data.length < 10)) {
  736. moreTxt = '暂无更多数据。'
  737. console.log('无')
  738. } else {
  739. moreTxt = ''
  740. console.log('有')
  741. }
  742. // 设置数据
  743. for (var i = 0; i < res.data.length; i++) {
  744. home.push(res.data[i]);
  745. }
  746. that.setData({
  747. home: home,
  748. morehide: true,
  749. moreTxt: moreTxt,
  750. })
  751. that.cancelLoading(); //数据加载完关闭
  752. return;
  753. }
  754. that.cancelLoading(); //数据加载完关闭
  755. that.setData({
  756. home_code: res.code,
  757. morehide: true,
  758. moreTxt:"暂无更多数据。"
  759. })
  760. })
  761. },
  762. More:function(){
  763. var that = this;
  764. // console.log(that.data.age);
  765. wx.navigateTo({
  766. url: '/pages/index_screen/index_screen?age=' + that.data.age + '&agezx=' + that.data.agezx + '&heightzx=' + that.data.heightzx + '&height=' + that.data.height + '&marry=' + that.data.marry + '&idmarry=' + that.data.idmarry + '&education=' + that.data.education + '&educationid=' + that.data.educationid + '&income=' + that.data.income + '&province=' + that.data.province + '&city=' + that.data.city + '&area=' + that.data.area + '&provincename=' + that.data.provincename + '&cityname=' + that.data.cityname + '&areaname=' + that.data.areaname + ''
  767. })
  768. },
  769. list: function () {
  770. var that = this;
  771. that.showLoading(); //提示加载中
  772. // 列表信息
  773. let home_url = 'circle/friend/home';
  774. let home_data = {
  775. page: that.data.page,
  776. limit: that.data.limit,
  777. age: that.data.age, // 年龄
  778. height: that.data.height, // 身高
  779. marry: that.data.marry, // 婚史
  780. education: that.data.education, // 学历
  781. income: that.data.income, //收入
  782. // province: that.data.province , // 市
  783. city: that.data.city, // 市
  784. // area: that.data.area, // 区
  785. };
  786. app.postRequest(home_url, home_data, function (res) {
  787. if (res.code == 201) {
  788. var moreTxt = '';
  789. if (res.data.length < 10) {
  790. moreTxt = '暂无更多数据。'
  791. } else {
  792. moreTxt = ''
  793. }
  794. // console.log(res.data);
  795. that.setData({
  796. home: res.data,
  797. moreTxt: moreTxt,
  798. home_code: res.code,
  799. })
  800. that.cancelLoading(); //数据加载完关闭
  801. return;
  802. }
  803. that.cancelLoading(); //数据加载完关闭
  804. that.setData({
  805. home: res.data,
  806. morehide: true,
  807. moreTxt: '暂无更多数据。'
  808. })
  809. })
  810. },
  811. // 加载
  812. showLoading: function () {
  813. wx.showToast({
  814. title: '加载中',
  815. icon: 'loading'
  816. });
  817. },
  818. // 关闭加载
  819. cancelLoading: function () {
  820. wx.hideToast();
  821. },
  822. // 分享
  823. onShareAppMessage: function (res) {
  824. var that = this;
  825. var code ='';
  826. // getApp().showLoading(); //提示加载中
  827. // 头部信息
  828. let datum_url = 'my/other/share';
  829. let datum_data = {
  830. };
  831. app.postRequest(datum_url, datum_data, function (res) {
  832. if (res.code == 201) {
  833. console.log(res.data.code);
  834. that.setData({
  835. code: res.data.code,
  836. })
  837. }
  838. })
  839. if (res.from === 'button') {
  840. console.log("来自页面内转发按钮");
  841. console.log(res.target);
  842. }
  843. else {
  844. console.log("来自右上角转发菜单")
  845. }
  846. return {
  847. title: '妹子图片',
  848. path: '/pages/share/share?code=' + _that.data.code +'',
  849. success: (res) => {
  850. console.log("转发成功", res);
  851. },
  852. fail: (res) => {
  853. console.log("转发失败", res);
  854. }
  855. }
  856. }
  857. })