import Taro, { Component } from '@tarojs/taro'
import { View, Text, Image, Swiper, SwiperItem,Picker } from '@tarojs/components'
import { AtIcon } from 'taro-ui'
import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent'
import LoginService from '../../util/LoginService'
import URL from '../../serviceAPI.config'
import './goods.scss'
import { getGlobalStorage } from '../../util/getSetStoage';
import { showLoading } from '../../util/hideShowLoading';
import onClickValueService from '../../util/onClickValueService'
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: '',
actived: 0,// 默认tab
subActived:0,//默认sub-tab
}
}
// 商品详情api
getGoodDescription() {
let goodId=decodeURIComponent(this.$router.params.id)
Taro.request({
url: URL.GetShopItemDetail,
method: 'POST',
dataType: 'json',
data: {
goodsID: goodId,
},
header: {
'content-type': 'application/x-www-form-urlencoded',
'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'),
}
})
.then(res => {
Taro.hideLoading()
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() {
if (!getGlobalStorage('userInfo').user_id) {
LoginService()
return
}
Taro.showToast({
title: '收藏成功',
icon: 'success',
duration: 1500
})
}
//添加到购物车
addToCart() {
if (!getGlobalStorage('userInfo').user_id) {
LoginService()
return
}
Taro.showToast({
title: '添加成功',
icon: 'success',
duration: 1500
})
}
clickTabHandler(e) {
let value = onClickValueService(e)
this.setState({
actived: value
})
}
clickSubTabHandler(e) {
let value = onClickValueService(e)
this.setState({
subActived: value
})
}
// 数量或者规格方法
onChange = e => {
this.setState({
selectorChecked: this.state.selector[e.detail.value]
})
}
componentDidMount() {
showLoading({
title: '加载中'
})
this.getGoodDescription()
}
componentWillReceiveProps(nextProps) {
console.log(this.props, nextProps)
}
componentWillUnmount() { }
componentDidShow() { }
componentDidHide() { }
render() {
const { actived,subActived } = this.state
const mainTabList = [{ title: '宝贝详情' }, { title: '全部评价' }, { title: '猜你喜欢' }]
const subTabList = [{ title: '全部' }, { title: '好评' }, { title: '中评' }, { title: '差评' }, { title: '公开' }, { title: '匿名' }]
const tabArrayElement = mainTabList.map((item, index) => {
return
{item.title}
})
const subTabArrayElement = subTabList.map((item, index) => {
return
{item.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}
{/* 详情和评论区 */}
{tabArrayElement}
{actived === 0 &&
商品细节:
{itemDescriptionPicsElementArray}
}
{actived===1&&
{subTabArrayElement}
{
subActived===0&&全部
}
{
subActived===1&&好评
}
{
subActived===2&&中评
}
{
subActived===3&&差评
}
{
subActived===4&&公开
}
{
subActived===5&&匿名
}
}
{actived === 2 && 标签页三的内容}
进店
收藏商品
加入购物车
)
}
}
export default Goods