index.jsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. import React from 'react';
  2. import $ from 'jquery/src/ajax';
  3. import {
  4. Form, Button, Input, Select, InputNumber, Spin, Table,
  5. message, DatePicker, Modal, Tabs
  6. } from 'antd';
  7. import moment from 'moment';
  8. import { ShowModal, } from '../../../tools.js';
  9. import { ChooseList } from "../../order/orderNew/chooseList";
  10. import "./index.less";
  11. const { TabPane } = Tabs
  12. const FormItem = Form.Item;
  13. const Standard = Form.create()(React.createClass({
  14. getInitialState() {
  15. return {
  16. searchValues: {},
  17. loading: false,
  18. changeList: undefined, // 更改后的表格显示数据
  19. dataSource: [],
  20. pagination: {
  21. defaultCurrent: 1,
  22. defaultPageSize: 10,
  23. showQuickJumper: true,
  24. pageSize: 20,
  25. onChange: function (page) {
  26. this.loadData(page);
  27. }.bind(this),
  28. showTotal: function (total) {
  29. return '共' + total + '条数据';
  30. }
  31. },
  32. columns: [
  33. {
  34. title: '链接',
  35. dataIndex: 'url',
  36. key: 'url',
  37. width: 360,
  38. render: text =>
  39. <a href={text} target="_blank">{text}</a>
  40. // <div onClick={e => {
  41. // window.open(text)
  42. // }}>
  43. // {text}
  44. // </div>
  45. },
  46. {
  47. title: '标准平台',
  48. dataIndex: 'name',
  49. key: 'name',
  50. },
  51. {
  52. title: '排序',
  53. dataIndex: 'sort',
  54. key: 'sort',
  55. },
  56. {
  57. title: '状态',
  58. dataIndex: 'status',
  59. key: 'status',
  60. render: text => <span style={{ color: ["red", "green"][text] }}>{["关闭", "开启"][text]}</span>
  61. },
  62. {
  63. title: '更新时间',
  64. dataIndex: 'updateTime',
  65. key: 'updateTime',
  66. },
  67. ],
  68. visible: "",
  69. data: {},
  70. };
  71. },
  72. componentWillMount() {
  73. this.loadData();
  74. },
  75. // 列表接口
  76. loadData(pageNo) {
  77. const { searchValues, pagination } = this.state;
  78. this.setState({
  79. loading: true,
  80. });
  81. let datas = Object.assign(searchValues, {
  82. pageNo: pageNo || 1,
  83. pageSize: pagination.pageSize,
  84. });
  85. $.ajax({
  86. method: "get",
  87. dataType: "json",
  88. crossDomain: false,
  89. url: globalConfig.context + "/api/admin/standardPlatformLink/list",
  90. data: datas,
  91. success: function (data) {
  92. ShowModal(this);
  93. this.setState({
  94. loading: false,
  95. });
  96. if (data.error && data.error.length === 0) {
  97. if (data.data.list) {
  98. pagination.current = data.data.pageNo;
  99. pagination.total = data.data.totalCount;
  100. if (data.data && data.data.list && !data.data.list.length) {
  101. pagination.current = 0;
  102. pagination.total = 0;
  103. }
  104. this.setState({
  105. dataSource: data.data.list,
  106. pagination: this.state.pagination,
  107. pageNo: data.data.pageNo,
  108. });
  109. } else {
  110. this.setState({
  111. dataSource: data.data,
  112. pagination: false,
  113. });
  114. }
  115. } else {
  116. message.warning(data.error[0].message);
  117. }
  118. }.bind(this),
  119. }).always(
  120. function () {
  121. this.setState({
  122. loading: false,
  123. });
  124. }.bind(this)
  125. );
  126. },
  127. // 搜索
  128. search() {
  129. this.loadData();
  130. },
  131. // 重置
  132. reset() {
  133. this.setState({
  134. searchValues: {}
  135. }, () => {
  136. this.loadData();
  137. })
  138. },
  139. changeList(arr) {
  140. const newArr = [];
  141. this.state.columns.forEach(item => {
  142. arr.forEach(val => {
  143. if (val === item.title) {
  144. newArr.push(item);
  145. }
  146. });
  147. });
  148. this.setState({
  149. changeList: newArr
  150. });
  151. },
  152. addClick() {
  153. this.setState({
  154. visible: "add"
  155. })
  156. },
  157. tableRowClick(e) {
  158. if (!adminData.isSuperAdmin) {
  159. return
  160. }
  161. this.setState({
  162. visible: "edit",
  163. })
  164. this.getDetails(e.id)
  165. },
  166. // 数据详情
  167. getDetails(id) {
  168. this.setState({
  169. loading: true
  170. });
  171. $.ajax({
  172. method: "get",
  173. dataType: "json",
  174. crossDomain: false,
  175. url: globalConfig.context + "/api/admin/standardPlatformLink/get",
  176. data: {
  177. id,
  178. },
  179. success: function (data) {
  180. let thedata = data.data || {};
  181. if (!thedata) {
  182. if (data.error && data.error.length) {
  183. message.warning(data.error[0].message);
  184. };
  185. }
  186. this.setState({
  187. data: thedata,
  188. })
  189. }.bind(this),
  190. }).always(function () {
  191. this.setState({
  192. loading: false
  193. });
  194. }.bind(this));
  195. },
  196. handleCancel() {
  197. this.setState({
  198. visible: "",
  199. data: {},
  200. })
  201. },
  202. // 提交保存
  203. handleSubmit() {
  204. const { data } = this.state
  205. if (!data.name) {
  206. message.warning('标准平台名称不能为空!');
  207. return;
  208. }
  209. if (!data.url) {
  210. message.warning('链接不能为空!');
  211. return;
  212. }
  213. if (!data.sort && data.sort != 0) {
  214. message.warning('排序不能为空!');
  215. return;
  216. }
  217. if (!data.status && data.status != 0) {
  218. message.warning('请选择状态!');
  219. return;
  220. }
  221. if (data.id) {
  222. delete data.createTime;
  223. delete data.updateTime;
  224. delete data.aid;
  225. }
  226. $.ajax({
  227. method: "POST",
  228. dataType: "json",
  229. crossDomain: false,
  230. url:
  231. data.id
  232. ? globalConfig.context + '/api/admin/standardPlatformLink/update'
  233. : globalConfig.context + '/api/admin/standardPlatformLink/add',
  234. data,
  235. }).done(function (data) {
  236. this.setState({
  237. loading: false
  238. });
  239. if (!data.error.length) {
  240. message.success('保存成功!');
  241. this.handleCancel();
  242. this.loadData(this.state.pageNo);
  243. } else {
  244. message.warning(data.error[0].message);
  245. }
  246. }.bind(this));
  247. },
  248. render() {
  249. const { RangePicker } = DatePicker;
  250. const { searchValues, data } = this.state
  251. const formItemLayout = {
  252. labelCol: { span: 8 },
  253. wrapperCol: { span: 16 },
  254. };
  255. return (
  256. <div className="user-content">
  257. <div className="content-title">
  258. <Tabs defaultActiveKey="1" className="test">
  259. <TabPane tab="搜索" key="1">
  260. <div className="user-search" style={{ marginLeft: 10 }}>
  261. <Input
  262. placeholder="请输入标准平台"
  263. value={searchValues["name"]
  264. ? searchValues["name"]
  265. : ""}
  266. onChange={(e) => {
  267. searchValues["name"] = e.target.value;
  268. this.setState({
  269. searchValues: searchValues,
  270. });
  271. }}
  272. />
  273. <Select
  274. placeholder="状态"
  275. style={{ width: 140 }}
  276. value={searchValues["status"]}
  277. onChange={(e) => {
  278. searchValues["status"] = e;
  279. this.setState({
  280. searchValues: searchValues,
  281. });
  282. }}
  283. >
  284. <Select.Option value={null}>全部</Select.Option>
  285. <Select.Option value={0}>关闭</Select.Option>
  286. <Select.Option value={1}>开启</Select.Option>
  287. </Select>
  288. <span>时间:</span>
  289. <RangePicker
  290. style={{ width: 300 }}
  291. value={[
  292. searchValues.startTime ? moment(searchValues.startTime) : null,
  293. searchValues.endTime ? moment(searchValues.endTime) : null,
  294. ]}
  295. onChange={(data, dataString) => {
  296. this.setState({
  297. searchValues: Object.assign(searchValues, {
  298. startTime: dataString[0],
  299. endTime: dataString[1],
  300. }),
  301. });
  302. }}
  303. />
  304. <Button
  305. type="primary"
  306. onClick={this.search}
  307. style={{ margin: "0 10px" }}
  308. >搜索</Button>
  309. <Button onClick={this.reset}>重置</Button>
  310. </div>
  311. </TabPane>
  312. <TabPane tab="更改表格显示数据" key="2">
  313. <div style={{ marginLeft: 10 }}>
  314. <ChooseList
  315. columns={this.state.columns}
  316. changeFn={this.changeList}
  317. changeList={this.state.changeList}
  318. top={55}
  319. margin={11}
  320. />
  321. </div>
  322. </TabPane>
  323. {adminData.isSuperAdmin ?
  324. <TabPane tab="新增" key="3">
  325. <Button
  326. type="primary"
  327. className="addButton"
  328. style={{ float: "left", marginBottom: 10, marginTop: 12 }}
  329. onClick={this.addClick}
  330. >
  331. 新增
  332. </Button>
  333. </TabPane> : ""}
  334. </Tabs>
  335. <div className="patent-table">
  336. <Spin spinning={this.state.loading}>
  337. <Table
  338. bordered
  339. columns={
  340. this.state.changeList
  341. ? this.state.changeList
  342. : this.state.columns
  343. }
  344. style={{
  345. cursor: 'pointer',
  346. }}
  347. dataSource={this.state.dataSource}
  348. pagination={this.state.pagination}
  349. onRowDoubleClick={this.tableRowClick}
  350. />
  351. </Spin>
  352. </div>
  353. </div>
  354. {
  355. this.state.visible != "" &&
  356. <Modal
  357. title={!!data.id ? "编辑标准平台链接" : "新增标准平台链接"}
  358. visible={this.state.visible != ""}
  359. width="600px"
  360. onCancel={this.handleCancel}
  361. maskClosable={false}
  362. footer=""
  363. className="admin-desc-content"
  364. >
  365. <Form
  366. layout="horizontal"
  367. // onSubmit={this.handleSubmit}
  368. id="demand-form"
  369. >
  370. <Spin spinning={this.state.loading}>
  371. <div className="clearfix">
  372. <FormItem
  373. className="half-middle"
  374. {...formItemLayout}
  375. label="标准平台链接"
  376. >
  377. <Input
  378. placeholder="请输入标准平台链接"
  379. value={data["url"]
  380. ? data["url"]
  381. : ""}
  382. style={{ width: "230px" }}
  383. onChange={(e) => {
  384. data["url"] = e.target.value;
  385. this.setState({
  386. data: data
  387. });
  388. }}
  389. />
  390. <span className="mandatory">*</span>
  391. </FormItem>
  392. <FormItem
  393. className="half-middle"
  394. {...formItemLayout}
  395. label="标准平台名称"
  396. >
  397. <Input
  398. placeholder="请输入标准平台名称"
  399. value={data["name"]
  400. ? data["name"]
  401. : ""}
  402. style={{ width: "230px" }}
  403. onChange={(e) => {
  404. data["name"] = e.target.value;
  405. this.setState({
  406. data: data
  407. });
  408. }}
  409. />
  410. <span className="mandatory">*</span>
  411. </FormItem>
  412. <FormItem
  413. className="half-middle"
  414. {...formItemLayout}
  415. label="排序"
  416. >
  417. <InputNumber
  418. min={0}
  419. max={999999}
  420. step={1}
  421. value={data["sort"]
  422. ? data["sort"]
  423. : ""}
  424. style={{ width: "130px" }}
  425. onChange={(e) => {
  426. data["sort"] = e;
  427. this.setState({
  428. data: data
  429. });
  430. }}
  431. />
  432. <span className="mandatory">数字越大排序越前</span>
  433. </FormItem>
  434. <FormItem
  435. className="half-middle"
  436. {...formItemLayout}
  437. label="状态"
  438. >
  439. <Select
  440. placeholder=""
  441. style={{ width: "80px" }}
  442. value={data.status}
  443. onChange={(e) => {
  444. data["status"] = e;
  445. this.setState({
  446. data: data,
  447. });
  448. }}
  449. >
  450. {[
  451. { key: "关闭", value: 0 },
  452. { key: "开启", value: 1 },
  453. ].map(function (item) {
  454. return (
  455. <Select.Option key={item.value} value={item.value}>
  456. {item.key}
  457. </Select.Option>
  458. );
  459. })}
  460. </Select>
  461. <span className="mandatory">*</span>
  462. </FormItem>
  463. </div>
  464. <FormItem className="half-middle">
  465. <Button
  466. className="set-submit"
  467. type="primary"
  468. onClick={this.handleSubmit}
  469. style={{ marginLeft: "150px" }}
  470. >
  471. 保存
  472. </Button>
  473. <Button
  474. className="set-submit"
  475. type="ghost"
  476. onClick={this.handleCancel}
  477. >
  478. 取消
  479. </Button>
  480. </FormItem>
  481. </Spin>
  482. </Form>
  483. </Modal>
  484. }
  485. </div>
  486. );
  487. }
  488. }));
  489. export default Standard;