import React from 'react'; import { AutoComplete, Switch, Tabs, Table, Icon, Tooltip, Modal, Popover, message, Spin, Upload, Input, InputNumber, Select, DatePicker, Button, Radio, Form, Cascader, Tag } from 'antd'; import moment from 'moment'; import './techDemand.less'; import ajax from 'jquery/src/ajax/xhr.js'; import $ from 'jquery/src/ajax'; import { IndustryObject, getIndustryCategory } from '../../DicIndustryList.js'; import { getTechField } from '../../DicTechFieldList.js'; import { beforeUploadFile, getTechAuditStatus, splitUrl, companySearch, getDemandType, getAchievementCategory,beforeUpload, getBase64 } from '../../tools.js'; import throttle from '../../throttle.js'; const KeyWordTagGroup = React.createClass({ getInitialState() { return { tags: [], inputVisible: false, inputValue: '' }; }, handleClose(removedTag) { const tags = this.state.tags.filter(tag => tag !== removedTag); this.props.tagsArr(tags); this.setState({ tags }); }, showInput() { this.setState({ inputVisible: true }, () => this.input.focus()); }, handleInputChange(e) { this.setState({ inputValue: e.target.value }); }, handleInputConfirm() { const state = this.state; const inputValue = state.inputValue; let tags = state.tags; if (inputValue && tags.indexOf(inputValue) === -1 && inputValue.replace(/(^\s*)|(\s*$)/g, "").length != 0) { tags = [...tags, inputValue.replace(/(^\s*)|(\s*$)/g, "")]; } this.props.tagsArr(tags); this.setState({ tags, inputVisible: false, inputValue: '', }); }, componentWillMount() { this.state.tags = this.props.keyWordArr; }, componentWillReceiveProps(nextProps) { if (this.props.keyWordArr != nextProps.keyWordArr) { this.state.tags = nextProps.keyWordArr; }; }, render() { const { tags, inputVisible, inputValue } = this.state; return (
{tags.map((tag, index) => { const isLongTag = tag.length > 10; const tagElem = ( this.handleClose(tag)}> {isLongTag ? `${tag.slice(0, 10)}...` : tag} ); return isLongTag ? {tagElem} : tagElem; })} {inputVisible && ( this.input = input} type="text" style={{ width: 78 }} value={inputValue} onChange={this.handleInputChange} onBlur={this.handleInputConfirm} onPressEnter={this.handleInputConfirm} /> )} {!inputVisible && }
); } }); const PicturesWall = React.createClass({ getInitialState() { return { previewVisible: false, previewImage: '', fileList: [], } }, handleCancel() { this.setState({ previewVisible: false }) }, handlePreview(file) { this.setState({ previewImage: file.url || file.thumbUrl, previewVisible: true, }); }, handleChange(info) { let fileList = info.fileList; this.setState({ fileList }); this.props.fileList(fileList); }, componentWillReceiveProps(nextProps) { this.state.fileList = nextProps.pictureUrl; }, render() { const { previewVisible, previewImage, fileList } = this.state; const uploadButton = (
点击上传
); return (
{fileList.length >= 5 ? null : uploadButton} example
); } }); const DemandDetailShow = Form.create()(React.createClass({ getInitialState() { return { visible: false, loading: false, contactsObj: {}, salesmanObj: {}, data: {}, tags: [], pictureUrl: [], coverImg: [] }; }, loadData(id, detailApiUrl) { this.setState({ loading: true }); $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + detailApiUrl, data: { id: id, dataCategory:this.props.data.dataCategory }, success: function (data) { let thisData = data.data; if (!thisData) { if (data.error && data.error.length) { message.warning(data.error[0].message); }; thisData = {}; }; this.setState({ data: thisData, switchValue: Boolean(!thisData.employerId), radios: thisData.hot == '1' ? true : false, tags: thisData.keyword ? (thisData.keyword.replace(/(,|、)/g, ",")).split(',') : [], pictureUrl: thisData.pictureUrl ? splitUrl(thisData.pictureUrl, ',', globalConfig.avatarHost + '/upload') : [], coverImg: thisData.coverImg ? splitUrl(thisData.coverImg, ',', globalConfig.avatarHost + '/upload') : [] }); }.bind(this), }).always(function () { this.setState({ loading: false }); }.bind(this)); }, getContactsList(theUid) { $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/getContacts", data: { uid: theUid }, success: function (data) { let theOption = []; if (!data.data) { if (data.error && data.error.length) { message.warning(data.error[0].message); }; } else { this.setState({ contactsObj: data.data }); }; }.bind(this), }); }, offShelf() { this.setState({ loading: true }); $.ajax({ method: "post", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/demand/offShelf", data: { "id": this.props.data.id } }).done(function (data) { if (!data.error.length) { message.success('撤销成功!'); this.props.handleOk(); } else { message.warning(data.error[0].message); }; this.setState({ loading: false, releaseSubmitVisible: false }); }.bind(this)); }, modifyBroker() { this.props.form.validateFields((err, values) => { if (!err) { this.setState({ loading: true }); $.ajax({ method: "POST", dataType: "json", crossDomain: false, url: globalConfig.context + '/api/admin/audit/modifyDemandTechBroker', data: { id: this.props.data.id, techBrokerId: values.modifyTechBrokerId } }).done(function (data) { this.state.auditStatus = 0; this.setState({ loading: false }); if (data.error && data.error.length) { message.warning(data.error[0].message); } else { message.success('保存成功!'); this.props.handleOk(); }; }.bind(this)); } }); }, formSubmit() { this.props.form.validateFields((err, values) => { if (values.auditStatus == 3 && !values.techBrokerId) { message.warning('必须选择一个技术经纪人!'); return }; if (!err) { this.setState({ loading: true }); $.ajax({ method: "POST", dataType: "json", crossDomain: false, url: globalConfig.context + '/api/admin/audit/demand', data: { id: this.props.data.id, techBroderId: values.techBrokerId, auditStatus: values.auditStatus } }).done(function (data) { this.state.auditStatus = 0; if (!data.error.length) { message.success('保存成功!'); this.setState({ formSubmitVisible: false }); this.props.handleOk(); } else { message.warning(data.error[0].message); this.setState({ loading: false, }); } }.bind(this)); } }); }, handleSubmit(e) { e.preventDefault(); this.props.form.validateFields((err, values) => { if (values.auditStatus == 4) { this.setState({ formSubmitVisible: true }); } else { this.formSubmit(); }; }); }, buildMatchList() { this.setState({ buttonLoading: true }); $.ajax({ method: "POST", dataType: "json", crossDomain: false, url: globalConfig.context + '/api/admin/demand/matchAchievement', data: { id: this.props.data.id, } }).done(function (data) { this.setState({ buttonLoading: false }); if (!data.error.length) { message.success('匹配完成!匹配到' + data.data + '条记录'); } else { message.warning(data.error[0].message); }; }.bind(this)); }, componentWillMount() { this.loadData(this.props.data.id, this.props.detailApiUrl); if (this.props.data.employerId && this.props.data.dataCategory) { this.getContactsList(this.props.data.employerId); }; }, componentWillReceiveProps(nextProps) { if (!this.props.visible && nextProps.visible) { this.loadData(nextProps.data.id, nextProps.detailApiUrl); if (nextProps.data.employerId && nextProps.data.dataCategory) { this.getContactsList(nextProps.data.employerId); }; this.props.form.resetFields(); }; }, render() { const theData = this.state.data || {}; const { getFieldDecorator } = this.props.form; const FormItem = Form.Item const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 12 }, }; return (
{theData.serialNumber} {theData.name}
{(() => { switch (theData.boutique) { case "0": return ; case "1": return ; } })()}
{this.state.radios==true ?
{ this.setState({ previewImage: file.url || file.thumbUrl, previewVisible: true, }); }} > { this.setState({ previewVisible: false }) }}>
:
} {this.state.switchValue ?
{theData.employerName} {theData.employerContactsMobile} {theData.employerContactsMailbox} {theData.employerAddress}
:
{theData.username} {this.props.data.dataCategory ? {this.state.contactsObj[theData.contacts]} : {theData.contactsName} }
}
{this.props.techBrodersObj[theData.techBrokerId]}
{theData.releaseDateFormattedDate}
{theData.urgentDays} {theData.urgentMoney}
{(() => { switch (theData.status) { case "0": return 未解决; case "1": return 已解决; } })()} {(() => { switch (theData.auditStatus) { case 0: return 未提交审核(草稿); case 1: return 提交审核; case 2: return 审核中; case 3: return 审核通过; case 4: return 审核未通过; } })()}
{(() => { switch (theData.infoSources) { case "0": return 平台采集; case "1": return 客户发布; case "2": return 批量导入; case "3": return 三方对接; } })()}
{this.state.tags.map((tag) => { return {tag} ; })} {getIndustryCategory(theData.industryCategoryA, theData.industryCategoryB)}
{getDemandType(theData.demandType)}
{theData.problemDes} {theData.remark} {theData.technicalRequirements}
{ this.setState({ previewImage: file.url || file.thumbUrl, previewVisible: true, }); }} > { this.setState({ previewVisible: false }) }}>
{theData.textFileUrl ? { window.open(globalConfig.context + '/api/admin/demand/download?id=' + this.props.data.id) }}>需求文件(文本文件) : 未上传!}
{theData.videoUrl}
{theData.fixedCycle} {theData.peopleNumber || 0} 人
{theData.fixedScheme}
{theData.budgetCost || 0} 万元 {(() => { switch (theData.costEscrow) { case 0: return ; case 1: return ; } })()} {theData.validityPeriodFormattedDate}
{window.showAuditStatus && theData.auditStatus == 2 ?
{getFieldDecorator('auditStatus')( 审核通过 审核未通过 )} {getFieldDecorator('techBrokerId', { initialValue: theData.techBrokerId })( )}
:
} {window.showAuditStatus && theData.auditStatus == 3 ?
:
} { this.setState({ formSubmitVisible: false }) }} > 确认该需求审核未通过?
) } })); const DemandDetailForm = Form.create()(React.createClass({ getInitialState() { return { visible: false, loading: false, auditStatus: 0, switchValue: false, radios: false, textFileList: [], videoFileList: [], contactsOption: [], data: {}, tags: [], pictureUrl: [], coverImg:[], dataSource: [] }; }, getContactsList(theUid) { $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/getContacts", data: { uid: theUid }, success: function (data) { let theOption = []; if (!data.data) { if (data.error && data.error.length) { message.warning(data.error[0].message); return; }; }; for (let item in data.data) { let theData = data.data[item]; theOption.push( {theData} ); }; this.setState({ contactsOption: theOption }); }.bind(this), }); }, loadData(id, detailApiUrl) { this.setState({ loading: true }); $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + detailApiUrl, data: { id: id, dataCategory:this.props.data.dataCategory }, success: function (data) { let thisData = data.data; if (!thisData) { if (data.error && data.error.length) { message.warning(data.error[0].message); }; thisData = {}; }; if (thisData.employerId) { this.getContactsList(thisData.employerId) }; this.setState({ data: thisData, dataCategory:(thisData.dataCategory>-1)?thisData.dataCategory.toString():'', switchValue: Boolean(!thisData.employerId), radios: thisData.hot == '1' ? true : false, tags: thisData.keyword ? (thisData.keyword.replace(/(,|、)/g, ",")).split(',') : [], pictureUrl: thisData.pictureUrl ? splitUrl(thisData.pictureUrl, ',', globalConfig.avatarHost + '/upload') : [], coverImg: thisData.coverImg ? splitUrl(thisData.coverImg, ',', globalConfig.avatarHost + '/upload') : [] }); }.bind(this), }).always(function () { this.setState({ loading: false }); }.bind(this)); }, getTagsArr(e) { this.setState({ tags: e }); }, getPictureUrl(e) { this.setState({ pictureUrl: e }); }, getcoverImg(e) { this.setState({ coverImg: e }); }, handleSubmit(e) { e.preventDefault(); this.props.form.validateFields((err, values) => { //keyword长度判断 if ((this.state.tags ? this.state.tags.length : this.props.tags.length) < 3) { message.warning('关键词数量不能小于3个!'); return; }; //url转化 let thePictureUrl = []; if (this.state.pictureUrl.length) { let picArr = []; this.state.pictureUrl.map(function (item) { if ( item.response && item.response.data && item.response.data.length ){ picArr.push(item.response.data); } }); thePictureUrl = picArr.join(","); }; let thecoverImg = []; if (this.state.coverImg.length) { let picArr = []; this.state.coverImg.map(function (item) { if ( item.response && item.response.data && item.response.data.length ){ picArr.push(item.response.data); } }); thecoverImg = picArr.join(","); }; if (!err) { this.setState({ loading: true }); $.ajax({ method: "POST", dataType: "json", crossDomain: false, url: this.props.data.id ? globalConfig.context + '/api/admin/demand/update' : globalConfig.context + '/api/admin/demand/apply', data: { id: this.props.data.id, dataCategory: this.state.dataCategory,//this.props.detailApiUrl.indexOf('org') >= 0 ? 1 : 0 serialNumber: this.props.data.serialNumber, name: values.name, keyword: this.state.tags ? this.state.tags.join(",") : this.props.tags.join(","), keywords: this.state.tags ? this.state.tags : this.props.tags, infoSources: 0, industryCategoryA: values.industryCategory ? values.industryCategory[0] : undefined, industryCategoryB: values.industryCategory ? values.industryCategory[1] : undefined, demandType: values.demandType, problemDes: values.problemDes, remark: values.remark, technicalRequirements: values.technicalRequirements, pictureUrl: thePictureUrl, coverImg: thecoverImg, textFileUrl: this.state.textFileUrl, videoUrl: values.videoUrl, fixedBudget: values.fixedBudget, fixedCycle: values.fixedCycle, peopleNumber: values.peopleNumber, fixedScheme: values.fixedScheme, costEscrow: values.costEscrow, budgetCost: values.budgetCost, // switchSign: this.state.switchValue ? 1 : 0, // employerId: !this.state.switchValue ? (this.state.dataSourceObj ? this.state.dataSourceObj[values.employerId] : this.props.data.employerId) : null, contacts: !this.state.switchValue ? values.contacts : null, //自定义 employerName: this.state.switchValue ? values.employerName : null, urgentDays: this.state.switchValue ? values.urgentDays : null, urgentMoney: this.state.switchValue ? values.urgentMoney : null, employerAddress: this.state.switchValue ? values.employerAddress : null, employerContactsMobile: this.state.switchValue ? values.employerContactsMobile : null, employerContactsMailbox: this.state.switchValue ? values.employerContactsMailbox : null, // releaseStatus: values.releaseStatus, principalId: values.principalId, validityPeriodFormattedDate: values.validityPeriod ? values.validityPeriod.format('YYYY-MM-DD') : undefined, // status: this.state.status, auditStatus: this.state.auditStatus, boutique: values.boutique, hot: values.hot, } }).done(function (data) { this.state.auditStatus = 0; if (!data.error.length) { message.success('保存成功!'); this.props.handleOk(); } else { message.warning(data.error[0].message); }; this.setState({ loading: false }); }.bind(this)); } }); }, handleSearch(e) { if (this.props.detailApiUrl.indexOf('org') != -1) { $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/achievement/orgOwner", data: { name: e }, success: function (data) { let theArr = []; let theObj = {}; if (!data.data) { if (data.error && data.error.length) { message.warning(data.error[0].message); }; } else if (!$.isEmptyObject(data.data)) { data.data.map(function (item) { theArr.push(item.unitName); theObj[item.unitName] = item.uid; }); }; this.setState({ dataSource: theArr, dataSourceObj: theObj }); }.bind(this), }); } else { $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/achievement/userOwner", data: { name: e }, success: function (data) { let theArr = []; let theObj = {}; if (!data.data) { if (data.error && data.error.length) { message.warning(data.error[0].message); }; } else if (!$.isEmptyObject(data.data)) { for (let item in data.data) { theArr.push(data.data[item]); theObj[data.data[item]] = item; }; }; this.setState({ dataSource: theArr, dataSourceObj: theObj }); }.bind(this), }); }; }, componentWillMount() { this.state.therottleSearch = throttle(this.handleSearch, 1000, { leading: false }).bind(this); if (this.props.data && this.props.data.id) { this.loadData(this.props.data.id, this.props.detailApiUrl); }; }, componentWillReceiveProps(nextProps) { if (!this.props.visible && nextProps.visible) { if (nextProps.data && nextProps.data.id) { this.loadData(nextProps.data.id, nextProps.detailApiUrl); }; this.state.contactsOption = []; this.state.data = {}; this.state.tags = []; this.state.switchValue = false; this.state.radios = false; this.state.pictureUrl = []; this.state.coverImg = []; this.state.textFileList = []; this.state.videoFileList = []; this.state.textFileUrl = undefined; this.props.form.resetFields(); this.state.dataCategory = undefined; }; }, render() { const theData = this.state.data || {}; const { getFieldDecorator } = this.props.form; const FormItem = Form.Item const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 12 }, }; return (
{theData.serialNumber} {getFieldDecorator('name', { rules: [{ required: true, message: '此项为必填项!' }], initialValue: theData.name })( )}
{getFieldDecorator('boutique', { initialValue: theData.boutique })( )}
{this.state.radios==true ?
尺寸为:320x160(像素)
:
} { this.setState({ switchValue: e }); }} /> {this.state.switchValue ?
{getFieldDecorator('employerName', { initialValue: theData.employerName })( )} {getFieldDecorator('employerContactsMobile', { initialValue: theData.employerContactsMobile })( )} {getFieldDecorator('employerContactsMailbox', { initialValue: theData.employerContactsMailbox })( )} {getFieldDecorator('employerAddress', { initialValue: theData.employerAddress })( )}
:
{getFieldDecorator('employerId', { initialValue: theData.username || '' })( { this.getContactsList(this.state.dataSourceObj[e]); }} /> )} {this.props.detailApiUrl.indexOf('org') >= 0 ? {getFieldDecorator('contacts', { initialValue: theData.contacts })( )} :
}
}
{theData.techBrokerId ? {this.props.techBrodersObj[theData.techBrokerId]} :
}
{theData.releaseStatus ?
{(() => { switch (theData.releaseStatus) { case "0": return 未发布; case "1": return 已发布; } })()} {theData.releaseDateFormattedDate}
:
}
{theData.releaseStatus == "1" ? {getFieldDecorator('status', { initialValue: theData.status })( 未解决 已解决 )} :
} {getTechAuditStatus(theData.auditStatus)}
{getFieldDecorator('industryCategory', { rules: [{ type: 'array', required: true, message: '此项为必填项!' }], initialValue: [theData.industryCategoryA, theData.industryCategoryB] })( )} {getFieldDecorator('urgentDays', { initialValue: theData.urgentDays })( )} {getFieldDecorator('urgentMoney', { initialValue: theData.urgentMoney })( )}
{getFieldDecorator('demandType', { rules: [{ required: true, message: '此项为必填项!' }], initialValue: theData.demandType })( )}
{getFieldDecorator('problemDes', { rules: [{ required: true, message: '此项为必填项!' }], initialValue: theData.problemDes })( )} {getFieldDecorator('remark', { initialValue: theData.remark })( )} {getFieldDecorator('technicalRequirements', { initialValue: theData.technicalRequirements })( )} { if (info.file.status !== 'uploading') { console.log(info.file, info.fileList); } if (info.file.status === 'done') { if (!info.file.response.error.length) { message.success(`${info.file.name} 文件上传成功!`); } else { message.warning(info.file.response.error[0].message); return; }; this.state.textFileUrl = info.file.response.data; } else if (info.file.status === 'error') { message.error(`${info.file.name} 文件上传失败。`); }; this.setState({ textFileList: info.fileList.slice(-1) }); }} >

