index.vue
4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<template>
<view class="content">
<view class="showBac">
<view class="seave" @click="GoSearch">
<van-search :value="value" placeholder="搜索" />
</view>
<view style="margin: 0 32rpx; margin-top: 104rpx;">
<swiper :autoplay="true" :indicator-dots="true" :current="swiperIndex" style="height:320rpx;">
<swiper-item v-for="(item,index) in dataList" :key="index" @click="GoSwiper(item.id)">
<view class="swiper-item">
<image :src="item" style="width:688rpx;height:320rpx;"></image>
</view>
</swiper-item>
</swiper>
</view>
<view style="display:flex;flex-wrap: wrap;padding: 32rpx 0;background: #ffffff;">
<scroll-view class="scroll-view_H" scroll-x="true" bindscroll="scroll" style="width: 100%">
<view style="display:flex;">
<view v-for="(item,index) in TabList" :key="index" @click="CheckTab()" class="topTab"
v-if="index<tabTopIndex">
<image :src="item.image" mode="" style="width: 88rpx;height: 88rpx;"></image>
<text class="title">{{item.title}}</text>
</view>
</view>
<view style="display:flex;">
<view v-for="(item,index) in TabList" :key="index" @click="CheckTab()" class="topTab"
v-if="index>=tabTopIndex">
<image :src="item.image" mode="" style="width: 88rpx;height: 88rpx;"></image>
<text class="title">{{item.title}}</text>
</view>
</view>
</scroll-view>
</view>
<view class="tbt">
<text class="reTui">最热推荐</text>
</view>
<view class="spin">
<view v-for="(item,index) in shopping" :key="index" class="pinBox" @click="goGoddDetail(item.id)">
<image :src="item.image" mode="" style="width: 336rpx;height: 336rpx;"></image>
<view style="margin: 0 24rpx; padding-bottom: 16rpx;box-sizing: border-box;">
<view class="unTitle">{{item.title}}</view>
<view style="text-align: end;">
<text class="fu">¥</text>
<text class="money">{{item.price}}</text>
</view>
</view>
</view>
</view>
</view>
</view>
</template>
<script>
import request from '../../utils/request.js'
export default {
data() {
return {
//输入值
value: '',
swiperIndex: 0,
dataList: [], //轮播图
shopping: [], //最热推荐
tabTopIndex: '',
TabList: [], //分类
}
},
onLoad() {
this.getData()
//计算scroll长度
let length = this.TabList.length
this.getLocations() //获取定位
},
methods: {
//获取定位
getLocations() {
let that = this
uni.getLocation({
type: 'gcj02',
altitude: true,
success(r) {
uni.setStorageSync('lat', r.latitude)
uni.setStorageSync('lot', r.longitude)
uni.request({
url: 'https://apis.map.qq.com/ws/geocoder/v1',
data: {
key: 'Y4PBZ-MBQ3Q-XSV5A-GWLXE-HXV4E-JNB3P',
location: (r.latitude + "," + r.longitude)
},
success: res => {
console.log(res,'res')
// wx.setStorageSync('locationCity', res.data.result.address_component
// .city)
// wx.setStorageSync('nowlocationCity', res.data.result.address_component
// .city)
// wx.setStorageSync('City', res.data.result.formatted_addresses
// .recommend)
// wx.setStorageSync('nowAddres', res.data.result.formatted_addresses
// .recommend)
// if (uni.getStorageSync("City") == "") {
// that.addressText = res.data.result.address_component.city
// } else {
// that.addressText = uni.getStorageSync("City")
// }
}
})
},
fail(err) {}
})
},
//获取轮播图 分类商品 商品
getData() {
request.get('/api/goods/index?page=1', {}).then(res => {
let bannerLit = res.data.banner
bannerLit.forEach((item, index) => {
this.dataList.push(item.image)
})
this.TabList = res.data.navigation
this.shopping = res.data.godos.data
let length = this.TabList.length
this.tabTopIndex = Number(length / 2).toFixed(0)
console.log(Number(length / 2).toFixed(0), 'length')
}).catch(err => {
})
},
//查看商品详情
goGoddDetail(id) {
uni.navigateTo({
url: '/pages/index/goodDeatil?id=' + id
})
},
//点图标
CheckTab() {
},
//跳转搜索页
GoSearch() {
uni.navigateTo({
url: '/pages/index/searchPage'
})
}
}
}
</script>
<style>
@import url("/common/index.css");
</style>