index.jsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. import React,{Component} from 'react';
  2. import {Button, Input, Table, Select, message, Popconfirm, Modal, Tag} from "antd";
  3. import $ from "jquery/src/ajax";
  4. import {
  5. getPicPath
  6. } from "@/tools.js";
  7. import ActivityOperation from './components/activityOperation';
  8. import SpinContainer from "../../../SpinContainer";
  9. class Activity extends Component{
  10. constructor(props) {
  11. super(props);
  12. this.state={
  13. loading: false,
  14. title: '',
  15. releaseStatus: '',
  16. pageNo: 1,
  17. dataSource: [],
  18. imgeditvisible: false,
  19. maximg: '',
  20. pagination: {
  21. defaultCurrent: 1,
  22. defaultPageSize: 10,
  23. showQuickJumper: true,
  24. pageSize: 10,
  25. onChange: function(page) {
  26. this.loadData(page);
  27. }.bind(this),
  28. showTotal: function(total) {
  29. return "共" + total + "条数据";
  30. }
  31. },
  32. activityId:'',
  33. columns: [
  34. {
  35. title: "序号",
  36. dataIndex: "key",
  37. key: "key",
  38. render: (v,a,k) => {
  39. return (
  40. (this.state.pageNo-1)*10+k+1
  41. )
  42. }
  43. },
  44. {
  45. title: "标题",
  46. dataIndex: "title",
  47. key: "title"
  48. },
  49. {
  50. title: "缩略图",
  51. dataIndex: "pictureUrl",
  52. key: "pictureUrl",
  53. render: url => {
  54. let path = getPicPath(globalConfig.avatarUploadHost, url);
  55. return (
  56. <div style={{
  57. display: 'flex',
  58. alignItems: 'center',
  59. justifyContent: 'center',
  60. }}>
  61. <img src={path} style={{ width: "100px", height: 50 }} />
  62. <Button
  63. className="buttonimg"
  64. style={{ marginLeft: 10 }}
  65. onClick={e => {
  66. e.stopPropagation();
  67. this.setState({
  68. imgeditvisible: true,
  69. maximg: path,
  70. })
  71. }}
  72. >
  73. 查看大图
  74. </Button>
  75. </div>
  76. );
  77. }
  78. },
  79. {
  80. title: "是否发布",
  81. dataIndex: "releaseStatus",
  82. key: "releaseStatus",
  83. render: text => {
  84. return (
  85. <span>
  86. {text === 0 ? <Tag color="#f50">未发布</Tag> : text === 1 ? <Tag color="#87d068">已发布</Tag> : <Tag>未知</Tag>}
  87. </span>
  88. )
  89. }
  90. },
  91. {
  92. title: "排序",
  93. dataIndex: "sort",
  94. key: "sort"
  95. },
  96. {
  97. title: "操作",
  98. dataIndex: "id",
  99. key: "id",
  100. render: (text,record) => {
  101. return (
  102. <span>
  103. <Button
  104. type="primary"
  105. style={{ marginLeft: "10px" }}
  106. onClick={(e) => {
  107. e.stopPropagation();
  108. this.setState({
  109. activityId: text,
  110. visible:true,
  111. })
  112. }}
  113. >
  114. 编辑
  115. </Button>
  116. <Popconfirm
  117. title="您确定删除该新闻吗?"
  118. onConfirm={(e) => {e.stopPropagation();this.delete(text);}}
  119. okText="是"
  120. cancelText="否"
  121. >
  122. <Button
  123. type="danger"
  124. style={{ marginLeft: "10px" }}
  125. onClick={e => {
  126. e.stopPropagation();
  127. }}
  128. >
  129. 删除
  130. </Button>
  131. </Popconfirm>
  132. {(record.releaseStatus === 0 || record.releaseStatus === 1) && <Button
  133. type="primary"
  134. style={{ marginLeft: "10px" }}
  135. onClick={e => {
  136. e.stopPropagation();
  137. this.update(text,record.releaseStatus === 0 ? 1 : 0);
  138. }}
  139. >
  140. {record.releaseStatus === 0 ? '发布' : '隐藏'}
  141. </Button>}
  142. </span>
  143. )
  144. }
  145. },
  146. ],
  147. visible: false,
  148. }
  149. this.loadData = this.loadData.bind(this);
  150. this.reset = this.reset.bind(this);
  151. }
  152. imghandleCancel() {
  153. this.setState({
  154. imgeditvisible: false
  155. });
  156. }
  157. loadData(pageNo) {
  158. this.setState({
  159. loading: true,
  160. });
  161. //发送请求
  162. $.ajax({
  163. method: "get",
  164. dataType: "json",
  165. crossDomain: false,
  166. url: globalConfig.context + "/api/admin/activity/list",
  167. data: {
  168. pageNo: pageNo || 1,
  169. pageSize: this.state.pagination.pageSize,
  170. title: this.state.title || undefined,
  171. releaseStatus: this.state.releaseStatus || undefined,
  172. },
  173. success: function(data) {
  174. if (!data.data || !data.data.list) {
  175. if (data.error && data.error.length) {
  176. message.warning(data.error[0].message);
  177. }
  178. } else {
  179. this.state.pagination.current = data.data.pageNo;
  180. this.state.pagination.total = data.data.totalCount;
  181. this.setState({
  182. pageNo:data.data.pageNo,
  183. dataSource: data.data.list,
  184. pagination: this.state.pagination
  185. });
  186. }
  187. }.bind(this)
  188. }).always(
  189. function() {
  190. this.setState({
  191. loading: false
  192. });
  193. }.bind(this)
  194. );
  195. }
  196. reset(){
  197. this.setState({
  198. title: '',
  199. releaseStatus: '',
  200. pageNo: 1,
  201. },()=>{
  202. this.loadData();
  203. })
  204. }
  205. delete(id){
  206. this.setState({
  207. loading: true
  208. });
  209. $.ajax({
  210. method: "post",
  211. dataType: "json",
  212. crossDomain: false,
  213. url: globalConfig.context + "/api/admin/activity/delete",
  214. data: {
  215. id
  216. },
  217. success: function(data) {
  218. if (data.error && data.error.length) {
  219. message.warning(data.error[0].message);
  220. } else {
  221. message.success('删除成功')
  222. this.loadData(this.state.pageNo);
  223. }
  224. }.bind(this)
  225. }).always(
  226. function() {
  227. this.setState({
  228. loading: false
  229. });
  230. }.bind(this)
  231. );
  232. }
  233. update(id,releaseStatus){
  234. this.setState({
  235. loading: true
  236. });
  237. $.ajax({
  238. method: "post",
  239. dataType: "json",
  240. crossDomain: false,
  241. url: globalConfig.context + "/api/admin/activity/update",
  242. data: {
  243. id,
  244. releaseStatus
  245. },
  246. success: function(data) {
  247. if (data.error && data.error.length) {
  248. message.warning(data.error[0].message);
  249. } else {
  250. message.success('修改成功')
  251. this.loadData(this.state.pageNo);
  252. }
  253. }.bind(this)
  254. }).always(
  255. function() {
  256. this.setState({
  257. loading: false
  258. });
  259. }.bind(this)
  260. );
  261. }
  262. componentDidMount() {
  263. this.loadData();
  264. }
  265. render() {
  266. return (
  267. <div className="user-content">
  268. <div className="content-title">
  269. <span>活动列表</span>
  270. </div>
  271. <div className="user-search">
  272. <Input
  273. placeholder="请输入活动标题"
  274. style={{
  275. width: "150px",
  276. marginRight: "10px",
  277. marginBottom: "10px"
  278. }}
  279. value={this.state.title}
  280. onChange={e => {
  281. this.setState({ title: e.target.value });
  282. }}
  283. />
  284. <Select
  285. placeholder="选择发布状态"
  286. style={{ width: 150, marginRight: '10px' }}
  287. value={this.state.releaseStatus}
  288. onChange={(e) => {
  289. this.setState({ releaseStatus: e })
  290. }}
  291. >
  292. <Select.Option value={0}>未发布</Select.Option>
  293. <Select.Option value={1}>已发布</Select.Option>
  294. </Select>
  295. <Button
  296. type="primary"
  297. onClick={e => {
  298. this.loadData();
  299. }}
  300. style={{ marginRight: "10px" }}
  301. >
  302. 搜索
  303. </Button>
  304. <Button onClick={this.reset} style={{ marginRight: "10px" }}>
  305. 重置
  306. </Button>
  307. <Button
  308. type="primary"
  309. onClick={()=>{
  310. this.setState({
  311. visible: true
  312. })
  313. }}
  314. style={{ marginLeft: "100px" }}
  315. >
  316. 新增活动
  317. </Button>
  318. </div>
  319. {/* 新闻表单 */}
  320. <div className="patent-table">
  321. <SpinContainer spinning={this.state.loading}>
  322. <Table
  323. columns={this.state.columns}
  324. dataSource={this.state.dataSource}
  325. pagination={this.state.pagination}
  326. onRowClick={(value)=>{
  327. this.setState({
  328. activityId: value.id,
  329. visible:true,
  330. })
  331. }}
  332. bordered
  333. size="small"
  334. ellipsis="true"
  335. />
  336. </SpinContainer>
  337. </div>
  338. <Modal
  339. visible={this.state.imgeditvisible}
  340. onCancel={()=>{this.imghandleCancel()}}
  341. onOk={()=>{this.imghandleCancel()}}
  342. footer={false}
  343. >
  344. <img style={{ width: "100%" }} src={this.state.maximg} />
  345. </Modal>
  346. {this.state.visible && <ActivityOperation
  347. id={this.state.activityId}
  348. visible={this.state.visible}
  349. onCancel={()=>{
  350. this.loadData(this.state.pageNo);
  351. this.setState({
  352. activityId: '',
  353. visible:false,
  354. })
  355. }}
  356. />}
  357. </div>
  358. )
  359. }
  360. }
  361. export default Activity;