requirements.js 20 KB

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