index.jsx 23 KB

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