businessCategory.jsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. import React from 'react';
  2. import ReactDom from 'react-dom';
  3. import ajax from 'jquery/src/ajax/xhr.js';
  4. import $ from 'jquery/src/ajax';
  5. import moment from 'moment';
  6. import { Form,Radio, Icon, Button, Input, Select, Spin, Table, Switch, message, DatePicker, Modal, Upload,Popconfirm,TimePicker } from 'antd';
  7. import {categoryState} from '@/dataDic.js';
  8. import {getCategoryState,splitUrl} from '@/tools.js';
  9. //图片组件
  10. const PicturesWall = React.createClass({
  11. getInitialState() {
  12. return {
  13. previewVisible: false,
  14. previewImage: '',
  15. fileList: [],
  16. tags: []
  17. };
  18. },
  19. handleCancel() {
  20. this.setState({ previewVisible: false });
  21. },
  22. handlePreview(file) {
  23. this.setState({
  24. previewImage: file.url || file.thumbUrl,
  25. previewVisible: true
  26. });
  27. },
  28. handleChange(info) {
  29. let fileList = info.fileList;
  30. this.setState({ fileList });
  31. this.props.fileList(fileList);
  32. },
  33. componentWillReceiveProps(nextProps) {
  34. this.state.fileList = nextProps.pictureUrl;
  35. },
  36. render() {
  37. const { previewVisible, previewImage, fileList } = this.state;
  38. const uploadButton = (
  39. <div>
  40. <Icon type="plus" />
  41. <div className="ant-upload-text">点击上传</div>
  42. </div>
  43. );
  44. return (
  45. <div className="clearfix">
  46. <Upload
  47. action={globalConfig.context + '/api/admin/jtBusiness/uploadPicture'}
  48. data={{ sign: 'jt_business_picture'}}
  49. listType="picture-card"
  50. fileList={fileList}
  51. onPreview={this.handlePreview}
  52. onChange={this.handleChange}
  53. >
  54. {fileList.length >=1 ? null : uploadButton}
  55. </Upload>
  56. <Modal maskClosable={false} visible={previewVisible} footer={null} onCancel={this.handleCancel}>
  57. <img alt="example" style={{ width: '100%' }} src={previewImage} />
  58. </Modal>
  59. </div>
  60. );
  61. }
  62. });
  63. const BusinessCategory=Form.create()(React.createClass({
  64. loadData(pageNo) {
  65. this.state.data = [];
  66. this.setState({
  67. loading: true,
  68. page:pageNo,
  69. });
  70. $.ajax({
  71. method: "get",
  72. dataType: "json",
  73. crossDomain: false,
  74. url: globalConfig.context + '/api/admin/jtBusiness/category/list',
  75. data: {
  76. pageNo: pageNo || 1,
  77. pageSize: this.state.pagination.pageSize,
  78. name:this.state.nameSearch, //品类名称
  79. layer:this.state.layerSearch,//组织层级
  80. },
  81. success: function (data) {
  82. let theArr = [];
  83. if (!data.data || !data.data.list) {
  84. if (data.error && data.error.length) {
  85. message.warning(data.error[0].message);
  86. };
  87. } else {
  88. for (let i = 0; i < data.data.list.length; i++) {
  89. let thisdata = data.data.list[i];
  90. theArr.push({
  91. key: i,
  92. id: thisdata.id,//品类ID
  93. sort:thisdata.sort,//品类序号
  94. number: thisdata.number,//品类编号
  95. module:thisdata.module?String(thisdata.module):undefined,
  96. name: thisdata.name,//品类名称
  97. layer:thisdata.layer,
  98. superId:thisdata.superId,
  99. layerName: thisdata.layerName,//品类层级
  100. superName: thisdata.superName,//上级品类
  101. });
  102. };
  103. this.state.pagination.current = data.data.pageNo;
  104. this.state.pagination.total = data.data.totalCount;
  105. };
  106. this.setState({
  107. dataSource: theArr,
  108. pagination: this.state.pagination
  109. });
  110. }.bind(this),
  111. }).always(function () {
  112. this.setState({
  113. loading: false
  114. });
  115. }.bind(this));
  116. },
  117. getInitialState() {
  118. return {
  119. searchMore: true,
  120. selectedRowKeys: [],
  121. pictureUrl: [],
  122. selectedRows: [],
  123. loading: false,
  124. pagination: {
  125. defaultCurrent: 1,
  126. defaultPageSize: 10,
  127. showQuickJumper: true,
  128. pageSize: 10,
  129. onChange: function (page) {
  130. this.loadData(page);
  131. this.setState({
  132. selectedRowKeys: [],
  133. })
  134. }.bind(this),
  135. showTotal: function (total) {
  136. return '共' + total + '条数据';
  137. }
  138. },
  139. columns: [
  140. {
  141. title: '品类编号',
  142. dataIndex: 'number',
  143. key: 'number',
  144. }, {
  145. title: '品类名称',
  146. dataIndex: 'name',
  147. key: 'name',
  148. }, {
  149. title: '品类层级',
  150. dataIndex: 'layerName',
  151. key: 'layerName'
  152. }, {
  153. title: '上级品类',
  154. dataIndex: 'superName',
  155. key: 'superName',
  156. },{
  157. title:'操作',
  158. dataIndex: 'superName1',
  159. key: 'superName1',
  160. render:(text,recard)=>{
  161. return (
  162. <div>
  163. {recard.layer=='1'&&<Button onClick={(e)=>{e.stopPropagation();this.nextAdd(recard)}}>新建下级品类</Button>}
  164. </div>
  165. )
  166. }
  167. }
  168. ],
  169. dataSource: [],
  170. };
  171. },
  172. componentWillMount() {
  173. this.loadData();
  174. },
  175. //新建下级
  176. nextAdd(recard){
  177. this.setState({
  178. recrdAdd:recard,
  179. visible: true,
  180. name:'',
  181. addFirst:1,
  182. superId:recard.id,
  183. module:recard.module
  184. });
  185. },
  186. //编辑保存
  187. edithandleSubmit(e){
  188. e.preventDefault();
  189. let thePictureUrl = [];
  190. if (this.state.pictureUrl.length) {
  191. let picArr = [];
  192. this.state.pictureUrl.map(function (item) {
  193. if ( item.response && item.response.data && item.response.data.length ){
  194. picArr.push(item.response.data);
  195. }
  196. });
  197. thePictureUrl = picArr.join(",");
  198. };
  199. $.ajax({
  200. method: "post",
  201. dataType: "json",
  202. crossDomain: false,
  203. url: globalConfig.context + "/api/admin/jtBusiness/category/update",
  204. data: {
  205. id: this.state.id,
  206. name:this.state.name,
  207. summary:this.state.summary,
  208. imgUrl:thePictureUrl
  209. }
  210. }).done(function (data) {
  211. if (!data.error.length) {
  212. message.success('保存成功!');
  213. this.setState({
  214. loading: false,
  215. editvisible:false
  216. });
  217. } else {
  218. message.warning(data.error[0].message);
  219. };
  220. this.loadData(this.state.page)
  221. }.bind(this));
  222. },
  223. //整行删除
  224. delectRow() {
  225. let deletedIds = '';
  226. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  227. let rowItem = this.state.selectedRows[idx];
  228. if (rowItem.id) {
  229. deletedIds=rowItem.id;
  230. };
  231. };
  232. this.setState({
  233. selectedRowKeys: [],
  234. loading: deletedIds.length > 0
  235. });
  236. $.ajax({
  237. method: "post",
  238. dataType: "json",
  239. crossDomain: false,
  240. url: globalConfig.context + "/api/admin/jtBusiness/category/delete",
  241. data: {
  242. id: deletedIds
  243. }
  244. }).done(function (data) {
  245. if (!data.error.length) {
  246. message.success('删除成功!');
  247. this.setState({
  248. loading: false,
  249. });
  250. } else {
  251. message.warning(data.error[0].message);
  252. };
  253. this.loadData(this.state.page)
  254. }.bind(this));
  255. },
  256. addClick() {
  257. this.state.RowData = {};
  258. this.setState({
  259. visible: true,
  260. addFirst:0,
  261. name:'',
  262. superId:'',
  263. module:'0'
  264. });
  265. },
  266. //新增保存
  267. addhandleSubmit(e){
  268. e.preventDefault();
  269. this.setState({
  270. loading:true
  271. })
  272. $.ajax({
  273. method: "post",
  274. dataType: "json",
  275. crossDomain: false,
  276. url: globalConfig.context + "/api/admin/jtBusiness/category/apply",
  277. data: {
  278. name:this.state.name,
  279. superId:this.state.superId,
  280. layer:this.state.addFirst?'2':'1',
  281. module:this.state.module
  282. }
  283. }).done(function (data) {
  284. if (!data.error.length) {
  285. message.success('新增成功!');
  286. this.setState({
  287. loading: false,
  288. visible:false
  289. });
  290. } else {
  291. message.warning(data.error[0].message);
  292. };
  293. this.loadData(this.state.page)
  294. }.bind(this));
  295. },
  296. editClick() {
  297. this.state.RowData = {};
  298. this.setState({
  299. editvisible: true
  300. });
  301. },
  302. detailes(recard){
  303. this.setState({
  304. loading: true,
  305. });
  306. $.ajax({
  307. method: "get",
  308. dataType: "json",
  309. crossDomain: false,
  310. url: globalConfig.context + '/api/admin/jtBusiness/category/detail',
  311. data: {
  312. id:recard.id
  313. },
  314. success: function (data) {
  315. if (!data.data) {
  316. if (data.error && data.error.length) {
  317. message.warning(data.error[0].message);
  318. };
  319. } else {
  320. let thisdata=data.data;
  321. this.setState({
  322. id:thisdata.id,//品类id
  323. name:thisdata.name,//品类名称
  324. createTime:thisdata.createTime?(new Date(thisdata.createTime)).toLocaleString():'',
  325. superId:thisdata.superId,//父类id
  326. pictureUrl: thisdata.imgUrl ? splitUrl(thisdata.imgUrl, ',', globalConfig.avatarHost + '/upload') : [],
  327. })
  328. };
  329. }.bind(this),
  330. }).always(function () {
  331. this.setState({
  332. loading: false
  333. });
  334. }.bind(this));
  335. },
  336. handleCancel() {
  337. this.setState({ visible: false })
  338. },
  339. edithandleCancel() {
  340. this.setState({ editvisible: false })
  341. },
  342. search() {
  343. this.loadData();
  344. },
  345. reset() {
  346. this.state.nameSearch = '';//品类名称清零
  347. this.state.layerSearch = undefined;//品类层级清零
  348. this.loadData();
  349. },
  350. searchSwitch() {
  351. this.setState({
  352. searchMore: !this.state.searchMore
  353. });
  354. },
  355. getPictureUrl(e) {
  356. this.setState({ pictureUrl: e });
  357. },
  358. tableRowClick(record, index) {
  359. this.setState({
  360. editvisible: true,
  361. visible:false,
  362. theData:record
  363. });
  364. this.detailes(record)
  365. },
  366. render() {
  367. const FormItem = Form.Item
  368. const rowSelection = {
  369. selectedRowKeys: this.state.selectedRowKeys,
  370. onChange: (selectedRowKeys, selectedRows) => {
  371. this.setState({
  372. selectedRows: selectedRows.slice(-1),
  373. selectedRowKeys: selectedRowKeys.slice(-1)
  374. });
  375. }
  376. };
  377. const hasSelected = this.state.selectedRowKeys.length > 0;
  378. const theData =this.state.theData ||{};
  379. const recrdAdd = this.state.recrdAdd ||{};
  380. return (
  381. <div className="user-content" >
  382. <div className="content-title">
  383. <div className="content-title">
  384. <span>项目业务管理</span>
  385. </div>
  386. <div className="user-search">
  387. <Input placeholder="业务品类名称" style={{width:'150px',marginRight:'10px',marginBottom:'10px'}}
  388. value={this.state.nameSearch}
  389. onChange={(e) => { this.setState({ nameSearch: e.target.value }); }} />
  390. <Select placeholder="品类层级"
  391. style={{ width:'200px',marginRight:'10px' }}
  392. value={this.state.layerSearch} onChange={(e)=>{this.setState({layerSearch:e})}}>
  393. <Select.Option value="1">一级</Select.Option>
  394. <Select.Option value="2">二级</Select.Option>
  395. </Select>
  396. <Button type="primary" onClick={this.search} style={{marginRight:'10px'}}>搜索</Button>
  397. <Button onClick={this.reset} style={{marginRight:'10px'}}>重置</Button>
  398. <Popconfirm title="是否删除?" onConfirm={this.delectRow} okText="是" cancelText="否">
  399. <Button style={{marginRight:'10px' ,marginLeft:'10px'}} type="danger"
  400. disabled={!hasSelected}
  401. >删除<Icon type="minus" />
  402. </Button>
  403. </Popconfirm>
  404. <Popconfirm title="是否停用?" onConfirm={this.blockRow} okText="是" cancelText="否">
  405. <Button style={{ background: "#ea0862", border: "none", color: "#fff",marginRight:'10px' ,marginLeft:'10px',display:'none'}}
  406. disabled={!hasSelected}
  407. >停用<Icon type="minus" />
  408. </Button>
  409. </Popconfirm>
  410. <Button type="primary" className="addButton" onClick={this.addClick} style={{float:'right',marginRight:'200px'}}>新增品类<Icon type="plus" /></Button>
  411. </div>
  412. <div className="patent-table">
  413. <Spin spinning={this.state.loading}>
  414. <Table columns={this.state.columns}
  415. dataSource={this.state.dataSource}
  416. rowSelection={rowSelection}
  417. pagination={this.state.pagination}
  418. onRowClick={this.tableRowClick} />
  419. </Spin>
  420. </div>
  421. <div className="patent-desc">
  422. <Modal maskClosable={false} visible={this.state.visible}
  423. onOk={this.checkPatentProcess} onCancel={this.handleCancel}
  424. width='420px'
  425. title='新增品类'
  426. footer=''
  427. className="admin-desc-content">
  428. <Form layout="horizontal" onSubmit={(e)=>{this.addhandleSubmit(e,{})}} id="demand-form">
  429. <Spin spinning={this.state.loading}>
  430. <div className="clearfix">
  431. <FormItem
  432. labelCol={{ span: 7 }}
  433. wrapperCol={{ span: 12 }}
  434. label="品类名称" >
  435. <Input placeholder="品类名称" value={this.state.name} style={{width:'94%'}}
  436. onChange={(e)=>{this.setState({name:e.target.value})}} required="required"/>
  437. <span className="mandatory" style={{color:'red',marginLeft:'5px'}}>*</span>
  438. </FormItem>
  439. </div>
  440. <div className="clearfix">
  441. <FormItem
  442. labelCol={{ span: 7 }}
  443. wrapperCol={{ span: 12 }}
  444. label="所属模块" >
  445. {!this.state.addFirst? <Select value ={this.state.module} onChange={(e)=>{this.setState({module:e})}}>
  446. <Select.Option value='0'>科技服务</Select.Option>
  447. <Select.Option value="1">知识产权服务</Select.Option>
  448. </Select>:<span>{this.state.module?'知识产权服务':'科技服务'}</span>}
  449. </FormItem>
  450. </div>
  451. <div className="clearfix">
  452. <FormItem
  453. labelCol={{ span: 7 }}
  454. wrapperCol={{ span: 12 }}
  455. label="上级品类"
  456. >
  457. <span>{this.state.addFirst?recrdAdd.name:'超级品类'}</span>
  458. </FormItem>
  459. </div>
  460. <FormItem wrapperCol={{ span: 12, offset: 7 }}>
  461. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  462. <Button className="set-submit" type="ghost" onClick={this.handleCancel} style={{marginLeft:'15px'}}>取消</Button>
  463. </FormItem>
  464. </Spin>
  465. </Form >
  466. </Modal>
  467. </div>
  468. <div className="patent-desc">
  469. <Modal maskClosable={false} visible={this.state.editvisible}
  470. onOk={this.checkPatentProcess} onCancel={this.edithandleCancel}
  471. width='600px'
  472. title='编辑品类'
  473. footer=''
  474. className="admin-desc-content">
  475. <Form layout='horizontal' onSubmit={this.edithandleSubmit} id="demand-form">
  476. <Spin spinning={this.state.loading}>
  477. <div className="clearfix">
  478. <FormItem
  479. labelCol={{ span: 7 }}
  480. wrapperCol={{ span: 12 }}
  481. label="品类名称" >
  482. <Input placeholder="组织名称" value={this.state.name}
  483. onChange={(e)=>{this.setState({name:e.target.value})}}/>
  484. </FormItem>
  485. </div>
  486. <div className="clearfix">
  487. <FormItem
  488. labelCol={{ span: 7 }}
  489. wrapperCol={{ span: 12 }}
  490. label="上级品类"
  491. >
  492. <span>{theData.superName?theData.superName:'超级品类'}</span>
  493. </FormItem>
  494. </div>
  495. <div className="clearfix">
  496. <FormItem
  497. labelCol={{ span: 7 }}
  498. wrapperCol={{ span: 12 }}
  499. label="业务品类图标" >
  500. <PicturesWall
  501. fileList={this.getPictureUrl}
  502. pictureUrl={this.state.pictureUrl}
  503. visible={this.props.visible}
  504. />
  505. </FormItem>
  506. </div>
  507. <div className="clearfix">
  508. <FormItem
  509. labelCol={{ span: 7 }}
  510. wrapperCol={{ span: 12 }}
  511. label="品类序号"
  512. >
  513. <span>{theData.sort}</span>
  514. </FormItem>
  515. </div>
  516. <div className="clearfix">
  517. <FormItem
  518. labelCol={{ span: 7 }}
  519. wrapperCol={{ span: 12 }}
  520. label="品类层级"
  521. >
  522. <span>{theData.layerName}</span>
  523. </FormItem>
  524. </div>
  525. <FormItem
  526. labelCol={{ span: 7 }}
  527. wrapperCol={{ span: 12 }}
  528. label="所属模块" >
  529. <span>{theData.module?'知识产权服务':'科技服务'}</span>
  530. </FormItem>
  531. <div className="clearfix">
  532. <FormItem
  533. labelCol={{ span: 7 }}
  534. wrapperCol={{ span: 12 }}
  535. label="品类编号"
  536. >
  537. <span>{theData.number}</span>
  538. </FormItem>
  539. </div>
  540. <div className="clearfix" >
  541. <FormItem
  542. labelCol={{ span: 7 }}
  543. wrapperCol={{ span: 12 }}
  544. label="创建人"
  545. >
  546. <span>超级管理员</span>
  547. </FormItem>
  548. </div>
  549. <div className="clearfix">
  550. <FormItem
  551. labelCol={{ span: 7 }}
  552. wrapperCol={{ span: 12 }}
  553. label="创建时间"
  554. >
  555. <span>{this.state.createTime}</span>
  556. </FormItem>
  557. </div>
  558. <FormItem wrapperCol={{ span: 12, offset: 7 }}>
  559. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  560. <Button className="set-submit" type="ghost" onClick={this.edithandleCancel} style={{marginLeft:'100px'}}>取消</Button>
  561. </FormItem>
  562. </Spin>
  563. </Form >
  564. </Modal>
  565. </div>
  566. </div>
  567. </div>
  568. );
  569. }
  570. }));
  571. export default BusinessCategory;