微信权限,登入。 图片上传

This commit is contained in:
郑茂强 2018-12-19 17:40:32 +08:00
parent 1383fe403d
commit 6887d4ccd8
5 changed files with 231 additions and 137 deletions

View File

@ -1,6 +1,6 @@
import Taro, { Component } from '@tarojs/taro'
import { View, Text, Radio, RadioGroup, Label } from '@tarojs/components'
import { AtInput, AtImagePicker, AtTextarea, AtButton, Picker } from 'taro-ui'
import { AtInput, AtImagePicker, AtTextarea, AtButton, Picker, AtToast } from 'taro-ui'
import SearchBarComponent from '../../component/searchBarComponent/searchBarComponent'
import copyrightComponent from '../../component/copyrightComponent/copyrightComponent'
@ -23,15 +23,11 @@ class GoodsPublish extends Component {
productPrice: '',
productUnit: '',
productDescript: '',
files: [{
url: 'https://jimczj.gitee.io/lazyrepay/aragaki1.jpeg',
},
{
url: 'https://jimczj.gitee.io/lazyrepay/aragaki2.jpeg',
},
{
url: 'https://jimczj.gitee.io/lazyrepay/aragaki3.png',
}], // 上传的图片
files: [], // 上传的图片
isUploadImageSuccess: false,
uploadImageTextTip: '',
isUploadProductSuccess: false,
uploadProductTextTip: '',
list: [
{
value: '美国',
@ -59,7 +55,8 @@ class GoodsPublish extends Component {
}
// 发布商品api
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}
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',
@ -67,38 +64,39 @@ class GoodsPublish extends Component {
data: {
deployType: 1,
action: 1,
goods: JSON.stringify({ "goods_name": "test2", "goods_price": "1.00", "goods_unit": "1", "goods_profiles": "test2", "class_id": "10103", "shop_class_id": "1899" }),
goodsFiles: JSON.stringify([{ "file_id": "27959", "file_type": 1, "if_cover": 1, "file_sort": 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 })
})
}
// 上传商品图片api
uploadGoodsImage() {
Taro.request({
url: URL.UploadPorductImage,
method: 'POST',
dataType: 'json',
data: {
file: 1,
},
header: {
'content-type': 'application/x-www-form-urlencoded',
}
})
.then(res => {
console.log('上传商品图片', res)
}
)
}
// 改变商品分类状态
onChange(e) {
onChangeProductType(e) {
this.setState({
selectorChecked: this.state.selector[e.detail.value]
})
@ -124,17 +122,37 @@ class GoodsPublish extends Component {
})
}
// 上传图片
onChangeImg(files, operationType,index) {
onChangeImg(files, operationType, index) {
const that = this
if (operationType === 'add') {
this.setState({
files
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) {
@ -142,10 +160,29 @@ class GoodsPublish extends Component {
}
// 删除图片
onImageClick(index) {
}
componentDidMount(){
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) {
@ -159,14 +196,25 @@ class GoodsPublish extends Component {
componentDidHide() { }
render() {
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>
return (
<View className='goods-publish'>
{imageUploadSuccess}
{productUploadSuccess}
<SearchBarComponent></SearchBarComponent>
<View className='goods-category'>
<View className='page-section'>
<View>
<Picker mode='selector' range={this.state.selector} onChange={this.onChange}>
<Picker mode='selector' range={this.state.selector} onChange={this.onChangeProductType.bind(this)}>
<View className='picker'>
<View className='title-box'>
<Text className='title'><Text className='require'>*</Text>:</Text> <Text className='selected'>{this.state.selectorChecked}</Text>
@ -295,7 +343,7 @@ class GoodsPublish extends Component {
</View>
<View className='button-box'>
<View className='button'>
<AtButton type='primary' size='small'>发布</AtButton>
<AtButton type='primary' size='small' onClick={this.onClickUploadGoods.bind(this)}>发布</AtButton>
</View>
<View className='button'>
<AtButton type='primary' className='button-a' size='small'>发布并新增</AtButton>

View File

@ -1,6 +1,6 @@
import Taro, { Component } from '@tarojs/taro'
import { View, Button, Text, Swiper, SwiperItem, Image, } from '@tarojs/components'
import { AtModal } from 'taro-ui'
import { AtModal, AtButton } from 'taro-ui'
import filteredShopComponent from '../../component/filteredShopComponent/filteredShopComponent'
import bottomNav from '../../component/bottomNav/bottomNav'
import URL from '../../serviceAPI.config'
@ -24,16 +24,7 @@ class Home extends Component {
isOpen: false, // 抢单消息提示
}
}
componentWillMount() {
}
componentDidMount() {
// 页面加载后 得到首页的基本信息和推荐店铺的信息
Taro.showLoading({ title: '加载中' })
this.getShops()
this.getHomeCategoriesInfo()
this.login()
}
@ -82,16 +73,12 @@ class Home extends Component {
}
// 登入api
login() {
Taro.login({
success(res) {
if (res.code) {
// 发起网络请求
console.log(res)
console.log('手机端微信code',res.code)
Taro.request({
url: URL.Login,
method: 'POST',
@ -104,17 +91,41 @@ class Home extends Component {
}
})
.then(response => {
console.log('登入', response)
// console.log('登入', response)
//储存后台返回的session_id 到local Storage
Taro.setStorageSync('session_id', response.data.session_id)
}
)}
else {
)
}
else {
console.log('登录失败!' + res.errMsg)
}
}
})
}
// 微信用户设置
// wxUserSetting() {
// Taro.getSetting({
// success(res) {
// if (res.authSetting['scope.userInfo']) {
// console.log('personal info', res)
// Taro.authorize({
// scope: 'scope.userInfo',
// success() {
// // 用户已经同意小程序使用录音功能,后续调用 wx.startRecord 接口不会弹窗询问
// // Taro.getUserInfo({
// // success(res1) {
// // console.log('res1',res1)
// // }
// // })
// console.log('权限允许')
// }
// })
// }
// }
// })
// }
// api 抢单请求
GrabDemand({ demandId = 218 }) {
Taro.request({
@ -164,6 +175,19 @@ class Home extends Component {
// 确认抢单之后
this.GrabDemand({})
}
componentDidMount() {
// 页面加载后 得到首页的基本信息和推荐店铺的信息
Taro.showLoading({ title: '加载中' })
this.getShops()
this.getHomeCategoriesInfo()
this.login()
}
componentWillMount() {
}
componentWillUnmount() { }
componentDidShow() { }
@ -171,10 +195,19 @@ class Home extends Component {
componentDidHide() { }
// 微信用户信息
onGotUserInfo(e) {
console.log(e.detail.errMsg)
console.log(e.detail.userInfo)
console.log(e.detail.rawData)
}
render() {
// 提示弹窗element
const modalMessage = <AtModal className='modal'
const modalMessageGrab= <AtModal className='modal'
isOpened={this.state.isOpen}
title='提示'
cancelText='取消'
@ -186,7 +219,7 @@ class Home extends Component {
/>
const demandingElemensArray = this.state.demanding.length ? this.state.demanding.map((item, index) => {
return < SwiperItem key={index} >
<View className='demanding-item'>
@ -241,7 +274,10 @@ class Home extends Component {
return (
<View className='home'>
{modalMessage}
{/* 获取微信用户的信息 */}
{/* <AtButton open-type='getUserInfo' lang='zh_CN' type='primary' size='normal' onGetUserInfo={this.onGotUserInfo.bind(this)}>获取微信用户的信息</AtButton> */}
{modalMessageGrab}
{/* 第一行图片滚动条 */}
<View className='first-banner'>

View File

@ -27,14 +27,11 @@ class Index extends Component {
//http://ihome6.com/Shop-supplyShops
componentDidMount(){
Taro.setStorageSync('PFWSSS','hq0erouhm4mea8b0mg34gdj0q7')
Taro.setStorageSync('X-Token','eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.IntcInVzZXJfaWRcIjpcIjI3XCIsXCJsb2dpbl9uYW1lXCI6XCJ5YW5neGJcIixcImF0XCI6XCIyMDE4LTEyLTE4IDEzOjM1OjUxXCJ9Ig.gXvZxXgU5asfwUJAG-z7k5g2p3dbts2e1X9L902KksE')
Taro.setStorageSync('PLU','%2Fm-more')
Taro.setStorageSync('localCity','think%3A%7B%2214%22%3A%22%25E7%25A6%258F%25E5%25BB%25BA%25E7%259C%2581%22%2C%2214001%22%3A%22%25E7%25A6%258F%25E5%25B7%259E%25E5%25B8%2582%22%7D')
Taro.navigateTo({
url: '/pages/home/home'
// url: '/pages/goodsPublish/goodsPublish'
// url: '/pages/goodsPublish/goodsPublish'
// url:'/pages/supplyDemandPublish/supplyDemandPublish'
})
}

View File

@ -1,6 +1,6 @@
import Taro, { Component } from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
import { AtInput, AtButton, Picker,AtIcon } from 'taro-ui'
import { AtInput, AtButton, Picker, AtIcon } from 'taro-ui'
import URL from '../../serviceAPI.config'
import copyrightComponent from '../../component/copyrightComponent/copyrightComponent'
@ -19,37 +19,50 @@ class MySupplyDemand extends Component {
constructor() {
super(...arguments)
this.state = {
demandSupplyCate: ['全部','需求', '供应', '人才'],
demandSupplyCate: ['全部', '需求', '供应', '人才'],
demandSupplyCateSelected: '全部',
demandSupplyState: ['全部','上架', '下架'],
demandSupplyState: ['全部', '上架', '下架'],
demandSupplyStatesSelected: '全部',
title:'',
title: '',
startDateSel: '2018-04-22',
endDateSel: '2018-04-22',
allDemandSupply: [],
totalDemandSupply:'',
}
}
//MySupplyDemand
getMySupplyDemand({ curr_page=1, page_count=20}) {
getMySupplyDemand({ curr_page = 1, page_count = 20 }) {
Taro.request({
url: URL.MySupplyDemand,
method: 'POST',
dataType: 'json',
data: {
curr_page: curr_page,
page_count: page_count
param: JSON.stringify({
curr_page: curr_page,
page_count: page_count
})
},
header: {
'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'),
'content-type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
}
}).then(res => {
console.log(res) // ------------------------------------------- to be continue----
console.log('个人供求=》暂时无数据, 后台需要权限验证')
// console.log('个人供求=》暂时无数据, 后台需要权限验证')
if (res.data.err_msg === "success") {
this.setState({ allDemandSupply: res.data.supplys,totalDemandSupply:res.data.count })
}
})
}
//修改供求类型
demSupplyCateChange = e => {
this.setState({
@ -62,8 +75,8 @@ class MySupplyDemand extends Component {
demandSupplyStatesSelected: this.state.demandSupplyState[e.detail.value]
})
}
titleChange(event){
this.setState({title:event})
titleChange(event) {
this.setState({ title: event })
}
// 修改开始日期
onStartDateChange = e => {
@ -81,7 +94,7 @@ class MySupplyDemand extends Component {
console.log(this.props, nextProps)
}
componentDidMount () {
componentDidMount() {
this.getMySupplyDemand({})
}
componentWillUnmount() { }
@ -91,6 +104,47 @@ class MySupplyDemand extends Component {
componentDidHide() { }
render() {
const demandSupplyElementArray = this.state.allDemandSupply.length ? this.state.allDemandSupply.map((item, index) => {
return <View key={index} className='info-container'>
<View className='type'>
<Text className='title'>需求类型</Text>
<Text className='info'>{item.type_name}</Text>
</View>
<View className='demand-title'>
<Text className='title'>需求标题</Text>
<Text className='info'>{item.sd_title}</Text>
</View>
<View className='contact-name'>
<Text className='title'>联系人</Text>
<Text className='info'>{item.user_name}</Text>
</View>
<View className='contact-number'>
<Text className='title'>电话号码</Text>
<Text className='info'>{item.user_phone}</Text>
</View>
<View className='demand-status'>
<Text className='title'>需求状态</Text>
<Text className='info'>{item.state}</Text>
</View>
<View className='update-time'>
<Text className='title'>更新时间</Text>
<Text className='info'>{item.update_date}</Text>
</View>
<View className='info-button-box'>
<View className='button'>
<AtButton type='primary' size='small'>查看</AtButton>
</View>
<View className='button'>
<AtButton type='primary' size='small'>编辑</AtButton>
</View>
<View className='button'>
<AtButton type='primary' className='button-a' size='small'>删除</AtButton>
</View>
</View>
</View>
}) : null
return (
<View className='mySupplyDemand'>
<searchBarComponent></searchBarComponent>
@ -124,12 +178,12 @@ class MySupplyDemand extends Component {
<View className='input-box'>
<Text className='require'>*</Text>
<AtInput
name='value'
title='供求标题:'
placeholder='供求标题·'
type='text'
value={this.state.title}
onChange={this.titleChange.bind(this)}
name='value'
title='供求标题:'
placeholder='供求标题·'
type='text'
value={this.state.title}
onChange={this.titleChange.bind(this)}
/>
</View>
{/* 开始和结束日期 */}
@ -140,17 +194,17 @@ class MySupplyDemand extends Component {
<View className='title-box'>
<Text className='title'><Text className='require'>*</Text>:</Text> <Text className='selected'>{this.state.startDateSel}</Text>
</View>
</View>
</Picker>
<Picker className='picker-container' mode='date' onChange={this.onEndDateChange}>
<Picker className='picker-container' mode='date' onChange={this.onEndDateChange}>
<View className='picker'>
<View className='title-box'>
<Text className='title'><Text className='require'>*</Text>:</Text> <Text className='selected'>{this.state.endDateSel}</Text>
</View>
</View>
</Picker>
</View>
</View>
@ -158,61 +212,20 @@ class MySupplyDemand extends Component {
<View className='button'>
<AtButton type='primary' size='small'>
<AtIcon value='search' size='12' color='white'></AtIcon>
搜索</AtButton>
搜索</AtButton>
</View>
<View className='button'>
<AtButton type='primary' className='button-a' size='small'>
<AtIcon value='add' size='12' color='white'></AtIcon>
新增</AtButton>
新增</AtButton>
</View>
</View>
<View className='total-count'>一共<Text className='number'>20</Text> </View>
<View className='total-count'>一共<Text className='number'>{this.state.totalDemandSupply}</Text> </View>
{/* 我的供求信息 */}
<View className='info-box'>
<View className='info-container'>
<View className='type'>
<Text className='title'>需求类型</Text>
<Text className='info'>1</Text>
</View>
<View className='demand-title'>
<Text className='title'>需求标题</Text>
<Text className='info'>1</Text>
</View>
<View className='contact-name'>
<Text className='title'>联系人</Text>
<Text className='info'>1</Text>
</View>
<View className='contact-number'>
<Text className='title'>电话号码</Text>
<Text className='info'>1</Text>
</View>
<View className='demand-status'>
<Text className='title'>需求状态</Text>
<Text className='info'></Text>
</View>
<View className='update-time'>
<Text className='title'>更新时间</Text>
<Text className='info'>1</Text>
</View>
<View className='info-button-box'>
<View className='button'>
<AtButton type='primary' size='small'>查看</AtButton>
</View>
<View className='button'>
<AtButton type='primary' size='small'>编辑</AtButton>
</View>
<View className='button'>
<AtButton type='primary' className='button-a' size='small'>删除</AtButton>
</View>
</View>
</View>
{demandSupplyElementArray}
</View>
<copyrightComponent></copyrightComponent>

View File

@ -18,7 +18,7 @@ const URL = {
BuyConsult: LOCALURL + 'Shop-consult',// 购买咨询
GetShopItemDetail: LOCALURL + 'GoodsQuery-wxGoodsDetail',// 商品详情
// 商品发布api接口
UploadPorductImage: LOCALURL + 'Goods-fileUp',// 上传商品图片
UploadPorductImage: LOCALURL + 'Goods-fileUpload',// 上传商品图片
UploadProduct: LOCALURL + 'Goods-phonePost',// 上传商品
UploadSupplyDemand: LOCALURL + 'Supply-post',// 上传供求