index.js 18 KB

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