index.jsx 15 KB

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