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

554 lines
22 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 { AtTag, AtIcon, AtPagination, AtActionSheet, AtActionSheetItem } from 'taro-ui'
2018-12-03 17:32:48 +08:00
import URL from '../../serviceAPI.config'
2018-12-14 17:10:23 +08:00
2018-12-03 17:32:48 +08:00
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-14 17:10:23 +08:00
import ShopDescription from '../shopDescription/shopDescription';
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-14 17:10:23 +08:00
isShopDetailsOn: false, // 是否显示店铺说明页面
shopItem: [], // 所有商品
2018-12-11 17:34:06 +08:00
value: '', // 搜索框的值
2018-12-14 17:10:23 +08:00
shopId: '', // 店铺的id
shopName: '', // 店铺名
FilterText: '', // 筛选的可选项
2018-12-18 17:37:23 +08:00
filterBar: ['all', 'amount', 'newProduct', 'price', 'popularity'], //筛选选项
filterBarKeys: { all: '综合排序', amount: '销量', newProduct: '新品', price: '价格', popularity: '人气' }, // 筛选选项对应值
2018-12-14 17:10:23 +08:00
selectedFilterValue: 0, //筛选项
isShowFilter: false, //是否显示侧边筛选
2018-12-18 17:37:23 +08:00
showShopHomePage: true,// 是否显示首页页面
2018-12-14 17:10:23 +08:00
shopDescriptionData: '',// 店铺详情信息
shopName: '',//店铺名称
shopAddress: '',//店铺地址
contactName: '',//联系人
contactNumber: '',//联系电话
shopDescription: '',//店铺简介
filterOptions: {
all: true,
amount: false,
newProduct: false,
price: false,
popularity: false,
},
cate: {
2018-12-05 17:30:18 +08:00
10101: false,// "橱柜"
10102: false,// "衣柜"
10106: false,// "装饰柜"
20101: false,// "定制设计"
20103: false,// "产品设计"
30101: false,// "橱柜"
30102: false,// "衣柜"
2018-12-14 17:10:23 +08:00
},
filterCondition: '',// 筛选条件
total: 0,// 信息条数
currentPage: 1,// 当前页
isShowShopAllCate: false,
shopAllInnerCate: '',
isBlurWindow:false,
2018-12-14 17:10:23 +08:00
2018-12-03 17:32:48 +08:00
}
}
2018-12-14 17:10:23 +08:00
//api 搜索栏的方法请求
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 => {
console.log('搜索栏的搜索结果', res)
})
2018-12-06 17:24:34 +08:00
2018-12-14 17:10:23 +08:00
}
2018-12-11 17:34:06 +08:00
2018-12-14 17:10:23 +08:00
// api 得到筛选的标签请求
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-14 17:10:23 +08:00
shop_name: shop_name,
shop_id: shop_id,
2018-12-05 17:30:18 +08:00
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-14 17:10:23 +08:00
// api 得到所有的产品请求
goodsSearch({ curr_page = 1, page_count = 10, 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,
2018-12-14 17:10:23 +08:00
method: 'POST',
2018-12-03 17:32:48 +08:00
dataType: 'json',
2018-12-14 17:10:23 +08:00
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-14 17:10:23 +08:00
}),
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',
2018-12-14 17:10:23 +08:00
'X-Requested-With': 'XMLHttpRequest'
2018-12-03 17:32:48 +08:00
}
})
.then(res => {
2018-12-14 17:10:23 +08:00
this.setState({ shopItem: res.data.goods, total: res.data.goodsCount, filterCondition: order })
2018-12-03 17:32:48 +08:00
})
}
2018-12-14 17:10:23 +08:00
// api 得到店铺详情请求
getShopDescription({ shopID = 808 }) {
Taro.request({
2018-12-18 17:37:23 +08:00
url: URL.ShopDescription,
2018-12-14 17:10:23 +08:00
method: 'POST',
dataType: 'json',
data: {
shopID: shopID,
},
header: {
'content-type': 'application/x-www-form-urlencoded',
}
})
.then(res => {
this.setState({
shopDescriptionData: res.data,
shopName: res.data.data.shop_name,
shopAddress: res.data.data.shop_address,
contactName: res.data.userRes.name,
contactNumber: res.data.userRes.phone,
shopDescription: res.data.data.shop_desc
}, () => {
// console.log(this.state.shopDescriptionData)
2018-12-14 17:10:23 +08:00
})
}
)
2018-12-05 17:30:18 +08:00
}
// api 获取店铺内的店铺分类请求 GetShopCategoryList
getShopInnerCate({ id = 808 }) {
Taro.request({
url: URL.GetShopCategoryList,
method: 'POST',
dataType: 'json',
data: {
id: id,
},
header: {
'content-type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(res => {
if (res.statusCode === 200) {
const originalData = res.data.data
const sortedData = []
for (let item in originalData) {
let each = originalData[item]
each['id'] = item
sortedData.push(each)
}
console.log('sorteddata', sortedData)
this.setState({ shopAllInnerCate: sortedData })
} else {
console.log('获取店铺内部分类失败')
}
}
)
}
2018-12-14 17:10:23 +08:00
// 产品排序
accendingDescending(value) {
2018-12-14 17:10:23 +08:00
this.setState({ selectedFilterValue: value })
if (value == 0) {
this.setState({
currentPage: 1,
filterOptions: {
all: true,
amount: false,
newProduct: false,
price: false,
popularity: false
}
}
)
this.goodsSearch({})
}
if (value == 1) {
this.setState({
currentPage: 1,
filterOptions: {
all: false,
amount: !this.state.filterOptions.amount,
newProduct: false,
price: false,
popularity: false
}
}, () => {
this.state.filterOptions.amount ? this.goodsSearch({ order: "g.sales_volume desc" }) : this.goodsSearch({ order: "g.sales_volume" })
}
)
}
if (value == 2) {
this.setState({
currentPage: 1,
filterOptions: {
all: false,
amount: false,
newProduct: !this.state.filterOptions.newProduct,
price: false,
popularity: false
}
}, () => {
this.state.filterOptions.newProduct ? this.goodsSearch({ order: "g.create_date desc" }) : this.goodsSearch({ order: "g.create_date" })
}
)
}
if (value == 3) {
this.setState({
currentPage: 1,
filterOptions: {
all: false,
amount: false,
newProduct: false,
price: !this.state.filterOptions.price,
popularity: false
}
}, () => {
this.state.filterOptions.price ? this.goodsSearch({ order: "g.goods_price desc" }) : this.goodsSearch({ order: "g.goods_price" })
}
)
}
if (value == 4) {
this.setState({
currentPage: 1,
filterOptions: {
all: false,
amount: false,
newProduct: false,
price: false,
popularity: !this.state.filterOptions.popularity
}
}, () => {
this.state.filterOptions.popularity ? this.goodsSearch({ order: "g.browse_times desc", }) : this.goodsSearch({ order: "g.browse_times" })
}
)
}
2018-12-05 17:30:18 +08:00
}
2018-12-11 17:34:06 +08:00
// 是否显示侧边筛选
2018-12-14 17:10:23 +08:00
showAndHideFilter() {
2018-12-05 17:30:18 +08:00
this.setState({ isShowFilter: !this.state.isShowFilter })
2018-12-04 17:32:30 +08:00
}
2018-12-11 17:34:06 +08:00
// 选择侧边筛选的标签
2018-12-14 17:10:23 +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]
}
}), () => {
this.getSearchParams({ goods_class_id: value, class_filter: 1 })
})
}
}
2018-12-04 17:32:30 +08:00
}
2018-12-14 17:10:23 +08:00
handleOnPageChange(value) {
this.setState({ currentPage: value.current })
// console.log('currentPage', currentPage ,'condition',this.state.filterCondition)
this.goodsSearch({ curr_page: value.current, order: this.state.filterCondition })
}
showHomePage() {
this.setState({ showShopHomePage: true })
}
showDescriptionPage() {
this.setState({ showShopHomePage: false })
}
isShowShopAllCate() {
this.setState({ isShowShopAllCate: !this.state.isShowShopAllCate,isBlurWindow:true })
2018-12-14 17:10:23 +08:00
}
handleShopInnerCate(id){
this.setState({
isShowShopAllCate: false,isBlurWindow:false
})
this.goodsSearch({shop_class_id:id,shop_id: this.$router.params.id})
}
closeBgWindow(){
this.setState({
isShowShopAllCate: false,isBlurWindow:false
})
}
2018-12-14 17:10:23 +08:00
2018-12-03 17:32:48 +08:00
componentWillMount() {
2018-12-14 17:10:23 +08:00
2018-12-03 17:32:48 +08:00
}
2018-12-14 17:10:23 +08:00
componentDidMount() {
2018-12-11 17:34:06 +08:00
//页面加载之后 得到指定店铺的商品 和 筛选标签
this.goodsSearch({ shop_id: this.$router.params.id }) // 加载店铺商品
this.getSearchParams({})// 加载筛选项
this.getShopDescription({ shopID: this.$router.params.id }) // 加载店铺说明
2018-12-11 17:34:06 +08:00
// this.getSearchBarkeyWords()
this.getShopInnerCate({id:this.$router.params.id})
2018-12-03 17:32:48 +08:00
}
componentDidShow() { }
componentDidHide() { }
render() {
2018-12-14 17:10:23 +08:00
const ShopItemElementsArray = this.state.shopItem.length ? this.state.shopItem.map((item, index) => {
2018-12-04 17:32:30 +08:00
return <View key={index} className='shop-item' >
<ShopItem item={item}></ShopItem>
2018-12-14 17:10:23 +08:00
</View>
}) : null
const filterElementsArray = this.state.filterBar.map((item, index) => {
let isTure = this.state.filterOptions[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'>
2018-12-14 17:10:23 +08:00
{this.state.filterBarKeys[item]}
2018-12-04 17:32:30 +08:00
</Text>
2018-12-14 17:10:23 +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-14 17:10:23 +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-14 17:10:23 +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) => {
2018-12-14 17:10:23 +08:00
2018-12-05 17:30:18 +08:00
let isTrue = this.state.cate[item.class_id]
return <AtTag style='margin-left:5px' key={index}
2018-12-14 17:10:23 +08:00
name={JSON.stringify(item)}
type='primary'
active={isTrue}
onClick={this.selectTag.bind(this, item.class_id)}
2018-12-05 17:30:18 +08:00
>{item.class_name}</AtTag>
2018-12-14 17:10:23 +08:00
}) : null
2018-12-11 17:34:06 +08:00
// 侧边筛选的商品类型项
2018-12-14 17:10:23 +08:00
const goodsTypeKeyArray = this.state.FilterText.goods_type ? Object.keys(this.state.FilterText.goods_type) : null
2018-12-06 17:24:34 +08:00
const goodsTypeElementsArray = goodsTypeKeyArray ? goodsTypeKeyArray.map((key, index) => {
let object = this.state.FilterText.goods_type
return <AtTag style='margin-left:5px' key={index}
2018-12-14 17:10:23 +08:00
name={JSON.stringify(object[key])}
type='primary'
active={this.state.isActive}
onClick={this.selectTag.bind(this)}
2018-12-06 17:24:34 +08:00
>{object[key].goods_type_ch_name}</AtTag>
2018-12-14 17:10:23 +08:00
}) : null
2018-12-11 17:34:06 +08:00
// 侧边筛选的其他项
2018-12-14 17:10:23 +08:00
const goodsParamKeyArray = this.state.FilterText.goodsParam ? Object.keys(this.state.FilterText.goodsParam) : null
2018-12-06 17:24:34 +08:00
const goodsParamElementsArray = goodsParamKeyArray ? goodsParamKeyArray.map((key, index) => {
let object = this.state.FilterText.goodsParam
2018-12-14 17:10:23 +08:00
return <View key={index}><View className='title' >{object[key].param_name}</View>
2018-12-06 17:24:34 +08:00
<View className='button-box'>
<AtTag style='margin-left:5px'
2018-12-14 17:10:23 +08:00
name={JSON.stringify(object[key])}
type='primary'
active={this.state.isActive}
onClick={this.selectTag.bind(this)}
2018-12-06 17:24:34 +08:00
>{object[key].param_value[0]}</AtTag>
</View>
</View>
2018-12-14 17:10:23 +08:00
}) : null
2018-12-04 17:32:30 +08:00
2018-12-14 17:10:23 +08:00
// 店铺页面/店铺主页
const shopHomepageElement = <View className='shop-home-page'>
<View className='filter-box'>
{filterElementsArray}
<View onClick={this.showAndHideFilter.bind(this)} className='filter-title' >
<Text className='text'>
筛选
</Text>
</View>
</View>
<View className={this.state.isShowFilter ? 'side-filter show' : 'side-filter'}>
<View className='left' onClick={this.showAndHideFilter.bind(this)}></View>
{/* 侧边筛选 */}
<View className='right'>
<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'>
2018-12-24 17:35:51 +08:00
<Button className='button' type='primary' size='mini' style='background-color:#FF7142' >确认</Button>
<Button className='button' type='primary' size='mini' style='background-color:#5cb85c'>重置</Button>
2018-12-14 17:10:23 +08:00
<View className='gap'></View>
</View>
</View>
</View>
</View>
{/* 店铺的商品列表 */}
<View className='container'>
{ShopItemElementsArray}
</View>
<View className='pagination'>
<AtPagination
total={Number(this.state.total)}
pageSize={10}
current={this.state.currentPage}
onPageChange={this.handleOnPageChange.bind(this)}
>
</AtPagination>
</View>
</View>
// 店铺详情
const shopDescriptionElement = <View className='shop-description'>
<View className='img-box'>
<Image mode='aspectFill' src={URL.Base + 'Public/images/shop/bg_banner.png'} style='height:150px' />
<View className='content'>
<View className='shop-name'>
{this.state.shopName}
</View>
<View className='shop-address'>
{this.state.shopAddress}
</View>
<View className='contact'>
<Text className='contact-name'>联系人:{this.state.contactName}</Text>
<Text className='contact-number'>联系电话{this.state.contactNumber}</Text>
</View>
</View>
</View>
<View className='shop-description2'>
<View className='title'>
店铺简介
</View>
<View className='description'>
<Text className='title-sub'>店铺介绍</Text>
<Text className='detail'>{this.state.shopDescription}</Text>
</View>
</View>
<View className='description-img'>
<View className='img-box'> <Image mode='aspectFit' src={URL.Base + 'Public/images/shop/bg_banner.png'} style='max-width: 100%; max-height:100%;' /></View>
<View className='img-box'> <Image mode='aspectFit' src={URL.Base + 'Public/images/shop/bg_banner.png'} style='max-width: 100%;max-height:100%;' /></View>
<View className='img-box'> <Image mode='aspectFit' src={URL.Base + 'Public/images/shop/bg_banner.png'} style='max-width: 100%;max-height:100%;' /></View>
</View>
</View>
const shopAllCateElementArray = this.state.shopAllInnerCate.map((item, index) => {
return <View key={index} className='item' onClick={this.handleShopInnerCate.bind(this,item.id)}> <Text>{item.n}</Text> </View>
})
2018-12-03 17:32:48 +08:00
return (
<View className='shop' >
<View onClick={this.state.closeBgWindow.bind(this)} className={this.state.isBlurWindow?'show-blur':''}></View>
2018-12-14 17:10:23 +08:00
<View className='banner-box'>
<Image src={URL.Base + 'Public/visual_editing/img/ksh_bg.jpg'} mode='aspectFill' style='height:120px' />
<View className='shop-name'>{this.state.shopName}</View>
2018-12-14 17:10:23 +08:00
</View>
<View className='nav-box'>
<View className='nav'>
<View className='shop-cate' onClick={this.isShowShopAllCate.bind(this)}>
2018-12-03 17:32:48 +08:00
<Text className='text'>
2018-12-14 17:10:23 +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>
<View className={this.state.isShowShopAllCate ? 'shopcate-selection show' : 'shopcate-selection'}>
{shopAllCateElementArray}</View>
2018-12-14 17:10:23 +08:00
<View className='homepage-link' onClick={this.showHomePage.bind()}>
2018-12-03 17:32:48 +08:00
<Text className='text'>
首页
</Text>
</View>
2018-12-14 17:10:23 +08:00
<View className='shoppage-link' onClick={this.showDescriptionPage.bind()}>
2018-12-03 17:32:48 +08:00
<Text className='text'>
店铺说明
</Text>
</View>
2018-12-14 17:10:23 +08:00
</View>
2018-12-03 17:32:48 +08:00
</View>
2018-12-14 17:10:23 +08:00
{/* 显示店铺首页或者店铺详情 */}
{this.state.showShopHomePage ? shopHomepageElement : shopDescriptionElement}
<copyrightComponent></copyrightComponent>
2018-12-06 17:24:34 +08:00
<View className='bottom-nav-box'>
2018-12-14 17:10:23 +08:00
<bottomNav otherData={{ menu: [{ name: '首页' }, { name: '分类' }, { name: '购物车' }, { name: '教程软件' }, { name: '更多' }] }} />
2018-12-06 17:24:34 +08:00
</View>
2018-12-14 17:10:23 +08:00
</View>
2018-12-03 17:32:48 +08:00
)
}
}
export default Shop