优惠券,登录跳转,h5注册

This commit is contained in:
chenhui0212
2019-03-06 18:46:42 +08:00
parent 650a31579d
commit 995c7883c8
14 changed files with 373 additions and 96 deletions

View File

@@ -1,7 +1,7 @@
import req from './req'
export function search (params = {}) {
return req.get('http://pjj.aixue7.com/index.php/api/wxapp/goods/items', params)
return req.get('http://pjj.aixue7.com/index.php/api/h5app/wxapp/goods/items', params)
}
export function detail (item_id) {
@@ -18,4 +18,4 @@ export function rateList (item_id) {
export function category () {
return req.get('/category.itemCategory')
}
}

View File

@@ -123,4 +123,4 @@ export default new API({
// }
})
export { API }
export { API }

View File

@@ -21,6 +21,7 @@ class App extends Component {
'pages/home/index',
'pages/item/list',
'pages/item/detail',
'pages/item/point-list',
'pages/cart/index',
'pages/cart/checkout',
@@ -35,7 +36,7 @@ class App extends Component {
'pages/member/index',
'pages/member/favorite',
'pages/member/integral',
'pages/member/point',
'pages/member/pay',
'pages/member/recharge',
'pages/member/recommend',

View File

@@ -23,6 +23,9 @@ export default class Login extends Component {
url: `/pages/auth/reg`
})
}
componentDidMount() {
console.log(Taro.getCurrentPages(), 44)
}
handleSubmit = async (e) => {
const { value } = e.detail
@@ -38,8 +41,22 @@ export default class Login extends Component {
return S.toast('请输入密码')
}
console.log(data, 19)
const { UserInfo } = await api.user.login(data)
console.log(UserInfo)
await api.user.login(data).then(res => {
S.setAuthToken(res.token)
console.log(res, 43)
if (Taro.getCurrentPages().length > 1) {
Taro.navigateBack({
delta: 1
});
} else {
Taro.redirectTo({
url: "/pages/home/index"
})
}
// Taro.navigateBack()
// let currentPages = Taro.getCurrentPages()
// Taro.navigateBack({ delta: Taro.getCurrentPages().length - 1 })
})
}
handleChange = (name, val) => {

View File

@@ -2,7 +2,7 @@ import Taro, { Component } from '@tarojs/taro'
import { View, Text, Picker } from '@tarojs/components'
import { AtForm, AtInput, AtButton } from 'taro-ui'
import { SpToast, Timer } from '@/components'
import { classNames } from '@/utils'
import { classNames, isString } from '@/utils'
import S from '@/spx'
import api from '@/api'
@@ -17,18 +17,19 @@ export default class Reg extends Component {
timerMsg: '获取验证码',
isVisible: false,
list: [],
selectorChecked: {},
// dateSel: '2018-04-22'
}
}
componentDidMount () {
console.log(Taro.getEnv())
if (Taro.getEnv() === 'WEAPP') {
this.setState({
info: {
user_type: 'wechat'
}
})
}else if (Taro.getEnv() === 'H5') {
}else if (Taro.getEnv() === 'WEB') {
this.setState({
info: {
user_type: 'local'
@@ -38,7 +39,11 @@ export default class Reg extends Component {
this.fetch()
}
// onDateChange = e => {
// this.setState({
// dateSel: e.detail.value
// })
// }
async fetch () {
let arr = []
let res = await api.user.regParam()
@@ -47,6 +52,9 @@ export default class Reg extends Component {
if(key === 'sex'){
res[key].items = ['男', '女']
}
if(key === 'birthday'){
res[key].items = []
}
arr.push({
key: key,
name: res[key].name,
@@ -82,6 +90,7 @@ export default class Reg extends Component {
this.state.list.map(item=>{
return item.is_required ? (item.is_required && data[item.key] ? true : S.toast(`请输入${item.name}`)) : null
})
console.log(data)
const { UserInfo } = await api.user.reg(data)
console.log(UserInfo)
@@ -90,13 +99,19 @@ export default class Reg extends Component {
handleChange = (name, val) => {
const { info, list } = this.state
info[name] = val
if(val.currentTarget){
if(val.currentTarget.dataset.item) {
info[name] = val.currentTarget.dataset.item.items[val.detail.value]
list.map(item => {
item.key === name ? item.value = val.currentTarget.dataset.item.items[val.detail.value] : null
})
}
if(!isString(val)) {
list.map(item => {
item.key === name ? info[name] = val.detail.value : null
if(name === 'birthday') {
item.key === name ? item.value = val.detail.value : null
} else {
item.key === name ? (item.items ? item.value = item.items[val.detail.value] : item.value = val.detail.value) : null
}
})
} else {
list.map(item => {
item.key === name ? item.value = val : null
})
}
this.setState({ list });
if(name === 'sex') {
@@ -203,27 +218,34 @@ export default class Reg extends Component {
{
item.items
? <View className='page-section'>
<View>
<Picker
mode='selector'
range={item.items}
data-item={item}
onChange={this.handleChange.bind(this, `${item.key}`)}
>
<View className='picker'>
<View className='picker__title'>{item.name}</View>
<Text
className={classNames(item.value ? 'pick-value' : 'pick-value-null')}
>{item.value ? item.value : `请选择${item.name}`}</Text>
</View>
</Picker>
<View key={index}>
{
item.key === 'birthday'
? <Picker mode='date' onChange={this.handleChange.bind(this, `${item.key}`)}>
<View className='picker'>
<View className='picker__title'>{item.name}</View>
<Text
className={classNames(item.value ? 'pick-value' : 'pick-value-null')}
>{item.value ? item.value : `请选择${item.name}`}</Text>
</View>
</Picker>
: <Picker mode='selector' range={item.items} key={index} data-item={item} onChange={this.handleChange.bind(this, `${item.key}`)}>
<View className='picker'>
<View className='picker__title'>{item.name}</View>
<Text
className={classNames(item.value ? 'pick-value' : 'pick-value-null')}
>{item.value ? item.value : `请选择${item.name}`}</Text>
</View>
</Picker>
}
</View>
</View>
: <View>
: <View key={index}>
<AtInput
title={item.name}
name='text'
key={index}
title={item.name} name={`${item.key}`}
placeholder={`请输入${item.name}`}
value={item.value}
onFocus={this.handleErrorToastClose}
onChange={this.handleChange.bind(this, `${item.key}`)}
/>

View File

@@ -21,7 +21,7 @@
margin: 0 0 $edge-size;
display: flex;
justify-content: flex-start;
border-bottom: 1PX solid rgba($color-brand-primary, 0.5);
border-bottom: 1PX solid rgba($color-brand-primary, 0.2);
&__title {
font-size: $font-size;
margin-right:16px;
@@ -30,7 +30,10 @@
.pick-value {
color: #333;
}
.pick-value-null {
span.pick-value-null {
color: #ccc;
}
text.pick-value-null {
color: #808080;
}
}

View File

@@ -10,7 +10,8 @@ export default class Index extends Component {
componentWillMount () {
if (process.env.NODE_ENV === 'development') {
Taro.redirectTo({
url: '/pages/member/coupon'
url: '/pages/item/point-list'
// url: '/pages/auth/login'
})
}
}

View File

@@ -0,0 +1,170 @@
import Taro, { Component } from '@tarojs/taro'
import { View, ScrollView } from '@tarojs/components'
import { withPager, withBackToTop } from '@/hocs'
import { BackToTop, Loading, FilterBar, SearchBar, GoodsItem } from '@/components'
import api from '@/api'
import { pickBy } from '@/utils'
import './point-list.scss'
@withPager
@withBackToTop
export default class List extends Component {
constructor (props) {
super(props)
this.state = {
...this.state,
curFilterIdx: 0,
filterList: [
{ title: '综合' },
{ title: '销量' },
{ title: '价格', sort: -1 }
],
query: null,
list: [],
listType: ''
}
}
componentDidMount () {
this.setState({
query: {
// keywords: '',
// distributor_id: 16,
// item_type: 'normal',
// approve_status: 'onsale,only_show',
// category: this.$router.params.cat_id
}
}, () => {
this.nextPage()
})
}
async fetch (params) {
const { page_no: page, page_size: pageSize } = params
const query = {
...this.state.query,
page,
pageSize
}
const { list, total_count: total } = await api.item.search(query)
const nList = pickBy(list, {
img: 'pics[0]',
item_id: 'item_id',
title: 'itemName',
desc: 'brief',
price: ({ price }) => (price/100).toFixed(2),
market_price: ({ market_price }) => (market_price/100).toFixed(2)
})
this.setState({
list: [...this.state.list, ...nList],
query
})
return {
total
}
}
handleFilterChange = (data) => {
const { current, sort } = data
const query = {
...this.state.query,
goodsSort: current === 0
? null
: current === 1
? 1
: (sort > 0 ? 3 : 2)
}
if (current !== this.state.curFilterIdx || (current === this.state.curFilterIdx && query.goodsSort !== this.state.query.goodsSort)) {
this.resetPage()
this.setState({
list: []
})
}
this.setState({
curFilterIdx: current,
query
}, () => {
this.nextPage()
})
}
handleListTypeChange = () => {
const listType = this.state.listType === 'grid' ? 'default' : 'grid'
this.setState({
listType
})
}
handleClickItem = (item) => {
const url = `/pages/item/detail?id=${item.item_id}`
Taro.navigateTo({
url
})
}
render () {
const { list, listType, curFilterIdx, filterList, showBackToTop, scrollTop, page } = this.state
return (
<View className='page-goods-list'>
<View className='goods-list__toolbar'>
<SearchBar />
<FilterBar
className='goods-list__tabs'
current={curFilterIdx}
list={filterList}
onChange={this.handleFilterChange}
>
<View
className='at-icon at-icon-bullet-list'
onClick={this.handleListTypeChange}
></View>
</FilterBar>
</View>
<ScrollView
className='goods-list__scroll'
scrollY
scrollTop={scrollTop}
scrollWithAnimation
onScroll={this.handleScroll}
onScrollToLower={this.nextPage}
>
<View className={`goods-list goods-list__type-${listType}`}>
{
list.map(item => {
return (
<GoodsItem
key={item.item_id}
info={item}
onClick={() => this.handleClickItem(item)}
/>
)
})
}
</View>
{
page.isLoading
? <Loading>正在加载...</Loading>
: null
}
</ScrollView>
<BackToTop
show={showBackToTop}
onClick={this.scrollBackToTop}
/>
</View>
)
}
}

View File

@@ -0,0 +1,62 @@
@import "../../style/imports";
.page-goods-list {
.goods-list {
padding: $edge-size 0;
&__toolbar {
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: $z-index-toolbar;
}
&__tabs {
}
&__scroll {
height: 100vh;
box-sizing: border-box;
padding: ($tabbar-height + 84px) 0 0;
}
&__type-grid {
@include clearfix();
.goods-item {
width: 48%;
float: left;
overflow: hidden;
margin-left: 1%;
margin-right: 1%;
&__img {
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
&-wrap {
width: 100%;
height: auto;
position: relative;
&:after {
content: "";
display: flex;
padding-top: 100%;
}
}
}
&__cont {
padding-left: floor($edge-size / 2);
padding-right: floor($edge-size / 2);
}
&__bd {
flex-direction: column;
}
&__cont {
height: 210px;
}
}
}
}
.goods-item {
margin-left: $edge-size;
margin-right: $edge-size;
}
}

View File

@@ -4,6 +4,7 @@ import { AtTabs, AtTabsPane } from 'taro-ui'
import { Loading, SpNote } from '@/components'
import api from '@/api'
import { withPager } from '@/hocs'
import { classNames, pickBy } from '@/utils'
import './coupon.scss'
@@ -16,16 +17,15 @@ export default class Coupon extends Component {
...this.state,
curTabIdx: 0,
tabList: [
{title: '可用', status: 'AVAIABLE'},
{title: '不可用', status: 'NOT_AVAIABLE'}
{title: '可用', status: '1'},
{title: '不可用', status: '2'}
],
list: []
}
}
componentDidMount () {
const { status } = this.$router.params
const tabIdx = this.state.tabList.findIndex(tab => tab.status === status)
const tabIdx = this.state.tabList.findIndex(tab => tab.status === '1')
if (tabIdx >= 0) {
this.setState({
@@ -39,14 +39,37 @@ export default class Coupon extends Component {
}
async fetch (params) {
const { tabList, curTabIdx } = this.state
const { page_no: page, page_size: pageSize } = params
const { curTabIdx } = this.state
console.log(curTabIdx, 43)
let vaildStatus
if(curTabIdx === 0) {
vaildStatus = true
}else {
vaildStatus = false
}
params = {
...params,
status: tabList[curTabIdx].status
valid: vaildStatus,
page,
pageSize
}
const { list, total_count: total } = await api.trade.list(params)
const nList = this.state.list.concat(list)
const { list, count: total } = await api.member.couponList(params)
const nList = pickBy(list, {
status: 'status',
reduce_cost: 'reduce_cost',
least_cost: 'least_cost',
begin_date: 'begin_date',
end_date: 'end_date',
card_type: 'card_type',
tagClass: 'tagClass',
title: 'title',
discount: 'discount'
})
this.setState({
list: [...this.state.list, ...nList],
})
this.setState({
list: nList
})
@@ -71,17 +94,6 @@ export default class Coupon extends Component {
})
}
// handleClickItem () {
// // console.log(item)
// // const { tid } = item
// Taro.navigateTo({
// url: `/pages/member/coupon-item`
// })
// }
handleClickItemBtn = (type, trade) => {
console.log(type, trade)
}
render () {
const { curTabIdx, tabList, list, page } = this.state
@@ -116,46 +128,35 @@ export default class Coupon extends Component {
list.map((item, idx) => {
return (
<View className='coupon-item' key={idx}>
{/*<View className='coupon-item__name'>*/}
{/*<View className='coupon-item___number'>¥<Text className='coupon-item___number_text'>200</Text></View>*/}
{/*<View className='coupon-item___info'>抵用券</View>*/}
{/*</View>*/}
{/*<View className='coupon-item__content'>*/}
{/*<View className='coupon-item___description'>订单满308元使用不含邮费</View>*/}
{/*<View className='coupon-item___time'>使用期限 <Text>2017.01.03-2017.02.01 22222</Text></View>*/}
{/*</View>*/}
{/*{*/}
{/*item.card_type === 'cash'*/}
{/*? <View className='coupon-item__name coupon-item__name-not'>*/}
{/*<View className='coupon-item___number'>¥<Text className='coupon-item___number_text'>{item.reduce_cost/100}</Text></View>*/}
{/*<View className='coupon-item___info'>满0.01可用</View>*/}
{/*</View>*/}
{/*: null*/}
{/*}*/}
{/*{*/}
{/*item.card_type === 'gift'*/}
{/*? <View className='coupon-item__name coupon-item__name-not'>*/}
{/*<View className='coupon-item___number'>兑换券</View>*/}
{/*</View>*/}
{/*: null*/}
{/*}*/}
{/*{*/}
{/*item.card_type === 'discount'*/}
{/*? */}
{/*: null*/}
{/*}*/}
<View className='coupon-item__name coupon-item__name-not'>
<View className='coupon-item___number'><Text className='coupon-item___number_text'>{(100-item.discount)/10}</Text></View>
<View className='coupon-item___info'>抵用券</View>
</View>
{
item.card_type === 'cash'
? <View className={classNames('coupon-item__name', item.status === '2' ? 'coupon-item__name-not' : null)}>
<View className='coupon-item___number'><Text className='coupon-item___number_text'>{item.reduce_cost/100}</Text></View>
<View className='coupon-item___info'>{item.least_cost > 0 ? item.least_cost/100 : 0.01}可用</View>
</View>
: null
}
{
item.card_type === 'gift'
? <View className={classNames('coupon-item__name', item.status === '2' ? 'coupon-item__name-not' : null)}>
<View className='coupon-item___number'>兑换券</View>
</View>
: null
}
{
item.card_type === 'discount'
? <View className={classNames('coupon-item__name', item.status === '2' ? 'coupon-item__name-not' : null)}>
<View className='coupon-item___number'><Text className='coupon-item___number_text'>{(100-item.discount)/10}</Text></View>
<View className='coupon-item___info'>{item.least_cost > 0 ? item.least_cost/100 : 0.01}可用</View>
</View>
: null
}
<View className='coupon-item__content'>
<View className='coupon-item___description'>
<Text>{item.title}</Text>
<View className='coupon-item___used'>已使用</View>
{
item.tagClass === 'used' ? <View className='coupon-item___used'>已使用</View> : null
}
</View>
<View className='coupon-item___time'>使用期限 <Text>{item.begin_date} ~ {item.end_date}</Text></View>
</View>

View File

@@ -6,7 +6,7 @@ import { Loading, SpNote } from '@/components'
import { withPager } from '@/hocs'
import api from '@/api'
import './integral.scss'
import './point.scss'
@withPager
export default class Integral extends Component {

View File

@@ -1,2 +1,2 @@
@import '../../style/imports';
@import './integral';
@import './point';

View File

@@ -1,5 +1,5 @@
@import '../../style/imports';
@import './integral';
@import './point';
.member-recommend{
display: flex;