index.vue 4.4 KB
<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>