import Taro, { Component } from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
import { AtInput, AtButton, Picker, AtIcon, AtModal, AtToast } from 'taro-ui'
import URL from '../../serviceAPI.config'
import copyrightComponent from '../../component/copyrightComponent/copyrightComponent'
import './mySupplyDemand.scss'
console.log('hi')
class MySupplyDemand extends Component {
config = {
navigationBarTitleText: '我的供求'
}
constructor() {
super(...arguments)
this.state = {
demandSupplyCate: ['全部', '需求', '供应', '人才'],
demandSupplyCateSelected: '全部',
demandSupplyState: ['全部', '上架', '下架'],
demandSupplyStatesSelected: '全部',
title: '',
startDateSel: '2018-04-22',
endDateSel: '2018-04-22',
allDemandSupply: [],
totalDemandSupply: '',
isToast: false,// 是否显示轻提示
toastContent: '', // 轻提示内容
isConfirmWindow: false, // 是否显示确认弹窗
demandSupplyItemName: '',// 确认框提示时 使用的供求名
demandSupplyId: '',// 删除我的供求时的供求id
}
}
//获取我的供求API
getMySupplyDemand({ curr_page = 1, page_count = 20 }) {
Taro.request({
url: URL.MySupplyDemand,
method: 'POST',
dataType: 'json',
data: {
param: JSON.stringify({
curr_page: curr_page,
page_count: page_count
})
},
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 , 如果没有就是空数组[]
this.setState({ allDemandSupply: res.data.supplys?res.data.supplys:[], totalDemandSupply: res.data.count })
}
})
}
//搜索我的供求api
searchDemandSupply({ curr_page = 1, page_count = 20, sd_type = "2", state = "1", sd_title = "1", update_dateL = "2018-12-18", update_dateU = "2018-12-20" }) {
Taro.request({
url: URL.SearchDemandSupply,
method: 'POST',
dataType: 'json',
data: {
param: JSON.stringify({
curr_page: curr_page,
page_count: page_count,
sd_type: sd_type,
state: state,
sd_title: sd_title,
update_dateL: update_dateL,
update_dateU: update_dateU
})
},
header: {
'content-type': 'application/x-www-form-urlencoded',
'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'),
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(res => {
//this.setState({ grabOrderSuccess: res.data.err_msg,isGrabOrderSuccess: true })
console.log('我的供求搜索结果', res)
this.setState({ allDemandSupply: res.data.supplys, totalDemandSupply: res.data.count })
})
}
// 删除我的供求api
onDelete({ sdID = 0 }) {
Taro.request({
url: URL.DeleteDemandSupply,
method: 'POST',
dataType: 'json',
data: {
sdID: sdID
},
header: {
'content-type': 'application/x-www-form-urlencoded',
'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'),
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(res => {
if (res.data.err_msg == 'success') {
console.log('删除成功')
this.setState({ toastContent: '删除成功', isToast: true }, () => {
setTimeout(() => {
this.setState({ isToast: false })
this.getMySupplyDemand({})
}, 2000)
})
}else{
this.setState({ toastContent: res.data.err_msg, isToast: true }, () => {
setTimeout(() => {
this.setState({ isToast: false })
}, 2000)
})
}
}
)
.catch(error => {
this.setState({ toastContent: '删除失败', isToast: true }, () => {
setTimeout(() => {
this.setState({ isToast: false })
}, 2000)
})
})
}
//搜索我的供求
// 新增我的供求
addDemandSupply() {
Taro.navigateTo({
url: '/pages/supplyDemandPublish/supplyDemandPublish'
})
}
//修改供求类型
demSupplyCateChange = e => {
this.setState({
demandSupplyCateSelected: this.state.demandSupplyCate[e.detail.value]
})
}
// 修改供求状态
demSupplyStateChange = e => {
this.setState({
demandSupplyStatesSelected: this.state.demandSupplyState[e.detail.value]
})
}
titleChange(event) {
this.setState({ title: event })
}
// 修改开始日期
onStartDateChange = e => {
this.setState({
startDateSel: e.detail.value
})
}
// 修改结束日期
onEndDateChange = e => {
this.setState({
endDateSel: e.detail.value
})
}
handleWindowModClose() {
this.setState({ isConfirmWindow: false })
}
handleWindowModCancel() {
this.setState({ isConfirmWindow: false })
}
handleWindowConfirm() {
this.setState({ isConfirmWindow: false })
this.onDelete({ sdID: this.state.demandSupplyId })
}
// 删除我的供求
handleOnDelete(id, itemName) {
this.setState({ isConfirmWindow: true, demandSupplyItemName: itemName, demandSupplyId: id })
}
// 编辑我的供求
//查看我的供求
componentWillReceiveProps(nextProps) {
console.log(this.props, nextProps)
}
componentDidMount() {
this.getMySupplyDemand({})
}
componentWillUnmount() { }
componentDidShow() { }
componentDidHide() { }
render() {
// 提示模态弹窗element
const modalMessageConfirmElement =
// 轻提示
const toastElement =
const demandSupplyElementArray = this.state.allDemandSupply.length ? this.state.allDemandSupply.map((item, index) => {
return
需求类型:
{item.type_name}
需求标题:
{item.sd_title}
联系人:
{item.user_name}
电话号码:
{item.user_phone}
需求状态:
{item.state}
更新时间:
{item.update_date}
查看
编辑
删除
}) :
没有更多了....
return (
{/* 是否删除供求确认框 */}
{modalMessageConfirmElement}
{/* 轻提示 */}
{toastElement}
{/* 供求类型 */}
*供求类型: {this.state.demandSupplyCateSelected}
{/* 供求状态 */}
*供求状态: {this.state.demandSupplyStatesSelected}
{/* 供求标题 */}
*
{/* 开始和结束日期 */}
*开始日期: {this.state.startDateSel}
*结束日期: {this.state.endDateSel}
搜索
新增
一共{this.state.totalDemandSupply} 条记录
{/* 我的供求信息 */}
{demandSupplyElementArray}
)
}
}
export default MySupplyDemand