index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. // pages/home/index.js
  2. const app = getApp()
  3. const util = require('../../utils/util.js')
  4. const url = require('../../utils/url.js')
  5. const call = require("../../utils/net.js")
  6. var QQMapWX = require('../../libs/qqmap-wx-jssdk.js');
  7. var qqmapsdk;
  8. Page({
  9. //查看详情要进行授权
  10. getUserInfo(e){
  11. //console.log(e)
  12. let ids = e.currentTarget.dataset.ids;
  13. let title = e.currentTarget.dataset.title;
  14. var userId = wx.getStorageSync('userId');
  15. if (userId) {
  16. wx.navigateTo({
  17. url: '/pages/home/detail/detail?id=' + ids + '&title=' + title,
  18. })
  19. } else {
  20. if (e.detail.errMsg == 'getUserInfo:ok') {
  21. let reqData = {
  22. 'signature': e.detail.signature,
  23. 'rawData': e.detail.rawData
  24. }
  25. wx.login({
  26. success(res) {
  27. if (res.code) {
  28. let code = res.code
  29. reqData['code'] = code
  30. call.request(url.host + url.login,
  31. { code: res.code },
  32. res => {
  33. //console.log(res.data)
  34. wx.setStorageSync('userId', res.data.data); //将userId存入本地缓存
  35. if (res.data.code == 200) {
  36. call.request(url.host + url.getuserinfo,
  37. reqData,
  38. res => {
  39. wx.navigateTo({
  40. url: '/pages/home/detail/detail?id=' + ids + '&title=' + title,
  41. })
  42. //console.log(res)
  43. },
  44. res => {
  45. //console.log(res)
  46. })
  47. } else {
  48. wx.showToast({
  49. icon: 'none',
  50. title: res.data.msg,
  51. })
  52. }
  53. },
  54. res => {
  55. //console.log(res)
  56. })
  57. } else {
  58. console.log('登录失败!' + res.errMsg)
  59. }
  60. }
  61. })
  62. } else if (e.detail.errMsg == 'getUserInfo:fail auth deny') {
  63. wx.showToast({
  64. icon: 'none',
  65. title: '授权失败!',
  66. })
  67. }
  68. }
  69. },
  70. /**
  71. * 页面的初始数据
  72. */
  73. data: {
  74. collegeTips: "点击'添加到我的小程序'",
  75. showShopPopup: false, // 是否显示收藏提示层
  76. animationData: {}, // 动画数据
  77. host: url.host,
  78. city: '',
  79. search: {
  80. pla: "搜索 社保/公积金/身份证"
  81. },
  82. currentSwiper: 0,
  83. banner:[
  84. // { img: '../../icon/ad/banner1.png', link:"https://www.wodeshebao.com/tax/index.html"},
  85. ],
  86. menu:[
  87. // { imgPath: '../../icon/menu/shebao.png', typeName: '社保', id:"1" },
  88. // { imgPath: '../../icon/menu/gongjijin.png', typeName: '公积金', id: "1" },
  89. // { imgPath: '../../icon/menu/xingshijiashi.png', typeName: '行驶驾驶', id: "1" },
  90. // { imgPath: '../../icon/menu/shuiwu.png', typeName: '税务', id: "1" },
  91. // { imgPath: '../../icon/menu/huzheng.png', typeName: '户政', id: "1" },
  92. // { imgPath: '../../icon/menu/huzheng.png', typeName: '户政', id: "1" },
  93. ],
  94. region: ['便民查询', '新鲜服务', '常见问题'],
  95. convenience:[
  96. { img: '../../icon/ad/shebaodaijiao.png', name: '社保代缴' ,id:'1'},
  97. { img: '../../icon/ad/geshuijisuanqi.png', name: '个税计算器' ,id:'2'},
  98. { img: '../../icon/ad/yaolaojisuanqi.png', name: '养老金计算器',id: '3'}
  99. ],
  100. service:[
  101. // { img: '../../icon/ad/lala.png', title: '啦啦队签证旅游', msg: '签证 旅游 住宿', id: '5' },
  102. { img: '../../icon/ad/nearjob.png', title: '附近的工作', msg: '走路上班回家吃饭', id: '3' },
  103. { img: '../../icon/ad/banruoshangcheng.png', title: '般若商城', msg: '招财 姻缘 风水', id: '4' }
  104. ],
  105. question:{
  106. range:null
  107. }
  108. },
  109. /**
  110. * 生命周期函数--监听页面加载
  111. */
  112. onLoad: function (options) {
  113. var that = this;
  114. if (options.city){
  115. this.setData({
  116. city: options.city
  117. })
  118. app.globalData.city = options.city;
  119. }else{
  120. // 实例化API核心类
  121. qqmapsdk = new QQMapWX({
  122. key: 'UPWBZ-LYEK2-FFUUS-CVJFM-X26WO-DFBWF'
  123. });
  124. this.getUserLocation();//授权后进行定位
  125. }
  126. //获取首页数据
  127. call.getData(url.host + url.getIndex,
  128. res=>{
  129. //console.log(res)
  130. that.setData({
  131. banner: res.data.data.ads,
  132. menu:res.data.data.types
  133. })
  134. },
  135. res=>{
  136. console.log(res)
  137. });
  138. },
  139. /**
  140. * 生命周期函数--监听页面初次渲染完成
  141. */
  142. onReady: function () {
  143. },
  144. /**
  145. * 生命周期函数--监听页面显示
  146. */
  147. onShow: function () {
  148. this.setData({
  149. city: app.globalData.city
  150. })
  151. if (typeof this.getTabBar === 'function' &&
  152. this.getTabBar()) {
  153. this.getTabBar().setData({
  154. selected: 0
  155. })
  156. }
  157. var that = this;
  158. this.showModal();
  159. //请求城市的热门话题的标题列表
  160. call.request(url.host + url.getCityHotTitle,
  161. { city: app.globalData.city },
  162. res => {
  163. //console.log(res)
  164. let range = "question.range"
  165. that.setData({
  166. [range]: res.data.data
  167. })
  168. },
  169. res => {
  170. console.log(res)
  171. })
  172. },
  173. /**
  174. * 生命周期函数--监听页面隐藏
  175. */
  176. onHide: function () {
  177. },
  178. /**
  179. * 生命周期函数--监听页面卸载
  180. */
  181. onUnload: function () {
  182. },
  183. /**
  184. * 页面相关事件处理函数--监听用户下拉动作
  185. */
  186. onPullDownRefresh: function () {
  187. },
  188. /**
  189. * 页面上拉触底事件的处理函数
  190. */
  191. onReachBottom: function () {
  192. },
  193. /**
  194. * 用户点击右上角分享
  195. */
  196. onShareAppMessage: function () {
  197. },
  198. //当前轮播
  199. swiperChange: function (e) {
  200. //console.log(e.detail.source)
  201. if (e.detail.source == 'touch'){
  202. this.setData({
  203. currentSwiper: e.detail.current
  204. })
  205. }else{
  206. this.setData({
  207. currentSwiper: e.detail.current
  208. })
  209. }
  210. },
  211. //请求授权地理位置
  212. getUserLocation: function () {
  213. let that = this;
  214. wx.getSetting({
  215. success: (res) => {
  216. //console.log(res)
  217. // res.authSetting['scope.userLocation'] == undefined 表示 初始化进入该页面
  218. // res.authSetting['scope.userLocation'] == false 表示 非初始化进入该页面,且未授权
  219. // res.authSetting['scope.userLocation'] == true 表示 地理位置已授权
  220. if (res.authSetting['scope.userLocation'] != undefined && res.authSetting['scope.userLocation'] != true) {
  221. wx.showModal({
  222. title: '请求授权当前位置',
  223. content: '需要获取您的地理位置,请确认授权',
  224. success: function (res) {
  225. if (res.cancel) {
  226. wx.showToast({
  227. title: '拒绝授权',
  228. icon: 'none',
  229. duration: 1000
  230. })
  231. } else if (res.confirm) {
  232. wx.openSetting({
  233. success: function (dataAu) {
  234. if (dataAu.authSetting["scope.userLocation"] == true) {
  235. wx.showToast({
  236. title: '授权成功',
  237. icon: 'success',
  238. duration: 1000
  239. })
  240. //再次授权,调用wx.getLocation的API
  241. that.getLocation();
  242. } else {
  243. wx.showToast({
  244. title: '授权失败',
  245. icon: 'none',
  246. duration: 1000
  247. })
  248. }
  249. }
  250. })
  251. }
  252. }
  253. })
  254. } else if (res.authSetting['scope.userLocation'] == undefined) {
  255. //调用wx.getLocation的API
  256. that.getLocation();
  257. }
  258. else {
  259. //调用wx.getLocation的API
  260. that.getLocation();
  261. }
  262. }
  263. })
  264. },
  265. // 微信获得经纬度
  266. getLocation: function () {
  267. let that = this;
  268. wx.getLocation({
  269. type: 'wgs84',
  270. success: function (res) {
  271. //console.log(res)
  272. var latitude = res.latitude
  273. var longitude = res.longitude
  274. that.getLocal(latitude, longitude)
  275. },
  276. fail: function (res) {
  277. console.log(res)
  278. }
  279. })
  280. },
  281. // 获取当前地理位置
  282. getLocal: function (latitude, longitude) {
  283. let that = this;
  284. qqmapsdk.reverseGeocoder({
  285. location: {
  286. latitude: latitude,
  287. longitude: longitude
  288. },
  289. success: function (res) {
  290. // console.log(res)
  291. let city = res.result.ad_info.city
  292. city = city.replace('市','')
  293. app.globalData.city = city
  294. that.setData({
  295. city: city
  296. })
  297. },
  298. fail: function (res) {
  299. console.log(res);
  300. },
  301. complete: function (res) {
  302. // console.log(res);
  303. }
  304. });
  305. },
  306. //菜单搜索
  307. menusearch:function(e){
  308. let ids = e.currentTarget.dataset.ids;
  309. let title = e.currentTarget.dataset.title;
  310. wx.navigateTo({
  311. url: '/pages/home/problem/problem?ids=' + ids + '&title=' + title,
  312. })
  313. },
  314. //便民查询
  315. towxchat:function(e){
  316. let id = e.currentTarget.dataset.id;
  317. switch (id) {
  318. case "1": {
  319. wx.navigateToMiniProgram({
  320. appId: 'wxbf3f03f8a7d0cdcf',
  321. extraData: {
  322. },
  323. success(res) {
  324. console.log("跳转小程序成功")
  325. }
  326. });
  327. break
  328. }
  329. case "2": {
  330. wx.navigateToMiniProgram({
  331. appId: 'wx7379ad24baaaf660',
  332. extraData: {
  333. },
  334. success(res) {
  335. console.log("跳转小程序成功")
  336. }
  337. });
  338. break
  339. }
  340. case "3": {
  341. wx.navigateToMiniProgram({
  342. appId: 'wxcb0ec6ae8c422c3b',
  343. extraData: {
  344. },
  345. success(res) {
  346. console.log("跳转小程序成功")
  347. }
  348. });
  349. break
  350. }
  351. }
  352. },
  353. //新鲜服务-跳转小程序
  354. goAdWx(e) {
  355. let id = e.currentTarget.dataset.id
  356. switch (id) {
  357. case "3": {
  358. wx.navigateToMiniProgram({
  359. appId: 'wx0fdd65237732c014',
  360. extraData: {
  361. },
  362. success(res) {
  363. // 打开成功
  364. wx.reportAnalytics('click_service', {
  365. service_title: '职友集',
  366. });
  367. }
  368. });
  369. break
  370. }
  371. case "4": {
  372. wx.navigateToMiniProgram({
  373. appId: 'wx7ab08191e61478c5',
  374. extraData: {
  375. },
  376. success(res) {
  377. // 打开成功
  378. wx.reportAnalytics('click_service', {
  379. service_title: '般若商城',
  380. });
  381. }
  382. });
  383. break
  384. }
  385. // case "5": {
  386. // wx.navigateToMiniProgram({
  387. // appId: 'wxab59d3c94759d509',
  388. // extraData: {
  389. // },
  390. // success(res) {
  391. // // 打开成功
  392. // wx.reportAnalytics('click_service', {
  393. // service_title: '啦啦队签证旅游',
  394. // });
  395. // }
  396. // });
  397. // break
  398. // }
  399. }
  400. },
  401. //跳转城市地点
  402. positioning:function(){
  403. wx.navigateTo({
  404. url: '/pages/home/location/location',
  405. })
  406. },
  407. //常见问题跳详情
  408. toproblem: function (e) {
  409. let ids = e.currentTarget.dataset.ids;
  410. let title = e.currentTarget.dataset.title;
  411. wx.navigateTo({
  412. url: '/pages/home/detail/detail?id=' + ids + '&title=' + title,
  413. })
  414. },
  415. //搜索按钮
  416. confirm: util.throttle(function (e) {
  417. let word = e.detail.value;
  418. //查询接口
  419. if (word.match(/^\s*$/) || word == null || word == undefined || word == '') {
  420. wx.showToast({
  421. icon: 'none',
  422. title: '请输入搜索关键词!',
  423. })
  424. }else{
  425. wx.navigateTo({
  426. url: './search/search?word=' + word,
  427. })
  428. }
  429. }, 1000),
  430. toWeb:function(e){
  431. let link = e.currentTarget.dataset.link;
  432. wx.navigateTo({
  433. url: '/pages/home/webView/webView?link='+link,
  434. })
  435. },
  436. //显示提示
  437. showModal() {
  438. // 创建动画
  439. var animation = wx.createAnimation({
  440. duration: 1000,
  441. timingFunction: "ease-in-out",
  442. delay: 0
  443. })
  444. this.animation = animation
  445. animation.translateX(0).step()
  446. this.setData({
  447. animationData: animation.export(), // export 方法每次调用后会清掉之前的动画操作。
  448. showShopPopup: true
  449. })
  450. animation.translateX(-202).step()
  451. this.setData({
  452. animationData: animation.export(), // export 方法每次调用后会清掉之前的动画操作。
  453. showShopPopup: true
  454. })
  455. setTimeout(() => {
  456. animation.translateX(0).step()
  457. this.setData({
  458. animationData: animation.export(), // export 方法每次调用后会清掉之前的动画操作。
  459. showShopPopup: true
  460. })
  461. }, 2500)
  462. },
  463. })