index.js 17 KB

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