index.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. // pages/index/index.js
  2. import {
  3. xcxsfsm,
  4. hqdw,
  5. xcxGetCompanyList,
  6. xcxGetCompanySwjg,
  7. xcxsmbd,
  8. xcxsy,
  9. } from "../../apis/index.js";
  10. // 屏幕信息
  11. let screenInfo = null;
  12. let movableInfo = null;
  13. Page({
  14. /**
  15. * 页面的初始数据
  16. */
  17. data: {
  18. navigation: {},
  19. addressInfo: {},
  20. userInfo: {},
  21. enterPriceList: [],
  22. enterpriceTypeShow: false,
  23. hall: {},
  24. markers: [],
  25. myYy: {},
  26. showVoice: false,
  27. searchValue: "",
  28. lbList: [
  29. {
  30. url:
  31. "https://smzc-1253299035.cos.ap-nanjing.myqcloud.com/pdjh/miniProgrameYyQh/indexLb1.png",
  32. name: "税费争议",
  33. event: "navigate",
  34. path: "../taxDisputes/index/index",
  35. },
  36. {
  37. url:
  38. "https://smzc-1253299035.cos.ap-nanjing.myqcloud.com/pdjh/miniProgrameYyQh/indexLb2.png",
  39. name: "",
  40. event: "miniProgram",
  41. appId: "wxc575845fbd5bac33",
  42. },
  43. ],
  44. lbIndex: 0,
  45. znzxX: 0,
  46. znzxY: "500rpx",
  47. },
  48. /**
  49. * 生命周期函数--监听页面加载
  50. */
  51. onLoad(options) {
  52. let that = this;
  53. that.init();
  54. that.getNavigationBar();
  55. that.getIndexInfos();
  56. },
  57. init() {
  58. let that = this;
  59. let device = wx.getSystemInfoSync();
  60. screenInfo = device.screenWidth - 50;
  61. that.setData({
  62. znzxX: screenInfo,
  63. });
  64. },
  65. getNavigationBar() {
  66. let that = this;
  67. const res = wx.getMenuButtonBoundingClientRect();
  68. let navigation = {
  69. width: res.left + "px",
  70. height: res.height + 6 + "px",
  71. paddingTop: res.top - 3 + "px",
  72. };
  73. that.setData({
  74. navigation: navigation,
  75. });
  76. },
  77. getIndexInfos() {
  78. let that = this;
  79. that.sfsm();
  80. },
  81. hqdw() {
  82. let that = this;
  83. wx.getLocation({
  84. type: "wgs84",
  85. isHighAccuracy: true,
  86. success(result) {
  87. hqdw().then((res) => {
  88. if (res.code == 200) {
  89. let data = JSON.parse(res.message);
  90. that.setData({
  91. addressInfo: {
  92. lat: result.latitude,
  93. lng: result.longitude,
  94. address:
  95. data.result.ad_info.district ||
  96. data.result.ad_info.city ||
  97. data.result.ad_info.province ||
  98. data.result.ad_info.nation,
  99. },
  100. });
  101. wx.setStorageSync(
  102. "ADDRESS",
  103. data.result.ad_info.district ||
  104. data.result.ad_info.city ||
  105. data.result.ad_info.province ||
  106. data.result.ad_info.nation
  107. );
  108. } else {
  109. that.setData({
  110. addressInfo: {
  111. lat: result.latitude,
  112. lng: result.longitude,
  113. address: "未知",
  114. },
  115. });
  116. wx.setStorageSync("ADDRESS", "未知");
  117. }
  118. });
  119. },
  120. fail: (err) => {
  121. hqdw().then((res) => {
  122. if (res.code == 200) {
  123. let data = JSON.parse(res.message);
  124. that.setData({
  125. addressInfo: {
  126. lat: data.result.location.lat,
  127. lng: data.result.location.lng,
  128. address:
  129. data.result.ad_info.district ||
  130. data.result.ad_info.city ||
  131. data.result.ad_info.province ||
  132. data.result.ad_info.nation,
  133. },
  134. });
  135. wx.setStorageSync(
  136. "ADDRESS",
  137. data.result.ad_info.district ||
  138. data.result.ad_info.city ||
  139. data.result.ad_info.province ||
  140. data.result.ad_info.nation
  141. );
  142. } else {
  143. that.setData({
  144. addressInfo: {
  145. lat: "",
  146. lng: "",
  147. address: "未知",
  148. },
  149. });
  150. wx.setStorageSync("ADDRESS", "未知");
  151. }
  152. });
  153. },
  154. });
  155. },
  156. authorizeSuccess() {
  157. let that = this;
  158. that.getIndexInfos();
  159. },
  160. sfsm() {
  161. let that = this;
  162. let publicId = wx.getStorageSync("PUBLIC_ID");
  163. if (publicId.unionid) {
  164. xcxsfsm({
  165. xcxId: publicId.openid,
  166. unionid: publicId.unionid,
  167. }).then((res) => {
  168. switch (res.code) {
  169. default:
  170. return;
  171. case 200:
  172. wx.setStorageSync("REAL_NAME", true);
  173. wx.setStorageSync("LOCK", false);
  174. var userInfos = {
  175. name: res.smxx.xm,
  176. idcard: res.smxx.sfzhm,
  177. phone: res.smxx.sjh,
  178. swjgdm: res.smxx.swjgdm || "",
  179. nsrsbh: res.smxx.nsrsbh || "",
  180. nsrmc: res.smxx.nsrmc || "",
  181. };
  182. wx.setStorageSync("USERINFO", userInfos);
  183. that.setData({
  184. userInfo: userInfos,
  185. });
  186. break;
  187. case 501:
  188. wx.setStorageSync("REAL_NAME", false);
  189. wx.setStorageSync("LOCK", false);
  190. wx.removeStorageSync("USERINFO");
  191. wx.removeStorageSync("MY_HALL");
  192. break;
  193. case 502:
  194. wx.setStorageSync("REAL_NAME", true);
  195. wx.setStorageSync("LOCK", true);
  196. var userInfos = {
  197. name: res.smxx.xm,
  198. idcard: res.smxx.sfzhm,
  199. phone: res.smxx.sjh,
  200. swjgdm: res.smxx.swjgdm || "",
  201. nsrsbh: res.smxx.nsrsbh || "",
  202. nsrmc: res.smxx.nsrmc || "",
  203. };
  204. wx.setStorageSync("USERINFO", userInfos);
  205. that.setData({
  206. userInfo: userInfos,
  207. });
  208. break;
  209. case 500:
  210. wx.removeStorageSync("USERINFO");
  211. wx.removeStorageSync("MY_HALL");
  212. break;
  213. }
  214. });
  215. } else {
  216. setTimeout(() => {
  217. that.sfsm();
  218. }, 500);
  219. }
  220. },
  221. getHall() {
  222. let that = this;
  223. let publicId = wx.getStorageSync("PUBLIC_ID");
  224. if (that.data.addressInfo.lat && that.data.addressInfo.lng) {
  225. let form = {
  226. xcxId: publicId.openid,
  227. unionid: publicId.unionid,
  228. longitude: String(that.data.addressInfo.lng),
  229. latitude: String(that.data.addressInfo.lat),
  230. nsrsbh: that.data.userInfo.nsrsbh || "",
  231. swjgdm: that.data.userInfo.swjgdm || "",
  232. };
  233. xcxsy(form).then((res) => {
  234. if (res.code == 200) {
  235. let halls = res.list.sort((a, b) => {
  236. return a.zxjl - b.zxjl;
  237. });
  238. wx.setStorageSync("HALL_LIST", halls);
  239. that.setMyHall(halls);
  240. that.setData({
  241. myYy: res.yyjl,
  242. });
  243. } else {
  244. wx.showToast({
  245. title: res.msg || res.message,
  246. icon: "none",
  247. duration: 5000,
  248. });
  249. }
  250. });
  251. } else {
  252. setTimeout(() => {
  253. that.getHall();
  254. }, 500);
  255. }
  256. },
  257. setMyHall(e) {
  258. let that = this;
  259. let userinfo = wx.getStorageSync("USERINFO");
  260. let myhall = wx.getStorageSync("MY_HALL");
  261. if (myhall) {
  262. let update = false;
  263. for (let i = 0; i < e.length; i++) {
  264. if (e[i].bsfwtDm == myhall.bsfwtDm) {
  265. update = true;
  266. that.setData({
  267. hall: e[i],
  268. });
  269. that.setMarker(e[i]);
  270. wx.setStorageSync("MY_HALL", e[i]);
  271. break;
  272. }
  273. }
  274. if (!update) {
  275. that.setData({
  276. hall: myhall,
  277. });
  278. that.setMarker(myhall);
  279. }
  280. } else {
  281. if (userinfo.swjgdm) {
  282. let hall = {};
  283. let uswjgdm = userinfo.swjgdm.substring(0, 7);
  284. for (let i = 0; i < e.length; i++) {
  285. let hswjgdm = e[i].ssswjgDm.substring(0, 7);
  286. if (uswjgdm == hswjgdm) {
  287. hall = e[i];
  288. break;
  289. }
  290. }
  291. if (!hall.bsfwtmc) hall = e[0];
  292. that.setData({
  293. hall: hall,
  294. });
  295. wx.setStorageSync("MY_HALL", hall);
  296. that.setMarker(hall);
  297. } else {
  298. let hall = e[0];
  299. that.setData({
  300. hall: hall,
  301. });
  302. wx.setStorageSync("MY_HALL", hall);
  303. that.setMarker(hall);
  304. }
  305. }
  306. },
  307. setMarker(e) {
  308. let that = this;
  309. let lat = e.latitude || e.lat;
  310. let lng = e.longitude || e.lng;
  311. let marker = {
  312. id: 9527,
  313. latitude: lat,
  314. longitude: lng,
  315. title: "",
  316. zIndex: 9,
  317. alpha: 0.9,
  318. iconPath: "../../icon/address.png",
  319. width: "30rpx",
  320. height: "30rpx",
  321. callout: {
  322. content: "大厅地址",
  323. color: "#313131",
  324. textAlign: "center",
  325. fontSize: 10,
  326. borderRadius: 5,
  327. bgColor: "#ffffff",
  328. padding: 5,
  329. display: "ALWAYS",
  330. },
  331. };
  332. that.setData({
  333. markers: [marker],
  334. });
  335. },
  336. changeType() {
  337. let that = this;
  338. let authorize = getApp().globalData.authorize();
  339. if (authorize == 0) {
  340. let nsrmc = that.data.userInfo.nsrmc;
  341. if (nsrmc.length > 2) {
  342. wx.showLoading({
  343. title: "正在切换身份...",
  344. });
  345. let publicId = wx.getStorageSync("PUBLIC_ID");
  346. let form = {
  347. xcxId: publicId.openid,
  348. unionid: publicId.unionid,
  349. xm: that.data.userInfo.name,
  350. sfzjhm: that.data.userInfo.idcard,
  351. sjh: that.data.userInfo.phone,
  352. nsrmc: "",
  353. nsrsbh: "",
  354. swjgdm: "",
  355. };
  356. xcxsmbd(form).then((res) => {
  357. wx.hideLoading();
  358. if (res.code == 200) {
  359. that.getIndexInfos();
  360. that.close();
  361. } else {
  362. wx.showToast({
  363. title: res.msg || res.message,
  364. icon: "none",
  365. duration: 5000,
  366. });
  367. }
  368. });
  369. } else {
  370. that.changeEnterprice();
  371. }
  372. } else {
  373. let authorizeBox = this.selectComponent("#authorizeBox");
  374. authorizeBox.show();
  375. }
  376. },
  377. changeEnterprice() {
  378. let that = this;
  379. that.setData({
  380. enterPriceList: [],
  381. });
  382. let authorize = getApp().globalData.authorize();
  383. if (authorize == 0) {
  384. wx.showLoading({
  385. title: "正在获取企业信息",
  386. });
  387. that.setData({
  388. enterpriceTypeShow: true,
  389. });
  390. xcxGetCompanyList({
  391. xm: that.data.userInfo.name,
  392. sfzjhm: that.data.userInfo.idcard,
  393. }).then((res) => {
  394. wx.hideLoading();
  395. if (res.code == 200) {
  396. that.setData({
  397. enterPriceList: res.list,
  398. });
  399. } else {
  400. wx.showToast({
  401. title: res.msg || res.message,
  402. icon: "none",
  403. duration: 5000,
  404. });
  405. }
  406. });
  407. }
  408. },
  409. async selectEnterprice(e) {
  410. let that = this;
  411. wx.showLoading({
  412. title: "正在切换...",
  413. });
  414. let publicId = wx.getStorageSync("PUBLIC_ID");
  415. let item = e.currentTarget.dataset.item;
  416. let form = {
  417. xcxId: publicId.openid,
  418. unionid: publicId.unionid,
  419. xm: that.data.userInfo.name,
  420. sfzjhm: that.data.userInfo.idcard,
  421. sjh: that.data.userInfo.phone,
  422. nsrmc: item.nsrmc,
  423. nsrsbh: item.nsrsbh,
  424. swjgdm: (await that.getEnterpriceSwjgdm(item)) || "",
  425. };
  426. xcxsmbd(form).then((res) => {
  427. wx.hideLoading();
  428. if (res.code == 200) {
  429. that.close();
  430. let userinfo = {
  431. idcard: form.sfzjhm,
  432. name: form.xm,
  433. nsrmc: form.nsrmc,
  434. nsrsbh: form.nsrsbh,
  435. phone: form.sjh,
  436. swjgdm: form.swjgdm,
  437. };
  438. wx.setStorageSync("USERINFO", userinfo);
  439. that.setData({
  440. userInfo: userinfo,
  441. });
  442. wx.removeStorageSync("MY_HALL");
  443. that.setMyHall(wx.getStorageSync("HALL_LIST"));
  444. } else {
  445. wx.showToast({
  446. title: res.msg || res.message,
  447. icon: "none",
  448. duration: 5000,
  449. });
  450. }
  451. });
  452. },
  453. getEnterpriceSwjgdm(e) {
  454. return new Promise((resolve, rejects) => {
  455. let form = {
  456. djxh: e.djxh,
  457. nsrsbh: e.nsrsbh,
  458. };
  459. xcxGetCompanySwjg(form).then((res) => {
  460. if (res.code == 200) {
  461. resolve(res.swjgdm);
  462. } else {
  463. resolve(null);
  464. }
  465. });
  466. });
  467. },
  468. close() {
  469. let that = this;
  470. that.setData({
  471. enterpriceTypeShow: false,
  472. });
  473. },
  474. selectHall(e) {
  475. let that = this;
  476. let type = e.currentTarget.dataset.type;
  477. let authorize = getApp().globalData.authorize();
  478. if (authorize == 0) {
  479. wx.navigateTo({
  480. url: "../indexPages/selectHall/selectHall?type=" + type,
  481. });
  482. } else {
  483. let authorizeBox = this.selectComponent("#authorizeBox");
  484. authorizeBox.show();
  485. }
  486. },
  487. start(e) {
  488. let type = e.currentTarget.dataset.type;
  489. let authorize = getApp().globalData.authorize();
  490. if (authorize == 0) {
  491. wx.navigateTo({
  492. url: "../indexPages/selectBusiness/selectBusiness?type=" + type,
  493. });
  494. } else {
  495. let authorizeBox = this.selectComponent("#authorizeBox");
  496. authorizeBox.show();
  497. }
  498. },
  499. toYyDetail(e) {
  500. let item = e.currentTarget.dataset.item;
  501. wx.navigateTo({
  502. url: "../recordPages/yyjl/yyjl?infos=" + JSON.stringify(item),
  503. });
  504. },
  505. toLookSsqh() {
  506. wx.switchTab({
  507. url: "../record/record",
  508. });
  509. },
  510. startSmrz() {
  511. let authorizeBox = this.selectComponent("#authorizeBox");
  512. authorizeBox.show();
  513. },
  514. toSearch() {
  515. console.log("search");
  516. },
  517. indexSearchInput(e) {
  518. let that = this;
  519. let value = e.detail.value;
  520. that.setData({
  521. searchValue: value,
  522. });
  523. },
  524. startVoice() {
  525. let that = this;
  526. that.setData({
  527. showVoice: true,
  528. });
  529. },
  530. closeVoice() {
  531. let that = this;
  532. that.setData({
  533. showVoice: false,
  534. });
  535. },
  536. resVoice(e) {
  537. let that = this;
  538. let searchValue = that.data.searchValue;
  539. searchValue = searchValue + e.detail;
  540. that.setData({
  541. searchValue: searchValue,
  542. });
  543. that.closeVoice();
  544. },
  545. movableEnd() {
  546. let that = this;
  547. if (movableInfo) {
  548. that.setData({
  549. znzxX: movableInfo.x,
  550. znzxY: movableInfo.y,
  551. });
  552. movableInfo = null;
  553. }
  554. },
  555. movable(e) {
  556. let that = this;
  557. let now = e.detail;
  558. let x = 0;
  559. if (now.x > screenInfo / 2) {
  560. x = screenInfo;
  561. } else {
  562. x = 0;
  563. }
  564. movableInfo = {
  565. x: x,
  566. y: now.y,
  567. };
  568. },
  569. toZnzx() {
  570. wx.navigateTo({
  571. url: "../other/znzx/znzx",
  572. });
  573. },
  574. lbChage(e) {
  575. let that = this;
  576. that.setData({
  577. lbIndex: e.detail.current,
  578. });
  579. },
  580. swiperTap(e) {
  581. let item = e.currentTarget.dataset.item;
  582. switch (item.event) {
  583. case "navigate":
  584. wx.navigateTo({
  585. url: item.path,
  586. });
  587. break;
  588. case "miniProgram":
  589. wx.navigateToMiniProgram({
  590. appId: item.appId,
  591. fail(err) {
  592. wx.showToast({
  593. title: '跳转工行服务小程序失败',
  594. icon: "none"
  595. })
  596. }
  597. })
  598. break;
  599. default:
  600. break;
  601. }
  602. },
  603. /**
  604. * 生命周期函数--监听页面初次渲染完成
  605. */
  606. onReady() {},
  607. /**
  608. * 生命周期函数--监听页面显示
  609. */
  610. onShow() {
  611. let that = this;
  612. that.hqdw();
  613. that.getHall();
  614. that.getIndexInfos();
  615. let userInfo = wx.getStorageSync("USERINFO");
  616. that.setData({
  617. userInfo: userInfo,
  618. });
  619. },
  620. /**
  621. * 生命周期函数--监听页面隐藏
  622. */
  623. onHide() {},
  624. /**
  625. * 生命周期函数--监听页面卸载
  626. */
  627. onUnload() {},
  628. /**
  629. * 页面相关事件处理函数--监听用户下拉动作
  630. */
  631. onPullDownRefresh() {},
  632. /**
  633. * 页面上拉触底事件的处理函数
  634. */
  635. onReachBottom() {},
  636. /**
  637. * 用户点击右上角分享
  638. */
  639. onShareAppMessage() {},
  640. });