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

381 lines
14 KiB
JavaScript
Raw Normal View History

import Taro, { Component } from '@tarojs/taro'
2018-12-29 17:15:59 +08:00
import { View, Text, Image, Button } from '@tarojs/components'
2019-01-14 17:04:08 +08:00
import { AtInput, Picker, AtIcon, AtModal, AtToast, AtModalHeader, AtModalContent, AtModalAction } from 'taro-ui'
2018-12-28 17:29:42 +08:00
import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent'
import ScrollToTopComponent from '../../component/scrollToTopComponent/scrollToTopComponent'
import InteractionComponent from '../../component/interactionComponent/interactionComponent'
import URL from '../../serviceAPI.config'
import './allDemanding.scss'
import eyeIcon from '../../icons/eye.png'
2019-01-14 17:04:08 +08:00
class AllDemanding extends Component {
config = {
navigationBarTitleText: '全部业主需求'
}
constructor() {
super(...arguments)
this.state = {
2018-12-14 17:10:23 +08:00
supplys: [], // 需求列表
2018-12-29 17:15:59 +08:00
demandingState: [{ name: '全部', id: '' }, { name: '在用', id: '1' }, { name: '已抢单', id: '2' }, { name: '已抢光', id: '3' },], // 供求状态选择
demandingStateSelected: { name: '全部', id: '' }, // 当前供求状态
industryTypeSelected: { name: '全部', id: '' },// 当前行业分类
title: '',
2018-12-29 17:15:59 +08:00
startDateSel: '',
endDateSel: '',
2018-12-21 11:59:24 +08:00
isOpenedGrabModal: false,
grabOrderId: '',//抢到订单的id
isGrabOrderSuccess: false,// 是否显示轻提示
grabOrderSuccess: '无法显示绑定后的字段',// 抢单成功返回字段
2019-01-14 17:04:08 +08:00
currentPage: 1,
isAddToList: false,// / 请求业主需求的时候是否添加到旧列表里
isShowTopNav: false,// 是否显示返回顶部按钮
loadMorePageIndex: 1
2018-12-21 11:59:24 +08:00
}
}
2019-01-14 17:04:08 +08:00
2018-12-29 17:15:59 +08:00
// 搜索业主需求函数
2019-01-14 17:04:08 +08:00
searchDemanding({
curr_page = 1,
page_count = 10,
sd_title = this.state.title,
2018-12-29 17:15:59 +08:00
state = this.state.demandingStateSelected.id,
update_dateL = this.state.startDateSel,
update_dateU = this.state.endDateSel,
class_id = this.state.industryTypeSelected.id
2018-12-29 17:15:59 +08:00
}) {
Taro.request({
url: URL.GetAllDemanding,
method: 'POST',
dataType: 'json',
data: {
param: JSON.stringify({
curr_page: curr_page,
page_count: page_count,
sd_title: sd_title,
2018-12-29 17:15:59 +08:00
state: state,
update_dateL: update_dateL,
update_dateU: update_dateU,
class_id: class_id
2018-12-11 17:34:06 +08:00
2018-12-29 17:15:59 +08:00
}),
},
header: {
'content-type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(res => {
Taro.hideLoading()
2019-01-09 17:35:32 +08:00
if (res.data.err_msg === 'success') {
2019-01-18 17:09:17 +08:00
if (res.data.supplys) {
2019-01-14 17:04:08 +08:00
if (this.state.isAddToList) {
2019-01-17 17:32:38 +08:00
this.setState({ supplys: this.state.supplys.concat(res.data.supplys), isAddToList: false })
2019-01-14 17:04:08 +08:00
} else {
this.setState({ supplys: res.data.supplys })
}
} else {
2019-01-18 17:09:17 +08:00
if (this.state.isAddToList) {
Taro.showToast({
title: '没有更多了',
icon: 'none'
})
}else{
this.setState({ supplys:[]})
}
2019-01-14 17:04:08 +08:00
}
2019-01-09 17:35:32 +08:00
} else {
Taro.showToast({
2019-01-09 17:35:32 +08:00
title: res.data.err_msg,
icon: 'none',
duration: 1500
})
}
2019-01-18 17:09:17 +08:00
this.setState({ isAddToList: false })
2018-12-29 17:15:59 +08:00
})
}
2019-01-14 17:04:08 +08:00
2018-12-11 17:34:06 +08:00
// 改变需求选项
changeDemandingState = e => {
this.setState({
demandingStateSelected: this.state.demandingState[e.detail.value]
})
}
titleChange(event) {
this.setState({ title: event })
}
2018-12-14 17:10:23 +08:00
//改变开始日期
2018-12-11 17:34:06 +08:00
onStartDateChange = e => {
this.setState({
2018-12-24 17:35:51 +08:00
startDateSel: e.detail.value,
2018-12-29 17:15:59 +08:00
2018-12-11 17:34:06 +08:00
})
}
2018-12-14 17:10:23 +08:00
// 改变结束日期
2018-12-11 17:34:06 +08:00
onEndDateChange = e => {
this.setState({
endDateSel: e.detail.value
})
}
2018-12-21 11:59:24 +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 => {
let textTip = res.data.err_msg
this.setState({ grabOrderSuccess: textTip, isGrabOrderSuccess: true }, () => {
setTimeout(() => {
this.setState({ isGrabOrderSuccess: false })
2018-12-24 17:35:51 +08:00
}, 2000)
2018-12-21 11:59:24 +08:00
})
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 })
2018-12-21 11:59:24 +08:00
this.GrabDemand({ demandId: this.state.grabOrderId })
}
2018-12-29 17:15:59 +08:00
searchHanlder() {
Taro.showLoading({ title: '加载中' })
this.searchDemanding({})
}
//清空筛选项
emptyFilter() {
this.setState({
title: '',
endDateSel: '',
startDateSel: '',
demandingStateSelected: { name: '全部', id: '' },
industryTypeSelected: { name: '全部', id: '' },
})
Taro.showToast({
title: '已清空',
icon: 'success',
duration: 1000
2018-12-29 17:15:59 +08:00
})
}
2018-12-29 17:15:59 +08:00
getDataFromChild(value) {
console.log('从子组件传回来的值', value)
this.setState({ industryTypeSelected: value })
2018-12-29 17:15:59 +08:00
}
// 翻页导航
2019-01-09 17:35:32 +08:00
paginationNav(type) {
Taro.showLoading({
title: '加载中'
})
this.setState({ currentPage: type.current, }, () => {
this.searchDemanding({
2019-01-14 17:04:08 +08:00
curr_page: this.state.currentPage,
page_count: 10,
2019-01-09 17:35:32 +08:00
sd_title: this.state.title,
state: this.state.demandingStateSelected.id,
update_dateL: this.state.startDateSel,
update_dateU: this.state.endDateSel,
class_id: this.state.industryTypeSelected.id
})
})
}
componentWillReceiveProps(nextProps) {
console.log(this.props, nextProps)
}
2018-12-14 17:10:23 +08:00
componentDidMount() {
2018-12-11 17:34:06 +08:00
// 得到第一页需求数据
2018-12-29 17:15:59 +08:00
Taro.showLoading({ title: '加载中' }).then(() => {
this.searchDemanding({})
})
2018-12-14 17:10:23 +08:00
}
componentWillUnmount() { }
componentDidShow() { }
componentDidHide() { }
// 页面位置
onPageScroll(location) {
if (location.scrollTop <= 300 && this.state.isShowTopNav) {
this.setState({ isShowTopNav: false })
} else if (location.scrollTop > 300 && !this.state.isShowTopNav) {
this.setState({ isShowTopNav: true })
}
}
2019-01-14 17:04:08 +08:00
// 底部加载
onReachBottom() {
Taro.showLoading({
title: '加载中'
})
this.setState({ isAddToList: true, loadMorePageIndex: this.state.loadMorePageIndex + 1 }, () => {
this.searchDemanding({ curr_page: this.state.loadMorePageIndex })
2019-01-14 17:04:08 +08:00
})
}
render() {
2018-12-21 11:59:24 +08:00
// 提示模态弹窗element
2018-12-29 17:15:59 +08:00
const modalMessageGrabElement = <AtModal isOpened={this.state.isOpenedGrabModal}>
<AtModalHeader>提示</AtModalHeader>
<AtModalContent>
确认抢单
</AtModalContent>
2018-12-29 17:15:59 +08:00
<AtModalAction> <Button onClick={this.handleGrabModalCancel.bind(this)}>取消</Button> <Button className='orange' onClick={this.handleGrabConfirm.bind(this)}></Button> </AtModalAction>
</AtModal>
2018-12-21 11:59:24 +08:00
// 抢单返回轻提示
2018-12-24 17:35:51 +08:00
const grabOrderSuccessElement = <AtToast
2018-12-29 17:15:59 +08:00
isOpened={this.state.isGrabOrderSuccess}
text={this.state.grabOrderSuccess}
duration={2000}
2018-12-21 11:59:24 +08:00
></AtToast>
2019-01-18 17:09:17 +08:00
const allDemandingElementArray = this.state.supplys.length ? this.state.supplys.map((item, index) => {
return <View className='demanding-info' key={index}>
2018-12-14 17:10:23 +08:00
<View className='header'>
2018-12-11 17:34:06 +08:00
<AtIcon value='user' size='12' color='#2196F3'></AtIcon>
<View className='name'> 业主:{item.user_name}</View>
<View className='others'>
2018-12-14 17:10:23 +08:00
<Text className='cate'>{item.class_name + ' '} </Text>
|
<Image src={eyeIcon} style='width:12px; height:12px; vertical-align:middle;' />
<Text className='watch'>{item.browse_times}</Text>
</View>
2018-12-14 17:10:23 +08:00
</View>
<View className='body'>
<View className='image-container'>
<Image style='width:110px;height:80px' src={URL.Base + item.file_path[0].thumb_path} />
2018-12-14 17:10:23 +08:00
</View>
<View className='detail'>
<View className='title'>{item.sd_title}</View>
<View className='para'>{item.sd_desc}</View>
2019-01-17 17:32:38 +08:00
{item.state === '1' ? <View className='button' onClick={this.grabOrder.bind(this, item.sd_id)}>
2019-01-10 17:36:45 +08:00
<Button size='mini' className='button-orange'>抢单</Button>
2019-01-17 17:32:38 +08:00
</View> : null || item.state === '2' ? <View className='button'>
<Button size='mini' className='button-orange blur'>{item.state_name}</Button>
</View> : null || item.state === '3' ? <View className='button'>
<Button size='mini' className='button-orange blur'>{item.state_name}</Button>
</View> : null}
</View>
2018-12-14 17:10:23 +08:00
</View>
<View className='footer'>
2019-01-09 17:35:32 +08:00
<View className='location'><AtIcon value='map-pin' size='12' color='black'></AtIcon>{item.user_address}</View>
<View className='time'>更新日期:{item.update_date}</View>
</View>
2018-12-14 17:10:23 +08:00
</View>
2019-01-18 17:09:17 +08:00
}) : <View className='no_more_title'>没有更多了</View>
return (
<View className='allDemanding'>
2018-12-21 11:59:24 +08:00
{/* 模态框 */}
2018-12-24 17:35:51 +08:00
{modalMessageGrabElement}
2018-12-21 11:59:24 +08:00
{/* 轻提示 */}
2018-12-24 17:35:51 +08:00
{grabOrderSuccessElement}
<View className='page-section'>
2018-12-11 17:34:06 +08:00
{/* 供求状态选择 */}
<View>
2018-12-29 17:15:59 +08:00
<Picker mode='selector' rangeKey='name' range={this.state.demandingState} onChange={this.changeDemandingState}>
<View className='picker'>
<View className='title-box'>
<Text className='title'> 供求状态:</Text> <Text className='selected'>{this.state.demandingStateSelected.name}</Text>
</View>
</View>
</Picker>
</View>
</View>
2018-12-29 17:15:59 +08:00
<View className='input-box'>
<AtInput
2018-12-29 17:15:59 +08:00
name='value'
title='需求标题:'
type='text'
placeholder='需求标题'
value={this.state.title}
onChange={this.titleChange.bind(this)}
/>
</View>
2018-12-11 17:34:06 +08:00
{/* 开始和结束日期选择 */}
<View className='page-section'>
<View className='picker-box'>
2018-12-11 17:34:06 +08:00
<Picker mode='date' className='picker-container' onChange={this.onStartDateChange}>
<View className='picker'>
<View className='title-box'>
<Text className='title'>开始日期:</Text> <Text className='date'>{this.state.startDateSel}</Text>
</View>
</View>
</Picker>
2018-12-24 17:35:51 +08:00
<Picker className='picker-container' mode='date' start={this.state.startDateSel} onChange={this.onEndDateChange}>
<View className='picker'>
<View className='title-box'>
<Text className='title'>结束日期:</Text> <Text className='date'>{this.state.endDateSel}</Text>
</View>
</View>
</Picker>
</View>
</View>
2018-12-11 17:34:06 +08:00
{/* 行业分类选择 */}
<InteractionComponent url={URL.GetIndustryTypeList} onPassDataToChild={this.getDataFromChild.bind(this)} selectedValue={this.state.industryTypeSelected}></InteractionComponent>
<View className='button-box'>
<View className='button' onClick={this.searchHanlder.bind(this)}>
2019-01-10 17:36:45 +08:00
<Button type='primary' size='mini' className='button-orange' >
<AtIcon value='search' size='12' color='white'></AtIcon>
2019-01-10 17:36:45 +08:00
搜索</Button>
</View>
<View className='button' onClick={this.emptyFilter.bind(this)}>
2019-01-10 17:36:45 +08:00
<Button type='primary' size='mini' className='button-dark-red' >
<AtIcon value='trash' size='12' color='white'></AtIcon>
2019-01-10 17:36:45 +08:00
清空</Button>
</View>
</View>
2018-12-14 17:10:23 +08:00
{/* 供求页面的数据加载 */}
2018-12-11 17:34:06 +08:00
<View className='demanding-box'>
{allDemandingElementArray}
</View>
{this.state.isShowTopNav ? <ScrollToTopComponent ></ScrollToTopComponent> : null}
2018-12-28 17:29:42 +08:00
<CopyrightComponent></CopyrightComponent>
</View>
)
}
}
export default AllDemanding