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

372 lines
14 KiB
JavaScript
Raw Normal View History

2019-01-02 17:31:07 +08:00
//grabOrderPage
import Taro, { Component } from '@tarojs/taro'
import { View, Text, Button, Image } from '@tarojs/components'
2019-01-10 17:36:45 +08:00
import { AtModal, AtModalHeader, AtModalContent, AtModalAction, AtIcon } from 'taro-ui'
2019-01-02 17:31:07 +08:00
2019-01-03 17:36:59 +08:00
import URL from '../../serviceAPI.config'
2019-02-14 17:35:44 +08:00
import RenderingView from './renderingView/renderingView'
2019-01-02 17:31:07 +08:00
import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent'
import './grabOrderPage.scss'
2019-02-20 16:59:06 +08:00
import loginExpired from '../../util/loginExpired';
2019-01-02 17:31:07 +08:00
class GrabOrderPage extends Component {
config = {
2019-02-12 08:54:34 +08:00
navigationBarTitleText: '业主需求'
2019-01-02 17:31:07 +08:00
}
2019-01-03 17:36:59 +08:00
constructor() {
super(...arguments);
this.state = {
2019-02-13 18:05:21 +08:00
isShowRendering: false,
2019-01-03 17:36:59 +08:00
type: '',
title: '',
browsing: '',
contactName: '',
contactNumber: '',
address: '',
content: '',
images: [],
2019-01-10 17:36:45 +08:00
isOpen: false, // 抢单消息提示
2019-01-17 17:32:38 +08:00
grabOrderId: this.$router.params.orderId,
stateId: '',
stateName: '',
2019-02-13 18:05:21 +08:00
userId: '',
renderingImage: [],
isDeleteModal: false
2019-01-03 17:36:59 +08:00
}
}
//获取抢单信息api supplyDemandDetails
getGrabOrderInfo() {
Taro.request({
url: URL.supplyDemandDetails,
method: 'GET',
dataType: 'json',
data: {
demandId: this.$router.params.orderId,
},
header: {
'content-type': 'application/x-www-form-urlencoded',
'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'),
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(res => {
console.log('抢单详情获取成功', res)
2019-02-20 16:59:06 +08:00
if (res.data.err_code === 0) {
this.setState({
type: res.data.sdInfo.class_name,
title: res.data.sdInfo.sd_title,
browsing: res.data.sdInfo.browse_times,
contactName: res.data.sdInfo.user_name,
contactNumber: res.data.sdInfo.user_phone,
address: res.data.sdInfo.user_address,
content: res.data.sdInfo.sd_desc,
images: res.data.sdInfo.file_path,
stateId: res.data.sdInfo.state,
stateName: res.data.sdInfo.state_name,
userId: res.data.sdInfo.user_id,
renderingImage: res.data.sdInfo.render_pics || []
})
} else if (res.data.err_code === 88888) {
Taro.clearStorageSync()
Taro.showToast({
title: res.data.err_msg,
icon: 'none'
})
setTimeout(() => {
Taro.reLaunch({
url: '/pages/home/home'
})
}, 1500);
}
2019-01-03 17:36:59 +08:00
}
)
.catch(error => {
console.log('抢单详情获取失败', error)
})
}
2019-01-10 17:36:45 +08:00
//抢单请求
GrabDemand({ demandId = 218 }) {
Taro.request({
url: URL.GrabDemand,
method: 'POST',
dataType: 'json',
data: {
demandId: demandId
},
header: {
'content-type': 'application/x-www-form-urlencoded',
'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'),
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(res => {
2019-02-20 16:59:06 +08:00
if (res.data.err_code === 0) {
2019-01-10 17:36:45 +08:00
Taro.showToast({
2019-01-17 17:32:38 +08:00
title: '抢单成功',
2019-01-10 17:36:45 +08:00
icon: 'success',
duration: 1500
})
2019-01-17 17:32:38 +08:00
setTimeout(() => {
Taro.navigateTo({
url: '/pages/home/home'
})
}, 1500);
2019-01-10 17:36:45 +08:00
2019-02-20 16:59:06 +08:00
} else if (res.data.err_code === 88888) {
loginExpired(res)
2019-01-17 17:32:38 +08:00
} else {
2019-01-10 17:36:45 +08:00
Taro.showToast({
2019-01-17 17:32:38 +08:00
title: res.data.err_msg,
2019-01-10 17:36:45 +08:00
icon: 'none',
duration: 1500
})
}
2019-01-17 17:32:38 +08:00
2019-01-10 17:36:45 +08:00
console.log('抢单请求:', res)
})
}
2019-02-13 18:05:21 +08:00
showImageButton() {
this.setState({
isShowRendering: true
})
}
2019-01-10 17:36:45 +08:00
callPhoneNumber() {
2019-01-03 17:36:59 +08:00
Taro.makePhoneCall({
phoneNumber: this.state.contactNumber
})
}
2019-01-10 17:36:45 +08:00
grabButtonHandler() {
this.setState({ isOpen: true })
2019-01-17 17:32:38 +08:00
}
2019-01-10 17:36:45 +08:00
handleGrabModalClose() {
this.setState({ isOpen: false })
}
handleGrabModalCancel() {
this.setState({ isOpen: false })
}
handleGrabConfirm() {
this.setState({ isOpen: false })
// 确认抢单之后
this.GrabDemand({ demandId: this.state.grabOrderId })
}
2019-01-03 17:36:59 +08:00
componentDidMount() {
2019-01-17 17:32:38 +08:00
2019-01-03 17:36:59 +08:00
this.getGrabOrderInfo()
2019-01-02 17:31:07 +08:00
}
componentWillReceiveProps(nextProps) {
console.log(this.props, nextProps)
}
componentWillUnmount() { }
componentDidShow() { }
componentDidHide() { }
2019-02-13 18:05:21 +08:00
goMyNeedsPublishPage() {
Taro.navigateTo({
url: '/pages/myNeedsPublish/myNeedsPublish'
})
}
goToMyNeedsPage() {
Taro.switchTab({
url: '/pages/myNeeds/myNeeds'
2019-02-13 18:05:21 +08:00
})
}
goMyNeedEditPage() {
let id = this.$router.params.orderId
Taro.navigateTo({
url: '/pages/myNeedsEdit/myNeedsEdit?id=' + id
})
}
deleteButton() {
this.setState({ isDeleteModal: true })
}
handleWindowModCancel() {
this.setState({ isDeleteModal: false })
}
handleWindowConfirm() {
this.setState({ isDeleteModal: false })
this.deleteMyNeeds({ demandId: this.$router.params.orderId })
}
deleteMyNeeds({ demandId }) {
Taro.request({
2019-02-14 17:35:44 +08:00
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'
}
2019-02-13 18:05:21 +08:00
}).then(res => {
2019-02-14 17:35:44 +08:00
2019-02-20 16:59:06 +08:00
if (res.data.err_code === 0) {
2019-02-14 17:35:44 +08:00
Taro.showToast({
title: '删除成功',
icon: 'success',
duration: 1500
})
setTimeout(() => {
Taro.reLaunch({
url: '/pages/myNeeds/myNeeds'
})
}, 1500);
2019-02-20 16:59:06 +08:00
} else if (res.data.err_code === 88888) {
loginExpired(res)
2019-02-14 17:35:44 +08:00
} else {
Taro.showToast({
title: res.data.err_msg,
icon: 'none',
duration: 1500
})
}
2019-02-13 18:05:21 +08:00
})
2019-02-14 17:35:44 +08:00
}
2019-01-02 17:31:07 +08:00
render() {
const localStoageUserId = Taro.getStorageSync('userInfo').user_id
2019-02-14 17:35:44 +08:00
2019-02-13 18:05:21 +08:00
// 提示框
const deleteModalWindowElement = <AtModal isOpened={this.state.isDeleteModal}>
<AtModalHeader>提示</AtModalHeader>
<AtModalContent>
确认删除{this.state.needsItem.sd_title}
</AtModalContent>
<AtModalAction> <Button onClick={this.handleWindowModCancel.bind(this)}>取消</Button> <Button className='orange' onClick={this.handleWindowConfirm.bind(this)}></Button> </AtModalAction>
</AtModal>
let ButtonElement
if (localStoageUserId === this.state.userId && this.state.stateId === '1') {
ButtonElement = <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)}>
2019-02-15 17:20:52 +08:00
<Button size='mini' className='button-orange'>
<AtIcon value='' size='12' color='white'></AtIcon>
我的需求</Button>
</View>
<View className='button' onClick={this.goMyNeedEditPage.bind(this)}>
2019-02-15 17:20:52 +08:00
<Button size='mini' className='button-blue'>
<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>
</View>
</View>
} else if (localStoageUserId === this.state.userId && this.state.stateId != '1') {
ButtonElement = <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)}>
2019-02-15 17:20:52 +08:00
<Button size='mini' className='button-orange'>
<AtIcon value='' size='12' color='white'></AtIcon>
我的需求</Button>
</View>
</View>
} else if (this.state.stateId === '1') {
ButtonElement = <View className='button-box'><View className='button' onClick={this.grabButtonHandler.bind(this)}>
<Button size='mini' className='button-orange'>抢单</Button>
</View></View>
} else if (this.state.stateId === '2') {
ButtonElement = <View className='button-box'><View className='button'>
<Button size='mini' className='button-orange blur'>{this.state.stateName}</Button>
</View></View>
} else if (this.state.stateId === '3') {
ButtonElement = <View className='button-box'><View className='button'>
<Button size='mini' className='button-orange blur'>{this.state.stateName}</Button>
</View></View>
}
2019-01-10 17:36:45 +08:00
// 提示模态弹窗element
const modalMessageGrabElement = <AtModal isOpened={this.state.isOpen}>
<AtModalHeader>提示</AtModalHeader>
<AtModalContent>
确认抢单
2019-01-17 17:32:38 +08:00
</AtModalContent>
2019-01-10 17:36:45 +08:00
<AtModalAction> <Button onClick={this.handleGrabModalCancel.bind(this)}>取消</Button> <Button className='orange' onClick={this.handleGrabConfirm.bind(this)}></Button> </AtModalAction>
</AtModal>
const imageElementArray = this.state.images.map((item, index) => {
return <View className='image-wrapper' key={index}>
2019-02-20 16:59:06 +08:00
<Image mode='aspectFit' src={URL.Base + item.file_path} style='max-width:100%; max-height:100%;' />
</View>
})
2019-01-10 17:36:45 +08:00
2019-01-02 17:31:07 +08:00
return (
<View className='grabOrderPage'>
2019-02-14 17:35:44 +08:00
2019-01-10 17:36:45 +08:00
{modalMessageGrabElement}
2019-02-13 18:05:21 +08:00
{deleteModalWindowElement}
2019-02-14 17:35:44 +08:00
{this.state.isShowRendering ? <RenderingView rendering={this.state.renderingImage}></RenderingView> : null}
2019-02-13 18:05:21 +08:00
{this.state.stateId === '3' && !this.state.isShowRendering ? <View className='button-box show-image-button'><View className='button' onClick={this.showImageButton.bind(this)}>
<Button className='button-orange'>查看效果图</Button>
</View></View> : null}
2019-01-02 17:31:07 +08:00
<View className='type box'>
<Text className='title'>行业分类</Text>
<Text className='content'>{this.state.type}</Text>
</View>
<View className='sd-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>
2019-01-03 17:36:59 +08:00
<View className='phone-number box' onClick={this.callPhoneNumber.bind(this)} >
2019-01-02 17:31:07 +08:00
<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='sd-content box'>
<Text className='title'>业主需求内容</Text>
<Text className='content'>{this.state.content}</Text>
</View>
<View className='image-container box'>
{this.state.images.length ? <Text className='title'>业主需求图片:</Text> : null}
{imageElementArray}
</View>
{ButtonElement}
2019-01-02 17:31:07 +08:00
<CopyrightComponent></CopyrightComponent>
</View>
)
}
}
export default GrabOrderPage