index.jsx 24 KB

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