index.vue 1.6 KB

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