From 995c7883c8341acf54b48bc0fe0e42edcb6723af Mon Sep 17 00:00:00 2001 From: chenhui0212 Date: Wed, 6 Mar 2019 18:46:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8,=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC=EF=BC=8Ch5=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/item.js | 4 +- src/api/req.js | 2 +- src/app.js | 3 +- src/pages/auth/login.js | 21 ++- src/pages/auth/reg.js | 78 +++++--- src/pages/auth/reg.scss | 7 +- src/pages/index/index.js | 3 +- src/pages/item/point-list.js | 170 ++++++++++++++++++ src/pages/item/point-list.scss | 62 +++++++ src/pages/member/coupon.js | 113 ++++++------ src/pages/member/{integral.js => point.js} | 2 +- .../member/{integral.scss => point.scss} | 0 src/pages/member/recharge.scss | 2 +- src/pages/member/recommend.scss | 2 +- 14 files changed, 373 insertions(+), 96 deletions(-) create mode 100644 src/pages/item/point-list.js create mode 100644 src/pages/item/point-list.scss rename src/pages/member/{integral.js => point.js} (99%) rename src/pages/member/{integral.scss => point.scss} (100%) diff --git a/src/api/item.js b/src/api/item.js index be8ac0a83..13c9a2d51 100644 --- a/src/api/item.js +++ b/src/api/item.js @@ -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') -} \ No newline at end of file +} diff --git a/src/api/req.js b/src/api/req.js index 79b983deb..e7ce5dbf9 100644 --- a/src/api/req.js +++ b/src/api/req.js @@ -123,4 +123,4 @@ export default new API({ // } }) -export { API } \ No newline at end of file +export { API } diff --git a/src/app.js b/src/app.js index 30ee49ce7..3a0dc667f 100644 --- a/src/app.js +++ b/src/app.js @@ -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', diff --git a/src/pages/auth/login.js b/src/pages/auth/login.js index 44c75c73e..149840213 100644 --- a/src/pages/auth/login.js +++ b/src/pages/auth/login.js @@ -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) => { diff --git a/src/pages/auth/reg.js b/src/pages/auth/reg.js index 4d221976a..2b37aab10 100644 --- a/src/pages/auth/reg.js +++ b/src/pages/auth/reg.js @@ -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 ? - - - - {item.name} - {item.value ? item.value : `请选择${item.name}`} - - + + { + item.key === 'birthday' + ? + + {item.name} + {item.value ? item.value : `请选择${item.name}`} + + + : + + {item.name} + {item.value ? item.value : `请选择${item.name}`} + + + } - : + : diff --git a/src/pages/auth/reg.scss b/src/pages/auth/reg.scss index 81aa828c8..b79f3f351 100644 --- a/src/pages/auth/reg.scss +++ b/src/pages/auth/reg.scss @@ -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; } } diff --git a/src/pages/index/index.js b/src/pages/index/index.js index f2f1d46da..32f0ce9bf 100644 --- a/src/pages/index/index.js +++ b/src/pages/index/index.js @@ -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' }) } } diff --git a/src/pages/item/point-list.js b/src/pages/item/point-list.js new file mode 100644 index 000000000..5b4c70da2 --- /dev/null +++ b/src/pages/item/point-list.js @@ -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 ( + + + + + + + + + + + + { + list.map(item => { + return ( + this.handleClickItem(item)} + /> + ) + }) + } + + { + page.isLoading + ? 正在加载... + : null + } + + + + + ) + } +} diff --git a/src/pages/item/point-list.scss b/src/pages/item/point-list.scss new file mode 100644 index 000000000..39ad80606 --- /dev/null +++ b/src/pages/item/point-list.scss @@ -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; + } +} diff --git a/src/pages/member/coupon.js b/src/pages/member/coupon.js index efc7410a8..30b376ad9 100644 --- a/src/pages/member/coupon.js +++ b/src/pages/member/coupon.js @@ -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 ( - {/**/} - {/*200*/} - {/*抵用券*/} - {/**/} - {/**/} - {/*订单满308元使用(不含邮费)*/} - {/*使用期限 2017.01.03-2017.02.01 22222*/} - {/**/} - {/*{*/} - {/*item.card_type === 'cash'*/} - {/*? */} - {/*{item.reduce_cost/100}*/} - {/*满0.01可用*/} - {/**/} - {/*: null*/} - {/*}*/} - - {/*{*/} - {/*item.card_type === 'gift'*/} - {/*? */} - {/*兑换券*/} - {/**/} - {/*: null*/} - {/*}*/} - - {/*{*/} - {/*item.card_type === 'discount'*/} - {/*? */} - {/*: null*/} - {/*}*/} - - - {(100-item.discount)/10} - 抵用券 - - + { + item.card_type === 'cash' + ? + {item.reduce_cost/100} + 满{item.least_cost > 0 ? item.least_cost/100 : 0.01}可用 + + : null + } + { + item.card_type === 'gift' + ? + 兑换券 + + : null + } + { + item.card_type === 'discount' + ? + {(100-item.discount)/10} + 满{item.least_cost > 0 ? item.least_cost/100 : 0.01}可用 + + : null + } {item.title} - 已使用 + { + item.tagClass === 'used' ? 已使用 : null + } 使用期限 {item.begin_date} ~ {item.end_date} diff --git a/src/pages/member/integral.js b/src/pages/member/point.js similarity index 99% rename from src/pages/member/integral.js rename to src/pages/member/point.js index 5a245db1f..a312a1a49 100644 --- a/src/pages/member/integral.js +++ b/src/pages/member/point.js @@ -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 { diff --git a/src/pages/member/integral.scss b/src/pages/member/point.scss similarity index 100% rename from src/pages/member/integral.scss rename to src/pages/member/point.scss diff --git a/src/pages/member/recharge.scss b/src/pages/member/recharge.scss index 3f72c3aa1..b779eeaa4 100644 --- a/src/pages/member/recharge.scss +++ b/src/pages/member/recharge.scss @@ -1,2 +1,2 @@ @import '../../style/imports'; -@import './integral'; +@import './point'; diff --git a/src/pages/member/recommend.scss b/src/pages/member/recommend.scss index a3786f992..73757ed71 100644 --- a/src/pages/member/recommend.scss +++ b/src/pages/member/recommend.scss @@ -1,5 +1,5 @@ @import '../../style/imports'; -@import './integral'; +@import './point'; .member-recommend{ display: flex;