|
@@ -43,16 +43,16 @@
|
|
|
<view class="home-list">
|
|
|
<u-grid :border="false" col="5">
|
|
|
<u-grid-item
|
|
|
- v-for="(listItem, listIndex) in list1"
|
|
|
- :key="listIndex"
|
|
|
- @tap="$Router.push(listItem.url)"
|
|
|
+ v-for="(item, index) in categories"
|
|
|
+ :key="item.id"
|
|
|
+ @tap="handleMenuClick(item)"
|
|
|
>
|
|
|
<u-icon
|
|
|
:customStyle="{ paddingTop: 20 + 'rpx' }"
|
|
|
- :name="listItem.name"
|
|
|
+ :name="item.icon"
|
|
|
:size="25"
|
|
|
></u-icon>
|
|
|
- <text class="grid-text">{{ listItem.title }}</text>
|
|
|
+ <text class="grid-text">{{ item.name }}</text>
|
|
|
</u-grid-item>
|
|
|
</u-grid>
|
|
|
<u-toast ref="uToast" />
|
|
@@ -67,7 +67,7 @@
|
|
|
>
|
|
|
<view slot="title" class="hot-title"> 热门推荐 </view>
|
|
|
</u-cell>
|
|
|
- <block v-if="homeData.recommends&&homeData.recommends.length > 0">
|
|
|
+ <block v-if="homeData.recommends && homeData.recommends.length > 0">
|
|
|
<view>
|
|
|
<u-grid :border="false" col="2">
|
|
|
<u-grid-item
|
|
@@ -99,7 +99,7 @@
|
|
|
>
|
|
|
<view slot="title" class="near-title"> 附近商家 </view>
|
|
|
</u-cell>
|
|
|
- <block v-if="homeData.nears&&homeData.nears.length > 0">
|
|
|
+ <block v-if="homeData.nears && homeData.nears.length > 0">
|
|
|
<view>
|
|
|
<u-grid :border="false" col="2">
|
|
|
<u-grid-item
|
|
@@ -125,7 +125,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { getHomePage } from '@/api/home';
|
|
|
+import { getHomePage, getCurrentLocation } from '@/api/home';
|
|
|
import { mapGetters } from 'vuex';
|
|
|
import RecommendItem from '@/components/merchant/RecommendItem.vue';
|
|
|
import HotItem from '@/components/merchant/HotItem.vue';
|
|
@@ -144,71 +144,8 @@ export default {
|
|
|
'https://cdn.uviewui.com/uview/swiper/swiper2.png',
|
|
|
'https://cdn.uviewui.com/uview/swiper/swiper3.png',
|
|
|
],
|
|
|
- list1: [
|
|
|
- {
|
|
|
- name: 'photo',
|
|
|
- title: '养车',
|
|
|
- url: '/pages/business/classify/index',
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'lock',
|
|
|
- title: '福利',
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'star',
|
|
|
- title: '分类',
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'hourglass',
|
|
|
- title: '自驾游',
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'home',
|
|
|
- title: '门店',
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'photo',
|
|
|
- title: '养车',
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'lock',
|
|
|
- title: '福利',
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'star',
|
|
|
- title: '分类',
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'hourglass',
|
|
|
- title: '自驾游',
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'home',
|
|
|
- title: '门店',
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'photo',
|
|
|
- title: '养车',
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'lock',
|
|
|
- title: '福利',
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'star',
|
|
|
- title: '分类',
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'hourglass',
|
|
|
- title: '自驾游',
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'home',
|
|
|
- title: '门店',
|
|
|
- },
|
|
|
- ],
|
|
|
homeData: {
|
|
|
- categories:[],
|
|
|
+ categories: [],
|
|
|
nears: [],
|
|
|
recommends: [],
|
|
|
},
|
|
@@ -229,6 +166,27 @@ export default {
|
|
|
}
|
|
|
return 1;
|
|
|
},
|
|
|
+ categories() {
|
|
|
+ let initData = this.homeData.categories.map(item => {
|
|
|
+ if (!item.icon) {
|
|
|
+ item.icon = 'level';
|
|
|
+ }
|
|
|
+ return item;
|
|
|
+ });
|
|
|
+ let result =
|
|
|
+ initData.length > 14
|
|
|
+ ? initData
|
|
|
+ .splice(0, 14)
|
|
|
+ .concat([
|
|
|
+ {
|
|
|
+ icon: 'grid-fill',
|
|
|
+ name: '全部',
|
|
|
+ type: { code: 'ALL', description: '全部' },
|
|
|
+ },
|
|
|
+ ])
|
|
|
+ : initData.push({ icon: 'grid-fill', name: '全部' });
|
|
|
+ return result;
|
|
|
+ },
|
|
|
},
|
|
|
onPageScroll(e) {
|
|
|
this.scrollTop = e.scrollTop;
|
|
@@ -257,17 +215,19 @@ export default {
|
|
|
click(name) {
|
|
|
this.$refs.uToast.success(`点击了第${name}个`);
|
|
|
},
|
|
|
+ // 获取首页数据
|
|
|
getHomeData(location) {
|
|
|
getHomePage(location)
|
|
|
.then(res => {
|
|
|
this.homeData = res.data;
|
|
|
// 将分类数据做缓存处理
|
|
|
- this.$store.commit('SET_CATEGORIES',this.homeData.categories)
|
|
|
+ this.$store.commit('SET_CATEGORIES', this.homeData.categories);
|
|
|
})
|
|
|
.catch(err => {
|
|
|
console.log(err);
|
|
|
});
|
|
|
},
|
|
|
+ // 手动选择城市
|
|
|
manualGetLocation() {
|
|
|
uni.chooseLocation({
|
|
|
success: res => {
|
|
@@ -278,11 +238,20 @@ export default {
|
|
|
},
|
|
|
});
|
|
|
},
|
|
|
+ // 点击菜单
|
|
|
+ handleMenuClick(item){
|
|
|
+ uni.showToast({
|
|
|
+ title:'跳转至分类页面',
|
|
|
+ icon:'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
watch: {
|
|
|
location: {
|
|
|
- handler: function (newVal, oldVal) {
|
|
|
- this.getHomeData(newVal);
|
|
|
+ handler: async function (newVal, oldVal) {
|
|
|
+ const result = await getCurrentLocation(newVal);
|
|
|
+ const param = Object.assign({}, { region: result.data.id }, newVal);
|
|
|
+ this.getHomeData(param);
|
|
|
},
|
|
|
},
|
|
|
},
|
|
@@ -333,6 +302,7 @@ export default {
|
|
|
background-color: #ffffff;
|
|
|
height: 360rpx;
|
|
|
margin: 0 20rpx 20rpx 20rpx;
|
|
|
+ padding: 20rpx 0;
|
|
|
border-radius: 10rpx;
|
|
|
|
|
|
.grid-text {
|