personaldataModifythe.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. const app = getApp();
  2. Page({
  3. data: {
  4. // selectArray: [], // 性别-数据
  5. // index: '', // 性别-下标、
  6. AgeArray: [], // 年龄-数据
  7. Ageindex: '', // 年龄-下标
  8. heightArray: [], // 身高-数据
  9. heightindex: '', // 身高-下标
  10. EducationArray: [], // 学历-数据
  11. Educationindex: '', // 学历-下标
  12. MarriageArray: [], // 婚史-数据
  13. Marriageindex: '', // 婚史-下标
  14. incomeArray: [], // 收入-数据
  15. incomeindex: '', // 收入-下标
  16. OccupationArray: [], // 职业-数据
  17. Occupationindex: '', // 职业-下标
  18. // contactArray: [], // 允许有意者联系我-数据
  19. // contactindex: '', // 允许有意者联系我-下标
  20. multiArray: [], // 地址-数据
  21. step: 0, // 地址
  22. multiIndex: [0, 0, 0], // 地址-下标
  23. nickname: '', //姓名
  24. // sex: '', // 性别
  25. age: '', // 年龄
  26. height: '', // 身高
  27. province: '', // 市
  28. city: '', // 市
  29. area: '', // 区
  30. education: '', // 学历
  31. marry: '', // 婚史
  32. income: '', // 收入
  33. occupation: '', // 职业
  34. // openid:'', //授权
  35. personacodel:''
  36. },
  37. onLoad: function () {
  38. var that = this
  39. // 获取个人信息
  40. let personal_url = 'my/personaldata/personal';
  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/personaldata/editinfo';
  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 = res.data.age;
  61. app.postRequest(Age_url, Age_data, function (res) { // 年龄 ajax
  62. if (res.code == 201) {
  63. for (let i = 0; i < res.data.length; i++) { //已选中的数据处理
  64. if (res.data[i] == _age) {
  65. that.setData({
  66. Ageindex: i,
  67. })
  68. }
  69. }
  70. let dictObject = res.data;
  71. // 对象转成数组
  72. var createArr = []
  73. for (let i in dictObject) {
  74. createArr.push(dictObject[i] + "岁");
  75. }
  76. // console.log(createArr);
  77. that.setData({
  78. AgeArray: createArr
  79. })
  80. }
  81. })
  82. // 身高 ajax
  83. let height_url = 'public/paramsgather?type=height';
  84. let height_data = {
  85. pid: '0'
  86. };
  87. let _height = res.data.height;
  88. app.postRequest(height_url, height_data, function (res) { // 身高 ajax
  89. if (res.code == 201) {
  90. for (let i = 0; i < res.data.length; i++) { //已选中的数据处理
  91. if (res.data[i] == _height) {
  92. that.setData({
  93. heightindex: i,
  94. })
  95. }
  96. }
  97. let dictObject = res.data;
  98. // 对象转成数组
  99. var createArr = []
  100. for (let i in dictObject) {
  101. createArr.push(dictObject[i] + "cm");
  102. }
  103. // console.log(createArr);
  104. that.setData({
  105. heightArray: createArr
  106. })
  107. }
  108. })
  109. // 学历 ajax
  110. let Education_url = 'public/paramsgather?type=xueli';
  111. let Education_data = {
  112. // pid: '0'
  113. };
  114. let _education = res.data.education;
  115. app.postRequest(Education_url, Education_data, function (res) { // 学历 ajax
  116. if (res.code == 201) {
  117. for (let i = 0; i < res.data.length; i++) { //已选中的数据处理
  118. if (res.data[i].id == _education) {
  119. that.setData({
  120. Educationindex: i,
  121. })
  122. }
  123. }
  124. that.setData({
  125. EducationArray: res.data
  126. })
  127. }
  128. })
  129. // 职业 ajax
  130. let Occupation_url = 'public/paramsgather?type=zhiye';
  131. let Occupation_data = {
  132. pid: '0'
  133. };
  134. let _occupation = res.data.occupation;
  135. app.postRequest(Occupation_url, Occupation_data, function (res) { // 职业 ajax
  136. if (res.code == 201) {
  137. for (let i = 0; i < res.data.length; i++) { //已选中的数据处理
  138. if (res.data[i].id == _occupation) {
  139. that.setData({
  140. Occupationindex: i,
  141. })
  142. }
  143. }
  144. that.setData({
  145. OccupationArray: res.data
  146. })
  147. }
  148. })
  149. // 收入 ajax
  150. let income_url = 'public/paramsgather?type=shouru';
  151. let income_data = {
  152. // pid: '0'
  153. };
  154. let _income = res.data.income;
  155. app.postRequest(income_url, income_data, function (res) { // 收入 ajax
  156. if (res.code == 201) {
  157. for (let i = 0; i < res.data.length; i++) { //已选中的数据处理
  158. if (res.data[i].id == _income) {
  159. that.setData({
  160. incomeindex: i,
  161. })
  162. }
  163. }
  164. that.setData({
  165. incomeArray: res.data
  166. })
  167. }
  168. })
  169. // 婚史 ajax
  170. let Marriage_url = 'public/paramsgather?type=marriage';
  171. let Marriage_data = {
  172. pid: '0'
  173. };
  174. app.postRequest(Marriage_url, Marriage_data, function (res) { // 婚史 ajax
  175. if (res.code == 201) {
  176. // console.log(res.data);
  177. that.setData({
  178. MarriageArray: res.data
  179. })
  180. }
  181. })
  182. if (res.code == 201) {
  183. // console.log(res.data);
  184. that.setData({
  185. nickname: res.data.nickname, //姓名
  186. // sex: res.data.sex, // 性别
  187. age: res.data.age, // 年龄
  188. height: res.data.height, // 身高
  189. province: res.data.province, // 市
  190. city: res.data.city, // 市
  191. area: res.data.area, // 区
  192. education: res.data.education, // 学历
  193. marry: res.data.marry, // 婚史
  194. income: res.data.income, // 收入
  195. occupation: res.data.occupation, // 职业
  196. Marriageindex: res.data.marry, // 婚史
  197. personacodel: res, //获取code 前台判断
  198. })
  199. }
  200. that.getProvince(); //地址 ajax
  201. })
  202. // 获取区域ID
  203. // var _openid = 0;
  204. // try {
  205. // var value = wx.getStorageSync('openid');
  206. // if (value) {
  207. // _openid = value
  208. // that.setData({
  209. // openid: _openid
  210. // })
  211. // }
  212. // console.log(_openid);
  213. // } catch (e) {
  214. // // Do something when catch error
  215. // }
  216. // 性别 ajax
  217. // let p_url = 'public/paramsgather?type=sex';
  218. // let p_data = {
  219. // // pid: '0'
  220. // };
  221. // app.postRequest(p_url, p_data, function (res) { // 性别 ajax
  222. // if (res.code == 201) {
  223. // // console.log(res.data);
  224. // that.setData({
  225. // selectArray: res.data
  226. // })
  227. // }
  228. // })
  229. // 允许有意者联系我 ajax
  230. // let contact_url = 'public/citypid';
  231. // let contact_data = {
  232. // pid: '0'
  233. // };
  234. // app.postRequest(contact_url, contact_data, function (res) { // 允许有意者联系我 ajax
  235. // // console.log(res);
  236. // that.setData({
  237. // contactArray: res.data
  238. // })
  239. // })
  240. },
  241. GenderEvent: function (e) { // 性别 单项选择器
  242. // console.log(this);
  243. // console.log(e);
  244. // console.log(this.data.selectArray[e.detail.value]);
  245. // console.log('picker发送选择改变,携带值为', e.detail.value)
  246. // this.setData({
  247. // index: e.detail.value,
  248. // sex: e.detail.value
  249. // })
  250. wx.showModal({
  251. title: '性别确定之后不可更改',
  252. content: '如需更改请联系管理员',
  253. showCancel: false,
  254. })
  255. },
  256. AgeEvent: function (e) { // 年龄 单项选择器
  257. // console.log(this);
  258. // console.log(e);
  259. // console.log(this.data.AgeArray[e.detail.value]);
  260. // console.log('picker发送选择改变,携带值为', e.detail.value)
  261. this.setData({
  262. Ageindex: e.detail.value,
  263. age: this.data.AgeArray[e.detail.value]
  264. })
  265. },
  266. heightEvent: function (e) { // 身高 单项选择器
  267. // console.log(this);
  268. // console.log(e);
  269. // console.log(this.data.heightArray[e.detail.value]);
  270. // console.log('picker发送选择改变,携带值为', e.detail.value)
  271. this.setData({
  272. heightindex: e.detail.value,
  273. height: this.data.heightArray[e.detail.value]
  274. })
  275. },
  276. EducationEvent: function (e) { // 学历 单项选择器
  277. // console.log(this);
  278. // console.log(e);
  279. // console.log(this.data.EducationArray[e.detail.value].id);
  280. // console.log('picker发送选择改变,携带值为', e.detail.value)
  281. this.setData({
  282. Educationindex: e.detail.value,
  283. education: this.data.EducationArray[e.detail.value].id
  284. })
  285. },
  286. MarriageEvent: function (e) { // 婚史 单项选择器
  287. // console.log(this);
  288. // console.log(e);
  289. // console.log(this.data.MarriageArray[e.detail.value]);
  290. // console.log('picker发送选择改变,携带值为', e.detail.value)
  291. this.setData({
  292. Marriageindex: e.detail.value,
  293. marry: e.detail.value
  294. })
  295. },
  296. incomeEvent: function (e) { // 收入 单项选择器
  297. // console.log(this);
  298. // console.log(e);
  299. // console.log(this.data.incomeArray[e.detail.value].id);
  300. // console.log('picker发送选择改变,携带值为', e.detail.value)
  301. this.setData({
  302. incomeindex: e.detail.value,
  303. income: this.data.incomeArray[e.detail.value].id
  304. })
  305. },
  306. OccupationEvent: function (e) { // 职业 单项选择器
  307. // console.log(this);
  308. // console.log(e);
  309. // console.log(this.data.OccupationArray[e.detail.value].id);
  310. // console.log('picker发送选择改变,携带值为', e.detail.value)
  311. this.setData({
  312. Occupationindex: e.detail.value,
  313. occupation: this.data.OccupationArray[e.detail.value].id
  314. })
  315. },
  316. // contactEvent: function (e) { // 允许有意者联系我 单项选择器
  317. // // console.log(this.data.selectArray[e.detail.value].area_name)
  318. // // console.log('picker发送选择改变,携带值为', e.detail.value)
  319. // console.log(this);
  320. // console.log(e);
  321. // console.log(this.data.contactArray[e.detail.value]);
  322. // console.log('picker发送选择改变,携带值为', e.detail.value)
  323. // this.setData({
  324. // contactindex: e.detail.value
  325. // })
  326. // },
  327. getProvince() { // 多项选择器
  328. let _this = this;
  329. let d_url = 'public/citypid';
  330. app.postRequest(d_url, { pid: '0' }, function (res) {
  331. if (res.code == '201') {
  332. var provinceList = res.data;
  333. var provinceArr = [];
  334. provinceArr = _this.mapArray(res.data);
  335. _this.setData({
  336. multiArray: [provinceArr, [], []],
  337. provinceList,
  338. provinceArr,
  339. })
  340. // console.log(provinceList);
  341. // console.log(provinceArr);
  342. var defaultCode = provinceList[0]['area_id']
  343. // console.log(provinceList[0]['area_id']);
  344. if (defaultCode) {
  345. _this.setData({
  346. currnetProvinceKey: defaultCode
  347. })
  348. _this.getCity(defaultCode)
  349. }
  350. }
  351. })
  352. },
  353. getCity(codes) {
  354. // 多项选择
  355. let _this = this;
  356. let d_url = 'public/citypid';
  357. app.postRequest(d_url, { pid: codes }, function (res) {
  358. var cityList = res.data;
  359. var cityArr = [];
  360. if (res.code == '201') {
  361. cityArr = _this.mapArray(res.data);
  362. _this.setData({
  363. multiArray: [_this.data.provinceArr, cityArr, []],
  364. cityArr,
  365. cityList
  366. })
  367. var defaultCode = cityList[0]['area_id']
  368. if (defaultCode) {
  369. _this.setData({
  370. currnetProvinceKey: defaultCode
  371. })
  372. _this.getArea(defaultCode)
  373. }
  374. }
  375. })
  376. },
  377. getArea(codes) {
  378. // 多项选择
  379. let _this = this;
  380. let d_url = 'public/citypid';
  381. app.postRequest(d_url, { pid: codes }, function (res) {
  382. var areaList = res.data;
  383. var areaArr = [];
  384. if (res.code == '201') {
  385. areaArr = _this.mapArray(res.data);
  386. }
  387. // console.log(areaList);
  388. // console.log(areaArr);
  389. _this.setData({
  390. multiArray: [_this.data.provinceArr, _this.data.cityArr, areaArr],
  391. areaList,
  392. areaArr
  393. })
  394. })
  395. },
  396. mapArray: function (data) {
  397. let cityArray = []
  398. if (data) {
  399. for (let i = 0; i < data.length; i++) {
  400. if (data[i].area_name) {
  401. cityArray[i] = data[i].area_name;
  402. }
  403. }
  404. }
  405. return cityArray;
  406. },
  407. columnchange(e) { // 滚动选择器 触发的事件
  408. var column = e.detail.column // 当前改变的列
  409. // console.log(column);
  410. // console.log(this.data.multiIndex);
  411. // console.log(JSON.parse(JSON.stringify(this.data.multiIndex)));
  412. var data = {
  413. multiIndex: this.data.multiIndex,
  414. multiArray: this.data.multiArray
  415. }
  416. data.multiIndex[column] = e.detail.value; // 第几列改变了就是对应multiIndex的第几个,更新它
  417. switch (column) { // 处理不同的逻辑
  418. case 0: // 第一列更改 就是省级的更改
  419. var currentProvinceKey = this.data.provinceList[e.detail.value].area_id
  420. if (currentProvinceKey != this.data.currnetProvinceKey) { // 判断当前的key是不是真正的更新了
  421. this.getCity(currentProvinceKey) // 获取当前key下面的市级数据
  422. }
  423. data.multiIndex[1] = 0 // 将市默认选择第一个
  424. break;
  425. case 1: // 市发生变化
  426. var currentCitykey = this.data.cityList[e.detail.value].area_id
  427. if (currentCitykey != this.data.currnetCityKey) { // 同样判断
  428. this.getArea(currentCitykey) // 获取门店
  429. }
  430. data.multiIndex[2] = 0
  431. break;
  432. }
  433. this.setData(data) // 更新数据
  434. },
  435. pickchange(e) {
  436. // console.log(this.data.provinceList[e.detail.value[0]].area_id);
  437. // console.log(this.data.cityList[e.detail.value[1]].area_id);
  438. // console.log(this.data.areaList[e.detail.value[2]].area_id);
  439. this.setData({
  440. step: 1, // 更新,用来选择用户选中的门店
  441. multiIndex: e.detail.value, // 更新下标字段
  442. province: this.data.provinceList[e.detail.value[0]].area_id, // 市
  443. city: this.data.cityList[e.detail.value[1]].area_id, // 市
  444. area: this.data.areaList[e.detail.value[2]].area_id // 区
  445. })
  446. },
  447. // 名字
  448. getPhone: function (e) {
  449. var nickname = e.detail.value;
  450. // console.log(nickname);
  451. this.setData({
  452. nickname: nickname
  453. });
  454. },
  455. //下一步事件
  456. register: function (e) {
  457. console.log(this.data.nickname); // 名字
  458. // console.log(this.data.sex); // 性别
  459. console.log(this.data.age); // 年龄
  460. console.log(this.data.height); // 身高
  461. console.log(this.data.education); // 学历
  462. console.log(this.data.marry); // 婚史
  463. console.log(this.data.income); // 收入
  464. console.log(this.data.province); // 省
  465. console.log(this.data.city); // 市
  466. console.log(this.data.area); // 区
  467. var nickname = this.data.nickname //姓名
  468. // var sex = this.data.sex // 性别
  469. var age = this.data.age // 年龄
  470. var height = this.data.height // 身高
  471. var province = this.data.province // 市
  472. var city = this.data.city // 市
  473. var area = this.data.area // 区
  474. var education = this.data.education // 学历
  475. var marry = this.data.marry // 婚史
  476. var income = this.data.income // 收入
  477. var occupation = this.data.occupation // 收入 occupation
  478. // wx.navigateTo({
  479. // url: '/pages/register/fillTel/fillTel?nickname=' + nickname + '&sex=' + sex + '&age=' + age + '&height=' + height + '&education=' + education + '&marry=' + marry + '&income=' + income + '&city=' + city + '&area=' + area + '&occupation=' + occupation + '&province=' + province + ''
  480. // })
  481. // 修改个人信息
  482. let editinfoform_url = 'my/personaldata/editinfoform';
  483. let editinfoform_data = {
  484. nickname: this.data.nickname, //姓名
  485. age: this.data.age, // 年龄
  486. height: this.data.height, // 身高
  487. province: this.data.province, // 市
  488. city: this.data.city, // 市
  489. area: this.data.area, // 区
  490. education: this.data.education, // 学历
  491. marry: this.data.marry, // 婚史
  492. income: this.data.income, // 收入
  493. occupation: this.data.occupation, // 职业
  494. };
  495. app.postRequest(editinfoform_url, editinfoform_data, function (res) {
  496. if (res.code == 201) {
  497. wx.showToast({
  498. title: '修改成功',
  499. icon: 'success',
  500. duration: 2000
  501. })
  502. }
  503. })
  504. },
  505. })