//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
行业分类:
{item.class_name}
需求标题:
{item.sd_title}
需求状态:
{item.state_name}
更新时间:
{item.update_date}
{item.state === '0'||item.state === '1' ?
查看
编辑
删除
:
查看
}
})
const deleteModalWindowElement=
提示
确认删除{this.state.needsItem.sd_title}?
return (
{/* 删除模态框 */}
{deleteModalWindowElement}
{/* 需求标题 */}
{/* 开始和结束日期 */}
开始日期:{this.state.startDateSel}
结束日期: {this.state.endDateSel}
{/* 行业分类开始 */}
{/* 行业分类结束 */}
{/* 需求类型 */}
需求类型: {this.state.needsTypeSelected.name}
{/* 需求状态 */}
需求状态: {this.state.needsStateSelected.name}
搜索
新增
清空
共{this.state.totalNeeds} 条记录
{/* 我的需求信息 */}
{this.state.totalNeeds != "0" ?
{myNeedsListArrayElement}
:
没有更多了....
}
)
}
}
export default MyNeeds