index.jsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. import React from 'react';
  2. import $ from 'jquery/src/ajax';
  3. import {
  4. Form, Icon, Button, Input, Select, AutoComplete, Spin, Table,
  5. message, DatePicker, Modal, Tabs
  6. } from 'antd';
  7. import moment from 'moment';
  8. import { ShowModal, splitUrl } from '../../../tools.js';
  9. import { ChooseList } from "../../order/orderNew/chooseList";
  10. import "./index.less";
  11. import ImgList from "../../../common/imgList";
  12. const PicturesWall = React.createClass({
  13. getInitialState() {
  14. return {
  15. previewVisible: false,
  16. previewImage: "",
  17. fileList: this.props.pictureUrl,
  18. };
  19. },
  20. getDefaultProps() {
  21. return {
  22. changeClick: this.modifyChange,
  23. };
  24. },
  25. handleCancel() {
  26. this.setState({ previewVisible: false });
  27. },
  28. handlePreview(file) {
  29. this.setState({
  30. previewImage: file.url || file.thumbUrl,
  31. previewVisible: true,
  32. });
  33. },
  34. handleChange(info) {
  35. let fileList = info.fileList;
  36. this.setState({ fileList });
  37. this.props.fileList(fileList);
  38. },
  39. componentWillReceiveProps(nextProps) {
  40. this.state.fileList = nextProps.pictureUrl;
  41. },
  42. render() {
  43. const { fileList } = this.state;
  44. return (
  45. <div style={{ display: "inline-block" }}>
  46. <ImgList
  47. isSupportPDF={true}
  48. limitation={false}
  49. domId={this.props.domId}
  50. uploadConfig={{
  51. action: globalConfig.context + "/api/admin/standard/uploadPicture",
  52. data: { sign: "standard_document" },
  53. multiple: true,
  54. listType: "picture-card",
  55. }}
  56. onChange={(infor) => {
  57. this.handleChange(infor);
  58. }}
  59. fileList={fileList}
  60. />
  61. </div>
  62. );
  63. },
  64. });
  65. const { TabPane } = Tabs
  66. const FormItem = Form.Item;
  67. const Standard = Form.create()(React.createClass({
  68. getInitialState() {
  69. return {
  70. searchValues: {},
  71. loading: false,
  72. changeList: undefined, // 更改后的表格显示数据
  73. dataSource: [],
  74. departmentArr: [],
  75. typeList: [
  76. { key: "国家标准", value: 0, },
  77. { key: "行业标准", value: 1, },
  78. { key: "地方标准", value: 2, },
  79. { key: "团体标准", value: 3, },
  80. { key: "国际标准", value: 4, },
  81. { key: "企业标准", value: 5, },
  82. ],
  83. pagination: {
  84. defaultCurrent: 1,
  85. defaultPageSize: 10,
  86. showQuickJumper: true,
  87. pageSize: 20,
  88. onChange: function (page) {
  89. this.loadData(page);
  90. }.bind(this),
  91. showTotal: function (total) {
  92. return '共' + total + '条数据';
  93. }
  94. },
  95. columns: [
  96. {
  97. title: '标准编号',
  98. dataIndex: 'serialNumber',
  99. key: 'serialNumber',
  100. },
  101. {
  102. title: '标准名称',
  103. dataIndex: 'name',
  104. key: 'name',
  105. },
  106. {
  107. title: '参考',
  108. dataIndex: 'reference',
  109. key: 'reference',
  110. render: (text, record) => <span>{['国家 ', '行业 ', '地方 ', '团体 ', '国际 ', '企业 '][record.type]}{text}</span>
  111. },
  112. {
  113. title: '部门',
  114. dataIndex: 'depName',
  115. key: 'depName',
  116. },
  117. {
  118. title: '负责人',
  119. dataIndex: 'adminName',
  120. key: 'adminName',
  121. },
  122. {
  123. title: '标准状态',
  124. dataIndex: 'status',
  125. key: 'status',
  126. render: text => <span style={{ color: ["red", "green"][text] }}>{["关闭", "开启"][text]}</span>
  127. },
  128. {
  129. title: '更新时间',
  130. dataIndex: 'updateTime',
  131. key: 'updateTime',
  132. },
  133. {
  134. title: '附件',
  135. dataIndex: 'url',
  136. key: 'url',
  137. render: (text, record, index) =>
  138. <div className='selStandard'>
  139. <ImgList
  140. fileList={text ? splitUrl(text, ',', globalConfig.avatarHost + '/upload') : []}
  141. domId={"selStandard" + index}
  142. />
  143. </div>
  144. },
  145. ],
  146. visible: "",
  147. data: {},
  148. orgCodeUrl: [],
  149. };
  150. },
  151. componentWillMount() {
  152. this.loadData();
  153. this.departmentList();
  154. },
  155. // 列表接口
  156. loadData(pageNo) {
  157. const { searchValues, pagination } = this.state;
  158. this.setState({
  159. loading: true,
  160. });
  161. let datas = Object.assign(searchValues, {
  162. pageNo: pageNo || 1,
  163. pageSize: pagination.pageSize,
  164. });
  165. $.ajax({
  166. method: "get",
  167. dataType: "json",
  168. crossDomain: false,
  169. url: globalConfig.context + "/api/admin/standard/list",
  170. data: datas,
  171. success: function (data) {
  172. ShowModal(this);
  173. this.setState({
  174. loading: false,
  175. });
  176. if (data.error && data.error.length === 0) {
  177. if (data.data.list) {
  178. pagination.current = data.data.pageNo;
  179. pagination.total = data.data.totalCount;
  180. if (data.data && data.data.list && !data.data.list.length) {
  181. pagination.current = 0;
  182. pagination.total = 0;
  183. }
  184. this.setState({
  185. dataSource: data.data.list,
  186. pagination: this.state.pagination,
  187. pageNo: data.data.pageNo,
  188. });
  189. } else {
  190. this.setState({
  191. dataSource: data.data,
  192. pagination: false,
  193. });
  194. }
  195. } else {
  196. message.warning(data.error[0].message);
  197. }
  198. }.bind(this),
  199. }).always(
  200. function () {
  201. this.setState({
  202. loading: false,
  203. });
  204. }.bind(this)
  205. );
  206. },
  207. //部门
  208. departmentList() {
  209. $.ajax({
  210. method: "get",
  211. dataType: "json",
  212. crossDomain: false,
  213. url: globalConfig.context + "/api/admin/organization/selectSuperId",
  214. data: {},
  215. success: function (data) {
  216. let thedata = data.data;
  217. let theArr = [];
  218. if (!thedata) {
  219. if (data.error && data.error.length) {
  220. message.warning(data.error[0].message);
  221. }
  222. } else {
  223. thedata.map(function (item, index) {
  224. theArr.push({
  225. key: index,
  226. name: item.name,
  227. id: item.id
  228. });
  229. });
  230. }
  231. this.setState({
  232. departmentArr: theArr
  233. });
  234. }.bind(this)
  235. }).always(
  236. function () {
  237. }.bind(this)
  238. );
  239. },
  240. search() {
  241. this.loadData();
  242. },
  243. reset() {
  244. this.setState({
  245. searchValues: {}
  246. }, () => {
  247. this.loadData();
  248. })
  249. },
  250. changeList(arr) {
  251. const newArr = [];
  252. this.state.columns.forEach(item => {
  253. arr.forEach(val => {
  254. if (val === item.title) {
  255. newArr.push(item);
  256. }
  257. });
  258. });
  259. this.setState({
  260. changeList: newArr
  261. });
  262. },
  263. addClick() {
  264. this.setState({
  265. visible: "add"
  266. })
  267. },
  268. tableRowClick(e) {
  269. if (!adminData.isSuperAdmin) {
  270. return
  271. }
  272. this.setState({
  273. visible: "edit",
  274. })
  275. this.getDetails(e.id)
  276. // const orgCodeUrl = e.url ? splitUrl(e.url, ',', globalConfig.avatarHost + '/upload') : []
  277. // this.setState({
  278. // visible: "edit",
  279. // data: e,
  280. // orgCodeUrl,
  281. // adminName: e.adminName,
  282. // })
  283. },
  284. getDetails(id) {
  285. this.setState({
  286. loading: true
  287. });
  288. $.ajax({
  289. method: "get",
  290. dataType: "json",
  291. crossDomain: false,
  292. url: globalConfig.context + "/api/admin/standard/get",
  293. data: {
  294. id,
  295. },
  296. success: function (data) {
  297. let thedata = data.data || {};
  298. let orgCodeUrl = []
  299. if (!thedata) {
  300. if (data.error && data.error.length) {
  301. message.warning(data.error[0].message);
  302. };
  303. } else {
  304. orgCodeUrl = thedata.url ? splitUrl(thedata.url, ',', globalConfig.avatarHost + '/upload') : []
  305. }
  306. this.setState({
  307. data: thedata,
  308. orgCodeUrl,
  309. adminName: thedata.adminName,
  310. })
  311. }.bind(this),
  312. }).always(function () {
  313. this.setState({
  314. loading: false
  315. });
  316. }.bind(this));
  317. },
  318. getOrgCodeUrl(e) {
  319. this.setState({
  320. orgCodeUrl: e
  321. });
  322. },
  323. handleCancel() {
  324. this.setState({
  325. visible: "",
  326. adminName: undefined,
  327. data: {},
  328. orgCodeUrl: [],
  329. })
  330. },
  331. handleSubmit() {
  332. const { data } = this.state
  333. if (!data.serialNumber) {
  334. message.warning('标准编号不能为空!');
  335. return;
  336. }
  337. if (!data.name) {
  338. message.warning('标准名称不能为空!');
  339. return;
  340. }
  341. if (!data.depId) {
  342. message.warning('部门不能为空!');
  343. return;
  344. }
  345. if (!data.status && data.status != 0) {
  346. message.warning('请选择状态!');
  347. return;
  348. }
  349. let pictureUrl = "";
  350. if (this.state.orgCodeUrl.length) {
  351. let picArr = [];
  352. this.state.orgCodeUrl.map(function (item) {
  353. if (
  354. item.response &&
  355. item.response.data &&
  356. item.response.data.length
  357. ) {
  358. picArr.push(item.response.data);
  359. }
  360. });
  361. pictureUrl = picArr.join(",");
  362. }
  363. $.ajax({
  364. method: "POST",
  365. dataType: "json",
  366. crossDomain: false,
  367. url:
  368. data.id
  369. ? globalConfig.context + '/api/admin/standard/update'
  370. : globalConfig.context + '/api/admin/standard/add',
  371. data: Object.assign(data, {
  372. url: pictureUrl,
  373. }),
  374. }).done(function (data) {
  375. this.setState({
  376. loading: false
  377. });
  378. if (!data.error.length) {
  379. message.success('保存成功!');
  380. this.handleCancel();
  381. this.loadData(this.state.pageNo);
  382. } else {
  383. message.warning(data.error[0].message);
  384. }
  385. }.bind(this));
  386. },
  387. followUp(e) {
  388. this.setState({
  389. adminName: e
  390. });
  391. $.ajax({
  392. method: "get",
  393. dataType: "json",
  394. crossDomain: false,
  395. url: globalConfig.context + "/api/admin/customer/listAdminByName",
  396. data: {
  397. adminName: e,
  398. },
  399. success: function (data) {
  400. let thedata = data.data || [];
  401. if (!thedata) {
  402. if (data.error && data.error.length) {
  403. message.warning(data.error[0].message);
  404. }
  405. thedata = {};
  406. }
  407. this.setState({
  408. fjlist: thedata,
  409. });
  410. }.bind(this),
  411. }).always(
  412. function () {
  413. this.setState({
  414. loading: false,
  415. });
  416. }.bind(this)
  417. );
  418. },
  419. selectF(value) {
  420. const { data, fjlist } = this.state;
  421. const newdataSources = JSON.stringify(fjlist) == "{}" ? [] : fjlist;
  422. this.setState({
  423. data: Object.assign(data, {
  424. aid: newdataSources.find((item) => item.name == value).id,
  425. }),
  426. });
  427. },
  428. render() {
  429. const { RangePicker } = DatePicker;
  430. let departmentArr = this.state.departmentArr || [];
  431. const { searchValues, data } = this.state
  432. const dataSources = this.state.fjlist || [];
  433. const options = dataSources.map((group) => (
  434. <Select.Option key={group.id} value={group.name}>
  435. {group.name}
  436. </Select.Option>
  437. ));
  438. const formItemLayout = {
  439. labelCol: { span: 8 },
  440. wrapperCol: { span: 14 },
  441. };
  442. return (
  443. <div className="user-content">
  444. <div className="content-title">
  445. <Tabs defaultActiveKey="1" className="test">
  446. <TabPane tab="搜索" key="1">
  447. <div className="user-search" style={{ marginLeft: 10 }}>
  448. <Input
  449. placeholder="请输入标准名称"
  450. value={searchValues["name"]
  451. ? searchValues["name"]
  452. : ""}
  453. onChange={(e) => {
  454. searchValues["name"] = e.target.value;
  455. this.setState({
  456. searchValues: searchValues,
  457. });
  458. }}
  459. />
  460. <Select
  461. placeholder="请输入部门名称"
  462. style={{ width: 230 }}
  463. value={searchValues["depId"]
  464. ? searchValues["depId"]
  465. : undefined}
  466. onChange={e => {
  467. searchValues["depId"] = e;
  468. this.setState({
  469. searchValues: searchValues,
  470. });
  471. }}
  472. >
  473. {departmentArr.map(function (item) {
  474. return (
  475. <Select.Option key={item.id}>{item.name}</Select.Option>
  476. );
  477. })}
  478. </Select>
  479. <Select
  480. placeholder="状态"
  481. style={{ width: 140 }}
  482. value={searchValues["status"]}
  483. onChange={(e) => {
  484. searchValues["status"] = e;
  485. this.setState({
  486. searchValues: searchValues,
  487. });
  488. }}
  489. >
  490. <Select.Option value={null}>全部</Select.Option>
  491. <Select.Option value={0}>关闭</Select.Option>
  492. <Select.Option value={1}>开启</Select.Option>
  493. </Select>
  494. <Select
  495. placeholder="标准类型"
  496. style={{ width: 140 }}
  497. value={searchValues["type"]}
  498. onChange={(e) => {
  499. searchValues["type"] = e;
  500. this.setState({
  501. searchValues: searchValues,
  502. });
  503. }}
  504. >
  505. {this.state.typeList.map(function (item) {
  506. return (
  507. <Select.Option key={item.value} value={item.value}>
  508. {item.key}
  509. </Select.Option>
  510. );
  511. })}
  512. </Select>
  513. <span>时间:</span>
  514. <RangePicker
  515. style={{ width: 300 }}
  516. value={[
  517. searchValues.startTime ? moment(searchValues.startTime) : null,
  518. searchValues.endTime ? moment(searchValues.endTime) : null,
  519. ]}
  520. onChange={(data, dataString) => {
  521. this.setState({
  522. searchValues: Object.assign(searchValues, {
  523. startTime: dataString[0],
  524. endTime: dataString[1],
  525. }),
  526. });
  527. }}
  528. />
  529. <Button
  530. type="primary"
  531. onClick={this.search}
  532. style={{ margin: "0 10px" }}
  533. >搜索</Button>
  534. <Button onClick={this.reset}>重置</Button>
  535. </div>
  536. </TabPane>
  537. <TabPane tab="更改表格显示数据" key="2">
  538. <div style={{ marginLeft: 10 }}>
  539. <ChooseList
  540. columns={this.state.columns}
  541. changeFn={this.changeList}
  542. changeList={this.state.changeList}
  543. top={55}
  544. margin={11}
  545. />
  546. </div>
  547. </TabPane>
  548. {adminData.isSuperAdmin ?
  549. <TabPane tab="新增" key="3">
  550. <Button
  551. type="primary"
  552. className="addButton"
  553. style={{ float: "left", marginBottom: 10, marginTop: 12 }}
  554. onClick={this.addClick}
  555. >
  556. 新增
  557. </Button>
  558. </TabPane> : ""}
  559. </Tabs>
  560. <div className="patent-table">
  561. <Spin spinning={this.state.loading}>
  562. <Table
  563. bordered
  564. columns={
  565. this.state.changeList
  566. ? this.state.changeList
  567. : this.state.columns
  568. }
  569. style={{
  570. cursor: 'pointer',
  571. }}
  572. dataSource={this.state.dataSource}
  573. pagination={this.state.pagination}
  574. onRowDoubleClick={this.tableRowClick}
  575. />
  576. </Spin>
  577. </div>
  578. </div>
  579. {
  580. this.state.visible != "" &&
  581. <Modal
  582. title={!!data.id ? "编辑标准" : "新增标准"}
  583. visible={this.state.visible != ""}
  584. width="600px"
  585. onCancel={this.handleCancel}
  586. maskClosable={false}
  587. footer=""
  588. className="admin-desc-content"
  589. >
  590. <Form
  591. layout="horizontal"
  592. // onSubmit={this.handleSubmit}
  593. id="demand-form"
  594. >
  595. <Spin spinning={this.state.loading}>
  596. <div className="clearfix">
  597. <FormItem
  598. className="half-middle"
  599. {...formItemLayout}
  600. label="标准编号"
  601. >
  602. <Input
  603. placeholder="标准编号"
  604. value={data["serialNumber"]
  605. ? data["serialNumber"]
  606. : ""}
  607. style={{ width: "230px" }}
  608. onChange={(e) => {
  609. data["serialNumber"] = e.target.value;
  610. this.setState({
  611. data: data
  612. });
  613. }}
  614. />
  615. <span className="mandatory">*</span>
  616. </FormItem>
  617. <FormItem
  618. className="half-middle"
  619. {...formItemLayout}
  620. label="标准名称"
  621. >
  622. <Input
  623. placeholder="标准名称"
  624. value={data["name"]
  625. ? data["name"]
  626. : ""}
  627. style={{ width: "230px" }}
  628. onChange={(e) => {
  629. data["name"] = e.target.value;
  630. this.setState({
  631. data: data
  632. });
  633. }}
  634. />
  635. <span className="mandatory">*</span>
  636. </FormItem>
  637. <FormItem
  638. className="half-middle"
  639. {...formItemLayout}
  640. label="参考"
  641. >
  642. <Select
  643. placeholder="请选择"
  644. style={{ width: "80px" }}
  645. value={data.type}
  646. onChange={(e) => {
  647. data["type"] = e;
  648. this.setState({
  649. data: data
  650. });
  651. }}
  652. >
  653. {this.state.typeList.map(function (item) {
  654. return (
  655. <Select.Option key={item.value} value={item.value}>
  656. {item.key}
  657. </Select.Option>
  658. );
  659. })}
  660. </Select>
  661. <Input
  662. placeholder="请输入参考网址"
  663. value={data["reference"]
  664. ? data["reference"]
  665. : ""}
  666. style={{ width: "140px", marginLeft: "10px" }}
  667. onChange={(e) => {
  668. data["reference"] = e.target.value;
  669. this.setState({
  670. data: data
  671. });
  672. }}
  673. />
  674. </FormItem>
  675. <FormItem
  676. className="half-middle"
  677. {...formItemLayout}
  678. label="部门"
  679. >
  680. <Select
  681. placeholder="请选择部门"
  682. style={{ width: 230 }}
  683. value={data["depId"]
  684. ? data["depId"]
  685. : undefined}
  686. onChange={e => {
  687. data["depId"] = e;
  688. this.setState({
  689. data: data,
  690. });
  691. }}
  692. >
  693. {departmentArr.map(function (item) {
  694. return (
  695. <Select.Option key={item.id}>{item.name}</Select.Option>
  696. );
  697. })}
  698. </Select>
  699. <span className="mandatory">*</span>
  700. </FormItem>
  701. <FormItem
  702. className="half-middle"
  703. {...formItemLayout}
  704. label="负责人"
  705. >
  706. <AutoComplete
  707. className="certain-category-search"
  708. dropdownClassName="certain-category-search-dropdown"
  709. dropdownMatchSelectWidth={false}
  710. style={{ width: 230 }}
  711. dataSource={options}
  712. placeholder="负责人名称"
  713. value={this.state.adminName}
  714. onChange={this.followUp.bind(this)}
  715. filterOption={true}
  716. onSelect={this.selectF.bind(this)}
  717. >
  718. <Input />
  719. </AutoComplete>
  720. </FormItem>
  721. <FormItem
  722. className="half-middle"
  723. {...formItemLayout}
  724. label="状态"
  725. >
  726. <Select
  727. placeholder=""
  728. style={{ width: "80px" }}
  729. value={data.status}
  730. onChange={(e) => {
  731. data["status"] = e;
  732. this.setState({
  733. data: data,
  734. });
  735. }}
  736. >
  737. {[
  738. { key: "关闭", value: 0 },
  739. { key: "开启", value: 1 },
  740. ].map(function (item) {
  741. return (
  742. <Select.Option key={item.value} value={item.value}>
  743. {item.key}
  744. </Select.Option>
  745. );
  746. })}
  747. </Select>
  748. <span className="mandatory">*</span>
  749. </FormItem>
  750. <FormItem
  751. className="half-middle"
  752. {...formItemLayout}
  753. label="上附件"
  754. >
  755. <PicturesWall
  756. domId={'standard'}
  757. fileList={this.getOrgCodeUrl}
  758. pictureUrl={this.state.orgCodeUrl}
  759. />
  760. </FormItem>
  761. <span className="mandatory" style={{ marginLeft: 210 }}>支持图片,pdf</span>
  762. </div>
  763. <FormItem className="half-middle">
  764. <Button
  765. className="set-submit"
  766. type="primary"
  767. onClick={this.handleSubmit}
  768. style={{ marginLeft: "150px" }}
  769. >
  770. 保存
  771. </Button>
  772. <Button
  773. className="set-submit"
  774. type="ghost"
  775. onClick={this.handleCancel}
  776. >
  777. 取消
  778. </Button>
  779. </FormItem>
  780. </Spin>
  781. </Form>
  782. </Modal>
  783. }
  784. </div>
  785. );
  786. }
  787. }));
  788. export default Standard;