OwnData.js 16 KB

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