index_screen.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  1. const app = getApp();
  2. Page({
  3. data: {
  4. Ageid: 0,
  5. AgeArray: [], // 年龄-数据
  6. AgeIndex: [0, 0], // 年龄-下标
  7. heightid: 0,
  8. heightArray: [], // 身高-数据
  9. heightindex: [0, 0], // 身高-下标
  10. EducationArray: [], // 学历-数据
  11. Educationindex: '', // 学历-下标
  12. MarriageArray: [], // 婚史-数据
  13. Marriageindex: '', // 婚史-下标
  14. incomeid: 0,
  15. incomeArray: [], // 收入-数据
  16. incomeindex: [0, 0], // 收入-下标
  17. inputValue: '', // id
  18. age: '', // 年龄
  19. height: '', // 身高
  20. marry: '', // 婚史
  21. idmarry: 0,
  22. education: '', // 学历
  23. educationid: 0,
  24. income: 0, // 收入
  25. Zero:0, //处理不限
  26. Zero1: 0, //处理不限
  27. heightZero: 0, //处理不限
  28. heightZero1: 0, //处理不限
  29. incomeZero:0,
  30. incomeZero1:0,
  31. // min = '';
  32. // max = '';
  33. // 省市区
  34. city: 0, // 市 要传的数据
  35. provinceName: '', // 省 要传的数据
  36. cityName: '', // 市 要传的数据
  37. areaName: '', // 区 要传的数据
  38. provincedata: '', //省数据
  39. provinceid: 1, //省选中ID
  40. provincetext: '北京', //省 名字
  41. citydata: '', //市数据
  42. cityidx: '', //市选中ID
  43. citytext: '', //市 名字
  44. areadata: '', //区数据
  45. scrolltop: '', //市区滚动条
  46. hiddenName: true, //显示隐藏
  47. },
  48. onLoad: function (option) {
  49. var that = this
  50. console.log(option)
  51. getApp().showLoading(); //提示加载中
  52. //先清空要传的数据
  53. app.globalData.Selection = 0; // 是否选中
  54. app.globalData.age = 0; // 年龄
  55. app.globalData.height = 0; // 身高
  56. app.globalData.marry = 0 // 婚史
  57. app.globalData.education = 0 // 学历
  58. app.globalData.income = 0; // 收入
  59. var _city = option.city // 市
  60. var _provincename = option.provinceName // 省
  61. var _cityname = option.cityName // 市
  62. var _areaname = option.areaName // 区
  63. var _idmarry = option.idmarry
  64. var _educationid = option.educationid
  65. that.setData({
  66. city: _city,
  67. provinceName: _provincename, // 省
  68. cityName: _cityname, // 市
  69. areaName: _areaname, // 区
  70. idmarry: _idmarry,
  71. educationid: _educationid,
  72. })
  73. // console.log(that.data.city)
  74. // console.log(that.data.provinceName)
  75. // console.log(that.data.cityName)
  76. // console.log(that.data.areaName)
  77. // 年龄 ajax
  78. let Age_url = 'public/paramsgather?type=age';
  79. let Age_data = {};
  80. var _age = option.age // 年龄
  81. var agenewArry = _age.split("-"); //转成数组
  82. var _age_min = agenewArry[0]
  83. var _age_max = agenewArry[1]
  84. // console.log(_age_min)
  85. // console.log(_age_max)
  86. that.setData({
  87. age: _age
  88. })
  89. app.postRequest(Age_url, Age_data, function (res) { // 年龄 ajax
  90. if (res.code == 201) {
  91. let newarray = ['不限'];
  92. var res_data = newarray.concat(res.data); //在原有的数据上 凭借上 不限
  93. let newarray1 = ['以上'];
  94. var res_data1 = newarray1.concat(res.data); //在原有的数据上 凭借上 以上
  95. let min = data_processing(res_data, _age_min); //已选中的数据处理 min
  96. let max = data_processing(res_data1, _age_max); //已选中的数据处理 max
  97. if (min == 0 && max == 0){
  98. that.setData({
  99. AgeIndex: [min, max],
  100. Zero:1,
  101. })
  102. }else{
  103. that.setData({
  104. AgeIndex: [min, max],
  105. Zero:0,
  106. })
  107. }
  108. let dictObject = res.data; //对象不能直接使用 以下转成数组
  109. // 对象转成数组
  110. var createArr = []
  111. for (let i in dictObject) {
  112. createArr.push(dictObject[i] + "岁"); //在数据后面凭借 岁
  113. }
  114. let bx = ['不限'];
  115. var Unlimited = bx.concat(createArr); //在原有的数据上 凭借上 不限
  116. let ys = ['以上'];
  117. var Above = ys.concat(createArr); //在原有的数据上 凭借上 以上
  118. that.setData({
  119. AgeArray: [Unlimited, Above],
  120. })
  121. // console.log(createArr);
  122. }
  123. })
  124. // 身高 ajax
  125. let height_url = 'public/paramsgather?type=height';
  126. let height_data = {
  127. pid: '0'
  128. };
  129. var _height = option.height // 身高
  130. var heightnewArry = _height.split("-"); //转成数组
  131. var heightSmall = heightnewArry[0]
  132. var heightlarge = heightnewArry[1]
  133. // console.log(heightSmall)
  134. // console.log(heightlarge)
  135. that.setData({
  136. height: _height
  137. })
  138. app.postRequest(height_url, height_data, function (res) { // 身高 ajax
  139. if (res.code == 201) {
  140. let newarray = ['不限'];
  141. var res_data = newarray.concat(res.data); //在原有的数据上 凭借上 不限
  142. let newarray1 = ['以上'];
  143. var res_data1 = newarray1.concat(res.data); //在原有的数据上 凭借上 以上
  144. let min = data_processing(res_data, heightSmall); //已选中的数据处理 min
  145. let max = data_processing(res_data1, heightlarge); //已选中的数据处理 max
  146. if (min == 0 && max == 0) {
  147. that.setData({
  148. heightindex: [min, max],
  149. heightZero: 1,
  150. })
  151. } else {
  152. that.setData({
  153. heightindex: [min, max],
  154. heightZero: 0,
  155. })
  156. }
  157. let dictObject = res.data; //对象不能直接使用 以下转成数组
  158. // 对象转成数组
  159. var createArr = []
  160. for (let i in dictObject) {
  161. createArr.push(dictObject[i] + "cm");
  162. }
  163. let bx = ['不限'];
  164. var Unlimited = bx.concat(createArr);
  165. let ys = ['以上'];
  166. var Above = ys.concat(createArr);
  167. // console.log(createArr);
  168. that.setData({
  169. heightArray: [Unlimited, Above],
  170. })
  171. }
  172. })
  173. // 婚史 ajax
  174. let Marriage_url = 'public/paramsgather?type=marriage';
  175. let Marriage_data = {
  176. pid: '0'
  177. };
  178. var _marry = option.marry // 婚史
  179. // console.log(_marry)
  180. that.setData({
  181. marry: _marry
  182. })
  183. app.postRequest(Marriage_url, Marriage_data, function (res) { // 婚史 ajax
  184. if (res.code == 201) {
  185. // console.log(res.data);
  186. for (let i = 0; i < res.data.length; i++) { //已选中的数据处理
  187. if (i == _marry) {
  188. that.setData({
  189. Marriageindex: i,
  190. })
  191. }
  192. }
  193. that.setData({
  194. MarriageArray: res.data,
  195. idmarry: that.data.idmarry,
  196. })
  197. }
  198. })
  199. // 学历 ajax
  200. let Education_url = 'public/paramsgather?type=xueli';
  201. let Education_data = {
  202. // pid: '0'
  203. };
  204. var _education = option.education // 学历
  205. // console.log(_education)
  206. that.setData({
  207. education: _education
  208. })
  209. app.postRequest(Education_url, Education_data, function (res) { // 学历 ajax
  210. if (res.code == 201) {
  211. // console.log(res.data);
  212. var obj = { id: 0, name: '不限' };
  213. var datares = res.data;
  214. datares.unshift(obj)
  215. for (let i = 0; i < datares.length; i++) { //已选中的数据处理
  216. if (datares[i].id == _education) {
  217. that.setData({
  218. Educationindex: i,
  219. })
  220. }
  221. }
  222. that.setData({
  223. EducationArray: datares,
  224. educationid: that.data.educationid
  225. })
  226. }
  227. })
  228. // 收入 ajax
  229. let income_url = 'public/paramsgather?type=shouru';
  230. let income_data = {
  231. // pid: '0'
  232. };
  233. var _income = option.income // 收入
  234. var incomenewArry = _income.split("-"); //转成数组
  235. var incomemin = incomenewArry[0];
  236. var incomemax = incomenewArry[1];
  237. that.setData({
  238. income: _income
  239. })
  240. app.postRequest(income_url, income_data, function (res) { // 收入 ajax
  241. if (res.code == 201) {
  242. let newarray = ['不限'];
  243. var res_data = newarray.concat(res.data); //在原有的数据上 凭借上 不限
  244. let newarray1 = ['以上'];
  245. var res_data1 = newarray1.concat(res.data); //在原有的数据上 凭借上 以上
  246. var min = data_processing(res_data, incomemin); //已选中的数据处理 min
  247. var max = data_processing(res_data1, incomemax); //已选中的数据处理 max
  248. if (min == 0 && max == 0) {
  249. that.setData({
  250. incomeindex: [min, max],
  251. incomeZero: 1,
  252. })
  253. } else {
  254. that.setData({
  255. incomeindex: [min, max],
  256. incomeZero: 0,
  257. })
  258. }
  259. that.setData({
  260. incomeArray: [res_data, res_data1],
  261. })
  262. }
  263. })
  264. },
  265. // 年龄双选
  266. AgeEvent: function (e) {
  267. var that= this;
  268. // console.log('picker发送选择改变,携带值为', e.detail.value)
  269. var _value = e.detail.value; //发送选择改变,携带值为
  270. var Small = this.data.AgeArray[0][e.detail.value[0]].substring(0, 2);
  271. var large = this.data.AgeArray[1][e.detail.value[1]].substring(0, 2);
  272. // console.log(Agedata);
  273. if (Small > large && Small != '不限' && large != '以上') { //判断 最小值 大于 最大值 数据互换
  274. // console.log('调换')
  275. var Agedata = large + '-' + Small;
  276. that.Exchange(_value); // 调用数组调换
  277. } else {
  278. var Agedata = Small + '-' + large; //否则正常选中
  279. }
  280. if (Small == '不限' && large == '以上'){
  281. that.setData({
  282. Zero1: 1
  283. })
  284. }else{
  285. that.setData({
  286. Zero1:0
  287. })
  288. }
  289. this.setData({
  290. AgeIndex: _value,
  291. age: Agedata,
  292. Ageid: 1,
  293. })
  294. },
  295. // 数组数据调换
  296. Exchange: function (data) {
  297. for (var i = 0; i < data.length / 2; i++) {
  298. var data_i = data[i];
  299. data[i] = data[data.length - 1 - i];
  300. data[data.length - 1 - i] = data_i;
  301. }
  302. return;
  303. },
  304. heightEvent: function (e) { // 身高
  305. var that = this;
  306. // console.log(this);
  307. // console.log(e);
  308. // console.log(this.data.heightArray[e.detail.value]);
  309. // console.log('picker发送选择改变,携带值为', e.detail.value)
  310. var _value = e.detail.value; //发送选择改变,携带值为
  311. var heightSmall = this.data.heightArray[0][e.detail.value[0]].substring(0, 3);
  312. var heightlarge = this.data.heightArray[1][e.detail.value[1]].substring(0, 3);
  313. // console.log(heightdata)
  314. if (heightSmall > heightlarge && heightSmall != '不限' && heightlarge != '以上') { //判断 最小值 大于 最大值 数据互换
  315. // console.log('调换')
  316. var heightdata = heightlarge + '-' + heightSmall;
  317. that.Exchange(_value); // 调用数组调换
  318. } else {
  319. var heightdata = heightSmall + '-' + heightlarge;
  320. }
  321. if (heightSmall == '不限' && heightlarge == '以上') {
  322. that.setData({
  323. heightZero1: 1
  324. })
  325. } else {
  326. that.setData({
  327. heightZero1: 0
  328. })
  329. }
  330. that.setData({
  331. heightindex: _value,
  332. height: heightdata,
  333. heightid: 1,
  334. })
  335. },
  336. MarriageEvent: function (e) { // 婚史 单项选择器
  337. // console.log(this);
  338. // console.log(e);
  339. // console.log(this.data.MarriageArray[e.detail.value]);
  340. // console.log('picker发送选择改变,携带值为', e.detail.value)
  341. this.setData({
  342. Marriageindex: e.detail.value,
  343. marry: e.detail.value,
  344. idmarry: 1,
  345. })
  346. },
  347. EducationEvent: function (e) { // 学历 单项选择器
  348. // console.log(this);
  349. // console.log(e);
  350. // console.log(this.data.EducationArray[e.detail.value].id);
  351. // console.log('picker发送选择改变,携带值为', e.detail.value)
  352. this.setData({
  353. Educationindex: e.detail.value,
  354. education: this.data.EducationArray[e.detail.value].id,
  355. educationid: 1,
  356. })
  357. },
  358. incomeEvent: function (e) { // 收入 单项选择器
  359. var that = this;
  360. // console.log(this);
  361. // console.log(e);
  362. // console.log(this.data.incomeArray[e.detail.value].id);
  363. // console.log('picker发送选择改变,携带值为', e.detail.value)
  364. var _value = e.detail.value; //发送选择改变,携带值为
  365. var srSmall = this.data.incomeArray[0][e.detail.value[0]];
  366. var srlarge = this.data.incomeArray[1][e.detail.value[1]];
  367. // console.log(Agedata);
  368. if (srSmall > srlarge && srSmall != '不限' && srlarge != '以上') { //判断 最小值 大于 最大值 数据互换
  369. // console.log('调换')
  370. var srdata = srlarge + '-' + srSmall;
  371. that.Exchange(_value); // 调用数组调换
  372. } else {
  373. var srdata = srSmall + '-' + srlarge; //否则正常选中
  374. }
  375. if (srSmall == '不限' && srlarge == '以上') {
  376. that.setData({
  377. incomeZero1: 1
  378. })
  379. } else {
  380. that.setData({
  381. incomeZero1: 0
  382. })
  383. }
  384. that.setData({
  385. incomeindex: _value,
  386. income: srdata,
  387. incomeid: 1,
  388. })
  389. },
  390. // 会员编码
  391. getPhone: function (e) {
  392. var _inputValue = e.detail.value;
  393. console.log(_inputValue);
  394. this.setData({
  395. inputValue: _inputValue
  396. });
  397. },
  398. //下一步事件
  399. register: function (e) {
  400. var _this= this;
  401. //设置全局变量(app已经定义 var app=getApp()) 赋值要传的参数
  402. app.globalData.inputValue = String(_this.data.inputValue); //用户ID
  403. app.globalData.age = String(_this.data.age); // 年龄
  404. app.globalData.height = String(_this.data.height); // 身高
  405. app.globalData.marry = String(_this.data.marry) // 婚史
  406. app.globalData.idmarry = String(_this.data.idmarry) // 婚史
  407. app.globalData.education = String(_this.data.education) // 学历
  408. app.globalData.educationid = String(_this.data.educationid) // 学历
  409. app.globalData.income = String(_this.data.income); // 收入
  410. app.globalData.Selection = String(1); // 是否选中 1 选中 0没选中
  411. app.globalData.city = String(_this.data.city); // 市
  412. app.globalData.provinceName = String(_this.data.provinceName); // 省
  413. app.globalData.cityName = String(_this.data.cityName); // 市
  414. app.globalData.areaName = String(_this.data.areaName); // 区
  415. wx.switchTab({
  416. url: '../index/index',
  417. })
  418. _this.setData({
  419. inputValue:'',
  420. })
  421. },
  422. // 重置
  423. Reset: function (e) {
  424. var _this = this;
  425. _this.setData({
  426. AgeIndex: ['', ''], // 年龄-下标
  427. age: 0, // 年龄
  428. Ageid: 0,
  429. heightindex: ['', ''], // 身高-下标
  430. height: 0, //身高
  431. heightid: 0,
  432. Marriageindex: '', // 婚史-下标
  433. marry: 0,
  434. idmarry: 0,
  435. Educationindex: '', //学历
  436. education: 0, //学历
  437. educationid: 0,
  438. incomeindex: ['', ''], //收入
  439. income: 0, //收入
  440. inputValue: '', //ID
  441. city: 0, // 市
  442. provinceName: '', // 省
  443. cityName: '', // 市
  444. areaName: '', // 区
  445. })
  446. app.globalData.inputValue = String(_this.data.inputValue); //用户ID
  447. app.globalData.age = String(_this.data.age); // 年龄
  448. app.globalData.height = String(_this.data.height); // 身高
  449. app.globalData.marry = String(_this.data.marry) // 婚史
  450. app.globalData.idmarry = String(_this.data.idmarry) // 婚史
  451. app.globalData.education = String(_this.data.education) // 学历
  452. app.globalData.educationid = String(_this.data.educationid) // 学历
  453. app.globalData.income = String(_this.data.income); // 收入
  454. app.globalData.Selection = String(1); // 是否选中 1 选中 0没选中
  455. app.globalData.city = String(_this.data.city); // 市
  456. app.globalData.provinceName = String(_this.data.provinceName); // 省
  457. app.globalData.cityName = String(_this.data.cityName); // 市
  458. app.globalData.areaName = String(_this.data.areaName); // 区
  459. },
  460. // 省市区三级联动 点击弹窗
  461. linkage: function (e) {
  462. var that = this;
  463. let citypid_url = 'public/citypid';
  464. let citypid_data = {};
  465. app.postRequest(citypid_url, citypid_data, function (res) { // 省市区三级联动 ajax
  466. if (res.code == 201) {
  467. that.setData({
  468. provincedata: res.data, // 省数据
  469. })
  470. // console.log(res.data)
  471. that.provinceOn();
  472. }
  473. })
  474. },
  475. // 省事件
  476. provinceOn: function (e) {
  477. var that = this;
  478. // console.log(e);
  479. if (e) {
  480. that.setData({
  481. provinceid: e.currentTarget.dataset.id, //省ID
  482. provincetext: e.currentTarget.dataset.text, //省名字
  483. })
  484. }
  485. // console.log(that.data.provinceid);
  486. // console.log(that.data.provincetext)
  487. let citypid_url = 'public/citypid';
  488. let citypid_data = {
  489. pid: that.data.provinceid,
  490. };
  491. app.postRequest(citypid_url, citypid_data, function (res) { // 省市区三级联动 ajax
  492. if (res.code == 201) {
  493. that.setData({
  494. hiddenName: false,
  495. citydata: res.data, // 市数据
  496. scrolltop: 0, //市区滚动条
  497. areadata: '', //区域数据清空
  498. cityidx: '', // idx 选中清空
  499. })
  500. // console.log(res.data)
  501. }
  502. })
  503. },
  504. // 市事件
  505. cityOn: function (e) {
  506. var that = this;
  507. var _cityidx = that.data.cityidx
  508. var cityid = e.currentTarget.dataset.id; //市ID
  509. var citytext = e.currentTarget.dataset.text; //市名字
  510. var _index = e.currentTarget.dataset.index + 1; //下标
  511. // console.log(_index);
  512. // console.log(_index*42,);
  513. // console.log(_cityidx);
  514. // console.log(cityid);
  515. that.setData({
  516. cityidx: cityid, // 市 选中
  517. citytext: citytext, // 市 选中名字
  518. areadata: '', //区域数据清空
  519. })
  520. let citypid_url = 'public/citypid';
  521. let citypid_data = {
  522. pid: cityid,
  523. };
  524. app.postRequest(citypid_url, citypid_data, function (res) { // 省市区三级联动 ajax
  525. if (res.code == 201) {
  526. if (_cityidx == cityid) {
  527. that.setData({
  528. areadata: '', // 区数据
  529. cityidx: '', // idx 选中清空
  530. })
  531. } else {
  532. that.setData({
  533. areadata: res.data, // 区数据
  534. scrolltop: _index * 42,
  535. })
  536. // console.log('执行')
  537. // console.log(_index * 42);
  538. }
  539. // console.log(res.data)
  540. }
  541. })
  542. },
  543. //区选中事件
  544. areaOn: function (e) {
  545. var that = this;
  546. var _style = e.currentTarget.dataset.style;
  547. // console.log(_style);
  548. var regionid = e.currentTarget.dataset.id; //传递地区ID
  549. // console.log(regionid);
  550. switch (_style) {
  551. case 'provinceLx':
  552. // console.log('省');
  553. that.setData({
  554. city: regionid,
  555. provinceName: that.data.provincetext, // 省名字
  556. cityName: '', // 市名字清空
  557. areaName: "", // 区名字
  558. })
  559. break;
  560. case 'cityLx':
  561. // console.log('市');
  562. that.setData({
  563. city: regionid,
  564. provinceName: that.data.provincetext, // 省名字
  565. cityName: that.data.citytext, // 省名字
  566. areaName: "", // 区名字
  567. })
  568. break;
  569. case 'areaLx':
  570. // console.log('区');
  571. var areatext = e.currentTarget.dataset.text; //区名字
  572. that.setData({
  573. city: regionid,
  574. provinceName: that.data.provincetext, // 省名字
  575. cityName: that.data.citytext, // 省名字
  576. areaName: areatext, // 区名字
  577. })
  578. break;
  579. }
  580. // console.log(that.data.city)
  581. // console.log(that.data.provinceName)
  582. // console.log(that.data.cityName)
  583. // console.log(that.data.areaName)
  584. //选择完清空
  585. that.setData({
  586. hiddenName: true,
  587. provinceid: 1,
  588. provincetext: '北京', //省 名字
  589. cityidx: 0,
  590. citytext: '',
  591. })
  592. },
  593. //省市区不限 清空
  594. regionBx: function () {
  595. var that = this;
  596. that.setData({
  597. hiddenName: true,
  598. provinceid: 1,
  599. provincetext: '北京', //省 名字
  600. cityidx: 0,
  601. citytext: '',
  602. city: 0, // 市数据清空
  603. provinceName: '', // 省名字
  604. cityName: '', // 市名字清空
  605. areaName: "", // 区名字
  606. })
  607. },
  608. //省市区关闭 清空
  609. Close: function () {
  610. var that = this;
  611. that.setData({
  612. hiddenName: true,
  613. provinceid: 1,
  614. provincetext: '北京', //省 名字
  615. cityidx: 0,
  616. citytext: '',
  617. })
  618. },
  619. })
  620. var data_processing = function (data, min_max,) {
  621. for (let i = 0; i < data.length; i++) { //已选中的数据处理
  622. if (data[i] == min_max) {
  623. return i;
  624. }
  625. }
  626. }