import Taro, { Component } from '@tarojs/taro'
import { View, Button, Text, Image } from '@tarojs/components'
import { AtSearchBar, AtTag, AtIcon, AtPagination } from 'taro-ui'
import URL from '../../serviceAPI.config'
import './shop.scss'
import ShopItem from '../../component/shopItemComponent/shopItemComponent'
import bottomNav from '../../component/bottomNav/bottomNav'
import copyrightComponent from '../../component/copyrightComponent/copyrightComponent'
import ShopDescription from '../shopDescription/shopDescription';
class Shop extends Component {
// 项目配置
config = {
navigationBarTitleText: '店铺'
}
constructor() {
super(...arguments)
this.state = {
isShopDetailsOn: false, // 是否显示店铺说明页面
shopItem: [], // 所有商品
value: '', // 搜索框的值
shopId: '', // 店铺的id
shopName: '', // 店铺名
FilterText: '', // 筛选的可选项
filterBar: ['all', 'amount', 'newProduct', 'price', 'popularity'], //筛选选项
filterBarKeys: { all: '综合排序', amount: '销量', newProduct: '新品', price: '价格', popularity: '人气' }, // 筛选选项对应值
selectedFilterValue: 0, //筛选项
isShowFilter: false, //是否显示侧边筛选
showShopHomePage: true,// 是否显示首页页面
shopDescriptionData: '',// 店铺详情信息
shopName: '',//店铺名称
shopAddress: '',//店铺地址
contactName: '',//联系人
contactNumber: '',//联系电话
shopDescription: '',//店铺简介
filterOptions: {
all: true,
amount: false,
newProduct: false,
price: false,
popularity: false,
},
cate: {
10101: false,// "橱柜"
10102: false,// "衣柜"
10106: false,// "装饰柜"
20101: false,// "定制设计"
20103: false,// "产品设计"
30101: false,// "橱柜"
30102: false,// "衣柜"
},
filterCondition: '',// 筛选条件
total: 0,// 信息条数
currentPage: 1,// 当前页
}
}
// 搜索栏值的改变方法
onChange(value) {
this.setState({
value: value
}, () => {
console.log(this.state.value)
})
}
//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)
})
}
// api 得到筛选的标签请求
getSearchParams({ shop_name = false, shop_id = 1305, shop_class_id = "", goods_class_id = 0, class_filter = 0 }) {
Taro.request({
url: URL.GetSearchParam,
method: 'POST',
dataType: 'json',
data: {
goods: JSON.stringify({
shop_name: shop_name,
shop_id: shop_id,
shop_class_id: shop_class_id,
goods_class_id: goods_class_id,
class_filter: class_filter,
}),
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 })
})
}
// api 得到所有的产品请求
goodsSearch({ curr_page = 1, page_count = 10, shop_name = false, shop_id = 1305, config_id = 4, shop_class_id = '', order = '', currPage = 1 }) {
Taro.request({
url: URL.GoodsSearch,
method: 'POST',
dataType: 'json',
data: {
goods: JSON.stringify({
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
}),
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 => {
this.setState({ shopItem: res.data.goods, total: res.data.goodsCount, filterCondition: order })
})
}
// api 得到店铺详情请求
getShopDescription({ shopID = 808 }) {
Taro.request({
url: URL.ShopDescription,
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)
})
}
)
}
// 产品排序
accendingDescending(value) {
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" })
}
)
}
}
// 是否显示侧边筛选
showAndHideFilter() {
this.setState({ isShowFilter: !this.state.isShowFilter })
}
// 选择侧边筛选的标签
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 })
})
}
}
}
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 })
}
componentWillMount() {
}
componentDidMount() {
this.setState({ shopId: this.$router.params.id, shopName: this.$router.params.name }) // 输出 { id: 2, type: 'test' }
//页面加载之后 得到指定店铺的商品 和 筛选标签
this.goodsSearch({})
this.getSearchParams({})
this.getShopDescription({})
// this.getSearchBarkeyWords()
}
componentDidShow() { }
componentDidHide() { }
render() {
const ShopItemElementsArray = this.state.shopItem.length ? this.state.shopItem.map((item, index) => {
return
}) : null
const filterElementsArray = this.state.filterBar.map((item, index) => {
let isTure = this.state.filterOptions[item]
return
{this.state.filterBarKeys[item]}
{index !== 0 && index !== 5 && (isTure ? : )}
})
// const widthness = this.state.FilterText ? this.state.FilterText.goodsParamExt[5].param_value[0] : null // filter 宽度选项
// 侧边筛选的分类项
const goodsClassElementsArray = this.state.FilterText.goods_class ? this.state.FilterText.goods_class.map((item, index) => {
let isTrue = this.state.cate[item.class_id]
return {item.class_name}
}) : null
// 侧边筛选的商品类型项
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 {object[key].goods_type_ch_name}
}) : null
// 侧边筛选的其他项
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 {object[key].param_name}
{object[key].param_value[0]}
}) : null
// 店铺页面/店铺主页
const shopHomepageElement =
{filterElementsArray}
筛选
{/* 侧边筛选 */}
分类
{goodsClassElementsArray}
商品类型
{goodsTypeElementsArray}
{goodsParamElementsArray}
宽度
{/* {widthness.value_desc} */}
{/* 店铺的商品列表 */}
{ShopItemElementsArray}
// 店铺详情
const shopDescriptionElement =
{this.state.shopName}
{this.state.shopAddress}
联系人:{this.state.contactName}
联系电话:{this.state.contactNumber}
店铺简介
店铺介绍:
{this.state.shopDescription}
return (
{shopName}
店铺全部分类
首页
店铺说明
{/* 显示店铺首页或者店铺详情 */}
{this.state.showShopHomePage ? shopHomepageElement : shopDescriptionElement}
)
}
}
export default Shop