index.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. import HTTP from "../../../../requestFn/Api"
  2. var common = require('../../utils/common');
  3. const app = getApp();
  4. const {
  5. baseURL
  6. } = app.globalData;
  7. Page({
  8. data: {
  9. inputShowed: false,
  10. inputVal: '',
  11. city: '成都',
  12. province_list: [],
  13. city_list: [],
  14. area_list: [],
  15. committee_list: [],
  16. garden_id: null,
  17. house_id: null,
  18. name: "",
  19. user_type: "",
  20. id_type: "",
  21. appendix: [],
  22. id_array: [{
  23. name: "身份证",
  24. value: 1
  25. }, {
  26. name: "护照",
  27. value: 2
  28. }],
  29. id_number: "",
  30. phone: "",
  31. files: [],
  32. applyInfo: [{
  33. name: "我的身份",
  34. click: "myType",
  35. array: [{
  36. value: 1,
  37. name: "业主"
  38. },
  39. {
  40. value: 2,
  41. name: "家人"
  42. },
  43. {
  44. value: 3,
  45. name: "租客"
  46. }
  47. ],
  48. value: "请选择",
  49. },
  50. {
  51. name: "省份",
  52. click: "selectProvice",
  53. array: [],
  54. value: "请选择",
  55. },
  56. {
  57. name: "城市",
  58. click: "selectCity",
  59. array: [],
  60. value: "请选择"
  61. },
  62. {
  63. name: "区域",
  64. click: "selectArea",
  65. array: [],
  66. value: "请选择"
  67. },
  68. {
  69. name: "街道",
  70. click: "selectStreet",
  71. array: [],
  72. value: "请选择"
  73. },
  74. {
  75. name: "社区",
  76. click: "selectCommittee",
  77. array: [],
  78. value: "请选择"
  79. },
  80. {
  81. name: "小区",
  82. click: "selectGarden",
  83. array: [],
  84. value: "请选择"
  85. },
  86. {
  87. name: "楼栋",
  88. click: "selectBuilding",
  89. array: [],
  90. value: "请选择"
  91. },
  92. {
  93. name: "单元",
  94. click: "selectUnit",
  95. array: [],
  96. value: "请选择"
  97. },
  98. {
  99. name: "房间",
  100. click: "selectHouse",
  101. array: [],
  102. value: "请选择"
  103. },
  104. ],
  105. Certification: false,
  106. navHeight: app.globalData.navHeight,
  107. navTop: app.globalData.navTop,
  108. listShowed: false,
  109. },
  110. onLoad() {
  111. const that = this;
  112. HTTP.GetProvince().then(res => {
  113. this.setData({
  114. "applyInfo[1].array": res.province_list,
  115. province_list: res.province_list,
  116. city_list: res.city_list,
  117. area_list: res.area_list
  118. })
  119. })
  120. },
  121. onShow() {
  122. const that = this;
  123. HTTP.GetUserInfo().then(res => {
  124. if (res.id_number && res.id_type && res.real_name) {
  125. that.setData({
  126. Certification: true
  127. })
  128. } else {
  129. that.setData({
  130. Certification: false
  131. })
  132. }
  133. })
  134. },
  135. showInput() {
  136. const {
  137. inputShowed
  138. } = this.data;
  139. this.setData({
  140. inputShowed: !inputShowed,
  141. });
  142. },
  143. hideList() {
  144. this.setData({
  145. listShowed: false,
  146. })
  147. },
  148. showList() {
  149. this.setData({
  150. listShowed: true,
  151. })
  152. },
  153. async searchGarden() {
  154. const garden_name = this.data.inputVal;
  155. const {
  156. list
  157. } = await HTTP.GetGardenList({
  158. garden_name
  159. });
  160. this.setData({
  161. garden_list: list,
  162. listShowed: true,
  163. })
  164. console.log(list);
  165. },
  166. clearInput() {
  167. this.setData({
  168. inputVal: '',
  169. });
  170. this.hideList();
  171. this.showInput();
  172. },
  173. inputTyping(e) {
  174. const {
  175. value
  176. } = e.detail;
  177. this.setData({
  178. inputVal: value,
  179. });
  180. if (value == '') {
  181. this.hideList();
  182. }
  183. },
  184. choiceGarden(e) {
  185. this.hideList();
  186. const {
  187. detail
  188. } = e.currentTarget.dataset;
  189. const {
  190. province_list,
  191. city_list,
  192. area_list,
  193. } = this.data;
  194. let province_index, city_index, area_index, street_index, committee_index;
  195. province_list.map((item, index) => {
  196. if (item.code == detail.province_code) {
  197. province_index = index
  198. }
  199. })
  200. const city = city_list.filter(item => item.province_code == detail.province_code);
  201. city.map((item, index) => {
  202. if (item.code == detail.city_code) {
  203. city_index = index
  204. }
  205. })
  206. const area = area_list.filter(item => item.city_code == detail.city_code)
  207. area.map((item, index) => {
  208. if (item.code == detail.area_code) {
  209. area_index = index
  210. }
  211. })
  212. this.setData({
  213. [`applyInfo[1].value`]: detail.province,
  214. [`applyInfo[1].index`]: province_index,
  215. "applyInfo[2].array": city,
  216. "applyInfo[2].value": detail.city + "市",
  217. [`applyInfo[2].index`]: city_index,
  218. "applyInfo[3].value": detail.area,
  219. "applyInfo[3].array": area,
  220. "applyInfo[3].index": area_index,
  221. })
  222. HTTP.GetStreetCommittee({
  223. area_code: detail.area_code
  224. }).then(res => {
  225. const street = res.committee_list.filter(item => item.street_code == detail.street_code);
  226. res.street_list.map((item, index) => {
  227. if (item.code == detail.street_code) {
  228. street_index = index
  229. }
  230. })
  231. street.map((item, index) => {
  232. if (item.code == detail.committee_code) {
  233. committee_index = index
  234. }
  235. })
  236. this.setData({
  237. "applyInfo[4].array": res.street_list,
  238. committee_list: res.committee_list,
  239. "applyInfo[4].value": detail.street,
  240. "applyInfo[5].array": street,
  241. "applyInfo[5].index": committee_index,
  242. "applyInfo[4].index": street_index,
  243. "applyInfo[5].value": detail.committee,
  244. })
  245. });
  246. this.findGarden(detail.province_code, detail.city_code, detail.area_code, detail.street_code, detail.committee_code, detail.garden_name, detail.id);
  247. },
  248. //获取定位
  249. getMap() {
  250. console.log("暂未开发");
  251. },
  252. selectProvice(e) {
  253. const index = e.detail.value;
  254. const value = this.data.applyInfo[1].array[index]
  255. const city = this.data.city_list.filter(item => item.province_code == value.code)
  256. this.setData({
  257. "applyInfo[2].array": city,
  258. "applyInfo[2].index": "",
  259. "applyInfo[3].index": "",
  260. "applyInfo[4].index": "",
  261. "applyInfo[5].index": "",
  262. "applyInfo[6].index": "",
  263. "applyInfo[2].value": "请选择",
  264. "applyInfo[3].value": "请选择",
  265. "applyInfo[4].value": "请选择",
  266. "applyInfo[5].value": "请选择",
  267. "applyInfo[6].value": "请选择",
  268. "applyInfo[7].value": "请选择",
  269. "applyInfo[8].value": "请选择",
  270. "applyInfo[9].value": "请选择",
  271. "applyInfo[3].array": [],
  272. "applyInfo[4].array": [],
  273. "applyInfo[5].array": [],
  274. "applyInfo[6].array": [],
  275. "applyInfo[7].array": [],
  276. "applyInfo[8].array": [],
  277. "applyInfo[9].array": [],
  278. "applyInfo[1].value": value.name,
  279. })
  280. },
  281. myType(e) {
  282. const value = this.data.applyInfo[0].array[e.detail.value]
  283. this.setData({
  284. "applyInfo[0].value": value.name,
  285. user_type: value.value
  286. });
  287. },
  288. selectCity(e) {
  289. const value = this.data.applyInfo[2].array[e.detail.value]
  290. const area = this.data.area_list.filter(item => item.city_code == value.code)
  291. this.setData({
  292. "applyInfo[3].array": area,
  293. "applyInfo[2].value": value.name,
  294. "applyInfo[3].index": "",
  295. "applyInfo[4].index": "",
  296. "applyInfo[5].index": "",
  297. "applyInfo[6].index": "",
  298. "applyInfo[3].value": "请选择",
  299. "applyInfo[4].value": "请选择",
  300. "applyInfo[5].value": "请选择",
  301. "applyInfo[6].value": "请选择",
  302. "applyInfo[7].value": "请选择",
  303. "applyInfo[8].value": "请选择",
  304. "applyInfo[9].value": "请选择",
  305. "applyInfo[4].array": [],
  306. "applyInfo[5].array": [],
  307. "applyInfo[6].array": [],
  308. "applyInfo[7].array": [],
  309. "applyInfo[8].array": [],
  310. "applyInfo[9].array": [],
  311. })
  312. },
  313. selectArea(e) {
  314. const value = this.data.applyInfo[3].array[e.detail.value]
  315. this.setData({
  316. "applyInfo[3].value": value.name,
  317. "applyInfo[4].index": "",
  318. "applyInfo[5].index": "",
  319. "applyInfo[6].index": "",
  320. "applyInfo[4].value": "请选择",
  321. "applyInfo[5].value": "请选择",
  322. "applyInfo[6].value": "请选择",
  323. "applyInfo[7].value": "请选择",
  324. });
  325. HTTP.GetStreetCommittee({
  326. area_code: value.code
  327. }).then(res => {
  328. this.setData({
  329. "applyInfo[4].array": res.street_list,
  330. "applyInfo[5].array": [{
  331. name: "请选择"
  332. }],
  333. "applyInfo[6].array": [{
  334. name: "请选择"
  335. }],
  336. "applyInfo[7].array": [{
  337. name: "请选择"
  338. }],
  339. committee_list: res.committee_list,
  340. })
  341. })
  342. },
  343. selectStreet(e) {
  344. const value = this.data.applyInfo[4].array[e.detail.value]
  345. const street = this.data.committee_list.filter(item => item.street_code == value.code)
  346. console.log(street);
  347. this.setData({
  348. "applyInfo[4].value": value.name,
  349. "applyInfo[5].array": street,
  350. "applyInfo[5].index": "",
  351. "applyInfo[6].index": "",
  352. "applyInfo[5].value": "请选择",
  353. "applyInfo[6].value": "请选择",
  354. "applyInfo[7].value": "请选择",
  355. "applyInfo[6].array": [],
  356. "applyInfo[8].value": "请选择",
  357. "applyInfo[9].value": "请选择",
  358. "applyInfo[7].array": [],
  359. "applyInfo[8].array": [],
  360. "applyInfo[9].array": [],
  361. });
  362. },
  363. selectCommittee(e) {
  364. const value = this.data.applyInfo[5].array[e.detail.value]
  365. this.setData({
  366. "applyInfo[5].value": value.name,
  367. "applyInfo[6].index": "",
  368. "applyInfo[6].value": "请选择",
  369. "applyInfo[7].value": "请选择",
  370. "applyInfo[8].value": "请选择",
  371. "applyInfo[9].value": "请选择",
  372. "applyInfo[7].array": [],
  373. "applyInfo[8].array": [],
  374. "applyInfo[9].array": [],
  375. });
  376. this.findGarden('', '', '', '', value.code, '');
  377. },
  378. findGarden(province_code, city_code, area_code, street_code, committee_code, garden_name, id = '') {
  379. HTTP.GetGardenList({
  380. province_code,
  381. city_code,
  382. area_code,
  383. street_code,
  384. committee_code,
  385. }).then(res => {
  386. if (res.list.length > 0) {
  387. const array = res.list.map(item => {
  388. return {
  389. garden_id: item.id,
  390. name: item.garden_name
  391. }
  392. })
  393. this.setData({
  394. "applyInfo[6].array": array,
  395. })
  396. if (garden_name) {
  397. let garden_index;
  398. array.map((item, index) => {
  399. if (item.garden_id == id) {
  400. garden_index = index
  401. }
  402. })
  403. this.setData({
  404. "applyInfo[6].value": garden_name,
  405. "applyInfo[6].index": garden_index,
  406. garden_id: id
  407. })
  408. this.getBuilding(id);
  409. }
  410. } else {
  411. this.setData({
  412. "applyInfo[6].array": []
  413. })
  414. }
  415. })
  416. },
  417. selectGarden(e) {
  418. const value = this.data.applyInfo[6].array[e.detail.value]
  419. this.setData({
  420. "applyInfo[6].value": value.name,
  421. "applyInfo[7].value": "请选择",
  422. "applyInfo[8].value": "请选择",
  423. "applyInfo[8].array": [],
  424. "applyInfo[9].array": [],
  425. "applyInfo[9].value": "请选择",
  426. garden_id: value.garden_id
  427. });
  428. this.getBuilding(value.garden_id);
  429. },
  430. getBuilding(garden_id){
  431. HTTP.GetGardenBuilding({
  432. garden_id
  433. }).then(res => {
  434. if (res.list.length > 0) {
  435. const array = res.list.map(item => {
  436. return {
  437. id: item.id,
  438. name: item.building_name
  439. }
  440. })
  441. this.setData({
  442. "applyInfo[7].array": array
  443. })
  444. } else {
  445. this.setData({
  446. "applyInfo[7].array": []
  447. })
  448. }
  449. })
  450. },
  451. selectBuilding(e) {
  452. const value = this.data.applyInfo[7].array[e.detail.value]
  453. this.setData({
  454. "applyInfo[7].value": value.name,
  455. "applyInfo[8].value": "请选择",
  456. "applyInfo[9].array": [],
  457. "applyInfo[9].value": "请选择",
  458. });
  459. HTTP.GetGardenUnit({
  460. garden_id: this.data.garden_id,
  461. building_id: value.id
  462. }).then(res => {
  463. if (res.list.length > 0) {
  464. const array = res.list.map(item => {
  465. return {
  466. id: item.id,
  467. name: item.unit_name
  468. }
  469. })
  470. this.setData({
  471. "applyInfo[8].array": array
  472. })
  473. } else {
  474. this.setData({
  475. "applyInfo[8].array": []
  476. })
  477. }
  478. })
  479. },
  480. selectUnit(e) {
  481. const value = this.data.applyInfo[8].array[e.detail.value]
  482. this.setData({
  483. "applyInfo[8].value": value.name,
  484. "applyInfo[9].value": "请选择",
  485. });
  486. HTTP.GetGardenHouse({
  487. unit_id: value.id,
  488. garden_id: this.data.garden_id
  489. }).then(res => {
  490. if (res.list.length > 0) {
  491. const array = res.list.map(item => {
  492. return {
  493. id: item.id,
  494. name: item.house_name
  495. }
  496. })
  497. this.setData({
  498. "applyInfo[9].array": array,
  499. })
  500. } else {
  501. this.setData({
  502. "applyInfo[9].array": []
  503. })
  504. }
  505. })
  506. },
  507. selectHouse(e) {
  508. const value = this.data.applyInfo[9].array[e.detail.value]
  509. this.setData({
  510. "applyInfo[9].value": value.name,
  511. house_id: value.id
  512. });
  513. },
  514. chooseImage() {
  515. const that = this;
  516. wx.chooseMedia({
  517. mediaType: ["image"],
  518. count: 9,
  519. sizeType: ['original', 'compressed'],
  520. sourceType: ['album', 'camera'],
  521. success(res) {
  522. const userInfo = wx.getStorageSync('userInfo')
  523. const pic = res.tempFiles.map(item => {
  524. wx.uploadFile({
  525. filePath: item.tempFilePath,
  526. name: 'file',
  527. url: baseURL + '/upload',
  528. header: {
  529. "token": userInfo.token
  530. },
  531. success(res) {
  532. const result = that.data.appendix;
  533. result.push(JSON.parse(res.data).data)
  534. that.setData({
  535. appendix: result
  536. })
  537. },
  538. fail(res) {
  539. console.log(res);
  540. }
  541. })
  542. return item.tempFilePath
  543. })
  544. that.setData({
  545. files: that.data.files.concat(pic),
  546. });
  547. },
  548. fail(res) {
  549. console.log(res);
  550. }
  551. });
  552. },
  553. previewImage(e) {
  554. wx.previewImage({
  555. current: this.data.files[e.currentTarget.dataset.index],
  556. urls: this.data.files,
  557. });
  558. },
  559. deleteImg(e) {
  560. var that = this
  561. wx.showModal({
  562. title: "提示",
  563. content: "是否删除图片",
  564. success: function (res) {
  565. if (res.confirm) {
  566. for (var i = 0; i < that.data.files.length; i++) {
  567. if (i == e.currentTarget.dataset.index) {
  568. that.data.files.splice(i, 1)
  569. that.data.appendix.splice(i, 1)
  570. }
  571. }
  572. that.setData({
  573. files: that.data.files
  574. })
  575. } else if (res.cancel) {
  576. console.log("用户点击取消")
  577. }
  578. }
  579. })
  580. },
  581. //提交申请
  582. submit(e) {
  583. const that = this;
  584. const user = that.data
  585. if (user.user_type == "") {
  586. wx.showToast({
  587. title: '请选择我的身份',
  588. })
  589. return false
  590. }
  591. if (user.garden_id == null) {
  592. wx.showToast({
  593. title: '请选择小区',
  594. })
  595. return false
  596. }
  597. if (user.house_id == null) {
  598. wx.showToast({
  599. title: '请选择房间',
  600. })
  601. return false
  602. }
  603. if (!user.Certification) {
  604. wx.showToast({
  605. title: "请点击实名认证进行实名认证",
  606. duration: 2000,
  607. icon: "none",
  608. });
  609. return false;
  610. }
  611. const {
  612. user_type,
  613. appendix,
  614. garden_id,
  615. house_id,
  616. } = user
  617. HTTP.HouseholdApply({
  618. user_type,
  619. appendix,
  620. garden_id,
  621. house_id,
  622. }).then(res => {
  623. if (res.code == 0) {
  624. wx.navigateTo({
  625. url: "../success/index",
  626. })
  627. }
  628. })
  629. .catch(res => {
  630. console.log(res);
  631. })
  632. },
  633. goInentity() {
  634. console.log(2);
  635. wx.navigateTo({
  636. url: '../setting/inentity/index',
  637. })
  638. },
  639. // 点击返回上级页面
  640. goBack() {
  641. let pages = getCurrentPages(); //获取小程序页面栈
  642. let beforePage = pages[pages.length - 2]; //获取上个页面的实例对象
  643. wx.navigateBack({ //返回上一页
  644. delta: 1
  645. })
  646. },
  647. });