index.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <view class="container">
  3. <serviceItem :item='init_list' :skipType='0'></serviceItem>
  4. <u-empty v-if="init_list.length == 0" mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png" > </u-empty>
  5. </view>
  6. </template>
  7. <script>
  8. import { getHomePageApi,getCurrentLocation } from '@/api/home';
  9. import serviceItem from '@/components/service/index.vue';
  10. export default{
  11. data(){
  12. return{
  13. queryParams:{
  14. region:null,//地区编码
  15. longitude:null,//经度
  16. latitude:null,//纬度
  17. },
  18. init_list:[]
  19. }
  20. },
  21. components:{
  22. serviceItem
  23. },
  24. mounted() {
  25. this.handlerInitLocation()
  26. },
  27. methods:{
  28. // 获取当前经纬度
  29. handlerInitLocation(){
  30. uni.getLocation({
  31. type: 'gcj02',
  32. success: res => {
  33. this.queryParams.longitude = res.longitude;
  34. this.queryParams.latitude = res.latitude;
  35. let point = {
  36. latitude: res.latitude,
  37. longitude: res.longitude
  38. }
  39. getCurrentLocation(point).then(rc=>{
  40. this.queryParams.region = rc.data.id
  41. this.handlerInitList()
  42. })
  43. },
  44. fail: (rs) => {
  45. uni.showToast({
  46. title:rs,
  47. icon:'none'
  48. })
  49. }
  50. });
  51. },
  52. // 初始化列表信息
  53. handlerInitList(){
  54. getHomePageApi(this.queryParams).then(res=>{
  55. this.init_list = res.data.nears
  56. this.total = res.data.nears.total
  57. })
  58. }
  59. }
  60. }
  61. </script>
  62. <style lang="scss" scoped>
  63. .container{
  64. }
  65. </style>