import Taro, { Component } from '@tarojs/taro' import { View, Button, Text, Swiper, SwiperItem, Image } from '@tarojs/components' import { AtSearchBar, AtTag, AtIcon ,AtSegmentedControl, AtTabBar, AtDrawer } 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' class Shop extends Component { // 项目配置 config = { navigationBarTitleText: '店铺' } constructor() { super(...arguments) this.state = { shopItem:'', value: '', shopId:'', shopName:'', FilterText:'', filterBar:['综合排序','销量','新品','价格','人气'], selectedFilterValue:0, isShowFilter:true, 综合排序:true, 销量:false, 新品:false, 价格:false, 人气:false, cate:{ 10101: false,// "橱柜" 10102: false,// "衣柜" 10106: false,// "装饰柜" 20101: false,// "定制设计" 20103: false,// "产品设计" 30101: false,// "橱柜" 30102: false,// "衣柜" } } } onChange(value) { this.setState({ value: value },()=>{ console.log(this.state.value) }) } 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) }) } 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 }) }) } // get goods info goodsSearch({ curr_page = 1, page_count = 50, 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 => { // console.log(res) this.setState({ shopItem:res.data}) }) } accendingDescending(value){ this.setState({selectedFilterValue:value}) 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" }) }) } } 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}) }) } } } componentWillMount() { this.setState({ shopId: this.$router.params.id, shopName: this.$router.params.name}) // 输出 { id: 2, type: 'test' } } componentDidMount(){ this.goodsSearch({}) this.getSearchParams({}) this.getSearchBarkeyWords() } componentDidShow() { } componentDidHide() { } render() { const shopName= this.state.shopName const ShopItemElementsArray =this.state.shopItem? this.state.shopItem.goods.map((item,index)=>{ return }):null const filterElementsArray=this.state.filterBar.map((item,index)=>{ let isTure=this.state[item] return {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 return ( {shopName} 店铺全部分类 首页 店铺说明 {filterElementsArray} 筛选 {/* sidebar 筛选 */} 分类 {goodsClassElementsArray} 商品类型 {goodsTypeElementsArray} {goodsParamElementsArray} 宽度 {/* {widthness.value_desc} */} {ShopItemElementsArray} ) } } export default Shop