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,
Tag
} from "antd";
import { areaSelect, getProvince } from "@/NewDicProvinceList"; //省市区
import {
getGameState,
splitUrl,
getprovince,
getStatuslist,
getLvl,
beforeUploadFile,
getPicPath
} from "@/tools.js";
const { Option } = Select;
const PicturesWall = React.createClass({
getInitialState() {
return {
previewVisible: false,
previewImage: "",
fileList: []
};
},
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 && fileList.length >= 1 ? null : uploadButton}
);
}
});
//主体
const AdvertisementList = Form.create()(
React.createClass({
loadData(pageNo) {
this.state.data = [];
this.setState({
loading: true,
page: pageNo
});
$.ajax({
method: "get",
dataType: "json",
// url: globalConfig.context + '/api/admin/listCases',
url: globalConfig.context + "/api/admin/banners/listBanners",
data: {
pageNo: pageNo || this.state.pagination.current || 1,
pageSize: this.state.pagination.pageSize,
position: this.state.positionSearch
},
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 + 1,
id: thisdata.id,
title: thisdata.title,
bannerUrl: thisdata.bannerUrl,
sort: thisdata.sort,
display: thisdata.display,
position: thisdata.position
});
}
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,
imgeditvisible: false,
activeKey: "1",
purchaseImg: [],
maximg: "",
timesArr: [],
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: "position",
key: "position",
render: text => {
if (text == 0) {
return 首页;
}else if(text == 1) {
return 产品中心;
}else if(text == 2) {
return 战略合作;
}else if(text == 3) {
return 服务客户;
}else if(text == 4) {
return 新闻动态;
}else if(text == 5) {
return 关于科德;
}else if(text == 6) {
return 联系我们;
}else {
return "未知"
}
}
},
{
title: "广告缩略图",
dataIndex: "bannerUrl",
key: "bannerUrl",
render: url => {
let path = getPicPath(globalConfig.avatarUploadHost, url);
return (
);
}
},
{
title: "是否显示",
dataIndex: "display",
key: "display",
render: s => {
return s ? (
显示
) : (
未显示
);
}
},
{
title: "排序",
dataIndex: "sort",
key: "sort"
},
{
title: "操作",
dataIndex: "c",
render: (text, record, index) => {
return (
{
}
{
{
this.delete(record.id);
}}
>
}
{!record.display ? (
) : (
)}
);
}
}
],
//数据列表
dataSource: [
]
};
},
componentWillMount() {
this.loadData();
},
detailes(record) {
this.setState({
loading: true
});
$.ajax({
method: "get",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/banners/selectBanners",
data: {
id: record.id
},
success: function(data) {
let thisdata = data.data;
this.setState({
id: thisdata.id,
title: thisdata.title,
bannerUrl: thisdata.bannerUrl
? splitUrl(thisdata.bannerUrl, ",", globalConfig.avatarUploadHost)
: [],
sortNumber: thisdata.sort,
display: thisdata.display,
position: thisdata.position
});
}.bind(this)
}).always(
function() {
this.setState({
loading: false
});
}.bind(this)
);
},
//点击大图
maximg(url) {
this.setState({
imgeditvisible: true,
maximg: url
});
},
//删除按钮
delete(id) {
$.ajax({
method: "post",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/banners/deleteBanners",
data: {
id
},
success: function(data) {
this.loadData();
}.bind(this)
}).always(
function() {
this.setState({
loading: false
});
}.bind(this)
);
},
//阻止默认冒泡
stopPropagation(e) {
e.stopPropagation();
e.nativeEvent.stopImmediatePropagation();
},
imghandleCancel() {
this.setState({
imgeditvisible: false
});
},
//项目列表整行点击
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
});
this.addReset();
},
cancelAdd() {
this.setState(
{
editvisible: false
},
() => {
this.setState({
flag: true
});
this.addReset();
}
);
this.loadData();
},
edit(record, display) {
if (!display) {
if (!this.state.bannerUrl || !this.state.bannerUrl.length) {
message.warning("请上传图片!");
return;
}
if (!this.state.title) {
message.warning("请填写广告标题");
return;
}
}
$.ajax({
method: "post",
dataType: "json",
url: globalConfig.context + "/api/admin/banners/updateBanners",
data: {
id: record ? record.id : this.state.id,
sort: this.state.sortNumber,
display: display || this.state.display,
position: this.state.position,
bannerUrl: this.state.bannerUrl
? this.state.bannerUrl[0].response.data
: undefined,
title: this.state.title
},
success: function(data) {
let theArr = [];
if (data.error.length || data.data.list == "") {
if (data.error && data.error.length) {
message.warning(data.error[0].message);
}
} else {
this.cancelAdd();
}
}.bind(this)
}).always(
function() {
this.setState({
loading: false
});
}.bind(this)
);
},
addNew() {
if (!this.state.bannerUrl || !this.state.bannerUrl.length) {
message.warning("请上传图片!");
return;
}
if (!this.state.title) {
message.warning("请填写广告标题");
return;
}
$.ajax({
method: "post",
dataType: "json",
url: globalConfig.context + "/api/admin/banners/addBanners",
data: {
sort: this.state.sortNumber,
display: this.state.display,
position: this.state.position,
bannerUrl: this.state.bannerUrl
? this.state.bannerUrl[0].response.data
: undefined,
title: this.state.title
},
success: function(data) {
let theArr = [];
if (data.error.length || data.data.list == "") {
if (data.error && data.error.length) {
message.warning(data.error[0].message);
}
} else {
this.loadData();
this.cancelAdd();
}
}.bind(this)
}).always(
function() {
this.setState({
loading: false
});
}.bind(this)
);
},
//新增框的清零
addReset() {
this.setState({
bannerUrl: undefined,
title: undefined,
sortNumber: undefined,
display: 1,
position: "0"
});
},
//搜索部分的清零
reset() {
this.state.positionSearch = undefined;
this.loadData();
},
imgOk() {
this.setState({
imgeditvisible: false
});
},
getOrgCodeUrl(e) {
this.setState({ bannerUrl: e });
},
render() {
const FormItem = Form.Item;
const rowSelection = {
selectedRowKeys: this.state.selectedRowKeys,
onChange: (selectedRowKeys, selectedRows) => {
this.setState({
selectedRows: selectedRows.slice(-1),
selectedRowKeys: selectedRowKeys.slice(-1)
});
}
};
const { TextArea } = Input; //文本域
const { TabPane } = Tabs; //标签页
const { MonthPicker, RangePicker, WeekPicker } = DatePicker; //日期输入框
const dateFormat = "YYYY/MM/DD"; //日期格式
const theData = this.state.data || {};
return (
广告列表
);
}
})
);
export default AdvertisementList;