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

no message

parent c1e3a70a
import Taro from '@tarojs/taro'
import BaseComponent from '@/helper/baseComponent';
import Taro, {Component} from '@tarojs/taro'
import { View, Image, Text, Swiper, SwiperItem, ScrollView, Button } from '@tarojs/components'
import { connect } from '@tarojs/redux'
import { setUserInfo } from '@/actions/user'
......@@ -14,10 +13,9 @@ import './index.scss'
dispatch(setUserInfo(data || {}))
},
}))
class Index extends BaseComponent {
class Index extends Component {
state = {
located: false
}
componentWillReceiveProps (nextProps) {
console.log(this.props, nextProps)
......@@ -31,18 +29,60 @@ class Index extends BaseComponent {
componentDidHide () { }
// 获取地址权限
// 获取地址授权
handleLocation() {
this.fetchLocation().then(res => {
this.setState({located: true})
}).catch(err => {
this.setState({located: true})
// 可以通过 wx.getSetting 先查询一下用户是否授权了 "scope.record" 这个 scope
Taro.getSetting({
success:function(res){
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(){
Taro.navigateTo({
url: '/pages/citySelect/index'
const {setUserInfo} = this.props
// 可以通过 wx.getSetting 先查询一下用户是否授权了 "scope.record" 这个 scope
Taro.chooseLocation({
success (res) {
setUserInfo(res)
},
fail (res) {
console.log(res)
}
})
}
// 跳转到门店详情
......@@ -51,20 +91,20 @@ class Index extends BaseComponent {
url: '/pages/storeDetail/index'
})
}
// 获取用户信息
bindGetUserInfo = e => {
//滚动页面触发
onScroll = (e) => {
console.log(e)
if (e.currentTarget.scrollTop > 275) {
console.log('出现搜索框')
} else {
console.log('隐藏搜索框')
}
// 获取手机号
bindGetPhoneNumber = e => {
console.log(e)
}
render () {
const {nav} = this.props
const titleTop = (nav.globalData.navHeight - nav.globalData.navTop - 17) / 2 + nav.globalData.navTop
const user = this.props.user;
console.log('user', user)
const noLoc = (!user || !user.longitude || !user.latitude);
return (
<View>
<NavBar pageName='首页' bgColor='#fff'>
......@@ -74,11 +114,14 @@ class Index extends BaseComponent {
onClick={this.selectCity}
>
<Image className='loc-icon' src='http://hh-oss-picture.miyapay.com/box/8dcd356a4ae1ff0c2c0ac9fd69733ab8.png' />
<Text className={`${noLoc ? 'no-loc' : ''}`}>{noLoc ? '未获取定位' : user.city}</Text>
</View>
</NavBar>
<Button openType='getUserInfo' onGetUserInfo={this.bindGetUserInfo}>授权登录</Button>
<Button openType='getPhoneNumber' onGetPhoneNumber={this.bindGetPhoneNumber}>授权手机号</Button>
<ScrollView
style="height: 508px"
className='scrollview'
scrollY
onScroll={this.onScroll}
>
<Swiper
className='swpier-view'
indicatorColor='#999'
......@@ -111,14 +154,20 @@ class Index extends BaseComponent {
<Text>领券中心</Text>
<Text>查看全部</Text>
</View>
<View className='store-list-title'>
<View className='store-list-title' id='store'>
<Text>附近门店</Text>
</View>
<View>
<ScrollView
className='scrollview'
scrollY
>
<View className='list-view' onClick={this.jumpDetail}>
<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' onClick={this.jumpDetail}>
<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'>
......@@ -169,8 +218,8 @@ class Index extends BaseComponent {
<Text>200m</Text>
</View>
</View>
</ScrollView>
</View>
</ScrollView>
</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