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

429 lines
13 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'
import { AtInput, AtButton, Picker, AtIcon, AtModal, AtModalHeader, AtModalContent, AtModalAction, AtPagination } from 'taro-ui'
import URL from '../../serviceAPI.config'
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'
import './myNeeds.scss'
class MyNeeds extends Component {
2019-01-08 17:33:52 +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: '',// 确认框提示时 使用的供求名
isDeleteModal:false,
2019-01-03 17:36:59 +08:00
}
}
2019-01-04 17:33:38 +08:00
2019-01-03 17:36:59 +08:00
//请求我的需求列表 api GetMyNeedsList
2019-01-04 17:33:38 +08:00
getMyNeedsList({ curr_page = 1,
page_count = 20,
sd_type = '4',
2019-01-04 17:33:38 +08:00
sd_title = '',
update_dateL = '',
update_dateU = '',
class_id = '',
state = ''
2019-01-04 17:33:38 +08:00
}) {
//由于后台返回的问题, 所有当state为空的时候不传state反之传state
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 => {
if (res.data.err_msg === "success") {
// 判断是否有res.data.supplys 如果没有就是空数组[]
Taro.hideLoading()
console.log('我的需求列表', res)
this.setState({
allNeedsList: res.data.supplys || [],
totalNeeds: Number(res.data.count)
})
}
})
}
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-08 13:51:26 +08:00
2019-01-04 17:33:38 +08:00
2019-01-03 17:36:59 +08:00
// 搜索按钮
onSearchButtonHandler() {
Taro.showLoading({ title: '加载中' }).then(() => {
setTimeout(() => {
2019-01-04 17:33:38 +08:00
this.getMyNeedsList({
curr_page: this.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==='-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
this.setState({ currentPage: 1 })
}, 1000);
})
}
// 新增我的需求
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
})
}
//清空筛选项
emptyFilter(){
this.setState({
title:'',
endDateSel:'',
startDateSel:'',
})
Taro.showToast({
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]
})
}
2019-01-08 17:33:52 +08:00
goToMyNeedsViewPage(id) {
2019-01-04 17:33:38 +08:00
Taro.navigateTo({
2019-01-08 17:33:52 +08:00
url: '/pages/myNeedsView/myNeedsView?id='+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-08 17:33:52 +08:00
url: '/pages/myNeedsEdit/myNeedsEdit?id='+id
2019-01-04 17:33:38 +08:00
})
}
deleteButton(item) {
this.setState({isDeleteModal:true,needsItem:item})
}
handleWindowModCancel(){
this.setState({isDeleteModal:false})
}
handleWindowConfirm(){
this.setState({isDeleteModal:false})
this.deleteMyNeeds({ demandId: this.state.needsItem.sd_id })
}
// 翻页导航
paginationNav(type) {
Taro.showLoading({
title:'加载中'
})
2019-01-04 17:33:38 +08:00
this.setState({ currentPage: type.current, }, () => {
this.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,
2019-01-04 17:33:38 +08:00
state: this.state.needsStateSelected.id
})
})
}
2019-01-03 17:36:59 +08:00
componentDidMount() {
2019-01-04 17:33:38 +08:00
this.getMyNeedsList({})
2019-01-08 13:51:26 +08:00
2019-01-03 17:36:59 +08:00
}
componentWillReceiveProps(nextProps) {
console.log(this.props, nextProps)
}
componentWillUnmount() { }
componentDidShow() { }
componentDidHide() { }
2019-01-04 17:33:38 +08:00
getDataFromChild(value){
console.log('从子组件传回来的值',value)
2019-01-08 13:51:26 +08:00
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>
<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>
{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-03 17:36:59 +08:00
<AtButton type='primary' size='small'>查看</AtButton>
</View>
2019-01-04 17:33:38 +08:00
<View className='button' onClick={this.goToMyNeedsEditPage.bind(this, item.sd_id)}>
<AtButton type='primary' size='small'>编辑</AtButton>
</View>
<View className='button-a' onClick={this.deleteButton.bind(this, item)}>
<AtButton type='primary' size='small'>删除</AtButton>
</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)}>
<AtButton type='primary' size='small'>查看</AtButton>
</View>
</View>
}
2019-01-03 17:36:59 +08:00
</View>
})
2019-01-04 17:33:38 +08:00
const deleteModalWindowElement= <AtModal isOpened={this.state.isDeleteModal}>
<AtModalHeader>提示</AtModalHeader>
<AtModalContent>
确认删除{this.state.needsItem.sd_title}
</AtModalContent>
<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-04 17:33:38 +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-08 17:33:52 +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)}>
<AtButton type='primary' size='small'>
<AtIcon value='search' size='12' color='white'></AtIcon>
搜索</AtButton>
</View>
2019-01-04 17:33:38 +08:00
<View className='button' onClick={this.addNeeds.bind(this)}>
2019-01-03 17:36:59 +08:00
<AtButton type='primary' className='button-a' size='small'>
<AtIcon value='add' size='12' color='white'></AtIcon>
新增</AtButton>
</View>
<View className='button' onClick={this.emptyFilter.bind(this)}>
<AtButton type='primary' className='button-b' size='small'>
<AtIcon value='trash' size='12' color='white'></AtIcon>
清空</AtButton>
</View>
2019-01-03 17:36:59 +08:00
</View>
<View className='total'>
<Text className='count'>{this.state.totalNeeds}</Text>
</View>
{/* 我的需求信息 */}
2019-01-04 17:33:38 +08:00
{this.state.totalNeeds != "0" ? <View className='info-box'>
2019-01-03 17:36:59 +08:00
{myNeedsListArrayElement}
2019-01-04 17:33:38 +08:00
</View> : <View className='nomore' >
没有更多了....
</View >}
2019-01-03 17:36:59 +08:00
<View className='pagination-box'>
<AtPagination
2019-01-04 17:33:38 +08:00
total={this.state.totalNeeds}
2019-01-03 17:36:59 +08:00
pageSize={10}
current={this.state.currentPage}
onPageChange={this.state.paginationNav.bind(this)}
>
</AtPagination>
</View>
2019-01-04 17:33:38 +08:00
<CopyrightComponent name='Wallace'></CopyrightComponent>
2019-01-03 17:36:59 +08:00
</View>
)
}
}
export default MyNeeds