import React from 'react';
import { Switch, Icon, Button, Input, Spin, Table, message, Radio, Select, Modal, Upload } from 'antd';
import { beforeUploadFile, newDownloadFile, getProportion, saveProportion, getPreview } from '../../../../tools.js';
import ajax from 'jquery/src/ajax/xhr.js';
import $ from 'jquery/src/ajax';
const StandardDesc = React.createClass({
getInitialState() {
return {
visible: false,
loading: false
};
},
handleOk() {
this.setState({
loading: true,
});
if (!this.state.standardName || !this.state.standardNumber || !this.state.year) {
message.warning('请输入正确信息!');
this.setState({
loading: false
});
return;
};
$.ajax({
method: "POST",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/developStandard",
data: {
id: this.props.data.id,
uid: this.props.uid,
standardName: this.state.standardName,
standardNumber: this.state.standardNumber,
year: this.state.year,
standardLevel: this.state.standardLevel,
participateWay: this.state.participateWay,
enclosureUrl: this.state.enclosureUrl
},
success: function (data) {
if (data.data) {
this.setState({
id: data.data.id,
standardName: data.data.standardName,
standardNumber: data.data.standardNumber,
standardLevel: data.data.standardLevel,
participateWay: data.data.participateWay,
enclosureUrl: this.state.enclosureUrl
});
} else if (data.error.length && data.error[0].message) {
message.warning(data.error[0].message);
}
}.bind(this),
}).done(function (data) {
if (!data.error.length) {
message.success('保存成功!');
this.setState({
loading: false,
visible: false
});
} else {
message.warning(data.error[0].message);
};
this.props.closeDesc(false, true);
}.bind(this));
},
handleCancel(e) {
this.setState({
visible: false,
});
this.props.closeDesc(false);
},
componentWillMount() {
const Option = Select.Option;
const d = new Date();
const thisYear = d.getFullYear();
let theOption = [];
for (let i = thisYear; i >= 1950; i--) {
theOption.push()
};
this.state.yearOption = theOption;
},
componentWillReceiveProps(nextProps) {
if (!this.state.visible && nextProps.showDesc) {
this.state.fileList = [];
this.state.enclosureUrl = undefined;
if (nextProps.data) {
this.state.standardName = nextProps.data.standardName;
this.state.standardNumber = nextProps.data.standardNumber;
this.state.year = nextProps.data.year;
this.state.standardLevel = nextProps.data.standardLevel;
this.state.participateWay = nextProps.data.participateWay;
this.state.enclosureUrl = nextProps.data.enclosureUrl;
};
};
this.state.visible = nextProps.showDesc;
},
render() {
if (this.props.data) {
return (
确认,
]}
className="admin-desc-content">
制定时间:
标准级别:
{ this.setState({ standardLevel: e.target.value }) }}>
国家
行业
参与方式:
{ this.setState({ participateWay: e.target.value }) }}>
主持
参与
);
} else {
return
}
},
});
const Standard = React.createClass({
loadData(pageNo) {
this.state.data = [];
this.setState({
loading: true
});
$.ajax({
method: "post",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/standard",
data: {
pageNo: pageNo || 1,
pageSize: this.state.pagination.pageSize,
uid: this.props.data.uid,
standardName: this.state.standardName,
standardNumber: this.state.standardNumber,
standardLevel: this.state.standardLevel,
participateWay: this.state.participateWay
},
success: function (data) {
if (data.error.length || !data.data || !data.data.list) {
message.warning(data.error[0].message);
return;
}
for (let i = 0; i < data.data.list.length; i++) {
let thisdata = data.data.list[i];
this.state.data.push({
key: i + 1,
id: thisdata.id,
uid: thisdata.uid,
standardName: thisdata.standardName,
standardNumber: thisdata.standardNumber,
year: thisdata.year,
enclosureUrl: thisdata.enclosureUrl,
standardLevel: thisdata.standardLevel,
participateWay: thisdata.participateWay,
createTime: thisdata.createTime,
createTimeFormattedDate: thisdata.createTimeFormattedDate
});
};
this.state.pagination.current = data.data.pageNo;
this.state.pagination.total = data.data.totalCount;
this.setState({
dataSource: this.state.data,
pagination: this.state.pagination
});
}.bind(this),
}).always(function () {
this.setState({
loading: false
});
}.bind(this));
let _me = this;
getProportion(this.props.data.uid, function (data) { _me.setState({ proportion: data }); });
},
getInitialState() {
return {
selectedRowKeys: [],
selectedRows: [],
loading: false,
pagination: {
defaultCurrent: 1,
defaultPageSize: 10,
showQuickJumper: true,
pageSize: 10,
onChange: function (page) {
this.loadData(page);
}.bind(this),
showTotal: function (total) {
return '共' + total + '条数据';
}
},
columns: [
{
title: '编号',
dataIndex: 'key',
key: 'key'
}, {
title: '标准名称',
dataIndex: 'standardName',
key: 'standardName'
}, {
title: '标准编号',
dataIndex: 'standardNumber',
key: 'standardNumber'
}, {
title: '制定时间',
dataIndex: 'year',
key: 'year'
}, {
title: '标准级别',
dataIndex: 'standardLevel',
key: 'standardLevel',
render: text => {
switch (text) {
case 0:
return "国家";
case 1:
return "行业";
}
}
}, {
title: '参与方式',
dataIndex: 'participateWay',
key: 'participateWay',
render: text => {
switch (text) {
case 0:
return "主持";
case 1:
return "参与";
}
}
}
],
dataSource: []
};
},
componentWillMount() {
this.loadData();
},
tableRowClick(record, index) {
this.state.RowData = record;
this.setState({
showDesc: true
});
},
delectRow() {
let deletedIds = [];
for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
let rowItem = this.state.selectedRows[idx];
if (rowItem.id) {
deletedIds.push(rowItem.id)
}
}
this.setState({
selectedRowKeys: [],
loading: deletedIds.length > 0
});
$.ajax({
method: "POST",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/deleteStandard",
data: {
ids: deletedIds
}
}).done(function (data) {
if (!data.error.length) {
message.success('删除成功!');
this.setState({
loading: false,
});
} else {
message.warning(data.error[0].message);
};
this.loadData();
}.bind(this));
},
closeDesc(e, s) {
this.state.showDesc = e;
if (s) {
this.loadData();
};
},
search() {
this.loadData();
},
reset() {
this.state.standardName = undefined;
this.state.standardNumber = undefined;
this.state.standardLevel = undefined;
this.state.participateWay = undefined;
this.loadData();
},
render() {
const rowSelection = {
selectedRowKeys: this.state.selectedRowKeys,
onChange: (selectedRowKeys, selectedRows) => {
this.setState({
selectedRows: selectedRows,
selectedRowKeys: selectedRowKeys
});
}
}
const hasSelected = this.state.selectedRowKeys.length > 0;
return (
标准制定情况汇总
是否已完成:
{
e ? this.state.proportion.standard = 1 : this.state.proportion.standard = 0;
saveProportion(this.state.proportion.id, this.props.data.uid, 'standard', this.state.proportion.standard);
this.setState({ proportion: this.state.proportion });
}} />
);
}
});
export default Standard;