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

470 lines
15 KiB
JavaScript
Raw Normal View History

2019-01-03 17:36:59 +08:00
//myNeeds
import Taro, { Component } from '@tarojs/taro'
import { View, Text, Button } from '@tarojs/components'
2019-01-14 17:04:08 +08:00
import { AtInput, Picker, AtIcon, AtModal, AtModalHeader, AtModalContent, AtModalAction } from 'taro-ui'
2019-01-03 17:36:59 +08:00
import URL from '../../serviceAPI.config'
import ScrollToTopComponent from '../../component/scrollToTopComponent/scrollToTopComponent'
2019-01-08 13:51:26 +08:00
import InteractionComponent from '../../component/interactionComponent/interactionComponent'
2019-01-03 17:36:59 +08:00
import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent'
2019-02-12 17:21:31 +08:00
import LoginService from '../../LoginService'
2019-01-03 17:36:59 +08:00
import './myNeeds.scss'
class MyNeeds extends Component {
2019-01-18 17:09:17 +08:00
2019-01-03 17:36:59 +08:00
config = {
navigationBarTitleText: '我的需求'
}
constructor() {
super(...arguments)
this.state = {
title: '',
startDateSel: '',
endDateSel: '',
industryTypeSelected: { name: '全部', id: '' },
2019-01-03 17:36:59 +08:00
needsType: [{ name: '业主需求', id: '4' }, { name: '效果图', id: '5' }],
needsTypeSelected: { name: '业主需求', id: '4' },
needsState: [
{ name: '全部', id: '' },
{ name: '作废', id: '0' }
, { name: '在用', id: '1' },
{ name: '已抢单', id: '2' },
{ name: '已抢光', id: '3' }],
2019-01-03 17:36:59 +08:00
needsStateSelected: { name: '全部', id: '' },
2019-01-04 17:33:38 +08:00
pageCount: 10,// 列表数量
2019-01-03 17:36:59 +08:00
allNeedsList: [],// 我的需求列表
totalNeeds: 0,// 我的需求数量
2019-01-04 17:33:38 +08:00
currentPage: 1,
needsItem: '',// 确认框提示时 使用的供求名
2019-01-18 17:09:17 +08:00
isDeleteModal: false,// 删除提示框
2019-01-14 17:04:08 +08:00
isAddToList: false,// 请求需求的时候是否添加到旧列表里
isShowTopNav: false,// 是否显示返回顶部按钮
2019-01-18 17:09:17 +08:00
loadMorePageIndex: 1,// 上拉加载页面数
2019-01-03 17:36:59 +08:00
}
}
2019-01-18 17:09:17 +08:00
2019-01-03 17:36:59 +08:00
//请求我的需求列表 api GetMyNeedsList
2019-01-18 17:09:17 +08:00
getMyNeedsList({
curr_page = this.state.currentPage,
page_count = this.state.pageCount,
sd_type = this.state.needsTypeSelected.id,
sd_title = this.state.title,
update_dateL = this.state.startDateSel,
update_dateU = this.state.endDateSel,
class_id = this.state.industryTypeSelected.id,
state = this.state.needsStateSelected.id
2019-01-04 17:33:38 +08:00
}) {
//由于后台返回的问题, 所有当state为空的时候不传state反之传state
2019-01-18 17:09:17 +08:00
const param = state ? {
param: JSON.stringify({
curr_page: curr_page,
page_count: page_count,
sd_type: sd_type,
sd_title: sd_title,
update_dateL: update_dateL,
update_dateU: update_dateU,
class_id: class_id,
state: state
})
} : {
param: JSON.stringify({
curr_page: curr_page,
page_count: page_count,
sd_type: sd_type,
sd_title: sd_title,
update_dateL: update_dateL,
update_dateU: update_dateU,
class_id: class_id,
})
}
2019-01-03 17:36:59 +08:00
Taro.request({
url: URL.GetMyNeedsList,
method: 'POST',
dataType: 'json',
data: param,
2019-01-03 17:36:59 +08:00
header: {
'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'),
'content-type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
}
}).then(res => {
2019-01-14 17:04:08 +08:00
Taro.hideLoading()
console.log('我的需求列表', res)
2019-01-03 17:36:59 +08:00
if (res.data.err_msg === "success") {
2019-01-18 17:09:17 +08:00
if (res.data.supplys) { // 查看res.data 里面是否有supplys 这个key
if (this.state.isAddToList) { // 如果是上拉
2019-01-14 17:04:08 +08:00
this.setState({
2019-01-18 17:09:17 +08:00
allNeedsList: this.state.allNeedsList.concat(res.data.supplys)
}, () => {
this.setState({ isAddToList: false })
2019-01-14 17:04:08 +08:00
})
2019-01-18 17:09:17 +08:00
} else {
this.setState({ isAddToList: false })
2019-01-14 17:04:08 +08:00
this.setState({
2019-01-18 17:09:17 +08:00
allNeedsList: res.data.supplys,
totalNeeds:Number(res.data.count)
2019-01-14 17:04:08 +08:00
})
}
2019-01-18 17:09:17 +08:00
} else {
if(this.state.isAddToList){
this.setState({ isAddToList: false })
Taro.showToast({
title: '没有更多了',
icon: 'none'
})
}else{
this.setState({allNeedsList:[],totalNeeds:0})
}
2019-01-14 17:04:08 +08:00
}
2019-01-18 17:09:17 +08:00
} else {
2019-02-15 17:20:52 +08:00
if(JSON.parse(res.data).err_code===88888){
Taro.showToast({
title: JSON.parse(res.data).err_msg,
icon: 'none'
})
}else{
Taro.showToast({
title: res.data.err_msg,
icon: 'none'
})
}
2019-01-03 17:36:59 +08:00
}
})
}
2019-01-04 17:33:38 +08:00
//删除我的需求 api DeleteMyNeeds
deleteMyNeeds({ demandId = 10 }) {
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 => {
console.log('删除我的列表', res)
if (res.data.err_msg === "success") {
Taro.showToast({
title: '删除成功',
icon: 'success',
duration: 1500
})
setTimeout(() => {
this.getMyNeedsList({
})
}, 1500);
} else {
Taro.showToast({
title: res.data.err_msg,
icon: 'none',
duration: 1500
})
}
})
}
2019-01-18 17:09:17 +08:00
2019-01-04 17:33:38 +08:00
2019-01-03 17:36:59 +08:00
// 搜索按钮
onSearchButtonHandler() {
Taro.showLoading({ title: '加载中' }).then(() => {
2019-01-18 17:09:17 +08:00
this.setState({ currentPage: 1, loadMorePageIndex: 1 }, () => {
2019-01-04 17:33:38 +08:00
this.getMyNeedsList({
2019-01-14 17:04:08 +08:00
curr_page: this.state.currentPage,
2019-01-04 17:33:38 +08:00
page_count: this.state.pageCount,
sd_type: this.state.needsTypeSelected.id,
sd_title: this.state.title,
update_dateL: this.state.startDateSel,
update_dateU: this.state.endDateSel,
2019-01-18 17:09:17 +08:00
class_id: this.state.industryTypeSelected.id === '-1' ? '' : this.state.industryTypeSelected.id,
2019-01-04 17:33:38 +08:00
state: this.state.needsStateSelected.id
})
})
2019-01-03 17:36:59 +08:00
})
}
// 新增我的需求
2019-01-04 17:33:38 +08:00
addNeeds() {
2019-01-03 17:36:59 +08:00
Taro.navigateTo({
2019-01-04 17:33:38 +08:00
url: '/pages/myNeedsPublish/myNeedsPublish'
2019-01-03 17:36:59 +08:00
})
}
//清空筛选项
2019-01-18 17:09:17 +08:00
emptyFilter() {
this.setState({
2019-01-18 17:09:17 +08:00
title: '',
endDateSel: '',
startDateSel: '',
industryTypeSelected: { name: '全部', id: '' },
needsTypeSelected: { name: '业主需求', id: '4' },
needsStateSelected: { name: '全部', id: '' },
2019-01-18 17:09:17 +08:00
currentPage: 1,
loadMorePageIndex: 1,
}, () => {
this.getMyNeedsList({})
})
Taro.showToast({
2019-01-18 17:09:17 +08:00
title: '已清空',
icon: 'success',
duration: 1000
})
}
2019-01-03 17:36:59 +08:00
titleChange(event) {
this.setState({ title: event })
}
// 修改开始日期
onStartDateChange = e => {
this.setState({
startDateSel: e.detail.value
})
}
// 修改结束日期
onEndDateChange = e => {
this.setState({
endDateSel: e.detail.value
})
}
needsTypeChange = e => {
this.setState({
needsTypeSelected: this.state.needsType[e.detail.value]
})
}
needsStateChange = e => {
this.setState({
needsStateSelected: this.state.needsState[e.detail.value]
})
}
goToMyNeedsViewPage(Id) {
Taro.navigateTo({
url: '/pages/grabOrderPage/grabOrderPage?orderId=' + Id
})
2019-01-04 17:33:38 +08:00
}
2019-01-08 17:33:52 +08:00
goToMyNeedsEditPage(id) {
2019-01-04 17:33:38 +08:00
Taro.navigateTo({
2019-01-18 17:09:17 +08:00
url: '/pages/myNeedsEdit/myNeedsEdit?id=' + id
2019-01-04 17:33:38 +08:00
})
}
deleteButton(item) {
2019-01-18 17:09:17 +08:00
this.setState({ isDeleteModal: true, needsItem: item })
2019-01-04 17:33:38 +08:00
}
2019-01-18 17:09:17 +08:00
handleWindowModCancel() {
this.setState({ isDeleteModal: false })
2019-01-04 17:33:38 +08:00
}
2019-01-18 17:09:17 +08:00
handleWindowConfirm() {
this.setState({ isDeleteModal: false })
2019-01-04 17:33:38 +08:00
this.deleteMyNeeds({ demandId: this.state.needsItem.sd_id })
}
2019-01-14 17:04:08 +08:00
2019-01-04 17:33:38 +08:00
2019-01-03 17:36:59 +08:00
componentDidMount() {
Taro.showLoading({
2019-01-18 17:09:17 +08:00
title: '加载中'
})
2019-01-04 17:33:38 +08:00
this.getMyNeedsList({})
2019-01-18 17:09:17 +08:00
2019-01-03 17:36:59 +08:00
}
componentWillReceiveProps(nextProps) {
console.log(this.props, nextProps)
}
componentWillUnmount() { }
2019-02-12 17:21:31 +08:00
componentDidShow() {
if (!Taro.getStorageSync('userInfo').user_id) {
LoginService()
return
}
}
2019-01-03 17:36:59 +08:00
componentDidHide() { }
2019-01-18 17:09:17 +08:00
// 页面位置
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-18 17:09:17 +08:00
// 底部加载
onReachBottom() {
2019-01-14 17:04:08 +08:00
Taro.showLoading({
2019-01-18 17:09:17 +08:00
title: '加载中'
2019-01-14 17:04:08 +08:00
})
2019-01-18 17:09:17 +08:00
this.setState({ isAddToList: true, loadMorePageIndex: this.state.loadMorePageIndex + 1 }, () => {
this.getMyNeedsList({ curr_page: this.state.loadMorePageIndex })
2019-01-14 17:04:08 +08:00
})
2019-01-18 17:09:17 +08:00
}
getDataFromChild(value) {
console.log('从子组件传回来的值', value)
this.setState({ industryTypeSelected: value })
2019-01-04 17:33:38 +08:00
}
2019-01-03 17:36:59 +08:00
render() {
2019-01-04 17:33:38 +08:00
const myNeedsListArrayElement = this.state.allNeedsList.map((item, index) => {
2019-01-03 17:36:59 +08:00
return <View className='needs-box' key={index}>
<View className='industy-type box'>
2019-01-04 17:33:38 +08:00
<Text className='title'>行业分类</Text>
<Text className='content'>{item.class_name}</Text>
2019-01-03 17:36:59 +08:00
</View>
<View className='needs-title box'>
2019-01-04 17:33:38 +08:00
<Text className='title'>需求标题</Text>
2019-01-18 17:09:17 +08:00
<Text className='content' onClick={this.state.goToMyNeedsViewPage.bind(this, item.sd_id)}>{item.sd_title}</Text>
2019-01-03 17:36:59 +08:00
</View>
<View className='needs-state box'>
2019-01-04 17:33:38 +08:00
<Text className='title'>需求状态</Text>
<Text className='content'>{item.state_name}</Text>
2019-01-03 17:36:59 +08:00
</View>
<View className='update-time box'>
2019-01-04 17:33:38 +08:00
<Text className='title'>更新时间</Text>
<Text className='content'>{item.update_date}</Text>
2019-01-03 17:36:59 +08:00
</View>
2019-01-18 17:09:17 +08:00
{item.state === '0' || item.state === '1' ? <View className='info-button-box'>
2019-01-04 17:33:38 +08:00
<View className='button' onClick={this.goToMyNeedsViewPage.bind(this, item.sd_id)}>
2019-01-18 17:09:17 +08:00
<Button size='mini' className='button-orange button-no-margin'>查看</Button>
2019-01-03 17:36:59 +08:00
</View>
2019-01-04 17:33:38 +08:00
<View className='button' onClick={this.goToMyNeedsEditPage.bind(this, item.sd_id)}>
2019-01-18 17:09:17 +08:00
<Button size='mini' className='button-orange button-no-margin'>编辑</Button>
2019-01-04 17:33:38 +08:00
</View>
<View className='button' onClick={this.deleteButton.bind(this, item)}>
2019-01-18 17:09:17 +08:00
<Button size='mini' className='button-dark-red button-no-margin' >删除</Button>
2019-01-04 17:33:38 +08:00
</View>
</View > : <View className='info-button-box'>
2019-01-04 17:33:38 +08:00
<View className='button' onClick={this.goToMyNeedsViewPage.bind(this, item.sd_id)}>
2019-01-18 17:09:17 +08:00
<Button size='mini' className='button-orange button-no-margin'>查看</Button>
2019-01-04 17:33:38 +08:00
</View>
</View>
}
2019-01-03 17:36:59 +08:00
</View>
})
2019-01-18 17:09:17 +08:00
const deleteModalWindowElement = <AtModal isOpened={this.state.isDeleteModal}>
<AtModalHeader>提示</AtModalHeader>
<AtModalContent>
确认删除{this.state.needsItem.sd_title}
2019-01-04 17:33:38 +08:00
</AtModalContent>
2019-01-18 17:09:17 +08:00
<AtModalAction> <Button onClick={this.handleWindowModCancel.bind(this)}>取消</Button> <Button className='orange' onClick={this.handleWindowConfirm.bind(this)}></Button> </AtModalAction>
</AtModal>
2019-01-03 17:36:59 +08:00
return (
<View className='myNeeds'>
2019-01-04 17:33:38 +08:00
{/* 删除模态框 */}
{deleteModalWindowElement}
2019-01-03 17:36:59 +08:00
{/* 需求标题 */}
<View className='input-box'>
<AtInput
name='value'
title='需求标题:'
placeholder='需求标题·'
type='text'
value={this.state.title}
onChange={this.titleChange.bind(this)}
/>
</View>
{/* 开始和结束日期 */}
<View className='page-section'>
<View className='picker-box'>
<Picker mode='date' className='picker-container' onChange={this.onStartDateChange}>
<View className='picker'>
<View className='title-box'>
2019-01-18 17:09:17 +08:00
开始日期:<Text className='selected date'>{this.state.startDateSel}</Text>
2019-01-03 17:36:59 +08:00
</View>
</View>
</Picker>
<Picker className='picker-container' mode='date' start={this.state.startDateSel} onChange={this.onEndDateChange}>
<View className='picker'>
<View className='title-box'>
2019-01-04 17:33:38 +08:00
结束日期: <Text className='selected date'>{this.state.endDateSel}</Text>
2019-01-03 17:36:59 +08:00
</View>
</View>
</Picker>
</View>
</View>
2019-01-04 17:33:38 +08:00
{/* 行业分类开始 */}
2019-01-18 17:09:17 +08:00
<InteractionComponent url={URL.GetIndustryTypeList} onPassDataToChild={this.getDataFromChild.bind(this)} selectedValue={this.state.industryTypeSelected}></InteractionComponent>
2019-01-04 17:33:38 +08:00
{/* 行业分类结束 */}
2019-01-03 17:36:59 +08:00
{/* 需求类型 */}
<View className='page-section'>
<View>
<Picker mode='selector' rangeKey='name' range={this.state.needsType} onChange={this.needsTypeChange.bind(this)}>
<View className='picker'>
<View className='title-box'>
<Text className='title'>需求类型:</Text> <Text className='selected'>{this.state.needsTypeSelected.name}</Text>
</View>
</View>
</Picker>
</View>
</View>
{/* 需求状态 */}
<View className='page-section'>
<View>
<Picker mode='selector' rangeKey='name' range={this.state.needsState} onChange={this.needsStateChange.bind(this)}>
<View className='picker'>
<View className='title-box'>
<Text className='title'> 需求状态:</Text> <Text className='selected'>{this.state.needsStateSelected.name}</Text>
</View>
</View>
</Picker>
</View>
</View>
<View className='button-box'>
<View className='button' onClick={this.onSearchButtonHandler.bind(this)}>
2019-01-18 17:09:17 +08:00
<Button size='mini' className='button-orange'>
2019-01-03 17:36:59 +08:00
<AtIcon value='search' size='12' color='white'></AtIcon>
2019-01-10 17:36:45 +08:00
搜索</Button>
2019-01-03 17:36:59 +08:00
</View>
2019-01-04 17:33:38 +08:00
<View className='button' onClick={this.addNeeds.bind(this)}>
2019-01-18 17:09:17 +08:00
<Button size='mini' className='button-green'>
2019-01-03 17:36:59 +08:00
<AtIcon value='add' size='12' color='white'></AtIcon>
2019-01-10 17:36:45 +08:00
新增</Button>
2019-01-03 17:36:59 +08:00
</View>
<View className='button' onClick={this.emptyFilter.bind(this)}>
2019-01-18 17:09:17 +08:00
<Button size='mini' className='button-dark-red'>
<AtIcon value='trash' size='12' color='white'></AtIcon>
2019-01-10 17:36:45 +08:00
清空</Button>
</View>
2019-01-03 17:36:59 +08:00
</View>
<View className='total'>
<Text className='count'>{this.state.totalNeeds}</Text>
</View>
{/* 我的需求信息 */}
2019-01-18 17:09:17 +08:00
{<View className='info-box'>
{this.state.allNeedsList.length?myNeedsListArrayElement:<View className='no-more-title'>没有更多了</View>}
</View>}
2019-01-18 17:09:17 +08:00
{this.state.isShowTopNav ? <ScrollToTopComponent ></ScrollToTopComponent> : null}
2019-01-03 17:36:59 +08:00
2019-01-14 17:04:08 +08:00
<CopyrightComponent ></CopyrightComponent>
2019-01-03 17:36:59 +08:00
</View>
)
}
}
export default MyNeeds