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

306 lines
11 KiB
JavaScript
Raw Normal View History

2018-12-06 17:24:34 +08:00
import Taro, { Component } from '@tarojs/taro'
import { View, Text, Image, Swiper, SwiperItem, Picker } from '@tarojs/components'
import { AtIcon } from 'taro-ui'
2018-12-18 17:37:23 +08:00
import GoodCommentSection from './goodCommentSection/goodCommentSection'
import AliGoodCommentSection from './aliGoodCommentSection/aliGoodCommentSection'
2019-01-11 17:33:26 +08:00
import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent'
import platformChecker from '../../util/plaformChecker'
2019-02-20 16:59:06 +08:00
import LoginService from '../../util/LoginService'
import URL from '../../serviceAPI.config'
2018-12-06 17:24:34 +08:00
import './goods.scss'
2019-03-08 17:32:42 +08:00
import { getGlobalStorage } from '../../util/getSetStoage';
import { showLoading } from '../../util/hideShowLoading';
import onClickValueService from '../../util/onClickValueService'
2019-01-14 17:04:08 +08:00
2018-12-06 17:24:34 +08:00
class Goods extends Component {
config = {
2018-12-11 17:34:06 +08:00
navigationBarTitleText: '商品详情'
2018-12-06 17:24:34 +08:00
}
constructor() {
super(...arguments)
this.state = {
2018-12-11 17:34:06 +08:00
current: 0, // 当前大类评论区
2018-12-18 17:37:23 +08:00
subCurrent: 0, // 当前小类评论区
2018-12-11 17:34:06 +08:00
selector: ['0', '1', '2', '3'], // 数量或者规格选择
selectorChecked: '0', // 已选择的数量或规格
2018-12-18 17:37:23 +08:00
productImagesUrl: '', // 图片地址
productName: '',// 商品名字
productDes: '',// 商品简介
oldPirce: '',// 原价
specialPrice: '',//促销价
productType: '',//商品类型
serviceArea: '',//服务区域
monthSold: '',//月销量
totalSold: '',//总销量
browsingCount: '',// 浏览数
shopId: '',
actived: 0,// 默认tab
subActived: 0,//默认sub-tab
2018-12-18 17:37:23 +08:00
}
}
2019-01-08 13:51:26 +08:00
2018-12-18 17:37:23 +08:00
// 商品详情api
getGoodDescription() {
let goodId = decodeURIComponent(this.$router.params.id)
2018-12-18 17:37:23 +08:00
Taro.request({
url: URL.GetShopItemDetail,
method: 'POST',
dataType: 'json',
data: {
2019-03-15 16:48:59 +08:00
goodsID: goodId,
2018-12-18 17:37:23 +08:00
},
header: {
'content-type': 'application/x-www-form-urlencoded',
2019-03-08 17:32:42 +08:00
'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'),
2018-12-18 17:37:23 +08:00
}
})
.then(res => {
2019-03-06 14:16:09 +08:00
Taro.hideLoading()
2018-12-18 17:37:23 +08:00
console.log('商品详情:', res)
2019-01-08 13:51:26 +08:00
if (res.data.err_msg === "success") {
2019-01-03 17:36:59 +08:00
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,
2019-01-08 13:51:26 +08:00
shopId: res.data.goods.shop_id
2019-01-03 17:36:59 +08:00
})
2019-01-08 13:51:26 +08:00
} else {
Taro.showToast({
title: res.data.err_msg,
icon: 'none',
duration: 1000
})
2019-01-03 17:36:59 +08:00
}
2018-12-18 17:37:23 +08:00
}
)
}
2018-12-06 17:24:34 +08:00
2018-12-11 17:34:06 +08:00
// 大类评论区方法
mainTabClick(value) {
2018-12-06 17:24:34 +08:00
this.setState({
current: value
})
}
2018-12-11 17:34:06 +08:00
// 小磊评论区方法
subTabClick(value) {
2018-12-06 17:24:34 +08:00
this.setState({
subCurrent: value
})
}
2018-12-11 17:34:06 +08:00
// 去其他页面
2018-12-18 17:37:23 +08:00
goShopPage() {
Taro.navigateTo({
2019-01-08 13:51:26 +08:00
url: '/pages/shop/shop?id=' + this.state.shopId
})
}
2018-12-11 17:34:06 +08:00
// 收藏商品
2018-12-18 17:37:23 +08:00
saveItem() {
2019-03-08 17:32:42 +08:00
if (!getGlobalStorage('userInfo').user_id) {
2019-02-12 17:21:31 +08:00
LoginService()
return
}
2019-01-03 17:36:59 +08:00
Taro.showToast({
2019-01-08 13:51:26 +08:00
title: '收藏成功',
icon: 'success',
duration: 1500
2019-01-03 17:36:59 +08:00
})
}
//添加到购物车
2019-01-08 13:51:26 +08:00
addToCart() {
2019-03-08 17:32:42 +08:00
if (!getGlobalStorage('userInfo').user_id) {
2019-02-12 17:21:31 +08:00
LoginService()
return
}
2019-01-03 17:36:59 +08:00
Taro.showToast({
2019-01-08 13:51:26 +08:00
title: '添加成功',
icon: 'success',
duration: 1500
2019-01-03 17:36:59 +08:00
})
}
aliMainTabClick(e) {
let value = onClickValueService(e)
this.setState({
actived: value
})
}
aliSubTabClick(e) {
let value = onClickValueService(e)
this.setState({
subActived: value
})
}
2018-12-11 17:34:06 +08:00
// 数量或者规格方法
onChange = e => {
this.setState({
selectorChecked: this.state.selector[e.detail.value]
})
}
2019-02-12 17:21:31 +08:00
2018-12-06 17:24:34 +08:00
componentDidMount() {
showLoading({
2019-03-06 14:16:09 +08:00
title: '加载中'
})
this.getGoodDescription()
2018-12-06 17:24:34 +08:00
}
componentWillReceiveProps(nextProps) {
console.log(this.props, nextProps)
}
componentWillUnmount() { }
componentDidShow() { }
componentDidHide() { }
render() {
2018-12-11 17:34:06 +08:00
// const subTabList = [{ title: '全部' }, { title: '好评' }, { title: '差评' }, { title: '公开' }, { title: '匿名' }]
2019-01-08 13:51:26 +08:00
const itemPicsBannerElementArray = this.state.productImagesUrl.map((item, index) => {
return <SwiperItem key={index} >
2019-01-08 13:51:26 +08:00
<Image mode='aspectFit' src={URL.Base + item.file_path} style='max-width: 100%; height:100%;' />
</SwiperItem >
2018-12-18 17:37:23 +08:00
})
2019-01-08 13:51:26 +08:00
2018-12-06 17:24:34 +08:00
return (
<View className='gooods=container'>
2019-01-08 13:51:26 +08:00
<View className='img-box'>
2018-12-18 17:37:23 +08:00
{/* <Image className='img' src={URL.Base + this.state.productImagesUrl}></Image> */}
<Swiper
className='swipper'
style='height:100%;'
indicatorColor='#999'
indicatorActiveColor='#333'
hotizontal
circular
indicatorDots
2018-12-18 17:37:23 +08:00
>
2019-01-08 13:51:26 +08:00
{itemPicsBannerElementArray}
2018-12-18 17:37:23 +08:00
2019-01-08 13:51:26 +08:00
</Swiper>
2018-12-18 17:37:23 +08:00
2018-12-06 17:24:34 +08:00
</View>
<View className='title-box'>
<View className='main-title'>
2018-12-18 17:37:23 +08:00
{this.state.productName}
2018-12-06 17:24:34 +08:00
</View>
<View className='subtitle-box'>
2018-12-18 17:37:23 +08:00
{this.state.productDes}
2018-12-06 17:24:34 +08:00
</View>
</View>
<View className='price-box'>
<View className='org-box'>
<Text className='title'>原价</Text>
2018-12-18 17:37:23 +08:00
<Text className='price'>{this.state.oldPirce}</Text>
2018-12-06 17:24:34 +08:00
</View>
<View className='spe-price'>
<Text className='title'>促销价</Text>
2018-12-18 17:37:23 +08:00
<Text className='price'>{this.state.specialPrice}</Text>
2018-12-06 17:24:34 +08:00
</View>
</View>
<View className='info-box'>
<View className='type'>
<Text className='title'>商品类型</Text>
2018-12-18 17:37:23 +08:00
<Text className='desc'>{this.state.productType}</Text>
2018-12-06 17:24:34 +08:00
</View>
<View className='district'>
<Text className='title'>服务区域</Text>
2018-12-18 17:37:23 +08:00
<Text className='desc'>{this.state.serviceArea}</Text>
2018-12-06 17:24:34 +08:00
</View>
</View>
<View className='counter-box'>
<View className='month-sold'>
<Text className='title'>月销量</Text>
2018-12-18 17:37:23 +08:00
<Text className='amount'>{this.state.monthSold}</Text>
2018-12-06 17:24:34 +08:00
</View>
<View className='total-sold'>
<Text className='title'>总销量</Text>
2018-12-18 17:37:23 +08:00
<Text className='amount'>{this.state.totalSold}</Text>
2018-12-06 17:24:34 +08:00
</View>
<View className='browsing-amount'>
<Text className='title'>浏览量</Text>
2018-12-18 17:37:23 +08:00
<Text className='amount'>{this.state.browsingCount}</Text>
2018-12-06 17:24:34 +08:00
</View>
</View>
<View className='standard-box'>
2018-12-18 17:37:23 +08:00
{/* 规格或者数量 */}
<Picker mode='selector' range={this.state.selector} onChange={this.onChange}>
<View className='picker'>
<View className='title'>
可选规格:
</View>
<View className='more'>
{this.state.selectorChecked}
2018-12-18 17:37:23 +08:00
</View>
</View>
</Picker>
2018-12-06 17:24:34 +08:00
</View>
2018-12-11 17:34:06 +08:00
{/* 详情和评论区 */}
2018-12-06 17:24:34 +08:00
{platformChecker() ? <GoodCommentSection
productImagesUrl={this.state.productImagesUrl}
mainCurrent={this.state.current}
subCurrent={this.state.subCurrent}
onMainOnClick={this.state.mainTabClick.bind(this)}
onSubOnClick={this.state.subTabClick.bind(this)}
/> : <AliGoodCommentSection
mainActived={this.state.actived}
subActived={this.state.subActived}
productImagesUrl={this.state.productImagesUrl}
onAliMainOnClick={this.state.aliMainTabClick.bind(this)}
onAliSubOnClick={this.state.aliSubTabClick.bind(this)}
/>}
2019-01-11 17:33:26 +08:00
<CopyrightComponent></CopyrightComponent>
<View className='gap' style='height:150rpx'>
</View>
2018-12-06 17:24:34 +08:00
<View className='shop-bottom-box' >
<View className='shop-bottom-nav'>
<View className='to-shop' onClick={this.goShopPage.bind(this)}>
<AtIcon className='icon' value='home' size='12' color='black'></AtIcon>
<Text className='title'>进店</Text>
2018-12-06 17:24:34 +08:00
</View>
<View className='collection' onClick={this.saveItem.bind(this)}>
2018-12-18 17:37:23 +08:00
<AtIcon className='icon' value='heart' size='12' color='white'></AtIcon>
2019-01-08 13:51:26 +08:00
2018-12-18 17:37:23 +08:00
<Text className='title'>收藏商品</Text>
2018-12-06 17:24:34 +08:00
</View>
2019-01-08 13:51:26 +08:00
<View className='add-cart' onClick={this.addToCart.bind(this)}>
2019-01-03 17:36:59 +08:00
<AtIcon className='icon' value='shopping-cart' size='12' color='white'></AtIcon>
2019-01-08 13:51:26 +08:00
<Text className='title'> 加入购物车</Text>
2018-12-06 17:24:34 +08:00
</View>
</View>
</View>
</View >
2018-12-06 17:24:34 +08:00
)
}
}
export default Goods