index_screen.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. const app = getApp();
  2. Page({
  3. data: {
  4. multiArray: [], // 地址-数据
  5. step: 0, // 地址
  6. multiIndex: [0, 0, 0], // 地址-下标
  7. CityRecord: '', //城市记录
  8. areaRecord: '', //区域记录
  9. CityRecordid: [], //下标记录
  10. UsedRecord: false, //是否初次
  11. provincename: '', // 省
  12. cityname: '', // 市
  13. areaname: '', // 区
  14. Ageid: 0,
  15. AgeArray: [], // 年龄-数据
  16. AgeIndex: [0, 0], // 年龄-下标
  17. heightid: 0,
  18. heightArray: [], // 身高-数据
  19. heightindex: [0, 0], // 身高-下标
  20. EducationArray: [], // 学历-数据
  21. Educationindex: '', // 学历-下标
  22. MarriageArray: [], // 婚史-数据
  23. Marriageindex: '', // 婚史-下标
  24. incomeid: 0,
  25. incomeArray: [], // 收入-数据
  26. incomeindex: [0, 0], // 收入-下标
  27. inputValue: '', // id
  28. province: '', // 市
  29. city: '', // 市
  30. area: '', // 区
  31. age: '', // 年龄
  32. height: '', // 身高
  33. marry: '', // 婚史
  34. education: '', // 学历
  35. income: 0, // 收入
  36. },
  37. onLoad: function (option) {
  38. var that = this
  39. getApp().showLoading(); //提示加载中
  40. //先清空要传的数据
  41. app.globalData.Selection = 0; // 是否选中
  42. app.globalData.age = 0; // 年龄
  43. app.globalData.height = 0; // 身高
  44. app.globalData.marry = 0 // 婚史
  45. app.globalData.education = 0 // 学历
  46. app.globalData.income = 0; // 收入
  47. console.log(option)
  48. var _province = option.province // 省
  49. var _city = option.city // 市
  50. var _area = option.area // 区
  51. var _provincename = option.provincename // 省
  52. var _cityname = option.cityname // 市
  53. var _areaname = option.areaname // 区
  54. // console.log(_province)
  55. // console.log(_city)
  56. // console.log(_area)
  57. that.setData({
  58. province: _province,
  59. city: _city,
  60. area: _area,
  61. provincename: _provincename, // 省
  62. cityname: _cityname , // 市
  63. areaname: _areaname , // 区
  64. })
  65. // // 获取区域ID
  66. // var _openid = 0;
  67. // try {
  68. // var value = wx.getStorageSync('openid');
  69. // if (value) {
  70. // _openid = value
  71. // that.setData({
  72. // openid: _openid
  73. // })
  74. // }
  75. // console.log(_openid);
  76. // } catch (e) {
  77. // // Do something when catch error
  78. // }
  79. // 年龄 ajax
  80. let Age_url = 'public/paramsgather?type=age';
  81. let Age_data = {
  82. // pid: '0'
  83. };
  84. var _age = option.age // 年龄
  85. var agenewArry = _age.split("-"); //转成数组
  86. var _age_min = agenewArry[0]
  87. var _age_max = agenewArry[1]
  88. // console.log(_age_min)
  89. // console.log(_age_max)
  90. that.setData({
  91. age: _age
  92. })
  93. app.postRequest(Age_url, Age_data, function (res) { // 年龄 ajax
  94. if (res.code == 201) {
  95. for (let i = 0; i < res.data.length; i++) { //已选中的数据处理
  96. if (res.data[i] == _age_min) { var _min = i; }
  97. if (res.data[i] == _age_max) { var _max = i; }
  98. that.setData({
  99. AgeIndex: [_min, _max]
  100. })
  101. }
  102. let dictObject = res.data; //对象不能直接使用 以下转成数组
  103. // 对象转成数组
  104. var createArr = []
  105. for (let i in dictObject) {
  106. createArr.push(dictObject[i] + "岁");
  107. }
  108. that.setData({
  109. AgeArray: [createArr, createArr],
  110. })
  111. // console.log(createArr);
  112. }
  113. })
  114. // 身高 ajax
  115. let height_url = 'public/paramsgather?type=height';
  116. let height_data = {
  117. pid: '0'
  118. };
  119. var _height = option.height // 身高
  120. var heightnewArry = _height.split("-"); //转成数组
  121. var heightSmall = heightnewArry[0]
  122. var heightlarge = heightnewArry[1]
  123. // console.log(heightSmall)
  124. // console.log(heightlarge)
  125. that.setData({
  126. height: _height
  127. })
  128. app.postRequest(height_url, height_data, function (res) { // 身高 ajax
  129. if (res.code == 201) {
  130. for (let i = 0; i < res.data.length; i++) { //已选中的数据处理
  131. // console.log(res.data[i])
  132. if (res.data[i] == heightSmall) { var _min = i; }
  133. if (res.data[i] == heightlarge) { var _max = i; }
  134. that.setData({
  135. heightindex: [_min, _max]
  136. })
  137. }
  138. let dictObject = res.data; //对象不能直接使用 以下转成数组
  139. // 对象转成数组
  140. var createArr = []
  141. for (let i in dictObject) {
  142. createArr.push(dictObject[i] + "cm");
  143. }
  144. that.setData({
  145. heightArray: [createArr, createArr],
  146. })
  147. }
  148. })
  149. // 婚史 ajax
  150. let Marriage_url = 'public/paramsgather?type=marriage';
  151. let Marriage_data = {
  152. pid: '0'
  153. };
  154. var _marry = option.marry // 婚史
  155. // console.log(_marry)
  156. that.setData({
  157. marry: _marry
  158. })
  159. app.postRequest(Marriage_url, Marriage_data, function (res) { // 婚史 ajax
  160. if (res.code == 201) {
  161. // console.log(res.data);
  162. for (let i = 0; i < res.data.length; i++) { //已选中的数据处理
  163. if (i == _marry) {
  164. that.setData({
  165. Marriageindex: i,
  166. })
  167. }
  168. }
  169. that.setData({
  170. MarriageArray: res.data
  171. })
  172. }
  173. })
  174. // 学历 ajax
  175. let Education_url = 'public/paramsgather?type=xueli';
  176. let Education_data = {
  177. // pid: '0'
  178. };
  179. var _education = option.education // 学历
  180. // console.log(_education)
  181. that.setData({
  182. education: _education
  183. })
  184. app.postRequest(Education_url, Education_data, function (res) { // 学历 ajax
  185. if (res.code == 201) {
  186. // console.log(res.data);
  187. for (let i = 0; i < res.data.length; i++) { //已选中的数据处理
  188. if (res.data[i].id == _education) {
  189. that.setData({
  190. Educationindex: i,
  191. })
  192. }
  193. }
  194. that.setData({
  195. EducationArray: res.data
  196. })
  197. }
  198. })
  199. // 收入 ajax
  200. let income_url = 'public/paramsgather?type=shouru';
  201. let income_data = {
  202. // pid: '0'
  203. };
  204. var _income = option.income // 身高
  205. var incomenewArry = _income.split("-"); //转成数组
  206. var incomemin = incomenewArry[0]
  207. var incomemax = incomenewArry[1]
  208. // console.log(incomemin)
  209. // console.log(heightlarge)
  210. that.setData({
  211. income: _income
  212. })
  213. app.postRequest(income_url, income_data, function (res) { // 收入 ajax
  214. if (res.code == 201) {
  215. for (let i = 0; i < res.data.length; i++) { //已选中的数据处理
  216. // console.log(res.data[i])
  217. if (res.data[i].min == incomemin) { var _min = i; }
  218. if (res.data[i].max == incomemax) { var _max = i; }
  219. that.setData({
  220. incomeindex: [_min, _max]
  221. })
  222. }
  223. let dictObject = res.data; //对象不能直接使用 以下转成数组
  224. // 对象转成数组
  225. var createArr = []
  226. var createArr1 = []
  227. for (let i in dictObject) {
  228. createArr.push(dictObject[i].min);
  229. createArr1.push(dictObject[i].max);
  230. }
  231. that.setData({
  232. incomeArray: [createArr, createArr1],
  233. })
  234. }
  235. })
  236. // 允许有意者联系我 ajax
  237. // let contact_url = 'public/citypid';
  238. // let contact_data = {
  239. // pid: '0'
  240. // };
  241. // app.postRequest(contact_url, contact_data, function (res) { // 允许有意者联系我 ajax
  242. // // console.log(res);
  243. // that.setData({
  244. // contactArray: res.data
  245. // })
  246. // })
  247. this.getProvince(); //地址 ajax
  248. },
  249. // 年龄双选
  250. AgeEvent: function (e) {
  251. // console.log('picker发送选择改变,携带值为', e.detail.value)
  252. var Small = this.data.AgeArray[0][e.detail.value[0]].substring(0, 2);
  253. var large = this.data.AgeArray[1][e.detail.value[1]].substring(0, 2);
  254. var Agedata = Small + '-' + large;
  255. // console.log(Agedata);
  256. this.setData({
  257. AgeIndex: e.detail.value,
  258. age: Agedata,
  259. Ageid: 1,
  260. })
  261. },
  262. heightEvent: function (e) { // 身高
  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 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. var heightdata = heightSmall + '-' + heightlarge;
  270. this.setData({
  271. heightindex: e.detail.value,
  272. height: heightdata,
  273. heightid: 1,
  274. })
  275. },
  276. MarriageEvent: function (e) { // 婚史 单项选择器
  277. // console.log(this);
  278. // console.log(e);
  279. // console.log(this.data.MarriageArray[e.detail.value]);
  280. // console.log('picker发送选择改变,携带值为', e.detail.value)
  281. this.setData({
  282. Marriageindex: e.detail.value,
  283. marry: e.detail.value
  284. })
  285. },
  286. EducationEvent: function (e) { // 学历 单项选择器
  287. // console.log(this);
  288. // console.log(e);
  289. // console.log(this.data.EducationArray[e.detail.value].id);
  290. // console.log('picker发送选择改变,携带值为', e.detail.value)
  291. this.setData({
  292. Educationindex: e.detail.value,
  293. education: this.data.EducationArray[e.detail.value].id
  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. var srSmall = this.data.incomeArray[0][e.detail.value[0]];
  302. var srlarge = this.data.incomeArray[1][e.detail.value[1]];
  303. var srdata = srSmall + '-' + srlarge;
  304. // console.log(srdata);
  305. this.setData({
  306. incomeindex: e.detail.value,
  307. income: srdata,
  308. incomeid: 1,
  309. })
  310. },
  311. // contactEvent: function (e) { // 允许有意者联系我 单项选择器
  312. // // console.log(this.data.selectArray[e.detail.value].area_name)
  313. // // console.log('picker发送选择改变,携带值为', e.detail.value)
  314. // console.log(this);
  315. // console.log(e);
  316. // console.log(this.data.contactArray[e.detail.value]);
  317. // console.log('picker发送选择改变,携带值为', e.detail.value)
  318. // this.setData({
  319. // contactindex: e.detail.value
  320. // })
  321. // },
  322. getProvince() { // 多项选择器
  323. let _this = this;
  324. let d_url = 'public/citypid';
  325. app.postRequest(d_url, { pid: '0' }, function (res) {
  326. if (res.code == '201') {
  327. var provinceList = res.data;
  328. var provinceArr = [];
  329. provinceArr = _this.mapArray(res.data);
  330. _this.setData({
  331. multiArray: [provinceArr, [], []],
  332. provinceList,
  333. provinceArr,
  334. })
  335. // console.log(provinceList);
  336. // console.log(provinceArr);
  337. // console.log(_this.data.CityRecord)
  338. // 方便取消事件调用 getProvince 判断 如果选择过城市 传选择过的城市
  339. if (_this.data.CityRecord){
  340. // console.log('有');
  341. var defaultCode = _this.data.CityRecord
  342. if (defaultCode) {
  343. _this.setData({
  344. currnetProvinceKey: defaultCode
  345. })
  346. _this.getCity(defaultCode)
  347. }
  348. }else{ //如果没有选择过 , 传第一个城市
  349. // console.log('无');
  350. var defaultCode = provinceList[0]['area_id']
  351. if (defaultCode) {
  352. _this.setData({
  353. currnetProvinceKey: defaultCode
  354. })
  355. _this.getCity(defaultCode)
  356. }
  357. }
  358. }
  359. })
  360. },
  361. getCity(codes) {
  362. // 多项选择
  363. let _this = this;
  364. let d_url = 'public/citypid';
  365. app.postRequest(d_url, { pid: codes }, function (res) {
  366. var cityList = res.data;
  367. var cityArr = [];
  368. if (res.code == '201') {
  369. cityArr = _this.mapArray(res.data);
  370. _this.setData({
  371. multiArray: [_this.data.provinceArr, cityArr, []],
  372. cityArr,
  373. cityList
  374. })
  375. // 方便取消事件调用 getProvince 判断 如果选择过城市 传选择过的城市
  376. if (_this.data.areaRecord && _this.data.cancelID == false) {
  377. // console.log('有');
  378. var defaultCode = _this.data.areaRecord
  379. // console.log(_this.data.areaRecord);
  380. if (defaultCode) {
  381. _this.setData({
  382. currnetProvinceKey: defaultCode
  383. })
  384. _this.getArea(defaultCode)
  385. }
  386. } else { //如果没有选择过 , 传第一个城市
  387. // console.log('无');
  388. var defaultCode = cityList[0]['area_id']
  389. // console.log(defaultCode);
  390. if (defaultCode) {
  391. _this.setData({
  392. currnetProvinceKey: defaultCode
  393. })
  394. _this.getArea(defaultCode)
  395. }
  396. }
  397. }
  398. })
  399. },
  400. getArea(codes) {
  401. // 多项选择
  402. let _this = this;
  403. let d_url = 'public/citypid';
  404. app.postRequest(d_url, { pid: codes }, function (res) {
  405. var areaList = res.data;
  406. var areaArr = [];
  407. if (res.code == '201') {
  408. areaArr = _this.mapArray(res.data);
  409. }
  410. // console.log(areaList);
  411. // console.log(areaArr);
  412. _this.setData({
  413. multiArray: [_this.data.provinceArr, _this.data.cityArr, areaArr],
  414. areaList,
  415. areaArr,
  416. })
  417. _this.setData({
  418. cancelID: true,
  419. })
  420. })
  421. },
  422. mapArray: function (data) {
  423. let cityArray = []
  424. if (data) {
  425. for (let i = 0; i < data.length; i++) {
  426. if (data[i].area_name) {
  427. cityArray[i] = data[i].area_name;
  428. }
  429. }
  430. }
  431. return cityArray;
  432. },
  433. columnchange(e) { // 滚动选择器 触发的事件
  434. var column = e.detail.column // 当前改变的列
  435. // console.log(column);
  436. // console.log(this.data.multiIndex);
  437. // console.log(JSON.parse(JSON.stringify(this.data.multiIndex)));
  438. var data = {
  439. multiIndex: this.data.multiIndex,
  440. multiArray: this.data.multiArray
  441. }
  442. data.multiIndex[column] = e.detail.value; // 第几列改变了就是对应multiIndex的第几个,更新它
  443. switch (column) { // 处理不同的逻辑
  444. case 0: // 第一列更改 就是省级的更改
  445. var currentProvinceKey = this.data.provinceList[e.detail.value].area_id
  446. if (currentProvinceKey != this.data.currnetProvinceKey) { // 判断当前的key是不是真正的更新了
  447. this.getCity(currentProvinceKey) // 获取当前key下面的市级数据
  448. }
  449. data.multiIndex[1] = 0 // 将市默认选择第一个
  450. break;
  451. case 1: // 市发生变化
  452. var currentCitykey = this.data.cityList[e.detail.value].area_id
  453. if (currentCitykey != this.data.currnetCityKey) { // 同样判断
  454. this.getArea(currentCitykey) // 获取门店
  455. }
  456. data.multiIndex[2] = 0
  457. break;
  458. }
  459. this.setData(data) // 更新数据
  460. // console.log(this.data.step)
  461. },
  462. pickchange(e) {
  463. // console.log(this.data.multiIndex);
  464. // console.log(this.data.provinceList[e.detail.value[0]].area_id);
  465. // console.log(this.data.cityList[e.detail.value[1]].area_id);
  466. // console.log(this.data.areaList[e.detail.value[2]].area_id);
  467. this.setData({
  468. step: 1, // 更新,用来选择用户选中的门店
  469. multiIndex: e.detail.value, // 更新下标字段
  470. province: this.data.provinceList[e.detail.value[0]].area_id, // 市
  471. city: this.data.cityList[e.detail.value[1]].area_id, // 市
  472. area: this.data.areaList[e.detail.value[2]].area_id, // 区
  473. provincename: this.data.provinceList[e.detail.value[0]].area_name, // 市
  474. cityname: this.data.cityList[e.detail.value[1]].area_name, // 市
  475. areaname: this.data.areaList[e.detail.value[2]].area_name, // 区
  476. CityRecord: this.data.provinceList[e.detail.value[0]].area_id, // 省
  477. areaRecord: this.data.cityList[e.detail.value[1]].area_id, // 市
  478. CityRecordid:this.data.multiIndex,
  479. UsedRecord:true, //已使用过
  480. })
  481. },
  482. // 城市取消
  483. cancel: function (e) {
  484. var _this = this;
  485. if (_this.data.UsedRecord == true){
  486. _this.setData({
  487. multiIndex: _this.data.CityRecordid,
  488. cancelID: false
  489. })
  490. // console.log(_this.data.CityRecordid);
  491. _this.getProvince(); //地址 ajax
  492. }
  493. },
  494. // 会员编码
  495. getPhone: function (e) {
  496. var nickname = e.detail.value;
  497. // console.log(nickname);
  498. this.setData({
  499. nickname: nickname
  500. });
  501. },
  502. //下一步事件
  503. register: function (e) {
  504. // console.log(this.data.photo); // 头像
  505. // console.log(this.data.sex); // 性别
  506. // console.log(this.data.nickname); // 名字
  507. // console.log(this.data.age); // 年龄
  508. // console.log(this.data.height); // 身高
  509. // console.log(this.data.province); // 区域 -市-县
  510. // console.log(this.data.city); // 区域 -市-县
  511. // console.log(this.data.area); // 区域 -市-县
  512. // console.log(this.data.education); // 学历
  513. // console.log(this.data.marry); // 婚史
  514. // console.log(this.data.income); // 收入
  515. // if (this.data.photo != ''){
  516. // console.log(1);
  517. // }
  518. // var photo = this.data.photo //头像
  519. // var sex = this.data.sex // 性别
  520. var nickname = this.data.nickname //姓名
  521. var age = this.data.age // 年龄
  522. var height = this.data.height // 身高
  523. var education = this.data.education // 学历
  524. var marry = this.data.marry // 婚史
  525. var income = this.data.income // 收入
  526. var province = this.data.province // 市
  527. var city = this.data.city // 市
  528. var area = this.data.area // 区
  529. var provincename = this.data.provincename // 市
  530. var cityname = this.data.cityname // 市
  531. var areaname = this.data.areaname // 区
  532. // var occupation = this.data.occupation // 职业
  533. //设置全局变量(app已经定义 var app=getApp()) 赋值要传的参数
  534. app.globalData.age = age; // 年龄
  535. app.globalData.height = height; // 身高
  536. app.globalData.marry = marry // 婚史
  537. app.globalData.education = education // 学历
  538. app.globalData.income = income; // 收入
  539. app.globalData.Selection = 1; // 是否选中 1 选中 0没选中
  540. app.globalData.province = province; // 省
  541. app.globalData.city = city; // 市
  542. app.globalData.area = area; // 区
  543. app.globalData.provincename = provincename; // 省
  544. app.globalData.cityname = cityname; // 市
  545. app.globalData.areaname = areaname; // 区
  546. wx.switchTab({
  547. url: '../index/index',
  548. })
  549. // if (photo == '') {
  550. // var _photo = '请上传头像'
  551. // getApp().Tips(_photo)
  552. // } else if (nickname == '') {
  553. // var _nickname = '请填写姓名'
  554. // getApp().Tips(_nickname)
  555. // } else if (sex == '') {
  556. // var _sex = '请选择性别'
  557. // getApp().Tips(_sex)
  558. // } else if (age == '') {
  559. // var _age = '请选择年龄'
  560. // getApp().Tips(_age)
  561. // } else if (height == '') {
  562. // var _height = '请选择身高'
  563. // getApp().Tips(_height)
  564. // } else if (province == '' && city == '' && area == '') {
  565. // var _province = '请选择住址'
  566. // getApp().Tips(_province)
  567. // } else if (education == '') {
  568. // var _education = '请选择学历'
  569. // getApp().Tips(_education)
  570. // } else if (marry == '') {
  571. // var _marry = '请选择婚史'
  572. // getApp().Tips(_marry)
  573. // } else if (income == '') {
  574. // var _income = '请选择收入'
  575. // getApp().Tips(_income)
  576. // } else if (occupation == '') {
  577. // var _occupation = '请选择职业'
  578. // getApp().Tips(_occupation)
  579. // } else {
  580. // }
  581. },
  582. // 重置
  583. Reset: function (e) {
  584. var _this = this;
  585. _this.setData({
  586. AgeIndex: ['', ''], // 年龄-下标
  587. age: 0, // 年龄
  588. Ageid: 0,
  589. heightindex: ['', ''], // 身高-下标
  590. height: 0, //身高
  591. heightid: 0,
  592. Marriageindex: '', // 婚史-下标
  593. marry: 0,
  594. Educationindex: '', //学历
  595. education: 0, //学历
  596. incomeindex: ['', ''], //收入
  597. income: 0, //收入
  598. step: 0, // 地址
  599. province: 0, // 市
  600. city: 0, // 市
  601. area: 0, // 区
  602. provincename:'', // 省
  603. cityname: '', // 市
  604. areaname:'' , // 区
  605. inputValue: '', //ID
  606. nickname: '',//ID
  607. })
  608. // console.log(this.data.province); // 区域 -市-县
  609. // console.log(this.data.city); // 区域 -市-县
  610. // console.log(this.data.area); // 区域 -市-县
  611. },
  612. })