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

317 lines
10 KiB
JavaScript
Raw Normal View History

2019-01-04 17:33:38 +08:00
import Taro, { Component } from '@tarojs/taro'
import { View, Text, Image, Button } from '@tarojs/components'
2019-01-10 17:36:45 +08:00
import { AtIcon, AtModal, AtModalHeader, AtModalContent, AtModalAction } from 'taro-ui'
2019-01-04 17:33:38 +08:00
import URL from '../../serviceAPI.config'
import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent'
import './myNeedsView.scss'
class SupplyDemandView extends Component {
config = {
2019-01-08 17:33:52 +08:00
navigationBarTitleText: '需求查看'
2019-01-04 17:33:38 +08:00
}
constructor() {
super(...arguments)
this.state = {
2019-01-08 17:33:52 +08:00
industryTypeSelected: '',
needsType: [{ name: '业主需求', id: '4' }, { name: '效果图', id: '5' }],
needsTypeSelected: { name: '业主需求', id: '4' },
needsState: [
{ name: '作废', id: '0' },
{ name: '在用', id: '1' },
],
needsStateSelected: { name: '全部', id: '' },
2019-01-04 17:33:38 +08:00
title: '',
browsing: '',
2019-01-08 17:33:52 +08:00
sd_id: '', //需求id
2019-01-04 17:33:38 +08:00
contactName: '',
contactNumber: '',
2019-01-08 17:33:52 +08:00
contactAddress: '',
content: '',//描述
pickerImageUrl: [],
ImagesInfo: [],
isShowAllButtons:true// 是否显示所有按钮
2019-01-04 17:33:38 +08:00
}
}
2019-01-08 17:33:52 +08:00
//获取需求信息api
getSingleMyNeedInfo() {
2019-01-04 17:33:38 +08:00
Taro.request({
// url: URL.EditMyNeeds,
url: URL.supplyDemandDetails,
2019-01-04 17:33:38 +08:00
method: 'GET',
dataType: 'json',
data: {
2019-01-08 17:33:52 +08:00
demandId: this.$router.params.id,
2019-01-04 17:33:38 +08:00
},
header: {
'content-type': 'application/x-www-form-urlencoded',
'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'),
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(res => {
2019-01-08 17:33:52 +08:00
console.log('需求详情获取成功', res)
// const selectedType = this.state.demandingSupplyCate.filter(item => item.id == res.data.sdInfo.sd_type)[0]
// const selectedState = this.state.needsState.filter(item => item.id == res.data.sdInfo.state)[0]
Taro.hideLoading()
if(res.data.err_msg==='success'){
let industryType = {}
const classId = res.data.sdInfo.class_id
for (let outter of res.data.supplyTree) {
if (outter.children) {
for (let inner of outter.children) {
if (inner.class_id === classId) {
industryType.name = inner.class_name
industryType.id = inner.class_id
break
}
2019-01-08 17:33:52 +08:00
}
}
if (outter.class_id === classId) {
industryType.name = outter.class_name
industryType.id = outter.class_id
break
}
2019-01-08 17:33:52 +08:00
}
// const needsType = this.state.needsType.filter(item => {
// return item.id === res.data.sdInfo.sd_type
// })[0]
// const imageFile = res.data.sdInfo.file_path.map(item => { return { url: URL.Base + item.file_path } })
// const needsState = this.state.needsState.filter(item => {
// return item.id === res.data.sdInfo.state
// })[0]
this.setState({
sd_id: res.data.sdInfo.sd_id,
industryTypeSelected: industryType,
needsTypeSelected: needsType,
title: res.data.sdInfo.sd_title,
browsing: res.data.sdInfo.browse_times,
contactName: res.data.sdInfo.user_name,
contactNumber: res.data.sdInfo.user_phone,
contactAddress: res.data.sdInfo.user_address,
content: res.data.sdInfo.sd_desc,
needsStateSelected: needsState,
pickerImageUrl: imageFile,
ImagesInfo: res.data.sdInfo.file_path,
isDeleteModal: false,
})
2019-01-04 17:33:38 +08:00
}else{
this.setState({
isShowAllButtons:false
})
Taro.showToast({
title:res.data.err_msg,
icon:'none'
})
}
2019-01-04 17:33:38 +08:00
}
2019-01-08 17:33:52 +08:00
2019-01-04 17:33:38 +08:00
)
.catch(error => {
console.log('供求详情获取失败', error)
})
}
2019-01-08 17:33:52 +08:00
//删除我的需求 api DeleteMyNeeds
deleteMyNeeds({ demandId = 10 }) {
Taro.request({
url: URL.DeleteMyNeeds,
method: 'POST',
dataType: 'json',
data: {
demandId: demandId
},
header: {
'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'),
'content-type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
}
}).then(res => {
console.log('删除我的列表', res)
if (res.data.err_msg === "success") {
Taro.showToast({
title: '删除成功',
icon: 'success',
duration: 1500
})
setTimeout(() => {
this.goToMyNeedsPage()
}, 1500);
} else {
Taro.showToast({
title: res.data.err_msg,
icon: 'none',
duration: 1500
})
}
})
}
2019-01-08 17:33:52 +08:00
goMyNeedsPublishPage() {
2019-01-04 17:33:38 +08:00
Taro.navigateTo({
2019-01-08 17:33:52 +08:00
url: '/pages/myNeedsPublish/myNeedsPublish',
2019-01-04 17:33:38 +08:00
})
}
2019-01-08 17:33:52 +08:00
goMyNeedEditPage() {
2019-01-04 17:33:38 +08:00
console.log('edit page')
console.log('id', this.state.sd_id)
2019-01-08 17:33:52 +08:00
Taro.navigateTo({
url: '/pages/myNeedsEdit/myNeedsEdit?id=' + this.state.sd_id
2019-01-08 17:33:52 +08:00
})
2019-01-04 17:33:38 +08:00
}
2019-01-08 17:33:52 +08:00
goToMyNeedsPage() {
2019-01-04 17:33:38 +08:00
Taro.navigateTo({
2019-01-08 17:33:52 +08:00
url: '/pages/myNeeds/myNeeds'
})
2019-01-04 17:33:38 +08:00
}
2019-01-08 17:33:52 +08:00
deleteButton() {
this.setState({ isDeleteModal: true })
2019-01-08 17:33:52 +08:00
}
handleWindowModCancel() {
this.setState({ isDeleteModal: false })
2019-01-08 17:33:52 +08:00
}
handleWindowConfirm() {
this.setState({ isDeleteModal: false })
2019-01-08 17:33:52 +08:00
this.deleteMyNeeds({ demandId: this.state.sd_id })
2019-01-04 17:33:38 +08:00
}
componentDidMount() {
Taro.showLoading({ title: '加载中' })
this.getSingleMyNeedInfo()
2019-01-04 17:33:38 +08:00
}
componentWillReceiveProps(nextProps) {
console.log(this.props, nextProps)
}
componentWillUnmount() { }
componentDidShow() { }
componentDidHide() { }
render() {
const deleteModalWindowElement = <AtModal isOpened={this.state.isDeleteModal}>
<AtModalHeader>提示</AtModalHeader>
<AtModalContent>
确认删除{this.state.needsItem.sd_title}
2019-01-08 17:33:52 +08:00
</AtModalContent>
<AtModalAction> <Button onClick={this.handleWindowModCancel.bind(this)}>取消</Button> <Button className='orange' onClick={this.handleWindowConfirm.bind(this)}></Button> </AtModalAction>
</AtModal>
// const imageArrayElement = this.state.ImagesInfo.map((item, index) => {
// return <Image key={index} className='image' mode='widthFix' src={URL.Base + item.file_path} style='max-width: 100%; max-height:100%;' />
// })
const imageArrayElement=this.state.ImagesInfo.map((item, index) => {
return <View className='image-wrapper' key={index}>
<Image mode='aspectFit' src={URL.Base + item.file_path} style='max-width:100%; max-height:100%;' />
</View>
})
2019-01-04 17:33:38 +08:00
return (
<View className='SupplyDemandItemView'>
{/* 删除模态框 */}
{deleteModalWindowElement}
2019-01-04 17:33:38 +08:00
<View className='type box'>
<Text className='title'>行业分类</Text>
<Text className='content'>{this.state.industryTypeSelected.name?this.state.industryTypeSelected.name:'--'}</Text>
2019-01-04 17:33:38 +08:00
</View>
<View className='needed-title box'>
<Text className='title'>需求标题</Text>
<Text className='content'>{this.state.title}</Text>
</View>
<View className='browsing-amount box'>
<Text className='title'>浏览量</Text>
<Text className='content'>{this.state.browsing}</Text>
</View>
<View className='contact-name box'>
<Text className='title'>联系人</Text>
<Text className='content'>{this.state.contactName}</Text>
</View>
<View className='phone-number box'>
<Text className='title'>联系电话</Text>
<Text className='content'>{this.state.contactNumber}</Text>
</View>
<View className='address box'>
<Text className='title'>联系地址</Text>
<Text className='content'>{this.state.address}</Text>
</View>
<View className='needed-content box'>
<Text className='title'>业主需求内容</Text>
<Text className='content'>{this.state.content}</Text>
</View>
<View className='image-container box'>
{this.state.ImagesInfo.length?<Text className='title'>业主需求图片:</Text>:null}
{imageArrayElement}
</View>
{/* {this.state.ImagesInfo.length?<View className='needed-image box'>
2019-01-08 17:33:52 +08:00
<Text className='title'>业主需求图片</Text>
<View className='img-box'>
{imageArrayElement}
2019-01-08 17:33:52 +08:00
</View>
</View>:null
} */}
2019-01-04 17:33:38 +08:00
{this.state.isShowAllButtons? <View className='button-box'>
2019-01-08 17:33:52 +08:00
<View className='button' onClick={this.goMyNeedsPublishPage.bind(this)}>
2019-01-10 17:36:45 +08:00
<Button size='mini' className='button-green'>
2019-01-04 17:33:38 +08:00
<AtIcon value='add' size='12' color='white'></AtIcon>
2019-01-10 17:36:45 +08:00
新增</Button>
2019-01-04 17:33:38 +08:00
</View>
2019-01-08 17:33:52 +08:00
<View className='button' onClick={this.goToMyNeedsPage.bind(this)}>
<Button size='mini' className='button-green'>
2019-01-04 17:33:38 +08:00
<AtIcon value='' size='12' color='white'></AtIcon>
2019-01-10 17:36:45 +08:00
我的需求</Button>
2019-01-04 17:33:38 +08:00
</View>
<View className='button' onClick={this.goMyNeedEditPage.bind(this)}>
<Button size='mini' className='button-orange'>
<AtIcon value='settings' size='12' color='white'></AtIcon>
修改</Button>
</View>
<View className='button' onClick={this.deleteButton.bind(this)}>
<Button size='mini' className='button-dark-red'>
<AtIcon value='trash' size='12' color='white'></AtIcon>
删除</Button>
2019-01-04 17:33:38 +08:00
</View>
</View>:<View className='button-box'>
<View className='button' onClick={this.goMyNeedsPublishPage.bind(this)}>
<Button size='mini' className='button-green'>
<AtIcon value='add' size='12' color='white'></AtIcon>
新增</Button>
</View>
<View className='button' onClick={this.goToMyNeedsPage.bind(this)}>
<Button size='mini' className='button-green'>
<AtIcon value='' size='12' color='white'></AtIcon>
我的需求</Button>
</View>
</View>}
2019-01-04 17:33:38 +08:00
<CopyrightComponent></CopyrightComponent>
</View>
)
}
}
export default SupplyDemandView