Commit 1715b0af authored by 陈潜's avatar 陈潜

no message

parent c1e3a70a
import Taro from '@tarojs/taro' import Taro, {Component} from '@tarojs/taro'
import BaseComponent from '@/helper/baseComponent';
import { View, Image, Text, Swiper, SwiperItem, ScrollView, Button } from '@tarojs/components' import { View, Image, Text, Swiper, SwiperItem, ScrollView, Button } from '@tarojs/components'
import { connect } from '@tarojs/redux' import { connect } from '@tarojs/redux'
import { setUserInfo } from '@/actions/user' import { setUserInfo } from '@/actions/user'
...@@ -14,10 +13,9 @@ import './index.scss' ...@@ -14,10 +13,9 @@ import './index.scss'
dispatch(setUserInfo(data || {})) dispatch(setUserInfo(data || {}))
}, },
})) }))
class Index extends BaseComponent { class Index extends Component {
state = { state = {
located: false
} }
componentWillReceiveProps (nextProps) { componentWillReceiveProps (nextProps) {
console.log(this.props, nextProps) console.log(this.props, nextProps)
...@@ -31,18 +29,60 @@ class Index extends BaseComponent { ...@@ -31,18 +29,60 @@ class Index extends BaseComponent {
componentDidHide () { } componentDidHide () { }
// 获取地址权限 // 获取地址授权
handleLocation() { handleLocation() {
this.fetchLocation().then(res => { // 可以通过 wx.getSetting 先查询一下用户是否授权了 "scope.record" 这个 scope
this.setState({located: true}) Taro.getSetting({
}).catch(err => { success:function(res){
this.setState({located: true}) if (!res.authSetting['scope.userLocation']) {
console.log("-------------不满足scope.userLocation权限----------");
//申请授权
Taro.authorize({
scope: 'scope.userLocation',
success() {},
fail () {
Taro.showModal({
title: '是否授权当前位置',
content: '需要获取您的地理位置,请确认授权,否则地图功能将无法使用',
success: function (tip) {
if (tip.confirm) {
Taro.openSetting({
success: function (data) {
if (data.authSetting["scope.userLocation"] === true) {
Taro.showToast({
title: '授权成功',
icon: 'success',
duration: 1000
})
} else {
Taro.showToast({
title: '授权失败',
icon: 'success',
duration: 1000
})
}
}
})
}
}
})
}
})
}
}
}) })
} }
// 手动选择地址 // 手动选择地址
selectCity(){ selectCity(){
Taro.navigateTo({ const {setUserInfo} = this.props
url: '/pages/citySelect/index' // 可以通过 wx.getSetting 先查询一下用户是否授权了 "scope.record" 这个 scope
Taro.chooseLocation({
success (res) {
setUserInfo(res)
},
fail (res) {
console.log(res)
}
}) })
} }
// 跳转到门店详情 // 跳转到门店详情
...@@ -51,20 +91,20 @@ class Index extends BaseComponent { ...@@ -51,20 +91,20 @@ class Index extends BaseComponent {
url: '/pages/storeDetail/index' url: '/pages/storeDetail/index'
}) })
} }
// 获取用户信息 //滚动页面触发
bindGetUserInfo = e => { onScroll = (e) => {
console.log(e)
}
// 获取手机号
bindGetPhoneNumber = e => {
console.log(e) console.log(e)
if (e.currentTarget.scrollTop > 275) {
console.log('出现搜索框')
} else {
console.log('隐藏搜索框')
}
} }
render () { render () {
const {nav} = this.props const {nav} = this.props
const titleTop = (nav.globalData.navHeight - nav.globalData.navTop - 17) / 2 + nav.globalData.navTop const titleTop = (nav.globalData.navHeight - nav.globalData.navTop - 17) / 2 + nav.globalData.navTop
const user = this.props.user; const user = this.props.user;
console.log('user', user) console.log('user', user)
const noLoc = (!user || !user.longitude || !user.latitude);
return ( return (
<View> <View>
<NavBar pageName='首页' bgColor='#fff'> <NavBar pageName='首页' bgColor='#fff'>
...@@ -74,11 +114,14 @@ class Index extends BaseComponent { ...@@ -74,11 +114,14 @@ class Index extends BaseComponent {
onClick={this.selectCity} onClick={this.selectCity}
> >
<Image className='loc-icon' src='http://hh-oss-picture.miyapay.com/box/8dcd356a4ae1ff0c2c0ac9fd69733ab8.png' /> <Image className='loc-icon' src='http://hh-oss-picture.miyapay.com/box/8dcd356a4ae1ff0c2c0ac9fd69733ab8.png' />
<Text className={`${noLoc ? 'no-loc' : ''}`}>{noLoc ? '未获取定位' : user.city}</Text>
</View> </View>
</NavBar> </NavBar>
<Button openType='getUserInfo' onGetUserInfo={this.bindGetUserInfo}>授权登录</Button> <ScrollView
<Button openType='getPhoneNumber' onGetPhoneNumber={this.bindGetPhoneNumber}>授权手机号</Button> style="height: 508px"
className='scrollview'
scrollY
onScroll={this.onScroll}
>
<Swiper <Swiper
className='swpier-view' className='swpier-view'
indicatorColor='#999' indicatorColor='#999'
...@@ -111,66 +154,72 @@ class Index extends BaseComponent { ...@@ -111,66 +154,72 @@ class Index extends BaseComponent {
<Text>领券中心</Text> <Text>领券中心</Text>
<Text>查看全部</Text> <Text>查看全部</Text>
</View> </View>
<View className='store-list-title'> <View className='store-list-title' id='store'>
<Text>附近门店</Text> <Text>附近门店</Text>
</View> </View>
<View> <View>
<ScrollView <View className='list-view' onClick={this.jumpDetail}>
className='scrollview' <Image className='img' src='https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1586229157&di=6997346b65b0e2e2ff7a733ae9b5fcc5&src=http://a3.att.hudong.com/14/75/01300000164186121366756803686.jpg' />
scrollY <View className='text-cont'>
> <Text>米雅遍历(北京店)</Text>
<View className='list-view' onClick={this.jumpDetail}> <Text>营业时间 10:00 - 18:00</Text>
<Image className='img' src='https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1586229157&di=6997346b65b0e2e2ff7a733ae9b5fcc5&src=http://a3.att.hudong.com/14/75/01300000164186121366756803686.jpg' /> </View>
<View className='text-cont'> <View className='distance'>
<Text>米雅遍历(北京店)</Text> <Text>200m</Text>
<Text>营业时间 10:00 - 18:00</Text> </View>
</View> </View>
<View className='distance'> <View className='list-view' onClick={this.jumpDetail}>
<Text>200m</Text> <Image className='img' src='https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1586229157&di=6997346b65b0e2e2ff7a733ae9b5fcc5&src=http://a3.att.hudong.com/14/75/01300000164186121366756803686.jpg' />
</View> <View className='text-cont'>
<Text>米雅遍历(北京店)</Text>
<Text>营业时间 10:00 - 18:00</Text>
</View>
<View className='distance'>
<Text>200m</Text>
</View>
</View>
<View className='list-view'>
<Image className='img' src='https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1586229157&di=6997346b65b0e2e2ff7a733ae9b5fcc5&src=http://a3.att.hudong.com/14/75/01300000164186121366756803686.jpg' />
<View className='text-cont'>
<Text>米雅遍历(北京店)</Text>
<Text>营业时间 10:00 - 18:00</Text>
</View>
<View className='distance'>
<Text>200m</Text>
</View>
</View>
<View className='list-view'>
<Image className='img' src='https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1586229157&di=6997346b65b0e2e2ff7a733ae9b5fcc5&src=http://a3.att.hudong.com/14/75/01300000164186121366756803686.jpg' />
<View className='text-cont'>
<Text>米雅遍历(北京店)</Text>
<Text>营业时间 10:00 - 18:00</Text>
</View> </View>
<View className='list-view'> <View className='distance'>
<Image className='img' src='https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1586229157&di=6997346b65b0e2e2ff7a733ae9b5fcc5&src=http://a3.att.hudong.com/14/75/01300000164186121366756803686.jpg' /> <Text>200m</Text>
<View className='text-cont'>
<Text>米雅遍历(北京店)</Text>
<Text>营业时间 10:00 - 18:00</Text>
</View>
<View className='distance'>
<Text>200m</Text>
</View>
</View> </View>
<View className='list-view'> </View>
<Image className='img' src='https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1586229157&di=6997346b65b0e2e2ff7a733ae9b5fcc5&src=http://a3.att.hudong.com/14/75/01300000164186121366756803686.jpg' /> <View className='list-view'>
<View className='text-cont'> <Image className='img' src='https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1586229157&di=6997346b65b0e2e2ff7a733ae9b5fcc5&src=http://a3.att.hudong.com/14/75/01300000164186121366756803686.jpg' />
<Text>米雅遍历(北京店)</Text> <View className='text-cont'>
<Text>营业时间 10:00 - 18:00</Text> <Text>米雅遍历(北京店)</Text>
</View> <Text>营业时间 10:00 - 18:00</Text>
<View className='distance'> </View>
<Text>200m</Text> <View className='distance'>
</View> <Text>200m</Text>
</View> </View>
<View className='list-view'> </View>
<Image className='img' src='https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1586229157&di=6997346b65b0e2e2ff7a733ae9b5fcc5&src=http://a3.att.hudong.com/14/75/01300000164186121366756803686.jpg' /> <View className='list-view'>
<View className='text-cont'> <Image className='img' src='https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1586229157&di=6997346b65b0e2e2ff7a733ae9b5fcc5&src=http://a3.att.hudong.com/14/75/01300000164186121366756803686.jpg' />
<Text>米雅遍历(北京店)</Text> <View className='text-cont'>
<Text>营业时间 10:00 - 18:00</Text> <Text>米雅遍历(北京店)</Text>
</View> <Text>营业时间 10:00 - 18:00</Text>
<View className='distance'>
<Text>200m</Text>
</View>
</View> </View>
<View className='list-view'> <View className='distance'>
<Image className='img' src='https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1586229157&di=6997346b65b0e2e2ff7a733ae9b5fcc5&src=http://a3.att.hudong.com/14/75/01300000164186121366756803686.jpg' /> <Text>200m</Text>
<View className='text-cont'>
<Text>米雅遍历(北京店)</Text>
<Text>营业时间 10:00 - 18:00</Text>
</View>
<View className='distance'>
<Text>200m</Text>
</View>
</View> </View>
</ScrollView> </View>
</View> </View>
</ScrollView>
</View> </View>
) )
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment