import Taro, { Component } from '@tarojs/taro'
import { View, Text, Image, Button } from '@tarojs/components'
import { AtButton, AtIcon, AtModal, AtModalHeader, AtModalContent, AtModalAction } from 'taro-ui'
import URL from '../../serviceAPI.config'
import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent'
import './myNeedsView.scss'
class SupplyDemandView extends Component {
config = {
navigationBarTitleText: '需求查看'
}
constructor() {
super(...arguments)
this.state = {
industryTypeSelected: '',
needsType: [{ name: '业主需求', id: '4' }, { name: '效果图', id: '5' }],
needsTypeSelected: { name: '业主需求', id: '4' },
needsState: [
{ name: '作废', id: '0' },
{ name: '在用', id: '1' },
],
needsStateSelected: { name: '全部', id: '' },
title: '',
browsing: '',
sd_id: '', //需求id
contactName: '',
contactNumber: '',
contactAddress: '',
content: '',//描述
pickerImageUrl: [],
ImagesInfo: '',
}
}
//获取需求信息api
getSingleMyNeedInfo() {
Taro.request({
url: URL.EditMyNeeds,
method: 'GET',
dataType: 'json',
data: {
demandId: this.$router.params.id,
},
header: {
'content-type': 'application/x-www-form-urlencoded',
'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'),
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(res => {
console.log('需求详情获取成功', res)
// const selectedType = this.state.demandingSupplyCate.filter(item => item.id == res.data.sdInfo.sd_type)[0]
// const selectedState = this.state.needsState.filter(item => item.id == res.data.sdInfo.state)[0]
Taro.hideLoading()
let industryType = {}
const classId = res.data.sdInfo.class_id
for (let outter of res.data.supplyTree) {
if (outter.children) {
for (let inner of outter.children) {
if (inner.class_id === classId) {
industryType.name = inner.class_name
industryType.id = inner.class_id
break
}
}
}
if (outter.class_id === classId) {
industryType.name = outter.class_name
industryType.id = outter.class_id
break
}
}
const needsType = this.state.needsType.filter(item => {
return item.id === res.data.sdInfo.sd_type
})[0]
const imageFile = res.data.sdInfo.file_path.map(item => { return { url: URL.Base + item.file_path } })
const needsState = this.state.needsState.filter(item => {
return item.id === res.data.sdInfo.state
})[0]
this.setState({
sd_id: res.data.sdInfo.sd_id,
industryTypeSelected: industryType,
needsTypeSelected: needsType,
title: res.data.sdInfo.sd_title,
browsing: res.data.sdInfo.browse_times,
contactName: res.data.sdInfo.user_name,
contactNumber: res.data.sdInfo.user_phone,
contactAddress: res.data.sdInfo.user_address,
content: res.data.sdInfo.sd_desc,
needsStateSelected: needsState,
pickerImageUrl: imageFile,
ImagesInfo: res.data.sdInfo.file_path,
isDeleteModal: false,
})
}
)
.catch(error => {
console.log('供求详情获取失败', error)
})
}
//删除我的需求 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.goToMyNeedsPage()
}, 1500);
} else {
Taro.showToast({
title: res.data.err_msg,
icon: 'none',
duration: 1500
})
}
})
}
goMyNeedsPublishPage() {
Taro.navigateTo({
url: '/pages/myNeedsPublish/myNeedsPublish',
})
}
goMyNeedEditPage() {
console.log('edit page')
console.log('id', this.state.sd_id)
Taro.navigateTo({
url: '/pages/myNeedsEdit/myNeedsEdit?id=' + this.state.sd_id
})
}
goToMyNeedsPage() {
Taro.navigateTo({
url: '/pages/myNeeds/myNeeds'
})
}
deleteButton() {
this.setState({ isDeleteModal: true })
}
handleWindowModCancel() {
this.setState({ isDeleteModal: false })
}
handleWindowConfirm() {
this.setState({ isDeleteModal: false })
this.deleteMyNeeds({ demandId: this.state.sd_id })
}
componentDidMount() {
Taro.showLoading({ title: '加载中' })
this.getSingleMyNeedInfo()
}
componentWillReceiveProps(nextProps) {
console.log(this.props, nextProps)
}
componentWillUnmount() { }
componentDidShow() { }
componentDidHide() { }
render() {
const deleteModalWindowElement =
提示
确认删除{this.state.needsItem.sd_title}?
const imageArrayElement = this.state.ImagesInfo.map((item, index) => {
return
})
return (
{/* 删除模态框 */}
{deleteModalWindowElement}
行业分类:
{this.state.industryTypeSelected.name?this.state.industryTypeSelected.name:'--'}
需求标题:
{this.state.title}
浏览量:
{this.state.browsing}
联系人:
{this.state.contactName}
联系电话:
{this.state.contactNumber}
联系地址:
{this.state.address}
业主需求内容:
{this.state.content}
{this.state.ImagesInfo.length?
业主需求图片:
{imageArrayElement}
:null
}
新增
我的需求
修改
删除
)
}
}
export default SupplyDemandView