requirements.js 20 KB

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