//grabOrderPage
import Taro, { Component } from '@tarojs/taro'
import { View, Text, Button } from '@tarojs/components'
import { AtModal, AtModalHeader, AtModalContent, AtModalAction, AtIcon } from 'taro-ui'
import URL from '../../serviceAPI.config'
import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent'
import './grabOrderPage.scss'
class GrabOrderPage extends Component {
config = {
navigationBarTitleText: '抢单页面'
}
constructor() {
super(...arguments);
this.state = {
type: '',
title: '',
browsing: '',
contactName: '',
contactNumber: '',
address: '',
content: '',
isOpen: false, // 抢单消息提示
grabOrderId:this.$router.params.orderId
}
}
//获取抢单信息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)
this.setState({
type: res.data.sdInfo.sd_type,
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,
})
}
)
.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_msg === 'success'){
Taro.showToast({
title: '抢单成功' ,
icon: 'success',
duration: 1500
})
setTimeout(() => {
Taro.navigateTo({
url:'/pages/home/home'
})
}, 1500);
}else{
Taro.showToast({
title: res.data.err_msg ,
icon: 'none',
duration: 1500
})
}
console.log('抢单请求:', res)
})
}
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() { }
render() {
// 提示模态弹窗element
const modalMessageGrabElement =
提示
确认抢单?
return (
{modalMessageGrabElement}
行业分类:
{this.state.type}
业主需求标题:
{this.state.title}
浏览量:
{this.state.browsing}
联系人:
{this.state.contactName}
联系电话:
{this.state.contactNumber}
联系地址:
{this.state.address}
业主需求内容:
{this.state.content}
)
}
}
export default GrabOrderPage