Cities.jsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. import React, { Component } from "react";
  2. import {
  3. Table,
  4. Modal,
  5. message,
  6. Spin,
  7. Input,
  8. Select,
  9. Button,
  10. Form,
  11. Upload,
  12. Popconfirm,
  13. AutoComplete,
  14. DatePicker,
  15. Col,
  16. Tabs,
  17. Tag,
  18. Radio,
  19. Group,
  20. InputNumber,
  21. } from "antd";
  22. import SpinContainer from "../../SpinContainer";
  23. import $ from "jquery/src/ajax";
  24. const { TextArea } = Input;
  25. const RadioGroup = Radio.Group;
  26. const Option = AutoComplete.Option;
  27. const confirm = Modal.confirm;
  28. class Cities extends Component {
  29. constructor(props) {
  30. super(props);
  31. this.state = {
  32. dataView: null,
  33. PublicView: null,
  34. contentView: "",
  35. remarksView: "",
  36. hid: 'none',
  37. contentViewLength: 0,
  38. contentViewLength1: 0,
  39. pagination: {
  40. defaultCurrent: 1,
  41. defaultPageSize: 10,
  42. showQuickJumper: true,
  43. pageSize: 10,
  44. onChange: function (page) {
  45. this.linkList(page);
  46. this.setState({
  47. selectedRowKeys: []
  48. });
  49. }.bind(this),
  50. showTotal: function (total) {
  51. return "共" + total + "条数据";
  52. }
  53. },
  54. columns: [
  55. {
  56. title: "序号",
  57. dataIndex: "id",
  58. key: "id",
  59. width: "80px",
  60. },
  61. {
  62. title: "排序",
  63. dataIndex: "sort",
  64. key: "sort",
  65. width: "80px",
  66. },
  67. {
  68. title: "链接地址",
  69. dataIndex: "url",
  70. key: "url",
  71. width: "100",
  72. },
  73. {
  74. title: "热门城市",
  75. dataIndex: "name",
  76. key: "name",
  77. width: "100",
  78. },
  79. // {
  80. // title: "互链",
  81. // dataIndex: "mutualChain",
  82. // key: "mutualChain",
  83. // width: "100",
  84. // render: (text, record) => {
  85. // return (
  86. // <div>
  87. // {
  88. // text == 0 ? '否': '是'
  89. // }
  90. // </div>
  91. // );
  92. // },
  93. // },
  94. {
  95. title: "备注",
  96. dataIndex: "remarks",
  97. key: "remarks",
  98. width: "100",
  99. },
  100. {
  101. title: "状态",
  102. dataIndex: "status",
  103. key: "status",
  104. width: "100",
  105. render: (text, record) => {
  106. return (
  107. <div>
  108. {
  109. text == 0 ? '正常' : '冻结'
  110. }
  111. </div>
  112. );
  113. },
  114. },
  115. {
  116. title: "操作",
  117. dataIndex: "cz",
  118. key: "cz",
  119. width: "100px",
  120. render: (text, record) => {
  121. return (
  122. <div>
  123. <Popconfirm
  124. title={record.status == 0 ? "确认冻结?" : "确认恢复?"}
  125. onConfirm={() => this.linksUpdate(record)}
  126. okText="确定"
  127. cancelText="取消"
  128. >
  129. <Button
  130. style={{ background: record.status ? '#009966' : '' }}
  131. type={record.status == 0 ? 'primary' : 'primary'}
  132. onClick={(e) => {
  133. e.stopPropagation();
  134. // this.setState({
  135. // addFlag: false,
  136. // });
  137. }}
  138. >
  139. {record.status == 0 ? "冻结" : "恢复"}
  140. </Button>
  141. </Popconfirm>
  142. </div>
  143. );
  144. },
  145. },
  146. ],
  147. dataSourceView: [],
  148. coorVisible: "none",
  149. list: [],
  150. visible: false,
  151. viewKey: 0,
  152. modalView: false,
  153. modalRecord: false,
  154. closable: false,
  155. disabledView: "none",
  156. loading: false,
  157. };
  158. this.formRef = {};
  159. this.submitOrder = this.submitOrder.bind(this);
  160. this.linkList = this.linkList.bind(this);
  161. this.linksUpdate = this.linksUpdate.bind(this)
  162. this.reset = this.reset.bind(this)
  163. this.tableRowClick = this.tableRowClick.bind(this)
  164. this.cleanAllpopularCities = this.cleanAllpopularCities.bind(this)
  165. }
  166. componentDidMount() {
  167. this.linkList(1)
  168. }
  169. cleanAllpopularCities() {
  170. $.ajax({
  171. method: "get",
  172. dataType: "json",
  173. crossDomain: false,
  174. url: globalConfig.context + "/api/admin/popularCities/cleanAllpopularCities",
  175. success: function (data) {
  176. if (data.error.length) {
  177. this.setState({
  178. loading: false,
  179. });
  180. message.warning(data.error[0].message);
  181. } else {
  182. message.success("清除成功");
  183. }
  184. }.bind(this),
  185. }).always(
  186. function () {
  187. this.setState({
  188. loading: false,
  189. });
  190. }.bind(this)
  191. );
  192. }
  193. // 修改链接状态
  194. linksUpdate(record) {
  195. if (!this.state.sort && !record.sort) {
  196. message.warning("请填写排序");
  197. return;
  198. } else if (!this.state.name && !record.name) {
  199. message.warning("请输入城市名");
  200. return;
  201. }
  202. this.setState({
  203. loading: true,
  204. });
  205. $.ajax({
  206. method: "post",
  207. dataType: "json",
  208. crossDomain: false,
  209. url: globalConfig.context + "/api/admin/popularCities/update",
  210. data: {
  211. sort: record.sort || this.state.sort,
  212. status: record.status == 0 ? '1' : '0' || this.state.status,
  213. // mutualChain: record.mutualChain || this.state.mutualChain,
  214. name: record.name || this.state.name,
  215. url: record.url || this.state.url,
  216. remarks: record.remarks || this.state.remarks,
  217. id: record.id || this.state.id,
  218. },
  219. success: function (data) {
  220. this.setState({
  221. loading: false,
  222. });
  223. if (data.error.length) {
  224. this.setState({
  225. loading: false,
  226. });
  227. message.warning(data.error[0].message);
  228. } else {
  229. this.setState({
  230. visible: false,
  231. hid: 'none'
  232. })
  233. this.linkList(1)
  234. message.success("修改成功");
  235. }
  236. }.bind(this),
  237. }).always(
  238. function () {
  239. this.setState({
  240. loading: false,
  241. });
  242. }.bind(this)
  243. );
  244. }
  245. reset() {
  246. this.setState({
  247. sortType1: undefined,
  248. name1: undefined,
  249. mutualChain1: undefined,
  250. status1: undefined
  251. }, () => {
  252. this.linkList();
  253. });
  254. }
  255. // 新增友情链接
  256. submitOrder() {
  257. if (!this.state.sort) {
  258. message.warning("请填写排序");
  259. return;
  260. } else if (!this.state.name) {
  261. message.warning("请输入城市名");
  262. return;
  263. }
  264. this.setState({
  265. loading: true,
  266. });
  267. $.ajax({
  268. method: "post",
  269. dataType: "json",
  270. crossDomain: false,
  271. url: globalConfig.context + "/api/admin/popularCities/add",
  272. data: {
  273. sort: this.state.sort,
  274. status: 0,
  275. // mutualChain:this.state.mutualChain,
  276. name: this.state.name,
  277. url: this.state.url,
  278. remarks: this.state.remarks
  279. },
  280. success: function (data) {
  281. if (data.error.length) {
  282. this.setState({
  283. loading: false,
  284. });
  285. message.warning(data.error[0].message);
  286. } else {
  287. this.setState({
  288. loading: false,
  289. visible: false,
  290. viewKey: this.state.viewKey + 1,
  291. sort: "",
  292. // mutualChain: "",
  293. name: '',
  294. url: '',
  295. remarks: ''
  296. });
  297. this.linkList(1)
  298. // this.assistList();
  299. message.success("添加成功");
  300. }
  301. }.bind(this),
  302. }).always(
  303. function () {
  304. this.setState({
  305. loading: false,
  306. });
  307. }.bind(this)
  308. );
  309. }
  310. linkList(page) {
  311. $.ajax({
  312. method: "get",
  313. dataType: "json",
  314. crossDomain: false,
  315. url: globalConfig.context + "/api/admin/popularCities/list",
  316. data: {
  317. sortType: this.state.sortType1 || undefined,
  318. name: this.state.name1 || undefined,
  319. // mutualChain:this.state.mutualChain || undefined,
  320. status: this.state.status1 || undefined,
  321. pageNo: page || 1,
  322. pageSize: 10
  323. },
  324. success: function (data) {
  325. if (data.error.length) {
  326. this.setState({
  327. loading: false,
  328. });
  329. message.warning(data.error[0].message);
  330. } else {
  331. this.setState({
  332. list: data.data.list,
  333. pagination: this.state.pagination
  334. });
  335. this.state.pagination.total = data.data.totalCount;
  336. this.state.pagination.current = data.data.pageNo;
  337. }
  338. if (data.data && data.data.list && !data.data.list.length) {
  339. this.state.pagination.total = 0;
  340. }
  341. }.bind(this),
  342. }).always(
  343. function () {
  344. this.setState({
  345. loading: false,
  346. });
  347. }.bind(this)
  348. );
  349. }
  350. // 双击表格弹出修改
  351. tableRowClick(record) {
  352. this.setState({
  353. visible: true,
  354. sort: record.sort,
  355. status: record.status,
  356. // mutualChain: record.mutualChain,
  357. name: record.name,
  358. url: record.url,
  359. remarks: record.remarks,
  360. id: record.id,
  361. hid: 'block'
  362. })
  363. }
  364. render() {
  365. const formItemLayout = {
  366. labelCol: { span: 8 },
  367. wrapperCol: { span: 14 },
  368. };
  369. return (
  370. <div>
  371. <div className="user-content">
  372. <div className="content-title">
  373. <span>热门城市</span>
  374. </div>
  375. <div className="user-search">
  376. <Select
  377. placeholder="排序从高到低"
  378. style={{ width: 150 }}
  379. value={
  380. this.state.sortType1
  381. }
  382. onChange={(e) => {
  383. this.setState({
  384. sortType1: e,
  385. });
  386. }}
  387. >
  388. <Option value="0">排序从高到低</Option>
  389. <Option value="1">排序从低到高</Option>
  390. </Select>
  391. {/* 显示名称关键字 */}
  392. <Input
  393. style={{ bottom: '6px' }}
  394. placeholder="请输入显示名称关键字"
  395. value={this.state.name1}
  396. onChange={(e) => {
  397. this.setState({ name1: e.target.value });
  398. }}
  399. />
  400. {/* 互链 */}
  401. {/* <Select
  402. placeholder="互链"
  403. style={{ width: 150 }}
  404. value={
  405. this.state.mutualChain
  406. }
  407. onChange={(e) => {
  408. this.setState({
  409. mutualChain: e,
  410. });
  411. }}
  412. >
  413. <Option value="1">是,以互链</Option>
  414. <Option value="0">否,没互链</Option>
  415. </Select> */}
  416. {/* */}
  417. <Select
  418. placeholder="状态"
  419. style={{ width: 150 }}
  420. value={
  421. this.state.status1
  422. }
  423. onChange={(e) => {
  424. this.setState({
  425. status1: e,
  426. });
  427. }}
  428. >
  429. <Option value="0">正常</Option>
  430. <Option value="1">冻结</Option>
  431. </Select>
  432. <Button
  433. type="primary"
  434. onClick={() => this.linkList(1)}
  435. style={{ marginLeft: "10px" }}
  436. >
  437. 搜索
  438. </Button>
  439. <Button onClick={this.reset}>重置</Button>
  440. <Button
  441. type="primary"
  442. onClick={() => {
  443. this.setState({
  444. visible: true,
  445. sort: "",
  446. mutualChain: "",
  447. name: '',
  448. url: '',
  449. remarks: ''
  450. });
  451. }}
  452. style={{ marginLeft: "100px" }}
  453. >
  454. 新增链接
  455. </Button>
  456. <Button
  457. type="primary"
  458. onClick={() => this.cleanAllpopularCities()}
  459. style={{ float: "right" }}
  460. >
  461. 清除热门城市缓存
  462. </Button>
  463. </div>
  464. <div className="patent-table">
  465. <SpinContainer spinning={this.state.loading}>
  466. <Table
  467. columns={this.state.columns}
  468. dataSource={this.state.list}
  469. pagination={this.state.pagination}
  470. onRowClick={this.tableRowClick}
  471. />
  472. </SpinContainer>
  473. </div>
  474. <Modal
  475. width={'600px'}
  476. visible={this.state.visible}
  477. key={this.state.viewKey}
  478. title="新增/编辑热门"
  479. onCancel={() => {
  480. this.setState({
  481. visible: false,
  482. viewKey: this.state.viewKey + 1
  483. });
  484. }}
  485. onOk={() => { }}
  486. footer={false}
  487. >
  488. <Form
  489. onSubmit={this.handleSubmit}
  490. ref={this.formRef}
  491. style={{ marginRight: "120px" }}
  492. >
  493. <Form.Item
  494. {...formItemLayout}
  495. label="排序"
  496. name="sort"
  497. hasFeedback
  498. >
  499. <InputNumber
  500. value={this.state.sort}
  501. min={1}
  502. onChange={(e) => {
  503. if (isNaN(e)) {
  504. message.info("请输入数字")
  505. }
  506. this.setState({ sort: e });
  507. }}
  508. />
  509. <span style={{ color: "red" }}>数字越大排序越前</span>
  510. </Form.Item>
  511. <Form.Item
  512. {...formItemLayout}
  513. label="链接"
  514. name="url"
  515. hasFeedback
  516. >
  517. <Input
  518. style={{ width: '140px' }}
  519. value={this.state.url}
  520. placeholder="请输入http://地址"
  521. onChange={(e) => {
  522. this.setState({ url: e.target.value });
  523. }}
  524. />
  525. <span style={{ color: "red", marginLeft: '10px' }}>请输入http://地址</span>
  526. </Form.Item>
  527. <Form.Item
  528. {...formItemLayout}
  529. label="热门城市"
  530. name="name"
  531. hasFeedback
  532. >
  533. <Input
  534. value={this.state.name}
  535. placeholder="请输入显示在页面的热门城市"
  536. onChange={(e) => {
  537. this.setState({ name: e.target.value });
  538. }}
  539. />
  540. </Form.Item>
  541. {/* <Form.Item
  542. {...formItemLayout}
  543. label="是否互链"
  544. name="mutualChain"
  545. hasFeedback
  546. >
  547. <RadioGroup onChange={(e) => {this.setState({
  548. mutualChain:e.target.value
  549. })}} value={this.state.mutualChain}>
  550. <Radio value={0}>是</Radio>
  551. <Radio value={1}>否</Radio>
  552. </RadioGroup>
  553. </Form.Item> */}
  554. <Form.Item
  555. {...formItemLayout}
  556. label="备注"
  557. name="remarks"
  558. hasFeedback
  559. >
  560. <TextArea
  561. value={this.state.remarks}
  562. maxLength={500}
  563. placeholder="请输入备注..."
  564. rows={4}
  565. onChange={(e) => {
  566. this.setState({
  567. remarks: e.target.value,
  568. })
  569. }}
  570. />
  571. </Form.Item>
  572. </Form>
  573. <div
  574. style={{
  575. display: "flex",
  576. justifyContent: "center",
  577. }}
  578. >
  579. <Button
  580. style={{ display: this.state.hid == 'none' ? 'block' : 'none' }}
  581. onClick={this.submitOrder}
  582. type="primary"
  583. loading={this.state.loading}
  584. >
  585. 保存并发布
  586. </Button>
  587. <Button
  588. style={{ display: this.state.hid }}
  589. onClick={this.linksUpdate}
  590. type="primary"
  591. loading={this.state.loading}
  592. >
  593. 完成修改
  594. </Button>
  595. <Button
  596. type="dashed"
  597. style={{ marginLeft: "15px" }}
  598. onClick={() => {
  599. this.setState({
  600. visible: false,
  601. viewKey: this.state.viewKey + 1,
  602. sort: "",
  603. // mutualChain: "",
  604. name: '',
  605. url: '',
  606. remarks: ''
  607. });
  608. }}
  609. >
  610. 取消
  611. </Button>
  612. </div>
  613. </Modal>
  614. </div>
  615. </div>
  616. );
  617. }
  618. }
  619. export default Cities;