2018-12-06 17:24:34 +08:00
|
|
|
import Taro, { Component } from '@tarojs/taro'
|
2018-12-18 17:37:23 +08:00
|
|
|
import { View, Text, Radio, RadioGroup, Label } from '@tarojs/components'
|
2018-12-19 17:40:32 +08:00
|
|
|
import { AtInput, AtImagePicker, AtTextarea, AtButton, Picker, AtToast } from 'taro-ui'
|
2018-12-06 17:24:34 +08:00
|
|
|
|
2018-12-10 17:38:17 +08:00
|
|
|
import SearchBarComponent from '../../component/searchBarComponent/searchBarComponent'
|
2018-12-07 17:17:46 +08:00
|
|
|
import copyrightComponent from '../../component/copyrightComponent/copyrightComponent'
|
2018-12-18 17:37:23 +08:00
|
|
|
import URL from '../../serviceAPI.config'
|
2018-12-06 17:24:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
import './goodsPublish.scss'
|
|
|
|
|
|
|
|
class GoodsPublish extends Component {
|
|
|
|
|
|
|
|
config = {
|
|
|
|
navigationBarTitleText: '商品发布'
|
|
|
|
}
|
|
|
|
constructor() {
|
|
|
|
super(...arguments)
|
|
|
|
this.state = {
|
2018-12-11 17:34:06 +08:00
|
|
|
selector: ['需求', '供应', '人才'], // 应该是树型结构,需要修改
|
2018-12-10 17:38:17 +08:00
|
|
|
selectorChecked: '需求',
|
2018-12-18 17:37:23 +08:00
|
|
|
productName: '',
|
|
|
|
productPrice: '',
|
|
|
|
productUnit: '',
|
|
|
|
productDescript: '',
|
2018-12-19 17:40:32 +08:00
|
|
|
files: [], // 上传的图片
|
|
|
|
isUploadImageSuccess: false,
|
|
|
|
uploadImageTextTip: '',
|
|
|
|
isUploadProductSuccess: false,
|
|
|
|
uploadProductTextTip: '',
|
2018-12-06 17:24:34 +08:00
|
|
|
list: [
|
|
|
|
{
|
|
|
|
value: '美国',
|
|
|
|
text: '美国',
|
|
|
|
checked: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '中国',
|
|
|
|
text: '中国',
|
|
|
|
checked: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '巴西',
|
|
|
|
text: '巴西',
|
|
|
|
checked: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '日本',
|
|
|
|
text: '日本',
|
|
|
|
checked: false
|
|
|
|
}
|
2018-12-18 17:37:23 +08:00
|
|
|
|
2018-12-11 17:34:06 +08:00
|
|
|
] // 店铺分类选项
|
2018-12-06 17:24:34 +08:00
|
|
|
}
|
|
|
|
}
|
2018-12-18 17:37:23 +08:00
|
|
|
|
|
|
|
// 发布商品api
|
2018-12-19 17:40:32 +08:00
|
|
|
//{ goods_name = "test2", goods_price= "1.00", goods_unit= "1",goods_profiles= "test2",class_id= "10103",shop_class_id= "1899", file_id= "27959",file_type= 1,if_cover= 1,file_sort= 1}
|
|
|
|
uploadGoods({ goods_name = "test2", goods_price = "1.00", goods_unit = "1", goods_profiles = "test2", class_id = "10103", shop_class_id = "1899", file_id = "27959", file_type = 1, if_cover = 1, file_sort = 1 }) {
|
2018-12-18 17:37:23 +08:00
|
|
|
Taro.request({
|
|
|
|
url: URL.UploadProduct,
|
|
|
|
method: 'POST',
|
|
|
|
dataType: 'json',
|
|
|
|
data: {
|
|
|
|
deployType: 1,
|
|
|
|
action: 1,
|
2018-12-19 17:40:32 +08:00
|
|
|
goods: JSON.stringify({
|
|
|
|
goods_name: goods_name,
|
|
|
|
goods_price: goods_price,
|
|
|
|
goods_unit: goods_unit,
|
|
|
|
goods_profiles: goods_profiles,
|
|
|
|
class_id: class_id,
|
|
|
|
shop_class_id: shop_class_id
|
|
|
|
}),
|
|
|
|
goodsFiles: JSON.stringify([{
|
|
|
|
file_id: file_id,
|
|
|
|
file_type: file_type,
|
|
|
|
if_cover: if_cover,
|
|
|
|
file_sort: file_sort
|
|
|
|
}])
|
2018-12-18 17:37:23 +08:00
|
|
|
},
|
|
|
|
header: {
|
|
|
|
'content-type': 'application/x-www-form-urlencoded',
|
2018-12-19 17:40:32 +08:00
|
|
|
'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'),
|
|
|
|
'X-Requested-With': 'XMLHttpRequest'
|
2018-12-18 17:37:23 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(res => {
|
2018-12-19 17:40:32 +08:00
|
|
|
this.setState({ uploadProductTextTip: '发布成功', isUploadProductSuccess: true })
|
2018-12-18 17:37:23 +08:00
|
|
|
console.log('上传商品', res) // 提示非法请求 ----- to be continue
|
|
|
|
}
|
|
|
|
)
|
2018-12-19 17:40:32 +08:00
|
|
|
.catch(error => {
|
|
|
|
this.setState({ uploadProductTextTip: '发布失败', isUploadProductSuccess: true })
|
|
|
|
})
|
2018-12-18 17:37:23 +08:00
|
|
|
}
|
2018-12-19 17:40:32 +08:00
|
|
|
|
2018-12-11 17:34:06 +08:00
|
|
|
// 改变商品分类状态
|
2018-12-19 17:40:32 +08:00
|
|
|
onChangeProductType(e) {
|
2018-12-10 17:38:17 +08:00
|
|
|
this.setState({
|
|
|
|
selectorChecked: this.state.selector[e.detail.value]
|
|
|
|
})
|
|
|
|
}
|
2018-12-18 17:37:23 +08:00
|
|
|
productNameChange(event) {
|
2018-12-06 17:24:34 +08:00
|
|
|
this.setState({
|
2018-12-11 17:34:06 +08:00
|
|
|
productName: event
|
2018-12-06 17:24:34 +08:00
|
|
|
})
|
|
|
|
}
|
2018-12-18 17:37:23 +08:00
|
|
|
productPriceChange(event) {
|
2018-12-11 17:34:06 +08:00
|
|
|
this.setState({
|
|
|
|
productPrice: event
|
|
|
|
})
|
|
|
|
}
|
2018-12-18 17:37:23 +08:00
|
|
|
productUnitChange(event) {
|
2018-12-11 17:34:06 +08:00
|
|
|
this.setState({
|
|
|
|
productUnit: event
|
|
|
|
})
|
|
|
|
}
|
2018-12-18 17:37:23 +08:00
|
|
|
productDescriptChange(event) {
|
2018-12-11 17:34:06 +08:00
|
|
|
this.setState({
|
|
|
|
productDescript: event.target.value
|
|
|
|
})
|
|
|
|
}
|
|
|
|
// 上传图片
|
2018-12-19 17:40:32 +08:00
|
|
|
onChangeImg(files, operationType, index) {
|
|
|
|
const that = this
|
2018-12-11 17:34:06 +08:00
|
|
|
if (operationType === 'add') {
|
2018-12-19 17:40:32 +08:00
|
|
|
Taro.uploadFile({
|
|
|
|
url: URL.UploadPorductImage, // 仅为示例,非真实的接口地址
|
|
|
|
filePath: files[files.length - 1].url,
|
|
|
|
name: 'file',
|
|
|
|
formData: {
|
|
|
|
user: 'test'
|
|
|
|
},
|
|
|
|
header: {
|
|
|
|
'content-type': 'multipart/form-data',
|
|
|
|
'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'),
|
|
|
|
'X-Requested-With': 'XMLHttpRequest'
|
|
|
|
},
|
|
|
|
success(response) {
|
|
|
|
const data = JSON.parse(response.data)
|
|
|
|
const imagePath = URL.Base + data.file_path
|
|
|
|
const newFiles = that.state.files.concat({ url: imagePath })
|
|
|
|
|
|
|
|
that.setState({ files: newFiles, isUploadImageSuccess: true, uploadImageTextTip: '上传成功' })
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2018-12-11 17:34:06 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
if (operationType === 'remove') {
|
|
|
|
this.state.files.splice(index, 1);
|
|
|
|
this.setState({ files: this.state.files });
|
2018-12-19 17:40:32 +08:00
|
|
|
that.setState({ isUploadImageSuccess: true, uploadImageTextTip: '删除成功' })
|
2018-12-11 17:34:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// 图片上传失败
|
2018-12-06 17:24:34 +08:00
|
|
|
onFail(mes) {
|
|
|
|
console.log(mes)
|
|
|
|
}
|
2018-12-11 17:34:06 +08:00
|
|
|
// 删除图片
|
|
|
|
onImageClick(index) {
|
2018-12-18 17:37:23 +08:00
|
|
|
}
|
2018-12-19 17:40:32 +08:00
|
|
|
onClickUploadGoods() {
|
|
|
|
if (this.state.productName && this.state.productPrice && this.state.productUnit && this.state.files.length) {
|
|
|
|
this.uploadGoods({
|
|
|
|
goods_name: this.state.productName,
|
|
|
|
goods_price: this.state.productPrice,
|
|
|
|
goods_unit: this.state.productUnit,
|
|
|
|
goods_profiles: this.state.productDescript,
|
|
|
|
class_id: "10103",
|
|
|
|
shop_class_id: "1899",
|
|
|
|
file_id: "27959",
|
|
|
|
file_type: 1,
|
|
|
|
if_cover: 1,
|
|
|
|
file_sort: 1
|
|
|
|
})
|
|
|
|
}else{
|
|
|
|
this.setState({ uploadProductTextTip: '请填写完表格', isUploadProductSuccess: true })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
2018-12-06 17:24:34 +08:00
|
|
|
}
|
2018-12-18 17:37:23 +08:00
|
|
|
|
2018-12-06 17:24:34 +08:00
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
console.log(this.props, nextProps)
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() { }
|
|
|
|
|
|
|
|
componentDidShow() { }
|
|
|
|
|
|
|
|
componentDidHide() { }
|
|
|
|
|
|
|
|
render() {
|
2018-12-19 17:40:32 +08:00
|
|
|
const imageUploadSuccess = <AtToast
|
|
|
|
isOpened={this.state.isUploadImageSuccess}
|
|
|
|
text={this.state.uploadImageTextTip}
|
|
|
|
duration={1000}
|
|
|
|
></AtToast>
|
|
|
|
const productUploadSuccess = <AtToast
|
|
|
|
isOpened={this.state.isUploadProductSuccess}
|
|
|
|
text={this.state.uploadProductTextTip}
|
|
|
|
duration={1000}
|
|
|
|
></AtToast>
|
2018-12-06 17:24:34 +08:00
|
|
|
return (
|
|
|
|
<View className='goods-publish'>
|
2018-12-19 17:40:32 +08:00
|
|
|
{imageUploadSuccess}
|
|
|
|
{productUploadSuccess}
|
2018-12-10 17:38:17 +08:00
|
|
|
<SearchBarComponent></SearchBarComponent>
|
2018-12-06 17:24:34 +08:00
|
|
|
<View className='goods-category'>
|
2018-12-10 17:38:17 +08:00
|
|
|
<View className='page-section'>
|
|
|
|
<View>
|
2018-12-19 17:40:32 +08:00
|
|
|
<Picker mode='selector' range={this.state.selector} onChange={this.onChangeProductType.bind(this)}>
|
2018-12-10 17:38:17 +08:00
|
|
|
<View className='picker'>
|
|
|
|
<View className='title-box'>
|
|
|
|
<Text className='title'><Text className='require'>*</Text>商品分类:</Text> <Text className='selected'>{this.state.selectorChecked}</Text>
|
|
|
|
</View>
|
|
|
|
|
|
|
|
</View>
|
|
|
|
</Picker>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
|
|
|
|
<View className='input-box'>
|
|
|
|
<Text className='require'>*</Text>
|
2018-12-06 17:24:34 +08:00
|
|
|
<AtInput
|
2018-12-18 17:37:23 +08:00
|
|
|
name='value'
|
|
|
|
title='商品名称:'
|
|
|
|
type='text'
|
|
|
|
value={this.state.productName}
|
|
|
|
onChange={this.productNameChange.bind(this)}
|
2018-12-06 17:24:34 +08:00
|
|
|
/>
|
|
|
|
</View>
|
2018-12-10 17:38:17 +08:00
|
|
|
<View className='input-box'>
|
|
|
|
<Text className='require'>*</Text>
|
2018-12-18 17:37:23 +08:00
|
|
|
<AtInput
|
|
|
|
name='value'
|
|
|
|
title='商品价格:'
|
|
|
|
type='number'
|
|
|
|
placeholder='¥'
|
|
|
|
value={this.state.productPrice}
|
|
|
|
onChange={this.productPriceChange.bind(this)}
|
|
|
|
/>
|
|
|
|
</View>
|
2018-12-10 17:38:17 +08:00
|
|
|
<View className='input-box'>
|
|
|
|
<Text className='require'>*</Text>
|
2018-12-18 17:37:23 +08:00
|
|
|
<AtInput
|
|
|
|
name='value'
|
|
|
|
title='商品单位:'
|
|
|
|
type='text'
|
|
|
|
value={this.state.productUnit}
|
|
|
|
onChange={this.productUnitChange.bind(this)}
|
|
|
|
/>
|
2018-12-10 17:38:17 +08:00
|
|
|
</View>
|
2018-12-11 17:34:06 +08:00
|
|
|
{/* 图片上传 */}
|
2018-12-06 17:24:34 +08:00
|
|
|
<View className='img-box'>
|
|
|
|
<View className='title-box'>
|
2018-12-10 17:38:17 +08:00
|
|
|
<Text className='require'>*</Text>
|
2018-12-06 17:24:34 +08:00
|
|
|
<Text className='title'>上传图片:</Text>
|
|
|
|
</View>
|
|
|
|
<View className='img-container'>
|
|
|
|
<AtImagePicker
|
2018-12-18 17:37:23 +08:00
|
|
|
multiple
|
|
|
|
files={this.state.files}
|
|
|
|
onChange={this.onChangeImg.bind(this)}
|
|
|
|
onFail={this.onFail.bind(this)}
|
|
|
|
onImageClick={this.onImageClick.bind(this)}
|
2018-12-06 17:24:34 +08:00
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
<View className='shoptype-box'>
|
2018-12-18 17:37:23 +08:00
|
|
|
{/* 店铺分类 */}
|
2018-12-06 17:24:34 +08:00
|
|
|
<View className='title-box'>
|
2018-12-10 17:38:17 +08:00
|
|
|
<Text className='require'>*</Text>
|
|
|
|
<Text className='title'>店铺分类:</Text>
|
2018-12-06 17:24:34 +08:00
|
|
|
</View>
|
|
|
|
<View className='shoptype-container'>
|
|
|
|
<View className='title-box'>
|
|
|
|
<Text className='title'>国家:</Text>
|
|
|
|
</View>
|
|
|
|
<View className='radio-box'>
|
|
|
|
<RadioGroup>
|
|
|
|
{this.state.list.map((item, i) => {
|
|
|
|
return (
|
|
|
|
<Label className='radio-list__label' for={i} key={i}>
|
|
|
|
<Radio color='#FF9500' className='radio-list__radio' value={item.value} checked={item.checked}>{item.text}</Radio>
|
|
|
|
</Label>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</RadioGroup>
|
|
|
|
</View>
|
|
|
|
<View className='title-box'>
|
|
|
|
<Text className='title'>国家:</Text>
|
|
|
|
</View>
|
|
|
|
<View className='radio-box'>
|
|
|
|
<RadioGroup>
|
|
|
|
{this.state.list.map((item, i) => {
|
|
|
|
return (
|
|
|
|
<Label className='radio-list__label' for={i} key={i}>
|
|
|
|
<Radio color='#FF9500' className='radio-list__radio' value={item.value} checked={item.checked}>{item.text}</Radio>
|
|
|
|
</Label>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</RadioGroup>
|
|
|
|
</View>
|
|
|
|
<View className='title-box'>
|
|
|
|
<Text className='title'>国家:</Text>
|
|
|
|
</View>
|
|
|
|
<View className='radio-box'>
|
|
|
|
<RadioGroup>
|
|
|
|
{this.state.list.map((item, i) => {
|
|
|
|
return (
|
|
|
|
<Label className='radio-list__label' for={i} key={i}>
|
|
|
|
<Radio color='#FF9500' className='radio-list__radio' value={item.value} checked={item.checked}>{item.text}</Radio>
|
|
|
|
</Label>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</RadioGroup>
|
|
|
|
</View>
|
|
|
|
|
|
|
|
</View>
|
2018-12-18 17:37:23 +08:00
|
|
|
|
2018-12-06 17:24:34 +08:00
|
|
|
</View>
|
2018-12-18 17:37:23 +08:00
|
|
|
|
2018-12-06 17:24:34 +08:00
|
|
|
<View className='description-box'>
|
|
|
|
<View className='title-box'>
|
2018-12-11 17:34:06 +08:00
|
|
|
<Text className='require'></Text>
|
2018-12-06 17:24:34 +08:00
|
|
|
<Text className='title'>商品简介:</Text>
|
|
|
|
</View>
|
2018-12-18 17:37:23 +08:00
|
|
|
|
2018-12-06 17:24:34 +08:00
|
|
|
<AtTextarea
|
2018-12-18 17:37:23 +08:00
|
|
|
value={this.state.productDescript}
|
|
|
|
onChange={this.productDescriptChange.bind(this)}
|
|
|
|
maxlength='200'
|
|
|
|
placeholder='你的产品简介'
|
2018-12-06 17:24:34 +08:00
|
|
|
/>
|
|
|
|
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
<View className='button-box'>
|
|
|
|
<View className='button'>
|
2018-12-19 17:40:32 +08:00
|
|
|
<AtButton type='primary' size='small' onClick={this.onClickUploadGoods.bind(this)}>发布</AtButton>
|
2018-12-06 17:24:34 +08:00
|
|
|
</View>
|
|
|
|
<View className='button'>
|
2018-12-18 17:37:23 +08:00
|
|
|
<AtButton type='primary' className='button-a' size='small'>发布并新增</AtButton>
|
2018-12-06 17:24:34 +08:00
|
|
|
</View>
|
|
|
|
<View className='button'>
|
2018-12-18 17:37:23 +08:00
|
|
|
<AtButton type='primary' className='button-a' size='small'>商品列表</AtButton>
|
2018-12-06 17:24:34 +08:00
|
|
|
</View>
|
2018-12-18 17:37:23 +08:00
|
|
|
|
|
|
|
|
2018-12-06 17:24:34 +08:00
|
|
|
|
|
|
|
</View>
|
|
|
|
|
2018-12-07 17:17:46 +08:00
|
|
|
<copyrightComponent></copyrightComponent>
|
|
|
|
|
2018-12-06 17:24:34 +08:00
|
|
|
</View>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default GoodsPublish
|