import React from 'react';
import $ from 'jquery/src/ajax';
import 'react-quill/dist/quill.bubble.css';
import moment from 'moment';
import {Form,Icon,Button,Input,Select,Spin,Table,message,DatePicker,Modal,Upload,Popconfirm,Cascader,InputNumber,Radio,TimePicker,Tabs} from 'antd';
import {areaSelect, getProvince} from '@/NewDicProvinceList';//省市区
import { getGameState, splitUrl, getprovince, getStatuslist, getLvl,beforeUploadFile,getSecretType,getBuyAuditType} from '@/tools.js';
const PicturesWall = React.createClass({
getInitialState() {
return {
previewVisible: false,
previewImage: '',
fileList: this.props.pictureUrl,
}
},
getDefaultProps(){
return{
changeClick:this.modifyChange
}
},
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 >= 18 ? null : uploadButton}
);
}
});
//主体
const BuyList = Form.create()(
React.createClass({
loadData(pageNo) {
this.state.data = [];
this.setState({
loading: true,
page: pageNo
});
$.ajax({
method: 'get',
dataType: 'json',
crossDomain: false,
url: globalConfig.context + '/api/user/purchase/listPurchase',
data: {
pageNo: pageNo || 1,
pageSize: this.state.pagination.pageSize,
auditStatus: this.state.auditStatusSearch,
type: this.state.typeSearch,
secretType: this.state.secretTypeSearch,
title: this.state.titleSearch,
},
success: function(data) {
let theArr = [];
if (!data.data || !data.data.list) {
if (data.error && data.error.length) {
message.warning(data.error[0].message);
}
} else {
for (let i = 0; i < data.data.list.length; i++) {
let thisdata = data.data.list[i];
theArr.push({
key: i,
id: thisdata.id,
title: thisdata.title,
type: thisdata.type,
secretType: thisdata.secretType,
auditStatus: thisdata.auditStatus,
topNumber: thisdata.topNumber,
sortNumber: thisdata.sortNumber,
home: thisdata.home,
contacts: thisdata.contacts,
contactsMobile:thisdata.contactsMobile,
orgName:thisdata.orgName,
endTimes:thisdata.endTimes,
userName:thisdata.userName,
});
}
this.state.pagination.current = data.data.pageNo;
this.state.pagination.total = data.data.totalCount;
}
this.setState({
dataSource: theArr,
pagination: this.state.pagination
});
}.bind(this)
}).always(
function() {
this.setState({
loading: false
});
}.bind(this)
);
},
getInitialState() {
return {
loading: false,
flag: true,
timesArr:[],
totalData:{
mark: false,
auditStatus: 0,
},
purchaseImg: [],
pagination: {
defaultCurrent: 1,
defaultPageSize: 10,
showQuickJumper: true,
pageSize: 10,
onChange: function(page) {
this.loadData(page);
this.setState({
selectedRowKeys: []
});
}.bind(this),
showTotal: function(total) {
return '共' + total + '条数据';
}
},
columns: [
{
title: '序号',
dataIndex: 'key',
key: 'key'
},
{
title: '标题',
dataIndex: 'title',
key: 'title'
},
{
title: '信息栏目',
dataIndex: 'type',
key: 'type',
render:text=>{
return text === 0?'中标公司':'投标公司'
}
},
{
title: '密级',
dataIndex: 'secretType',
key: 'secretType',
render:(text)=>{
return getSecretType(text);
}
},
{
title: '有限时限',
dataIndex: 'endTimes',
key: 'endTimes',
width: 200,
},
{
title: '发布人',
dataIndex: 'userName',
key: 'userName',
},
{
title: '排序',
dataIndex: 'sortNumber',
key: 'sortNumber'
},
{
title: '审核状态',
dataIndex: 'auditStatus',
key: 'auditStatus',
render:text=>{
return getBuyAuditType(text);
}
},
{
title: '置顶',
dataIndex: 'topNumber',
key: 'topNumber',
render:(text)=>{
return text?'否':'是';
}
},
{
title: '操作',
dataIndex: 'ads',
key: 'ads',
render:(text,record,index)=>{
return !record.auditStatus?
{
}
{
{
this.delete(record.id)
}}>
}
:''
}
},
],
dataSource: []
};
},
componentWillMount() {
this.loadData()
},
detailes(record) {
this.setState({
loading:true
});
$.ajax({
method: 'get',
dataType: 'json',
crossDomain: false,
url: globalConfig.context + '/api/user/purchase/details',
data: {
id: record.id,
},
success: function(data) {
let theArr = [];
let thisdata = data.data;
if (!data.data || !data.data.list) {
if (data.error && data.error.length) {
message.warning(data.error[0].message);
}
}
this.setState({
purchaseImg: thisdata.purchaseImg ? splitUrl(thisdata.purchaseImg, ',', globalConfig.avatarHost + '/upload') : [],
})
Object.assign(this.state.totalData,{
content: thisdata.content,
},this.state.RowData)
}.bind(this)
}).always(
function() {
this.setState({
loading: false
});
}.bind(this)
);
},
stopPropagation(e){
e.stopPropagation();
e.nativeEvent.stopImmediatePropagation();
},
//项目列表整行点击
tableRowClick(record, index) {
this.state.RowData = record;
this.setState({
editvisible: true,
});
this.detailes(record);
},
edithandleCancel(e) {
this.setState({
editvisible: false
},()=>{
this.addReset()
});
this.loadData()
},
search() {
this.loadData();
},
add(){
this.setState({
editvisible: true,
flag: false,
});
console.log(this.state.totalData)
},
addNew(){
let theorgCodeUrl = [];
if (this.state.purchaseImg.length) {
let picArr = [];
this.state.purchaseImg.map(function (item) {
if ( item.response && item.response.data && item.response.data.length ){
picArr.push(item.response.data);
}
});
theorgCodeUrl = picArr.join(",");
};
this.setState({
loading:true
});
if(theorgCodeUrl.length){
this.change("purchaseImg",theorgCodeUrl)
}else{
this.change("purchaseImg",[])
}
$.ajax({
method: 'post',
dataType: 'json',
crossDomain: false,
url: (this.state.flag?'/api/user/purchase/update':'/api/user/purchase/apply'),
data: this.state.totalData,
}).done(function(data) {
this.setState({
loading: false
});
if(!data.error.length) {
message.success('保存成功!');
this.setState({
editvisible:false,
flag:true
})
this.addReset()
this.loadData()
} else {
message.warning(data.error[0].message);
}
}.bind(this));
},
issueNew(){
this.change("auditStatus",1,()=>{
this.addNew()
})
},
delete(id){
this.setState({
loading:true
});
$.ajax({
method: 'post',
dataType: 'json',
crossDomain: false,
url: "/api/user/purchase/delete",
data: {
id: id,
},
}).done(function(data) {
this.setState({
loading: false
});
if(!data.error.length) {
message.success('删除成功!');
this.loadData()
} else {
message.warning(data.error[0].message);
}
}.bind(this));
},
cancelAdd(){
this.setState({
editvisible: false,
},()=>{
this.setState({
flag:true
})
this.addReset()
});
this.loadData()
},
//新增框的清零
addReset(){
this.setState({
totalData:{
auditStatus: 0,
},
purchaseImg:[],
})
},
//搜索部分的清零
reset() {
this.setState({
auditStatusSearch: undefined,
typeSearch: undefined,
secretTypeSearch: undefined,
titleSearch: undefined,
})
this.loadData();
},
getOrgCodeUrl(e) {
this.setState({ purchaseImg: e });
},
change(key, e, f){
if(f === undefined ){
this.state.totalData[key] = e
this.setState({
totalData:this.state.totalData
})
}else if(typeof(f) === "function"){
this.state.totalData[key] = e
this.setState({
totalData:this.state.totalData
},f)
}
},
render() {
const FormItem = Form.Item;
const rowSelection = {
selectedRowKeys: this.state.selectedRowKeys,
onChange: (selectedRowKeys, selectedRows) => {
this.setState({
selectedRows: selectedRows.slice(-1),
selectedRowKeys: selectedRowKeys.slice(-1)
});
}
};
let data = this.state.totalData;
const { TextArea } = Input;//文本域
const { TabPane } = Tabs;//标签页
const { MonthPicker, RangePicker, WeekPicker } = DatePicker;//日期输入框
return (
);
}
})
);
export default BuyList;