429 lines
13 KiB
JavaScript
429 lines
13 KiB
JavaScript
//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'
|
||
|
||
import InteractionComponent from '../../component/interactionComponent/interactionComponent'
|
||
import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent'
|
||
|
||
|
||
import './myNeeds.scss'
|
||
|
||
|
||
class MyNeeds extends Component {
|
||
|
||
config = {
|
||
navigationBarTitleText: '我的需求'
|
||
}
|
||
constructor() {
|
||
super(...arguments)
|
||
this.state = {
|
||
title: '',
|
||
startDateSel: '',
|
||
endDateSel: '',
|
||
industryTypeSelected: { name: '全部', id: '' },
|
||
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' }],
|
||
needsStateSelected: { name: '全部', id: '' },
|
||
pageCount: 10,// 列表数量
|
||
allNeedsList: [],// 我的需求列表
|
||
totalNeeds: 0,// 我的需求数量
|
||
currentPage: 1,
|
||
needsItem: '',// 确认框提示时 使用的供求名
|
||
isDeleteModal:false,
|
||
|
||
}
|
||
}
|
||
|
||
|
||
//请求我的需求列表 api GetMyNeedsList
|
||
getMyNeedsList({ curr_page = 1,
|
||
page_count = 20,
|
||
sd_type = '4',
|
||
sd_title = '',
|
||
update_dateL = '',
|
||
update_dateU = '',
|
||
class_id = '',
|
||
state = ''
|
||
}) {
|
||
//由于后台返回的问题, 所有当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,
|
||
})}
|
||
|
||
Taro.request({
|
||
url: URL.GetMyNeedsList,
|
||
method: 'POST',
|
||
dataType: 'json',
|
||
data: param,
|
||
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)
|
||
})
|
||
}
|
||
})
|
||
|
||
}
|
||
//删除我的需求 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
|
||
})
|
||
}
|
||
})
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
// 搜索按钮
|
||
onSearchButtonHandler() {
|
||
Taro.showLoading({ title: '加载中' }).then(() => {
|
||
setTimeout(() => {
|
||
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,
|
||
state: this.state.needsStateSelected.id
|
||
})
|
||
this.setState({ currentPage: 1 })
|
||
}, 1000);
|
||
|
||
})
|
||
|
||
}
|
||
// 新增我的需求
|
||
addNeeds() {
|
||
Taro.navigateTo({
|
||
url: '/pages/myNeedsPublish/myNeedsPublish'
|
||
})
|
||
}
|
||
//清空筛选项
|
||
emptyFilter(){
|
||
|
||
this.setState({
|
||
title:'',
|
||
endDateSel:'',
|
||
startDateSel:'',
|
||
|
||
})
|
||
Taro.showToast({
|
||
title:'已清空',
|
||
icon:'success',
|
||
duration:1000
|
||
})
|
||
}
|
||
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/myNeedsView/myNeedsView?id='+id
|
||
})
|
||
}
|
||
goToMyNeedsEditPage(id) {
|
||
Taro.navigateTo({
|
||
url: '/pages/myNeedsEdit/myNeedsEdit?id='+id
|
||
})
|
||
}
|
||
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:'加载中'
|
||
})
|
||
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,
|
||
state: this.state.needsStateSelected.id
|
||
})
|
||
})
|
||
}
|
||
|
||
|
||
componentDidMount() {
|
||
this.getMyNeedsList({})
|
||
|
||
}
|
||
componentWillReceiveProps(nextProps) {
|
||
console.log(this.props, nextProps)
|
||
}
|
||
|
||
componentWillUnmount() { }
|
||
|
||
componentDidShow() { }
|
||
|
||
componentDidHide() { }
|
||
|
||
|
||
getDataFromChild(value){
|
||
console.log('从子组件传回来的值',value)
|
||
this.setState({industryTypeSelected:value})
|
||
}
|
||
render() {
|
||
const myNeedsListArrayElement = this.state.allNeedsList.map((item, index) => {
|
||
return <View className='needs-box' key={index}>
|
||
<View className='industy-type box'>
|
||
<Text className='title'>行业分类:</Text>
|
||
<Text className='content'>{item.class_name}</Text>
|
||
|
||
</View>
|
||
<View className='needs-title box'>
|
||
<Text className='title'>需求标题:</Text>
|
||
<Text className='content' onClick={this.state.goToMyNeedsViewPage.bind(this,item.sd_id)}>{item.sd_title}</Text>
|
||
</View>
|
||
<View className='needs-state box'>
|
||
<Text className='title'>需求状态:</Text>
|
||
<Text className='content'>{item.state_name}</Text>
|
||
</View>
|
||
<View className='update-time box'>
|
||
<Text className='title'>更新时间:</Text>
|
||
<Text className='content'>{item.update_date}</Text>
|
||
</View>
|
||
{item.state === '0'||item.state === '1' ? <View className='info-button-box'>
|
||
<View className='button' onClick={this.goToMyNeedsViewPage.bind(this, item.sd_id)}>
|
||
<AtButton type='primary' size='small'>查看</AtButton>
|
||
</View>
|
||
<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'>
|
||
<View className='button' onClick={this.goToMyNeedsViewPage.bind(this, item.sd_id)}>
|
||
<AtButton type='primary' size='small'>查看</AtButton>
|
||
</View>
|
||
</View>
|
||
}
|
||
|
||
</View>
|
||
})
|
||
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>
|
||
return (
|
||
<View className='myNeeds'>
|
||
{/* 删除模态框 */}
|
||
{deleteModalWindowElement}
|
||
{/* 需求标题 */}
|
||
<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'>
|
||
开始日期:<Text className='selected date'>{this.state.startDateSel}</Text>
|
||
</View>
|
||
|
||
</View>
|
||
</Picker>
|
||
<Picker className='picker-container' mode='date' start={this.state.startDateSel} onChange={this.onEndDateChange}>
|
||
<View className='picker'>
|
||
<View className='title-box'>
|
||
结束日期: <Text className='selected date'>{this.state.endDateSel}</Text>
|
||
</View>
|
||
</View>
|
||
</Picker>
|
||
|
||
</View>
|
||
</View>
|
||
{/* 行业分类开始 */}
|
||
<InteractionComponent url={URL.GetIndustryTypeList} onPassDataToChild={this.getDataFromChild.bind(this)} selectedValue={this.state.industryTypeSelected}></InteractionComponent>
|
||
{/* 行业分类结束 */}
|
||
{/* 需求类型 */}
|
||
<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>
|
||
<View className='button' onClick={this.addNeeds.bind(this)}>
|
||
<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>
|
||
</View>
|
||
<View className='total'>
|
||
共<Text className='count'>{this.state.totalNeeds}</Text> 条记录
|
||
</View>
|
||
{/* 我的需求信息 */}
|
||
{this.state.totalNeeds != "0" ? <View className='info-box'>
|
||
{myNeedsListArrayElement}
|
||
</View> : <View className='nomore' >
|
||
没有更多了....
|
||
</View >}
|
||
|
||
<View className='pagination-box'>
|
||
<AtPagination
|
||
total={this.state.totalNeeds}
|
||
pageSize={10}
|
||
current={this.state.currentPage}
|
||
onPageChange={this.state.paginationNav.bind(this)}
|
||
>
|
||
</AtPagination>
|
||
|
||
</View>
|
||
<CopyrightComponent name='Wallace'></CopyrightComponent>
|
||
|
||
</View>
|
||
)
|
||
}
|
||
}
|
||
|
||
export default MyNeeds
|