selectHall.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. // pages/indexPages/selectHall/selectHall.js
  2. import {
  3. hqdw
  4. } from "../../../apis/index.js"
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. navigation: {},
  11. type: "",
  12. selectTab: [{
  13. label: "企业匹配的税务机关",
  14. value: "0"
  15. }, {
  16. label: "距离排序",
  17. value: "0"
  18. }, {
  19. label: "我的收藏",
  20. value: "1"
  21. }],
  22. selectTabIndex: 1,
  23. barStart: null,
  24. containerStyle: '',
  25. addressInfo: {},
  26. myHall: {},
  27. hall: [],
  28. nowHall: [],
  29. markers: [],
  30. searchText: "",
  31. searchTime: false
  32. },
  33. /**
  34. * 生命周期函数--监听页面加载
  35. */
  36. onLoad(options) {
  37. let that = this
  38. that.init(options)
  39. that.getNavigationBar()
  40. that.hqdw()
  41. },
  42. none() {
  43. return
  44. },
  45. init(e) {
  46. let that = this
  47. if (e) {
  48. if (e.type) {
  49. that.setData({
  50. type: e.type
  51. })
  52. }
  53. }
  54. },
  55. getNavigationBar() {
  56. let that = this
  57. const res = wx.getMenuButtonBoundingClientRect()
  58. let navigation = {
  59. width: res.left + 'px',
  60. height: res.height + 6 + 'px',
  61. paddingTop: res.top - 3 + 'px'
  62. }
  63. that.setData({
  64. navigation: navigation
  65. })
  66. },
  67. hqdw() {
  68. let that = this
  69. wx.getLocation({
  70. type: 'wgs84',
  71. isHighAccuracy: true,
  72. success(result) {
  73. that.setMarker(result)
  74. hqdw().then(res => {
  75. if (res.code == 200) {
  76. let data = JSON.parse(res.message)
  77. that.setData({
  78. addressInfo: {
  79. lat: result.latitude,
  80. lng: result.longitude,
  81. address: data.result.ad_info.district || data.result.ad_info.city || data.result.ad_info.province || data.result.ad_info.nation
  82. }
  83. })
  84. wx.setStorageSync('ADDRESS', data.result.ad_info.district || data.result.ad_info.city || data.result.ad_info.province || data.result.ad_info.nation)
  85. } else {
  86. that.setData({
  87. addressInfo: {
  88. lat: result.latitude,
  89. lng: result.longitude,
  90. address: "未知"
  91. }
  92. })
  93. wx.setStorageSync('ADDRESS', "未知")
  94. }
  95. })
  96. },
  97. fail: (err) => {
  98. hqdw().then(res => {
  99. if (res.code == 200) {
  100. let data = JSON.parse(res.message)
  101. that.setMarker(data.result)
  102. that.setData({
  103. addressInfo: {
  104. lat: data.result.location.lat,
  105. lng: data.result.location.lng,
  106. address: data.result.ad_info.district || data.result.ad_info.city || data.result.ad_info.province || data.result.ad_info.nation
  107. }
  108. })
  109. wx.setStorageSync('ADDRESS', data.result.ad_info.district || data.result.ad_info.city || data.result.ad_info.province || data.result.ad_info.nation)
  110. } else {
  111. that.setData({
  112. addressInfo: {
  113. lat: "",
  114. lng: "",
  115. address: "未知"
  116. }
  117. })
  118. wx.setStorageSync('ADDRESS', "未知")
  119. }
  120. })
  121. }
  122. })
  123. that.getHall()
  124. },
  125. getHall() {
  126. let that = this
  127. let myHall = wx.getStorageSync('MY_HALL')
  128. let index = that.data.selectTabIndex
  129. let hallList = wx.getStorageSync('HALL_LIST')
  130. if (index === 0) {
  131. let userinfo = wx.getStorageSync('USERINFO')
  132. if (userinfo.swjgdm) {
  133. let hall = []
  134. let uswjgdm = userinfo.swjgdm.substring(0, 7)
  135. for (let i = 0; i < hallList.length; i++) {
  136. let hswjgdm = hallList[i].ssswjgDm.substring(0, 7)
  137. if (uswjgdm == hswjgdm) {
  138. hall = hall.push(hallList[i])
  139. }
  140. }
  141. that.setData({
  142. hall: hall,
  143. myHall: myHall,
  144. nowHall: hall
  145. })
  146. } else {
  147. that.setData({
  148. hall: [],
  149. nowHall: [],
  150. myHall: myHall
  151. })
  152. }
  153. } else if (index === 1) {
  154. that.setData({
  155. hall: hallList,
  156. nowHall: hallList,
  157. myHall: myHall
  158. })
  159. } else {
  160. that.setData({
  161. hall: [],
  162. nowHall: [],
  163. myHall: myHall
  164. })
  165. }
  166. },
  167. selectHall(e) {
  168. let that = this
  169. let item = e.currentTarget.dataset.item
  170. wx.setStorageSync('MY_HALL', item)
  171. wx.navigateBack()
  172. },
  173. call(e) {
  174. let that = this
  175. let item = e.currentTarget.dataset.item
  176. wx.makePhoneCall({
  177. phoneNumber: item.kfdh,
  178. })
  179. },
  180. daohang(e) {
  181. let item = e.currentTarget.dataset.item
  182. wx.openLocation({
  183. latitude: Number(item.latitude),
  184. longitude: Number(item.longitude),
  185. scale: 18,
  186. name: item.bsfwtmc,
  187. address: item.bsfwtdz,
  188. complete: (res) => {
  189. console.log(res)
  190. }
  191. })
  192. },
  193. bardown(e) {
  194. let that = this
  195. that.setData({
  196. barStart: e.changedTouches[0].pageY
  197. })
  198. },
  199. barmove(e) {
  200. let that = this
  201. let barStart = that.data.barStart
  202. if (barStart) {
  203. let now = e.changedTouches[0].pageY
  204. let differ = now - barStart
  205. if (differ > 60) {
  206. that.setData({
  207. containerStyle: 'down'
  208. })
  209. } else if (differ < -60) {
  210. that.setData({
  211. containerStyle: ''
  212. })
  213. }
  214. }
  215. },
  216. setMarker(e) {
  217. let that = this
  218. let lat = e.latitude || e.lat
  219. let lng = e.longitude || e.lng
  220. let marker = {
  221. id: 9527,
  222. latitude: lat,
  223. longitude: lng,
  224. title: "",
  225. zIndex: 9,
  226. alpha: 0.9,
  227. iconPath: "../../../icon/address.png",
  228. width: "50rpx",
  229. height: "50rpx",
  230. callout: {
  231. content: "我的位置",
  232. color: "#313131",
  233. fontSize: 12,
  234. borderRadius: 5,
  235. bgColor: "#ffffff",
  236. padding: 5,
  237. display: "ALWAYS"
  238. }
  239. }
  240. that.setData({
  241. markers: [marker]
  242. })
  243. },
  244. back() {
  245. wx.navigateBack()
  246. },
  247. selectTab(e) {
  248. let that = this
  249. let index = e.currentTarget.dataset.index
  250. that.setData({
  251. selectTabIndex: index
  252. })
  253. let hallList = wx.getStorageSync('HALL_LIST')
  254. if (index === 0) {
  255. let userinfo = wx.getStorageSync('USERINFO')
  256. if (userinfo.swjgdm) {
  257. let hall = []
  258. let uswjgdm = userinfo.swjgdm.substring(0, 7)
  259. for (let i = 0; i < hallList.length; i++) {
  260. let hswjgdm = hallList[i].ssswjgDm.substring(0, 7)
  261. if (uswjgdm == hswjgdm) {
  262. hall = hall.push(hallList[i])
  263. }
  264. }
  265. that.setData({
  266. hall: hall,
  267. nowHall: hall
  268. })
  269. } else {
  270. that.setData({
  271. hall: [],
  272. nowHall: []
  273. })
  274. }
  275. } else if (index === 1) {
  276. that.setData({
  277. hall: hallList,
  278. nowHall: hallList
  279. })
  280. } else {
  281. that.setData({
  282. hall: [],
  283. nowHall: []
  284. })
  285. }
  286. },
  287. search(e) {
  288. let that = this
  289. let value = e.detail.value
  290. that.setData({
  291. searchText: value
  292. })
  293. that.startSearch(value)
  294. },
  295. startSearch(e) {
  296. let that = this
  297. let searchTime = that.data.searchTime
  298. if (e.length != 0) {
  299. if (!searchTime) {
  300. that.setData({
  301. searchTime: true
  302. })
  303. setTimeout(() => {
  304. /* */
  305. let hall = that.data.nowHall
  306. let newHall = hall.filter((item) => {
  307. return item.bsfwtmc.indexOf(e) != -1
  308. })
  309. that.setData({
  310. hall: newHall
  311. })
  312. /* */
  313. setTimeout(() => {
  314. that.setData({
  315. searchTime: false
  316. })
  317. }, 500);
  318. }, 0);
  319. }
  320. } else {
  321. that.getHall()
  322. }
  323. },
  324. // start(e) {
  325. // let type = e.currentTarget.dataset.type
  326. // wx.navigateTo({
  327. // url: '../selectBusiness/selectBusiness?type=' + type,
  328. // })
  329. // },
  330. /**
  331. * 生命周期函数--监听页面初次渲染完成
  332. */
  333. onReady() {
  334. },
  335. /**
  336. * 生命周期函数--监听页面显示
  337. */
  338. onShow() {
  339. },
  340. /**
  341. * 生命周期函数--监听页面隐藏
  342. */
  343. onHide() {
  344. },
  345. /**
  346. * 生命周期函数--监听页面卸载
  347. */
  348. onUnload() {
  349. },
  350. /**
  351. * 页面相关事件处理函数--监听用户下拉动作
  352. */
  353. onPullDownRefresh() {
  354. },
  355. /**
  356. * 页面上拉触底事件的处理函数
  357. */
  358. onReachBottom() {
  359. },
  360. /**
  361. * 用户点击右上角分享
  362. */
  363. onShareAppMessage() {
  364. }
  365. })