import { Component } from 'react'; import { Input, Select, Spin, Table, message, Button,Icon } from 'antd'; import BannerFrom from '@/administration/banner/bannerDes.jsx'; import { splitUrl} from '@/tools.js'; import Crop from '@/crop/cropBlock'; class Banner extends Component { constructor(props) { super(props); this.state = { loading: false, dataSource: [], showDesc:false, selectedRowKey:[], selectedRowKeys:[], 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: 'text', key: 'text' }, { title: '跳转地址', dataIndex: 'forwardUrl', key: 'forwardUrl' }, { title: '位置', dataIndex: 'client', key: 'client', render:(text=>{ return text==1?'APP':'网站' }) }, { title: '轮播图API', dataIndex: 'apiUrl', key: 'apiUrl' }, ] }; } loadData(pageNo) { this.setState({ page:pageNo, loading: true, selectedRowKeys:[], }); $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/banners/list", data: { pageNo: pageNo || 1, pageSize: this.state.pagination.pageSize, apiUrl:this.state.apiSearch, client: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, id: thisdata.id, //品类ID text: thisdata.text, //品类序号 apiUrl:thisdata.apiUrl, forwardUrl:thisdata.forwardUrl, client:thisdata.client, imgUrl: thisdata.imgUrl ? splitUrl(thisdata.imgUrl, ',', globalConfig.avatarHost + '/upload') : [], }); }; } this.state.pagination.current = data.data.pageNo; this.state.pagination.total = data.data.totalCount; if(data.data&&data.data.list&&!data.data.list.length){ this.state.pagination.current=0 this.state.pagination.total=0 } this.setState({ dataSource: theArr, pagination: this.state.pagination }); }.bind(this), }).always(function () { this.setState({ loading: false }); }.bind(this)); } search() { this.loadData(); } reset() { this.state.apiSearch = ''; this.state.positionSearch = undefined; this.loadData(); } closeDesc(e, s) { this.state.showDesc = e; if (s) { this.loadData(this.state.page); }; } addClick() { this.state.RowData = {}; this.setState({ showDesc: true }); } tableRowClick(record, index) { this.state.RowData = record; this.setState({ showDesc: true, }); } delectRow() { this.setState({ loading:true }) let deletedIds =[]; let rowItem = this.state.selectedRowKeys[0]; let data = this.state.dataSource ||[]; if (data.length) { deletedIds.push(data[rowItem].id); } $.ajax({ method: "POST", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/banners/delete", data: { id: deletedIds[0] } }).done(function (data) { if (!data.error.length) { message.success('删除成功!'); this.setState({ loading: false }); this.loadData(this.state.page); } else { message.warning(data.error[0].message); }; }.bind(this)); } componentWillMount() { this.loadData(); } render() { const rowSelection = { selectedRowKeys: this.state.selectedRowKeys, onChange: (selectedRowKeys, selectedRows) => { this.setState({ selectedRows: selectedRows.slice(-1), selectedRowKeys: selectedRowKeys.slice(-1) }); } }; const hasSelect = this.state.selectedRowKeys.length; return (