import Taro, { Component } from '@tarojs/taro'
import { View, Text, Image } from '@tarojs/components'
import { AtInput, AtButton, Picker, AtIcon, AtLoadMore, AtModal, AtToast } from 'taro-ui'
import copyrightComponent from '../../component/copyrightComponent/copyrightComponent'
import URL from '../../serviceAPI.config'
import './allDemanding.scss'
import eyeIcon from '../../icons/eye.png'
let currentPage = 1
class AllDemanding extends Component {
config = {
navigationBarTitleText: '全部业主需求'
}
constructor() {
super(...arguments)
this.state = {
supplys: [], // 需求列表
isMore: 'more', // 上拉加载状态
demandingState: ['全部', '在用', '已抢单', '已抢光'], // 供求状态选择
demandingStateSelected: '全部', // 当前供求状态
industryCate: ['全部', '制定家具', '成品家具', '办公家具', '设计'], // 行业分类状态选择
industryCateSelected: '全部', // 当前行业分类状态
startDateSel: '2018-04-22',
endDateSel: '2018-04-22',
startValidDate:'',
isOpenedGrabModal: false,
grabOrderId: '',//抢到订单的id
isGrabOrderSuccess: false,// 是否显示轻提示
grabOrderSuccess: '无法显示绑定后的字段',// 抢单成功返回字段
}
}
GetAllDemanding({ curr_page = 1, page_count = 20 }) {
Taro.request({
url: URL.GetAllDemanding,
method: 'POST',
dataType: 'json',
data: {
param: JSON.stringify({
curr_page: curr_page,
page_count: page_count
}),
},
header: {
'content-type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(res => {
if (res.data.supplys.length) {
const newSupplys = this.state.supplys.concat(res.data.supplys)
this.setState({ supplys: newSupplys, isMore: 'more' })
} else {
this.setState({ isMore: 'noMore' })
}
})
}
// 向上拉升延迟一秒加载数据
handleLoadMore() {
this.setState({ isMore: 'loading' })
setTimeout(() => {
currentPage += 1
this.GetAllDemanding({ curr_page: currentPage })
}, 1000);
}
// 改变需求选项
changeDemandingState = e => {
this.setState({
demandingStateSelected: this.state.demandingState[e.detail.value]
})
}
// 改变行业类别选项
changeIndustryCate = e => {
this.setState({
industryCateSelected: this.state.industryCate[e.detail.value]
})
}
//改变开始日期
onStartDateChange = e => {
this.setState({
startDateSel: e.detail.value,
})
}
// 改变结束日期
onEndDateChange = e => {
this.setState({
endDateSel: e.detail.value
})
}
// 抢单接口
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 => {
let textTip = res.data.err_msg
this.setState({ grabOrderSuccess: textTip, isGrabOrderSuccess: true }, () => {
setTimeout(() => {
this.setState({ isGrabOrderSuccess: false })
}, 2000)
})
console.log('抢单请求:', res)
})
}
grabOrder(Id) {
this.setState({ isOpenedGrabModal: true, grabOrderId: Id })
}
handleGrabModalClose() {
this.setState({ isOpenedGrabModal: false })
}
handleGrabModalCancel() {
this.setState({ isOpenedGrabModal: false })
}
handleGrabConfirm() {
this.setState({ isOpenedGrabModal: false })
this.GrabDemand({ demandId: this.state.grabOrderId })
}
componentWillReceiveProps(nextProps) {
console.log(this.props, nextProps)
}
componentDidMount() {
// 得到第一页需求数据
this.GetAllDemanding({})
}
componentWillUnmount() { }
componentDidShow() { }
componentDidHide() { }
render() {
// 提示模态弹窗element
const modalMessageGrabElement =
// 抢单返回轻提示
const grabOrderSuccessElement =
const allDemandingElementArray = this.state.supplys ? this.state.supplys.map((item, index) => {
return
业主:{item.user_name}
{item.class_name + ' '}
|
{item.browse_times}
{item.sd_title}
{item.sd_desc}
{item.state_name === '在用' ? '抢单' : '已抢单'}
没有数据
更新日期:{item.update_date}
}) : null
return (
{/* 模态框 */}
{modalMessageGrabElement}
{/* 轻提示 */}
{grabOrderSuccessElement}
{/* 供求状态选择 */}
*供求状态: {this.state.demandingStateSelected}
*
{/* 开始和结束日期选择 */}
*开始日期: {this.state.startDateSel}
*结束日期: {this.state.endDateSel}
{/* 行业分类选择 */}
*行业分类: {this.state.industryCateSelected}
搜索
{/* 供求页面的数据加载 */}
{allDemandingElementArray}
)
}
}
export default AllDemanding