import Taro, { Component } from '@tarojs/taro' import { View, Text, Image, Swiper, SwiperItem } from '@tarojs/components' import { AtTabs, AtTabsPane, AtSegmentedControl, AtIcon, Picker } from 'taro-ui' import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent' import URL from '../../serviceAPI.config' import './goods.scss' class Goods extends Component { config = { navigationBarTitleText: '商品详情' } constructor() { super(...arguments) this.state = { current: 0, // 当前大类评论区 subCurrent: 0, // 当前小类评论区 selector: ['0', '1', '2', '3'], // 数量或者规格选择 selectorChecked: '0', // 已选择的数量或规格 productImagesUrl: '', // 图片地址 productName: '',// 商品名字 productDes: '',// 商品简介 oldPirce: '',// 原价 specialPrice: '',//促销价 productType: '',//商品类型 serviceArea: '',//服务区域 monthSold: '',//月销量 totalSold: '',//总销量 browsingCount: '',// 浏览数 shopId: '' } } // 商品详情api getGoodDescription() { Taro.request({ url: URL.GetShopItemDetail, method: 'POST', dataType: 'json', data: { goodsID: this.$router.params.id, }, header: { 'content-type': 'application/x-www-form-urlencoded', 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), } }) .then(res => { console.log('商品详情:', res) if (res.data.err_msg === "success") { this.setState({ productImagesUrl: res.data.goods.goods_pic, productName: res.data.goods.goods_name, productDes: res.data.goods.goods_profiles, oldPirce: res.data.goods.goods_org_price, specialPrice: res.data.goods.goods_price, productType: res.data.goods.goods_type_name, serviceArea: res.data.goodsRegionName[0], monthSold: res.data.goods.month_sales, totalSold: res.data.goods.sales_volume, browsingCount: res.data.goods.browse_times, shopId: res.data.goods.shop_id }) } else { Taro.showToast({ title: res.data.err_msg, icon: 'none', duration: 1000 }) } } ) } // 大类评论区方法 handleClick(value) { this.setState({ current: value }) } // 小磊评论区方法 onClick(value) { this.setState({ subCurrent: value }) } // 去其他页面 goShopPage() { Taro.navigateTo({ url: '/pages/shop/shop?id=' + this.state.shopId }) } // 收藏商品 saveItem() { Taro.showToast({ title: '收藏成功', icon: 'success', duration: 1500 }) } //添加到购物车 addToCart() { Taro.showToast({ title: '添加成功', icon: 'success', duration: 1500 }) } // 数量或者规格方法 onChange = e => { this.setState({ selectorChecked: this.state.selector[e.detail.value] }) } componentDidMount() { this.getGoodDescription() } componentWillReceiveProps(nextProps) { console.log(this.props, nextProps) } componentWillUnmount() { } componentDidShow() { } componentDidHide() { } render() { const mainTabList = [{ title: '宝贝详情' }, { title: '全部评价' }, { title: '猜你喜欢' }] // const subTabList = [{ title: '全部' }, { title: '好评' }, { title: '差评' }, { title: '公开' }, { title: '匿名' }] const itemPicsBannerElementArray = this.state.productImagesUrl.map((item, index) => { return }) const itemDescriptionPicsElementArray = this.state.productImagesUrl.map((item, index) => { return }) return ( {/* */} {itemPicsBannerElementArray} {this.state.productName} {this.state.productDes} 原价 ¥{this.state.oldPirce} 促销价 ¥{this.state.specialPrice} 商品类型 {this.state.productType} 服务区域 {this.state.serviceArea} 月销量 {this.state.monthSold} 总销量 {this.state.totalSold} 浏览量 {this.state.browsingCount} {/* 规格或者数量 */} 可选规格: {this.state.selectorChecked} {/* 详情和评论区 */} {/* 大类 */} 商品细节: {itemDescriptionPicsElementArray} { /*子标签类*/} { this.state.subCurrent === 0 ? 全部 : null } { this.state.subCurrent === 1 ? 好评 : null } { this.state.subCurrent === 2 ? 中评 : null } { this.state.subCurrent === 3 ? 差评 : null } { this.state.subCurrent === 4 ? 公开 : null } { this.state.subCurrent === 5 ? 匿名 : null } 标签页三的内容 进店 收藏商品 加入购物车 ) } } export default Goods