import Taro, { Component } from '@tarojs/taro'
import { View, Text, Radio, RadioGroup, Label } from '@tarojs/components'
import { AtInput, AtImagePicker, AtTextarea, AtButton, Picker, AtToast } from 'taro-ui'
import SearchBarComponent from '../../component/searchBarComponent/searchBarComponent'
import copyrightComponent from '../../component/copyrightComponent/copyrightComponent'
import URL from '../../serviceAPI.config'
import './goodsPublish.scss'
class GoodsPublish extends Component {
config = {
navigationBarTitleText: '商品发布'
}
constructor() {
super(...arguments)
this.state = {
selector: ['需求', '供应', '人才'], // 应该是树型结构,需要修改
selectorChecked: '需求',
productName: '',
productPrice: '',
productUnit: '',
productDescript: '',
files: [], // 上传的图片
isUploadImageSuccess: false,
uploadImageTextTip: '',
isUploadProductSuccess: false,
uploadProductTextTip: '',
list: [
{
value: '美国',
text: '美国',
checked: false
},
{
value: '中国',
text: '中国',
checked: true
},
{
value: '巴西',
text: '巴西',
checked: false
},
{
value: '日本',
text: '日本',
checked: false
}
] // 店铺分类选项
}
}
// 发布商品api
//{ 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 }) {
Taro.request({
url: URL.UploadProduct,
method: 'POST',
dataType: 'json',
data: {
deployType: 1,
action: 1,
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
}])
},
header: {
'content-type': 'application/x-www-form-urlencoded',
'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'),
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(res => {
this.setState({ uploadProductTextTip: '发布成功', isUploadProductSuccess: true })
console.log('上传商品', res) // 提示非法请求 ----- to be continue
}
)
.catch(error => {
this.setState({ uploadProductTextTip: '发布失败', isUploadProductSuccess: true })
})
}
// 改变商品分类状态
onChangeProductType(e) {
this.setState({
selectorChecked: this.state.selector[e.detail.value]
})
}
productNameChange(event) {
this.setState({
productName: event
})
}
productPriceChange(event) {
this.setState({
productPrice: event
})
}
productUnitChange(event) {
this.setState({
productUnit: event
})
}
productDescriptChange(event) {
this.setState({
productDescript: event.target.value
})
}
// 上传图片
onChangeImg(files, operationType, index) {
const that = this
if (operationType === 'add') {
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: '上传成功' })
}
})
}
if (operationType === 'remove') {
this.state.files.splice(index, 1);
this.setState({ files: this.state.files });
that.setState({ isUploadImageSuccess: true, uploadImageTextTip: '删除成功' })
}
}
// 图片上传失败
onFail(mes) {
console.log(mes)
}
// 删除图片
onImageClick(index) {
}
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() {
}
componentWillReceiveProps(nextProps) {
console.log(this.props, nextProps)
}
componentWillUnmount() { }
componentDidShow() { }
componentDidHide() { }
render() {
const imageUploadSuccess =
const productUploadSuccess =
return (
{imageUploadSuccess}
{productUploadSuccess}
*商品分类: {this.state.selectorChecked}
*
*
*
{/* 图片上传 */}
*
上传图片:
{/* 店铺分类 */}
*
店铺分类:
国家:
{this.state.list.map((item, i) => {
return (
)
})}
国家:
{this.state.list.map((item, i) => {
return (
)
})}
国家:
{this.state.list.map((item, i) => {
return (
)
})}
商品简介:
发布
发布并新增
商品列表
)
}
}
export default GoodsPublish