businessCategory.jsx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  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="user-search">
  384. <Input placeholder="业务品类名称" style={{width:'150px',marginRight:'10px',marginBottom:'10px'}}
  385. value={this.state.nameSearch}
  386. onChange={(e) => { this.setState({ nameSearch: e.target.value }); }} />
  387. <Select placeholder="品类层级"
  388. style={{ width:'200px',marginRight:'10px' }}
  389. value={this.state.layerSearch} onChange={(e)=>{this.setState({layerSearch:e})}}>
  390. <Select.Option value="1">一级</Select.Option>
  391. <Select.Option value="2">二级</Select.Option>
  392. </Select>
  393. <Button type="primary" onClick={this.search} style={{marginRight:'10px'}}>搜索</Button>
  394. <Button onClick={this.reset} style={{marginRight:'10px'}}>重置</Button>
  395. <Popconfirm title="是否删除?" onConfirm={this.delectRow} okText="是" cancelText="否">
  396. <Button style={{marginRight:'10px' ,marginLeft:'10px'}} type="danger"
  397. disabled={!hasSelected}
  398. >删除<Icon type="minus" />
  399. </Button>
  400. </Popconfirm>
  401. <Popconfirm title="是否停用?" onConfirm={this.blockRow} okText="是" cancelText="否">
  402. <Button style={{ background: "#ea0862", border: "none", color: "#fff",marginRight:'10px' ,marginLeft:'10px',display:'none'}}
  403. disabled={!hasSelected}
  404. >停用<Icon type="minus" />
  405. </Button>
  406. </Popconfirm>
  407. <Button type="primary" className="addButton" onClick={this.addClick} style={{float:'right',marginRight:'200px'}}>新增品类<Icon type="plus" /></Button>
  408. </div>
  409. <div className="patent-table">
  410. <Spin spinning={this.state.loading}>
  411. <Table columns={this.state.columns}
  412. dataSource={this.state.dataSource}
  413. rowSelection={rowSelection}
  414. pagination={this.state.pagination}
  415. onRowClick={this.tableRowClick} />
  416. </Spin>
  417. </div>
  418. <div className="patent-desc">
  419. <Modal maskClosable={false} visible={this.state.visible}
  420. onOk={this.checkPatentProcess} onCancel={this.handleCancel}
  421. width='420px'
  422. title='新增品类'
  423. footer=''
  424. className="admin-desc-content">
  425. <Form layout="horizontal" onSubmit={(e)=>{this.addhandleSubmit(e,{})}} id="demand-form">
  426. <Spin spinning={this.state.loading}>
  427. <div className="clearfix">
  428. <FormItem
  429. labelCol={{ span: 7 }}
  430. wrapperCol={{ span: 12 }}
  431. label="品类名称" >
  432. <Input placeholder="品类名称" value={this.state.name} style={{width:'94%'}}
  433. onChange={(e)=>{this.setState({name:e.target.value})}} required="required"/>
  434. <span className="mandatory" style={{color:'red',marginLeft:'5px'}}>*</span>
  435. </FormItem>
  436. </div>
  437. <div className="clearfix">
  438. <FormItem
  439. labelCol={{ span: 7 }}
  440. wrapperCol={{ span: 12 }}
  441. label="所属模块" >
  442. {!this.state.addFirst? <Select value ={this.state.module} onChange={(e)=>{this.setState({module:e})}}>
  443. <Select.Option value='0'>科技服务</Select.Option>
  444. <Select.Option value="1">知识产权服务</Select.Option>
  445. </Select>:<span>{this.state.module?'知识产权服务':'科技服务'}</span>}
  446. </FormItem>
  447. </div>
  448. <div className="clearfix">
  449. <FormItem
  450. labelCol={{ span: 7 }}
  451. wrapperCol={{ span: 12 }}
  452. label="上级品类"
  453. >
  454. <span>{this.state.addFirst?recrdAdd.name:'超级品类'}</span>
  455. </FormItem>
  456. </div>
  457. <FormItem wrapperCol={{ span: 12, offset: 7 }}>
  458. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  459. <Button className="set-submit" type="ghost" onClick={this.handleCancel} style={{marginLeft:'15px'}}>取消</Button>
  460. </FormItem>
  461. </Spin>
  462. </Form >
  463. </Modal>
  464. </div>
  465. <div className="patent-desc">
  466. <Modal maskClosable={false} visible={this.state.editvisible}
  467. onOk={this.checkPatentProcess} onCancel={this.edithandleCancel}
  468. width='600px'
  469. title='编辑品类'
  470. footer=''
  471. className="admin-desc-content">
  472. <Form layout='horizontal' onSubmit={this.edithandleSubmit} id="demand-form">
  473. <Spin spinning={this.state.loading}>
  474. <div className="clearfix">
  475. <FormItem
  476. labelCol={{ span: 7 }}
  477. wrapperCol={{ span: 12 }}
  478. label="品类名称" >
  479. <Input placeholder="组织名称" value={this.state.name}
  480. onChange={(e)=>{this.setState({name:e.target.value})}}/>
  481. </FormItem>
  482. </div>
  483. <div className="clearfix">
  484. <FormItem
  485. labelCol={{ span: 7 }}
  486. wrapperCol={{ span: 12 }}
  487. label="上级品类"
  488. >
  489. <span>{theData.superName?theData.superName:'超级品类'}</span>
  490. </FormItem>
  491. </div>
  492. <div className="clearfix">
  493. <FormItem
  494. labelCol={{ span: 7 }}
  495. wrapperCol={{ span: 12 }}
  496. label="业务品类图标" >
  497. <PicturesWall
  498. fileList={this.getPictureUrl}
  499. pictureUrl={this.state.pictureUrl}
  500. visible={this.props.visible}
  501. />
  502. </FormItem>
  503. </div>
  504. <div className="clearfix">
  505. <FormItem
  506. labelCol={{ span: 7 }}
  507. wrapperCol={{ span: 12 }}
  508. label="品类序号"
  509. >
  510. <span>{theData.sort}</span>
  511. </FormItem>
  512. </div>
  513. <div className="clearfix">
  514. <FormItem
  515. labelCol={{ span: 7 }}
  516. wrapperCol={{ span: 12 }}
  517. label="品类层级"
  518. >
  519. <span>{theData.layerName}</span>
  520. </FormItem>
  521. </div>
  522. <FormItem
  523. labelCol={{ span: 7 }}
  524. wrapperCol={{ span: 12 }}
  525. label="所属模块" >
  526. <span>{theData.module?'知识产权服务':'科技服务'}</span>
  527. </FormItem>
  528. <div className="clearfix">
  529. <FormItem
  530. labelCol={{ span: 7 }}
  531. wrapperCol={{ span: 12 }}
  532. label="品类编号"
  533. >
  534. <span>{theData.number}</span>
  535. </FormItem>
  536. </div>
  537. <div className="clearfix" >
  538. <FormItem
  539. labelCol={{ span: 7 }}
  540. wrapperCol={{ span: 12 }}
  541. label="创建人"
  542. >
  543. <span>超级管理员</span>
  544. </FormItem>
  545. </div>
  546. <div className="clearfix">
  547. <FormItem
  548. labelCol={{ span: 7 }}
  549. wrapperCol={{ span: 12 }}
  550. label="创建时间"
  551. >
  552. <span>{this.state.createTime}</span>
  553. </FormItem>
  554. </div>
  555. <FormItem wrapperCol={{ span: 12, offset: 7 }}>
  556. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  557. <Button className="set-submit" type="ghost" onClick={this.edithandleCancel} style={{marginLeft:'100px'}}>取消</Button>
  558. </FormItem>
  559. </Spin>
  560. </Form >
  561. </Modal>
  562. </div>
  563. </div>
  564. </div>
  565. );
  566. }
  567. }));
  568. export default BusinessCategory;