{theData.textFileUrl ? { window.open(globalConfig.context + '/api/admin/demand/download?id=' + this.props.data.id) }}>需求文件(文本文件) : 未上传!}

{getFieldDecorator('videoUrl', { initialValue: theData.videoUrl })( )}
{getFieldDecorator('fixedCycle', { initialValue: theData.fixedCycle })( )} {getFieldDecorator('peopleNumber', { initialValue: theData.peopleNumber || 0 })( )}
{getFieldDecorator('fixedScheme', { initialValue: theData.fixedScheme })( )}
{getFieldDecorator('budgetCost', { initialValue: theData.budgetCost || 0 })( )} 万元 {getFieldDecorator('costEscrow', { initialValue: theData.costEscrow })( )} {getFieldDecorator('validityPeriod', { initialValue: theData.validityPeriod ? moment(theData.validityPeriod) : null })( )}
{theData.employerAddress} {theData.employerContacts} {theData.employerContactsMobile} {theData.employerContactsMailbox}
) } })); const DemandDetail = React.createClass({ getInitialState() { return { visible: false, techBrodersObj: {}, tabsKey: "1", columns: [ { title: '编号', dataIndex: 'serialNumber', key: 'serialNumber', }, { title: '名称', dataIndex: 'name', key: 'name', }, { title: '关键字', dataIndex: 'keyword', key: 'keyword', }, { title: '类型', dataIndex: 'category', key: 'category', render: text => { return getAchievementCategory(text); } }, { title: '所有人名称', dataIndex: 'theName', key: 'theName', }, { title: '所有人类型', dataIndex: 'ownerType', key: 'ownerType', render: text => { switch (text) { case "0": return 个人; case "1": return 组织 } } }, { title: '发布时间', dataIndex: 'releaseDateFormattedDate', key: 'releaseDateFormattedDate', } ], dataSource: [], }; }, getTechBrodersList() { this.setState({ loading: true }); $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/audit/techBroders", success: function (data) { if (!data.data) { if (data.error && data.error.length) { message.warning(data.error[0].message); } return; }; let _me = this, theArr = []; for (var item in data.data) { theArr.push( {data.data[item]} ) }; this.setState({ techBrodersOption: theArr, techBrodersObj: data.data }); }.bind(this), }).always(function () { this.setState({ loading: false }); }.bind(this)); }, getTableList() { this.setState({ loading: true }); $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/demand/achievementDemand", data: { id: this.props.data.id }, success: function (data) { let theArr = []; if (!data.data) { if (data.error && data.error.length) { message.warning(data.error[0].message); }; } else if (data.data.length) { for (let i = 0; i < data.data.length; i++) { let thisdata = data.data[i]; theArr.push({ key: i, id: thisdata.id, serialNumber: thisdata.serialNumber, dataCategory: thisdata.dataCategory, name: thisdata.name, keyword: thisdata.keyword, category: thisdata.category, ownerType: thisdata.ownerType, theName: thisdata.username || thisdata.unitName, releaseDate: thisdata.releaseDate, releaseDateFormattedDate: thisdata.releaseDateFormattedDate }); }; }; this.setState({ dataSource: theArr, }); }.bind(this), }).always(function () { this.setState({ loading: false }); }.bind(this)); }, tableRowClick(record, index) { window.open(globalConfig.context + '/portal/detail/achievementDetail.html?id=' + record.id + '&type=' + record.ownerType); }, handleCancel(e) { this.setState({ visible: false, }); this.props.closeDesc(false); }, handleOk(e) { this.setState({ visible: false, }); this.props.closeDesc(false, true); }, componentWillMount() { this.getTechBrodersList(); }, componentWillReceiveProps(nextProps) { if (!this.state.visible && nextProps.showDesc) { this.state.tabsKey = "1"; }; this.state.visible = nextProps.showDesc; }, render() { if (this.props.data) { return (
{ this.setState({ tabsKey: e }); if (e == "2") { this.getTableList(); }; }} > {(() => { if (this.props.data.id && this.props.data.auditStatus != "0" && this.props.data.auditStatus != "4"&& this.props.data.auditStatus != "2") { return } else { return } })()} ); } else { return
} }, }); export default DemandDetail;