requirements.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. const app = getApp();
  2. Page({
  3. data: {
  4. // selectArray: [], // 性别-数据
  5. // index: '', // 性别-下标、
  6. heightid:0,
  7. heightArray: [], // 身高-数据
  8. heightindex: [0, 0], // 身高-下标
  9. EducationArray: [], // 学历-数据
  10. Educationindex: '', // 学历-下标
  11. MarriageArray: [], // 婚史-数据
  12. Marriageindex: '', // 婚史-下标
  13. incomeid:0,
  14. incomeArray: [], // 收入-数据
  15. incomeindex: [0, 0], // 收入-下标
  16. OccupationArray: [], // 职业-数据
  17. Occupationindex: '', // 职业-下标
  18. // contactArray: [], // 允许有意者联系我-数据
  19. // contactindex: '', // 允许有意者联系我-下标
  20. multiArray: [], // 地址-数据
  21. step: 0, // 地址
  22. multiIndex: [0, 0, 0], // 地址-下标
  23. // sex: '', // 性别
  24. age: '', // 年龄
  25. height: '', // 身高
  26. province: '', // 省
  27. city: '', // 市
  28. area: '', // 区
  29. education: '', // 学历
  30. marry: '', // 婚史
  31. income: '', // 收入
  32. occupation: '', // 职业
  33. Ageid:0,
  34. AgeArray: [], // 年龄-数据
  35. AgeIndex: [0, 0], // 年龄-下标
  36. },
  37. onLoad: function () {
  38. var that = this
  39. // 获取择偶信息
  40. let personal_url = 'my/personaloption/optioninfo';
  41. let personal_data = {
  42. };
  43. app.postRequest(personal_url, personal_data, function (res) {
  44. if (res.code == 201) {
  45. that.setData({
  46. personal: res.data, //获取全部数据
  47. })
  48. }
  49. })
  50. // 默认择偶信息
  51. let editinfo_url = 'my/personaloption/editoption';
  52. let editinfo_data = {
  53. };
  54. app.postRequest(editinfo_url, editinfo_data, function (res) {
  55. // 年龄 ajax
  56. let Age_url = 'public/paramsgather?type=age';
  57. let Age_data = {
  58. // pid: '0'
  59. };
  60. let _age_min = res.data.age_min;
  61. let _age_max = res.data.age_max;
  62. // console.log(_age_min);
  63. // console.log(_age_max);
  64. app.postRequest(Age_url, Age_data, function (res) { // 年龄 ajax
  65. if (res.code == 201) {
  66. let min = data_processing(res.data, _age_min); //已选中的数据处理 min
  67. let max = data_processing(res.data, _age_max); //已选中的数据处理 max
  68. that.setData({
  69. AgeIndex: [min, max]
  70. })
  71. let dictObject = res.data; //对象不能直接使用 以下转成数组
  72. // 对象转成数组
  73. var createArr = []
  74. for (let i in dictObject) {
  75. createArr.push(dictObject[i] + "岁");
  76. }
  77. that.setData({
  78. AgeArray: [createArr, createArr],
  79. })
  80. // console.log(createArr);
  81. }
  82. })
  83. // 身高 ajax
  84. let height_url = 'public/paramsgather?type=height';
  85. let height_data = {
  86. pid: '0'
  87. };
  88. let _height_min = res.data.height_min;
  89. let _height_max = res.data.height_max;
  90. // console.log(_height_min);
  91. // console.log(_height_max);
  92. app.postRequest(height_url, height_data, function (res) { // 身高 ajax
  93. if (res.code == 201) {
  94. let min = data_processing(res.data, _height_min); //已选中的数据处理 min
  95. let max = data_processing(res.data, _height_max); //已选中的数据处理 max
  96. that.setData({
  97. heightindex: [min, max]
  98. })
  99. let dictObject = res.data; //对象不能直接使用 以下转成数组
  100. // 对象转成数组
  101. var createArr = []
  102. for (let i in dictObject) {
  103. createArr.push(dictObject[i] + "cm");
  104. }
  105. // console.log(createArr);
  106. that.setData({
  107. heightArray: [createArr, createArr],
  108. })
  109. }
  110. })
  111. // 学历 ajax
  112. let Education_url = 'public/paramsgather?type=xueli';
  113. let Education_data = {
  114. // pid: '0'
  115. };
  116. let _education = res.data.education;
  117. app.postRequest(Education_url, Education_data, function (res) { // 学历 ajax
  118. if (res.code == 201) {
  119. for (let i = 0; i < res.data.length; i++) { //已选中的数据处理
  120. if (res.data[i].id == _education) {
  121. // console.log(res.data[i].id)
  122. that.setData({
  123. Educationindex: i
  124. })
  125. }
  126. }
  127. that.setData({
  128. EducationArray: res.data
  129. })
  130. }
  131. })
  132. // 婚史 ajax
  133. let Marriage_url = 'public/paramsgather?type=marriage';
  134. let Marriage_data = {
  135. pid: '0'
  136. };
  137. app.postRequest(Marriage_url, Marriage_data, function (res) { // 婚史 ajax
  138. if (res.code == 201) {
  139. that.setData({
  140. MarriageArray: res.data
  141. })
  142. }
  143. })
  144. // 收入 ajax
  145. let income_url = 'public/paramsgather?type=shouru1';
  146. let income_data = {
  147. // pid: '0'
  148. };
  149. let _income_min = res.data.income_min;
  150. let _income_max = res.data.income_max;
  151. // console.log(_income_min);
  152. // console.log(_income_max);
  153. app.postRequest(income_url, income_data, function (res) { // 收入 ajax
  154. if (res.code == 201) {
  155. var min = data_processing(res.data, _income_min); //已选中的数据处理 min
  156. var max = data_processing(res.data, _income_max); //已选中的数据处理 max
  157. that.setData({
  158. incomeindex: [min, max]
  159. })
  160. that.setData({
  161. incomeArray: [res.data, res.data],
  162. })
  163. }
  164. })
  165. // 职业 ajax
  166. let Occupation_url = 'public/paramsgather?type=zhiye';
  167. let Occupation_data = {
  168. // pid: '0'
  169. };
  170. let _occupation = res.data.occupation;
  171. app.postRequest(Occupation_url, Occupation_data, function (res) { // 职业 ajax
  172. if (res.code == 201) {
  173. // console.log(res);
  174. for (let i = 0; i < res.data.length; i++) { //已选中的数据处理
  175. if (res.data[i].id == _occupation) {
  176. // console.log(res.data[i].id)
  177. that.setData({
  178. Occupationindex: i
  179. })
  180. }
  181. }
  182. that.setData({
  183. OccupationArray: res.data
  184. })
  185. }
  186. })
  187. if (res.code == 201) {
  188. that.setData({
  189. // sex: res.data.sex, // 性别
  190. age: res.data.age_min + '-' + res.data.age_max, // 年龄
  191. height: res.data.height_min + '-' + res.data.height_max, // 身高
  192. province: res.data.province, // 市
  193. city: res.data.city, // 市
  194. area: res.data.area, // 区
  195. education: res.data.education, // 学历
  196. marry: res.data.marry, // 婚史
  197. income: res.data.income_min + '-' + res.data.income_max, // 收入
  198. occupation: res.data.occupation, // 职业
  199. Marriageindex: res.data.marry, // 婚史
  200. personacodel: res, //获取全部数据
  201. })
  202. }
  203. that.getProvince(); //地址 ajax
  204. })
  205. // 性别 ajax
  206. // let p_url = 'public/paramsgather?type=sex';
  207. // let p_data = {
  208. // // pid: '0'
  209. // };
  210. // app.postRequest(p_url, p_data, function (res) { // 性别 ajax
  211. // if (res.code == 201) {
  212. // // console.log(res.data);
  213. // that.setData({
  214. // selectArray: res.data
  215. // })
  216. // }
  217. // })
  218. // 允许有意者联系我 ajax
  219. // let contact_url = 'public/citypid';
  220. // let contact_data = {
  221. // pid: '0'
  222. // };
  223. // app.postRequest(contact_url, contact_data, function (res) { // 允许有意者联系我 ajax
  224. // // console.log(res);
  225. // that.setData({
  226. // contactArray: res.data
  227. // })
  228. // })
  229. },
  230. // GenderEvent: function (e) { // 性别 单项选择器
  231. // // console.log(this);
  232. // // console.log(e);
  233. // // console.log(this.data.selectArray[e.detail.value]);
  234. // // console.log('picker发送选择改变,携带值为', e.detail.value)
  235. // this.setData({
  236. // index: e.detail.value,
  237. // sex: e.detail.value
  238. // })
  239. // },
  240. // 年龄双选
  241. AgeEvent: function (e) {
  242. var that =this;
  243. console.log('picker发送选择改变,携带值为', e.detail.value)
  244. var _value = e.detail.value; //发送选择改变,携带值为
  245. var Small = this.data.AgeArray[0][e.detail.value[0]].substring(0, 2);
  246. var large = this.data.AgeArray[1][e.detail.value[1]].substring(0, 2);
  247. if (Small > large && Small != '不限' && large != '以上') { //判断 最小值 大于 最大值 数据互换
  248. // console.log('调换')
  249. var Agedata = large + '-' + Small;
  250. that.Exchange(_value); // 调用数组调换
  251. } else {
  252. var Agedata = Small + '-' + large; //否则正常选中
  253. }
  254. console.log(Agedata);
  255. this.setData({
  256. AgeIndex: _value,
  257. age: Agedata,
  258. Ageid: 1,
  259. })
  260. },
  261. heightEvent: function (e) { // 身高 单项选择器
  262. var that = this;
  263. // console.log(this);
  264. // console.log(e);
  265. // console.log(this.data.heightArray[e.detail.value]);
  266. // console.log('picker发送选择改变,携带值为', e.detail.value)
  267. var _value = e.detail.value; //发送选择改变,携带值为
  268. var heightSmall = this.data. heightArray[0][e.detail.value[0]].substring(0, 3);
  269. var heightlarge = this.data. heightArray[1][e.detail.value[1]].substring(0, 3);
  270. // console.log(heightdata)
  271. if (heightSmall > heightlarge && heightSmall != '不限' && heightlarge != '以上') { //判断 最小值 大于 最大值 数据互换
  272. // console.log('调换')
  273. var heightdata = heightlarge + '-' + heightSmall;
  274. that.Exchange(_value); // 调用数组调换
  275. } else {
  276. var heightdata = heightSmall + '-' + heightlarge;
  277. }
  278. this.setData({
  279. heightindex: _value,
  280. height: heightdata,
  281. heightid: 1,
  282. })
  283. },
  284. EducationEvent: function (e) { // 学历 单项选择器
  285. console.log(this);
  286. // console.log(e);
  287. console.log(this.data.EducationArray[e.detail.value].id);
  288. // console.log('picker发送选择改变,携带值为', e.detail.value)
  289. this.setData({
  290. Educationindex: e.detail.value,
  291. education: this.data.EducationArray[e.detail.value].id
  292. })
  293. },
  294. MarriageEvent: function (e) { // 婚史 单项选择器
  295. // console.log(this);
  296. // console.log(e);
  297. // console.log(this.data.MarriageArray[e.detail.value]);
  298. // console.log('picker发送选择改变,携带值为', e.detail.value)
  299. this.setData({
  300. Marriageindex: e.detail.value,
  301. marry: e.detail.value
  302. })
  303. },
  304. incomeEvent: function (e) { // 收入 单项选择器
  305. var that = this;
  306. // console.log(this);
  307. // console.log(e);
  308. // console.log(this.data.incomeArray[e.detail.value].id);
  309. // console.log('picker发送选择改变,携带值为', e.detail.value)
  310. var _value = e.detail.value; //发送选择改变,携带值为
  311. var srSmall = this.data.incomeArray[0][e.detail.value[0]];
  312. var srlarge = this.data.incomeArray[1][e.detail.value[1]];
  313. if (srSmall > srlarge && srSmall != '不限' && srlarge != '以上') { //判断 最小值 大于 最大值 数据互换
  314. // console.log('调换')
  315. var srdata = srlarge + '-' + srSmall;
  316. that.Exchange(_value); // 调用数组调换
  317. } else {
  318. var srdata = srSmall + '-' + srlarge; //否则正常选中
  319. }
  320. // console.log(srdata);
  321. this.setData({
  322. incomeindex: _value,
  323. income: srdata,
  324. incomeid:1,
  325. })
  326. },
  327. OccupationEvent: function (e) { // 职业 单项选择器
  328. // console.log(this);
  329. // console.log(e);
  330. // console.log(this.data.OccupationArray[e.detail.value].id);
  331. // console.log('picker发送选择改变,携带值为', e.detail.value)
  332. this.setData({
  333. Occupationindex: e.detail.value,
  334. occupation: this.data.OccupationArray[e.detail.value].id
  335. })
  336. },
  337. // 数组数据调换
  338. Exchange: function (data) {
  339. for (var i = 0; i < data.length / 2; i++) {
  340. var data_i = data[i];
  341. data[i] = data[data.length - 1 - i];
  342. data[data.length - 1 - i] = data_i;
  343. }
  344. return;
  345. },
  346. // contactEvent: function (e) { // 允许有意者联系我 单项选择器
  347. // // console.log(this.data.selectArray[e.detail.value].area_name)
  348. // // console.log('picker发送选择改变,携带值为', e.detail.value)
  349. // console.log(this);
  350. // console.log(e);
  351. // console.log(this.data.contactArray[e.detail.value]);
  352. // console.log('picker发送选择改变,携带值为', e.detail.value)
  353. // this.setData({
  354. // contactindex: e.detail.value
  355. // })
  356. // },
  357. getProvince() { // 多项选择器
  358. let _this = this;
  359. let d_url = 'public/citypid';
  360. app.postRequest(d_url, { pid: '0' }, function (res) {
  361. // console.log(res.data);
  362. if (res.code == '201') {
  363. var provinceList = res.data;
  364. var provinceArr = [];
  365. provinceArr = _this.mapArray(res.data);
  366. _this.setData({
  367. multiArray: [provinceArr, [], []],
  368. provinceList,
  369. provinceArr,
  370. })
  371. // console.log(provinceList);
  372. // console.log(provinceArr);
  373. var defaultCode = provinceList[0]['area_id']
  374. // console.log(provinceList[0]['area_id']);
  375. if (defaultCode) {
  376. _this.setData({
  377. currnetProvinceKey: defaultCode
  378. })
  379. _this.getCity(defaultCode)
  380. }
  381. }
  382. })
  383. },
  384. getCity(codes) {
  385. // 多项选择
  386. let _this = this;
  387. let d_url = 'public/citypid';
  388. app.postRequest(d_url, { pid: codes }, function (res) {
  389. var cityList = res.data;
  390. var cityArr = [];
  391. if (res.code == '201') {
  392. cityArr = _this.mapArray(res.data);
  393. _this.setData({
  394. multiArray: [_this.data.provinceArr, cityArr, []],
  395. cityArr,
  396. cityList
  397. })
  398. var defaultCode = cityList[0]['area_id']
  399. if (defaultCode) {
  400. _this.setData({
  401. currnetProvinceKey: defaultCode
  402. })
  403. _this.getArea(defaultCode)
  404. }
  405. }
  406. })
  407. },
  408. getArea(codes) {
  409. // 多项选择
  410. let _this = this;
  411. let d_url = 'public/citypid';
  412. app.postRequest(d_url, { pid: codes }, function (res) {
  413. var areaList = res.data;
  414. var areaArr = [];
  415. if (res.code == '201') {
  416. areaArr = _this.mapArray(res.data);
  417. }
  418. // console.log(areaList);
  419. // console.log(areaArr);
  420. _this.setData({
  421. multiArray: [_this.data.provinceArr, _this.data.cityArr, areaArr],
  422. areaList,
  423. areaArr
  424. })
  425. })
  426. },
  427. mapArray: function (data) {
  428. let cityArray = []
  429. if (data) {
  430. for (let i = 0; i < data.length; i++) {
  431. if (data[i].area_name) {
  432. cityArray[i] = data[i].area_name;
  433. }
  434. }
  435. }
  436. return cityArray;
  437. },
  438. columnchange(e) { // 滚动选择器 触发的事件
  439. var column = e.detail.column // 当前改变的列
  440. // console.log(column);
  441. // console.log(this.data.multiIndex);
  442. // console.log(JSON.parse(JSON.stringify(this.data.multiIndex)));
  443. var data = {
  444. multiIndex: this.data.multiIndex,
  445. multiArray: this.data.multiArray
  446. }
  447. data.multiIndex[column] = e.detail.value; // 第几列改变了就是对应multiIndex的第几个,更新它
  448. switch (column) { // 处理不同的逻辑
  449. case 0: // 第一列更改 就是省级的更改
  450. var currentProvinceKey = this.data.provinceList[e.detail.value].area_id
  451. if (currentProvinceKey != this.data.currnetProvinceKey) { // 判断当前的key是不是真正的更新了
  452. this.getCity(currentProvinceKey) // 获取当前key下面的市级数据
  453. }
  454. data.multiIndex[1] = 0 // 将市默认选择第一个
  455. break;
  456. case 1: // 市发生变化
  457. var currentCitykey = this.data.cityList[e.detail.value].area_id
  458. if (currentCitykey != this.data.currnetCityKey) { // 同样判断
  459. this.getArea(currentCitykey) // 获取门店
  460. }
  461. data.multiIndex[2] = 0
  462. break;
  463. }
  464. this.setData(data) // 更新数据
  465. },
  466. pickchange(e) {
  467. // console.log(this.data.provinceList[e.detail.value[0]].area_id);
  468. // console.log(this.data.cityList[e.detail.value[1]].area_id);
  469. // console.log(this.data.areaList[e.detail.value[2]].area_id);
  470. this.setData({
  471. step: 1, // 更新,用来选择用户选中的门店
  472. multiIndex: e.detail.value, // 更新下标字段
  473. province: this.data.provinceList[e.detail.value[0]].area_id, // 市
  474. city: this.data.cityList[e.detail.value[1]].area_id, // 市
  475. area: this.data.areaList[e.detail.value[2]].area_id // 区
  476. })
  477. },
  478. //下一步事件
  479. register: function (e) {
  480. // console.log(this.data.sex); // 性别
  481. // console.log(this.data.age); // 年龄
  482. // console.log(this.data.height); // 身高
  483. // console.log(this.data.education); // 学历
  484. // console.log(this.data.marry); // 婚史
  485. // console.log(this.data.income); // 收入
  486. // console.log(this.data.province); // 省
  487. // console.log(this.data.city); // 市
  488. // console.log(this.data.area); // 区
  489. // console.log(this.data.occupation); // 职业
  490. // var sex = this.data.sex // 性别
  491. var age = this.data.age // 年龄
  492. var height = this.data.height // 身高
  493. var province = this.data.province // 省
  494. var city = this.data.city // 市
  495. var area = this.data.area // 区
  496. var education = this.data.education // 学历
  497. var marry = this.data.marry // 婚史
  498. var income = this.data.income // 收入
  499. var occupation = this.data.occupation // 职业
  500. if (age == '') {
  501. var _age = '请选择年龄'
  502. getApp().Tips(_age)
  503. } else if (province == '' && city == '' && area == '') {
  504. var _province = '请选择地址'
  505. getApp().Tips(_province)
  506. } else if (height == '') {
  507. var _height = '请选择身高'
  508. getApp().Tips(_height)
  509. } else if (marry == '') {
  510. var _marry = '请选择婚史'
  511. getApp().Tips(_marry)
  512. } else if (income == '') {
  513. var _income = '请选择收入'
  514. getApp().Tips(_income)
  515. } else if (education == '') {
  516. var _education = '请选择学历'
  517. getApp().Tips(_education)
  518. } else if (occupation == '') {
  519. var _occupation = '请选择职业'
  520. getApp().Tips(_occupation)
  521. } else{
  522. // 修改择偶信息
  523. let editinfoform_url = 'my/personaloption/editoptionform';
  524. let editinfoform_data = {
  525. age: this.data.age, // 年龄
  526. height: this.data.height, // 身高
  527. province: this.data.province, // 市
  528. city: this.data.city, // 市
  529. area: this.data.area, // 区
  530. education: this.data.education, // 学历
  531. marry: this.data.marry, // 婚史
  532. income: this.data.income, // 收入
  533. occupation: this.data.occupation, // 职业
  534. };
  535. app.postRequest(editinfoform_url, editinfoform_data, function (res) {
  536. if (res.code == 201) {
  537. wx.showToast({
  538. title: '修改成功',
  539. icon: 'success',
  540. duration: 2000
  541. })
  542. return;
  543. }
  544. var fail = '修改失败' //调用提示框
  545. getApp().Tips(fail)
  546. })
  547. }
  548. },
  549. })
  550. var data_processing = function (data, min_max, ) {
  551. for (let i = 0; i < data.length; i++) { //已选中的数据处理
  552. if (data[i] == min_max) {
  553. return i;
  554. }
  555. }
  556. }