personaldataModifythe.js 17 KB

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