Cities.jsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  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. $.ajax({
  203. method: "post",
  204. dataType: "json",
  205. crossDomain: false,
  206. url: globalConfig.context + "/api/admin/popularCities/update",
  207. data: {
  208. sort: record.sort || this.state.sort,
  209. status: record.status == 0 ? '1' :'0' || this.state.status,
  210. // mutualChain: record.mutualChain || this.state.mutualChain,
  211. name: record.name || this.state.name,
  212. url: record.url || this.state.url,
  213. remarks: record.remarks || this.state.remarks,
  214. id: record.id || this.state.id,
  215. },
  216. success: function (data) {
  217. if (data.error.length) {
  218. this.setState({
  219. loading: false,
  220. });
  221. message.warning(data.error[0].message);
  222. } else {
  223. this.setState({
  224. visible:false,
  225. hid:'none'
  226. })
  227. this.linkList(1)
  228. message.success("修改成功");
  229. }
  230. }.bind(this),
  231. }).always(
  232. function () {
  233. this.setState({
  234. loading: false,
  235. });
  236. }.bind(this)
  237. );
  238. }
  239. reset() {
  240. this.setState({
  241. sortType1:undefined,
  242. name1:undefined,
  243. mutualChain1:undefined,
  244. status1:undefined
  245. },()=>{
  246. this.linkList();
  247. });
  248. }
  249. // 新增友情链接
  250. submitOrder() {
  251. if (!this.state.sort) {
  252. message.warning("请填写排序");
  253. return;
  254. } else if(!this.state.name) {
  255. message.warning("请输入城市名");
  256. return;
  257. }
  258. this.setState({
  259. loading: true,
  260. });
  261. $.ajax({
  262. method: "post",
  263. dataType: "json",
  264. crossDomain: false,
  265. url: globalConfig.context + "/api/admin/popularCities/add",
  266. data: {
  267. sort: this.state.sort,
  268. status: 0,
  269. // mutualChain:this.state.mutualChain,
  270. name:this.state.name,
  271. url:this.state.url,
  272. remarks:this.state.remarks
  273. },
  274. success: function (data) {
  275. if (data.error.length) {
  276. this.setState({
  277. loading: false,
  278. });
  279. message.warning(data.error[0].message);
  280. } else {
  281. this.setState({
  282. loading: false,
  283. visible:false,
  284. viewKey: this.state.viewKey + 1,
  285. sort: "",
  286. // mutualChain: "",
  287. name: '',
  288. url: '',
  289. remarks:''
  290. });
  291. this.linkList(1)
  292. // this.assistList();
  293. message.success("添加成功");
  294. }
  295. }.bind(this),
  296. }).always(
  297. function () {
  298. this.setState({
  299. loading: false,
  300. });
  301. }.bind(this)
  302. );
  303. }
  304. linkList(page){
  305. $.ajax({
  306. method: "get",
  307. dataType: "json",
  308. crossDomain: false,
  309. url: globalConfig.context + "/api/admin/popularCities/list",
  310. data: {
  311. sortType:this.state.sortType1 || undefined,
  312. name: this.state.name1 || undefined,
  313. // mutualChain:this.state.mutualChain || undefined,
  314. status:this.state.status1 || undefined,
  315. pageNo:page || 1,
  316. pageSize:10
  317. },
  318. success: function (data) {
  319. if (data.error.length) {
  320. this.setState({
  321. loading: false,
  322. });
  323. message.warning(data.error[0].message);
  324. } else {
  325. this.setState({
  326. list: data.data.list,
  327. pagination: this.state.pagination
  328. });
  329. this.state.pagination.total = data.data.totalCount;
  330. this.state.pagination.current = data.data.pageNo;
  331. }
  332. if (data.data && data.data.list && !data.data.list.length) {
  333. this.state.pagination.total = 0;
  334. }
  335. }.bind(this),
  336. }).always(
  337. function () {
  338. this.setState({
  339. loading: false,
  340. });
  341. }.bind(this)
  342. );
  343. }
  344. // 双击表格弹出修改
  345. tableRowClick(record) {
  346. this.setState({
  347. visible:true,
  348. sort: record.sort,
  349. status: record.status,
  350. // mutualChain: record.mutualChain,
  351. name: record.name,
  352. url: record.url,
  353. remarks: record.remarks,
  354. id:record.id,
  355. hid:'block'
  356. })
  357. }
  358. render() {
  359. const formItemLayout = {
  360. labelCol: { span: 8 },
  361. wrapperCol: { span: 14 },
  362. };
  363. return (
  364. <div>
  365. <div className="user-content">
  366. <div className="content-title">
  367. <span>热门城市</span>
  368. </div>
  369. <div className="user-search">
  370. <Select
  371. placeholder="排序从高到低"
  372. style={{ width: 150 }}
  373. value={
  374. this.state.sortType1
  375. }
  376. onChange={(e) => {
  377. this.setState({
  378. sortType1: e,
  379. });
  380. }}
  381. >
  382. <Option value="0">排序从高到低</Option>
  383. <Option value="1">排序从低到高</Option>
  384. </Select>
  385. {/* 显示名称关键字 */}
  386. <Input
  387. style={{bottom:'6px'}}
  388. placeholder="请输入显示名称关键字"
  389. value={this.state.name1}
  390. onChange={(e) => {
  391. this.setState({ name1: e.target.value });
  392. }}
  393. />
  394. {/* 互链 */}
  395. {/* <Select
  396. placeholder="互链"
  397. style={{ width: 150 }}
  398. value={
  399. this.state.mutualChain
  400. }
  401. onChange={(e) => {
  402. this.setState({
  403. mutualChain: e,
  404. });
  405. }}
  406. >
  407. <Option value="1">是,以互链</Option>
  408. <Option value="0">否,没互链</Option>
  409. </Select> */}
  410. {/* */}
  411. <Select
  412. placeholder="状态"
  413. style={{ width: 150 }}
  414. value={
  415. this.state.status1
  416. }
  417. onChange={(e) => {
  418. this.setState({
  419. status1: e,
  420. });
  421. }}
  422. >
  423. <Option value="0">正常</Option>
  424. <Option value="1">冻结</Option>
  425. </Select>
  426. <Button
  427. type="primary"
  428. onClick={()=>this.linkList(1)}
  429. style={{ marginLeft: "10px" }}
  430. >
  431. 搜索
  432. </Button>
  433. <Button onClick={this.reset}>重置</Button>
  434. <Button
  435. type="primary"
  436. onClick={() => {
  437. this.setState({
  438. visible: true ,
  439. sort: "",
  440. mutualChain: "",
  441. name: '',
  442. url: '',
  443. remarks:''
  444. });
  445. }}
  446. style={{ marginLeft: "100px" }}
  447. >
  448. 新增链接
  449. </Button>
  450. <Button
  451. type="primary"
  452. onClick={() => this.cleanAllpopularCities()}
  453. style={{ float: "right" }}
  454. >
  455. 清除热门城市缓存
  456. </Button>
  457. </div>
  458. <div className="patent-table">
  459. <SpinContainer spinning={this.state.loading}>
  460. <Table
  461. columns={this.state.columns}
  462. dataSource={this.state.list}
  463. pagination={this.state.pagination}
  464. onRowClick={this.tableRowClick}
  465. />
  466. </SpinContainer>
  467. </div>
  468. <Modal
  469. width={'600px'}
  470. visible={this.state.visible}
  471. key={this.state.viewKey}
  472. title="新增/编辑热门"
  473. onCancel={() => {
  474. this.setState({
  475. visible: false,
  476. viewKey:this.state.viewKey+1
  477. });
  478. }}
  479. onOk={() => {}}
  480. footer={false}
  481. >
  482. <Form
  483. onSubmit={this.handleSubmit}
  484. ref={this.formRef}
  485. style={{ marginRight: "120px" }}
  486. >
  487. <Form.Item
  488. {...formItemLayout}
  489. label="排序"
  490. name="sort"
  491. hasFeedback
  492. >
  493. <InputNumber
  494. value={this.state.sort}
  495. min={1}
  496. onChange={(e) => {
  497. if(isNaN(e)) {
  498. message.info("请输入数字")
  499. }
  500. this.setState({ sort: e });
  501. }}
  502. />
  503. <span style={{ color: "red" }}>数字越大排序越前</span>
  504. </Form.Item>
  505. <Form.Item
  506. {...formItemLayout}
  507. label="链接"
  508. name="url"
  509. hasFeedback
  510. >
  511. <Input
  512. style={{width:'140px'}}
  513. value={this.state.url}
  514. placeholder="请输入http://地址"
  515. onChange={(e) => {
  516. this.setState({ url: e.target.value });
  517. }}
  518. />
  519. <span style={{ color: "red",marginLeft:'10px' }}>请输入http://地址</span>
  520. </Form.Item>
  521. <Form.Item
  522. {...formItemLayout}
  523. label="热门城市"
  524. name="name"
  525. hasFeedback
  526. >
  527. <Input
  528. value={this.state.name}
  529. placeholder="请输入显示在页面的热门城市"
  530. onChange={(e) => {
  531. this.setState({ name: e.target.value });
  532. }}
  533. />
  534. </Form.Item>
  535. {/* <Form.Item
  536. {...formItemLayout}
  537. label="是否互链"
  538. name="mutualChain"
  539. hasFeedback
  540. >
  541. <RadioGroup onChange={(e) => {this.setState({
  542. mutualChain:e.target.value
  543. })}} value={this.state.mutualChain}>
  544. <Radio value={0}>是</Radio>
  545. <Radio value={1}>否</Radio>
  546. </RadioGroup>
  547. </Form.Item> */}
  548. <Form.Item
  549. {...formItemLayout}
  550. label="备注"
  551. name="remarks"
  552. hasFeedback
  553. >
  554. <TextArea
  555. value={this.state.remarks}
  556. maxLength={500}
  557. placeholder="请输入备注..."
  558. rows={4}
  559. onChange={(e) => {
  560. this.setState({
  561. remarks: e.target.value,
  562. })
  563. }}
  564. />
  565. </Form.Item>
  566. </Form>
  567. <div
  568. style={{
  569. display: "flex",
  570. justifyContent: "center",
  571. }}
  572. >
  573. <Button
  574. style={{display:this.state.hid == 'none' ? 'block' :'none'}}
  575. onClick={this.submitOrder}
  576. type="primary"
  577. loading={this.state.loading}
  578. >
  579. 保存并发布
  580. </Button>
  581. <Button
  582. style={{display:this.state.hid}}
  583. onClick={this.linksUpdate}
  584. type="primary"
  585. loading={this.state.loading}
  586. >
  587. 完成修改
  588. </Button>
  589. <Button
  590. type="dashed"
  591. style={{ marginLeft: "15px" }}
  592. onClick={() => {
  593. this.setState({
  594. visible: false,
  595. viewKey: this.state.viewKey + 1,
  596. sort: "",
  597. // mutualChain: "",
  598. name: '',
  599. url: '',
  600. remarks:''
  601. });
  602. }}
  603. >
  604. 取消
  605. </Button>
  606. </div>
  607. </Modal>
  608. </div>
  609. </div>
  610. );
  611. }
  612. }
  613. export default Cities;