//grabOrderPage
import Taro, { Component } from '@tarojs/taro'
import { View, Text, Button, Image } from '@tarojs/components'
import { AtModal, AtModalHeader, AtModalContent, AtModalAction, AtIcon } from 'taro-ui'
import URL from '../../serviceAPI.config'
import RenderingView from './renderingView/renderingView'
import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent'
import './grabOrderPage.scss'
import loginExpired from '../../util/loginExpired';
class GrabOrderPage extends Component {
config = {
navigationBarTitleText: '业主需求'
}
constructor() {
super(...arguments);
this.state = {
isShowRendering: false,
type: '',
title: '',
browsing: '',
contactName: '',
contactNumber: '',
address: '',
content: '',
images: [],
isOpen: false, // 抢单消息提示
grabOrderId: this.$router.params.orderId,
stateId: '',
stateName: '',
userId: '',
renderingImage: [],
isDeleteModal: false
}
}
//获取抢单信息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)
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);
}
}
)
.catch(error => {
console.log('抢单详情获取失败', error)
})
}
//抢单请求
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 => {
if (res.data.err_code === 0) {
Taro.showToast({
title: '抢单成功',
icon: 'success',
duration: 1500
})
setTimeout(() => {
Taro.navigateTo({
url: '/pages/home/home'
})
}, 1500);
} else if (res.data.err_code === 88888) {
loginExpired(res)
} else {
Taro.showToast({
title: res.data.err_msg,
icon: 'none',
duration: 1500
})
}
console.log('抢单请求:', res)
})
}
showImageButton() {
this.setState({
isShowRendering: true
})
}
callPhoneNumber() {
Taro.makePhoneCall({
phoneNumber: this.state.contactNumber
})
}
grabButtonHandler() {
this.setState({ isOpen: true })
}
handleGrabModalClose() {
this.setState({ isOpen: false })
}
handleGrabModalCancel() {
this.setState({ isOpen: false })
}
handleGrabConfirm() {
this.setState({ isOpen: false })
// 确认抢单之后
this.GrabDemand({ demandId: this.state.grabOrderId })
}
componentDidMount() {
this.getGrabOrderInfo()
}
componentWillReceiveProps(nextProps) {
console.log(this.props, nextProps)
}
componentWillUnmount() { }
componentDidShow() { }
componentDidHide() { }
goMyNeedsPublishPage() {
Taro.navigateTo({
url: '/pages/myNeedsPublish/myNeedsPublish'
})
}
goToMyNeedsPage() {
Taro.switchTab({
url: '/pages/myNeeds/myNeeds'
})
}
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({
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 => {
if (res.data.err_code === 0) {
Taro.showToast({
title: '删除成功',
icon: 'success',
duration: 1500
})
setTimeout(() => {
Taro.reLaunch({
url: '/pages/myNeeds/myNeeds'
})
}, 1500);
} else if (res.data.err_code === 88888) {
loginExpired(res)
} else {
Taro.showToast({
title: res.data.err_msg,
icon: 'none',
duration: 1500
})
}
})
}
render() {
const localStoageUserId = Taro.getStorageSync('userInfo').user_id
// 提示框
const deleteModalWindowElement =
提示
确认删除{this.state.needsItem.sd_title}?
let ButtonElement
if (localStoageUserId === this.state.userId && this.state.stateId === '1') {
ButtonElement =
} else if (localStoageUserId === this.state.userId && this.state.stateId != '1') {
ButtonElement =
} else if (this.state.stateId === '1') {
ButtonElement =
} else if (this.state.stateId === '2') {
ButtonElement =
} else if (this.state.stateId === '3') {
ButtonElement =
}
// 提示模态弹窗element
const modalMessageGrabElement =
提示
确认抢单?
const imageElementArray = this.state.images.map((item, index) => {
return
})
return (
{modalMessageGrabElement}
{deleteModalWindowElement}
{this.state.isShowRendering ? : null}
{this.state.stateId === '3' && !this.state.isShowRendering ?
: null}
行业分类:
{this.state.type}
业主需求标题:
{this.state.title}
浏览量:
{this.state.browsing}
联系人:
{this.state.contactName}
联系电话:
{this.state.contactNumber}
联系地址:
{this.state.address}
业主需求内容:
{this.state.content}
{this.state.images.length ? 业主需求图片: : null}
{imageElementArray}
{ButtonElement}
)
}
}
export default GrabOrderPage