cf-wx-app/src/pages/shop/shop.js

352 lines
14 KiB
JavaScript
Raw Normal View History

2018-12-03 17:32:48 +08:00
import Taro, { Component } from '@tarojs/taro'
2018-12-11 17:34:06 +08:00
import { View, Button, Text, Image } from '@tarojs/components'
import { AtSearchBar, AtTag, AtIcon } from 'taro-ui'
2018-12-03 17:32:48 +08:00
import URL from '../../serviceAPI.config'
import './shop.scss'
2018-12-04 17:32:30 +08:00
import ShopItem from '../../component/shopItemComponent/shopItemComponent'
2018-12-06 17:24:34 +08:00
import bottomNav from '../../component/bottomNav/bottomNav'
import copyrightComponent from '../../component/copyrightComponent/copyrightComponent'
2018-12-05 17:30:18 +08:00
2018-12-03 17:32:48 +08:00
class Shop extends Component {
// 项目配置
config = {
navigationBarTitleText: '店铺'
}
constructor() {
super(...arguments)
this.state = {
2018-12-11 17:34:06 +08:00
isShopDetailsOn:false, // 是否显示店铺说明页面
shopItem:'', // 所有商品
value: '', // 搜索框的值
shopId:'', // 店铺的id
shopName:'', // 店铺名
FilterText:'', // 筛选的可选项
2018-12-05 17:30:18 +08:00
filterBar:['综合排序','销量','新品','价格','人气'],
2018-12-11 17:34:06 +08:00
selectedFilterValue:0, //筛选项
isShowFilter:false, //是否显示侧边筛选
综合排序:true,
2018-12-05 17:30:18 +08:00
销量:false,
新品:false,
价格:false,
人气:false,
cate:{
10101: false,// "橱柜"
10102: false,// "衣柜"
10106: false,// "装饰柜"
20101: false,// "定制设计"
20103: false,// "产品设计"
30101: false,// "橱柜"
30102: false,// "衣柜"
}
2018-12-03 17:32:48 +08:00
}
}
2018-12-11 17:34:06 +08:00
// 搜索栏值的改变方法
2018-12-03 17:32:48 +08:00
onChange(value) {
2018-12-06 17:24:34 +08:00
2018-12-03 17:32:48 +08:00
this.setState({
value: value
2018-12-06 17:24:34 +08:00
},()=>{
console.log(this.state.value)
2018-12-03 17:32:48 +08:00
})
}
2018-12-11 17:34:06 +08:00
// 搜索栏的方法
2018-12-06 17:24:34 +08:00
getSearchBarkeyWords(){
Taro.request({
url: URL.SearchBarKeyWords,
method: 'POST',
dataType: 'json',
data:{
searchContent: '背板',
searchType: 1
},
header: {
'content-type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
}
}).then(res => {
2018-12-11 17:34:06 +08:00
console.log('搜索栏的搜索结果',res)
2018-12-06 17:24:34 +08:00
})
}
2018-12-11 17:34:06 +08:00
// 得到筛选的标签
2018-12-05 17:30:18 +08:00
getSearchParams({shop_name = false, shop_id = 1305, shop_class_id = "", goods_class_id=0,class_filter=0}){
2018-12-04 17:32:30 +08:00
Taro.request({
2018-12-05 17:30:18 +08:00
url: URL.GetSearchParam,
2018-12-04 17:32:30 +08:00
method: 'POST',
dataType: 'json',
data: {
goods: JSON.stringify({
2018-12-05 17:30:18 +08:00
shop_name: shop_name,
shop_id: shop_id,
shop_class_id: shop_class_id,
goods_class_id: goods_class_id,
class_filter: class_filter,
}),
2018-12-04 17:32:30 +08:00
goodsSpec: JSON.stringify([]),
goodsParam: JSON.stringify([]),
goodsParamExt: JSON.stringify([]),
},
header: {
'content-type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(res => {
this.setState({ FilterText: res.data })
})
}
2018-12-05 17:30:18 +08:00
2018-12-11 17:34:06 +08:00
// 得到所有的产品
2018-12-05 17:30:18 +08:00
goodsSearch({ curr_page = 1, page_count = 50, shop_name = false, shop_id = 1305, config_id = 4, shop_class_id = '', order = '', currPage = 1 }) {
2018-12-03 17:32:48 +08:00
Taro.request({
url: URL.GoodsSearch,
method:'POST',
dataType: 'json',
data:{
goods: JSON.stringify({
2018-12-05 17:30:18 +08:00
curr_page: curr_page,
page_count: page_count,
shop_name: shop_name,
shop_id: shop_id,
config_id: config_id,
shop_class_id: shop_class_id,
order: order,
currPage: currPage
2018-12-03 17:32:48 +08:00
}),
goodsRegion: JSON.stringify({}),
goodsSpec: JSON.stringify([]),
goodsParam: JSON.stringify([]),
goodsParamExt: JSON.stringify([]),
},
header: {
'content-type': 'application/x-www-form-urlencoded',
'X-Requested-With':'XMLHttpRequest'
}
})
.then(res => {
2018-12-04 17:32:30 +08:00
// console.log(res)
this.setState({ shopItem:res.data})
2018-12-03 17:32:48 +08:00
})
}
2018-12-11 17:34:06 +08:00
// 产品排序
2018-12-05 17:30:18 +08:00
accendingDescending(value){
2018-12-04 17:32:30 +08:00
this.setState({selectedFilterValue:value})
2018-12-05 17:30:18 +08:00
if(value==0){
this.setState({ 综合排序: !this.state.综合排序 })
this.goodsSearch({})
}
if(value==1){
this.setState({ 销量: !this.state.销量 },()=>{
this.state.销量 ? this.goodsSearch({ order: "g.sales_volume desc" }) : this.goodsSearch({ order: "g.sales_volume" })
})
}
if(value==2){
this.setState({ 新品: !this.state.新品 },()=>{
this.state.新品 ? this.goodsSearch({ order: "g.create_date desc" }) : this.goodsSearch({ order: "g.create_date" })
})
}
if(value==3){
this.setState({ 价格: !this.state.价格 },()=>{
this.state.价格 ? this.goodsSearch({ order: "g.goods_price desc" }) : this.goodsSearch({ order: "g.goods_price" })
})
}
if(value==4){
this.setState({ 人气: !this.state.人气 },()=>{
this.state.人气 ? this.goodsSearch({ order: "g.browse_times desc" }) : this.goodsSearch({ order: "g.browse_times" })
})
}
}
2018-12-11 17:34:06 +08:00
// 是否显示侧边筛选
2018-12-05 17:30:18 +08:00
showAndHideFilter(){
this.setState({ isShowFilter: !this.state.isShowFilter })
2018-12-04 17:32:30 +08:00
}
2018-12-11 17:34:06 +08:00
// 选择侧边筛选的标签
2018-12-05 17:30:18 +08:00
selectTag(value){
for(let item in this.state.cate){
if(value===item){
this.setState(prevState => ({
cate: {
...prevState.cate,
[item]:!this.state.cate[item]
}
}),()=>{
2018-12-06 17:24:34 +08:00
this.getSearchParams({ goods_class_id: value , class_filter :1})
2018-12-05 17:30:18 +08:00
})
}
}
2018-12-04 17:32:30 +08:00
}
2018-12-03 17:32:48 +08:00
componentWillMount() {
this.setState({ shopId: this.$router.params.id, shopName: this.$router.params.name}) // 输出 { id: 2, type: 'test' }
}
componentDidMount(){
2018-12-11 17:34:06 +08:00
//页面加载之后 得到指定店铺的商品 和 筛选标签
2018-12-05 17:30:18 +08:00
this.goodsSearch({})
2018-12-11 17:34:06 +08:00
this.getSearchParams({})
// this.getSearchBarkeyWords()
2018-12-03 17:32:48 +08:00
}
componentDidShow() { }
componentDidHide() { }
render() {
2018-12-11 17:34:06 +08:00
// const shopName= this.state.shopName
2018-12-04 17:32:30 +08:00
const ShopItemElementsArray =this.state.shopItem? this.state.shopItem.goods.map((item,index)=>{
return <View key={index} className='shop-item' >
<ShopItem item={item}></ShopItem>
</View>
}):null
const filterElementsArray=this.state.filterBar.map((item,index)=>{
2018-12-05 17:30:18 +08:00
let isTure=this.state[item]
return <View key={index} onClick={this.accendingDescending.bind(this, index)} className={index===this.state.selectedFilterValue ? 'filter-title actived' : 'filter-title'}>
2018-12-04 17:32:30 +08:00
<Text className='text'>
{item}
</Text>
2018-12-05 17:30:18 +08:00
{index!==0&&index!==5&&(isTure? <AtIcon value='chevron-down' size='10' color='#F00'></AtIcon> : <AtIcon value='chevron-up' size='10' color='#F00'></AtIcon>)}
2018-12-04 17:32:30 +08:00
</View>
})
2018-12-05 17:30:18 +08:00
// const widthness = this.state.FilterText ? this.state.FilterText.goodsParamExt[5].param_value[0] : null // filter 宽度选项
2018-12-11 17:34:06 +08:00
// 侧边筛选的分类项
2018-12-05 17:30:18 +08:00
const goodsClassElementsArray = this.state.FilterText.goods_class ? this.state.FilterText.goods_class.map((item, index) => {
let isTrue = this.state.cate[item.class_id]
return <AtTag style='margin-left:5px' key={index}
name={JSON.stringify(item)}
type='primary'
active={isTrue}
onClick={this.selectTag.bind(this, item.class_id)}
>{item.class_name}</AtTag>
}):null
2018-12-11 17:34:06 +08:00
// 侧边筛选的商品类型项
2018-12-06 17:24:34 +08:00
const goodsTypeKeyArray = this.state.FilterText.goods_type ? Object.keys(this.state.FilterText.goods_type):null
const goodsTypeElementsArray = goodsTypeKeyArray ? goodsTypeKeyArray.map((key, index) => {
let object = this.state.FilterText.goods_type
return <AtTag style='margin-left:5px' key={index}
name={JSON.stringify(object[key])}
type='primary'
active={this.state.isActive}
onClick={this.selectTag.bind(this)}
>{object[key].goods_type_ch_name}</AtTag>
}):null
2018-12-05 17:30:18 +08:00
2018-12-11 17:34:06 +08:00
// 侧边筛选的其他项
2018-12-06 17:24:34 +08:00
const goodsParamKeyArray = this.state.FilterText.goodsParam ? Object.keys(this.state.FilterText.goodsParam):null
const goodsParamElementsArray = goodsParamKeyArray ? goodsParamKeyArray.map((key, index) => {
let object = this.state.FilterText.goodsParam
return <View key={index}><View className='title' >{object[key].param_name}</View>
<View className='button-box'>
<AtTag style='margin-left:5px'
name={JSON.stringify(object[key])}
type='primary'
active={this.state.isActive}
onClick={this.selectTag.bind(this)}
>{object[key].param_value[0]}</AtTag>
</View>
</View>
}):null
2018-12-04 17:32:30 +08:00
2018-12-03 17:32:48 +08:00
return (
<View className='shop'>
<View className='searchBar-box'>
2018-12-04 17:32:30 +08:00
<AtSearchBar className='search-button'
2018-12-06 17:24:34 +08:00
actionName='搜索'
2018-12-05 17:30:18 +08:00
value={this.state.value}
onChange={this.onChange.bind(this)}
onActionClick={this.onActionClick.bind(this)}
/>
2018-12-03 17:32:48 +08:00
</View>
<View className='banner-box'>
<Image src={URL.Base + 'Public/visual_editing/img/ksh_bg.jpg'} mode='aspectFill' style='height:120px' />
{/* <View className='shop-name'>{shopName}</View> */}
2018-12-03 17:32:48 +08:00
</View>
<View className='nav-box'>
<View className='nav'>
<View className='shop-cate'>
<Text className='text'>
2018-12-06 17:24:34 +08:00
店铺全部分类
2018-12-03 17:32:48 +08:00
</Text>
2018-12-06 17:24:34 +08:00
<AtIcon value='menu' size='10' color='white'></AtIcon>
2018-12-03 17:32:48 +08:00
</View>
2018-12-06 17:24:34 +08:00
<View className='homepage-link'>
2018-12-03 17:32:48 +08:00
<Text className='text'>
首页
</Text>
</View>
2018-12-06 17:24:34 +08:00
<View className='shoppage-link'>
2018-12-03 17:32:48 +08:00
<Text className='text'>
店铺说明
</Text>
</View>
</View>
</View>
<View className='filter-box'>
2018-12-04 17:32:30 +08:00
{filterElementsArray}
2018-12-05 17:30:18 +08:00
<View onClick={this.showAndHideFilter.bind(this)} className='filter-title' >
<Text className='text'>
筛选
</Text>
</View>
2018-12-04 17:32:30 +08:00
</View>
2018-12-05 17:30:18 +08:00
<View className={this.state.isShowFilter ? 'side-filter show' :'side-filter'}>
<View className='left' onClick={this.showAndHideFilter.bind(this)}></View>
2018-12-11 17:34:06 +08:00
{/* 侧边筛选 */}
2018-12-04 17:32:30 +08:00
<View className='right'>
2018-12-05 17:30:18 +08:00
<View className='filter-box'>
<View className='title'>分类</View>
<View className='button-box'>{goodsClassElementsArray}</View>
<View className='title'>商品类型</View>
<View className='button-box'>{goodsTypeElementsArray}</View>
{goodsParamElementsArray}
<View className='title'>宽度</View>
<View className='button-box'>
{/* <AtTag style='margin-left:5px'
name={JSON.stringify(widthness)}
type='primary'
active={this.state.isActive}
onClick={this.selectTag.bind(this)}
>{widthness.value_desc}</AtTag> */}
</View>
<View className='confirm-button'>
<Button className='button' type='primary' size='mini' style='background-color:#FF9900' >确认</Button>
<Button className='button' type='primary' size='mini' style='background-color:#FF9900'>重置</Button>
<View className='gap'></View>
2018-12-05 17:30:18 +08:00
</View>
</View>
2018-12-04 17:32:30 +08:00
</View>
</View>
2018-12-11 17:34:06 +08:00
{/* 店铺的商品列表 */}
2018-12-04 17:32:30 +08:00
<View className='container'>
{ShopItemElementsArray}
2018-12-03 17:32:48 +08:00
</View>
<copyrightComponent></copyrightComponent>
2018-12-06 17:24:34 +08:00
<View className='bottom-nav-box'>
<bottomNav otherData={{menu:[{ name: '首页' }, { name: '分类' }, { name: '购物车' }, { name: '教程软件' }, { name:'更多'}]}} />
</View>
2018-12-03 17:32:48 +08:00
</View>
)
}
}
export default Shop