businessCategory.jsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. import React from 'react';
  2. import $ from 'jquery/src/ajax';
  3. import { Form, Icon, Button, Input, Select, Spin, Table, message, Modal, Upload,Popconfirm } from 'antd';
  4. import {typeModule} from '@/dataDic.js';
  5. import {splitUrl,getTypeModule} from '@/tools.js';
  6. //图片组件
  7. const PicturesWall = React.createClass({
  8. getInitialState() {
  9. return {
  10. previewVisible: false,
  11. previewImage: '',
  12. fileList: [],
  13. tags: []
  14. };
  15. },
  16. handleCancel() {
  17. this.setState({ previewVisible: false });
  18. },
  19. handlePreview(file) {
  20. this.setState({
  21. previewImage: file.url || file.thumbUrl,
  22. previewVisible: true
  23. });
  24. },
  25. handleChange(info) {
  26. let fileList = info.fileList;
  27. this.setState({ fileList });
  28. this.props.fileList(fileList);
  29. },
  30. componentWillReceiveProps(nextProps) {
  31. this.state.fileList = nextProps.pictureUrl;
  32. },
  33. render() {
  34. const { previewVisible, previewImage, fileList } = this.state;
  35. const uploadButton = (
  36. <div>
  37. <Icon type="plus" />
  38. <div className="ant-upload-text">点击上传</div>
  39. </div>
  40. );
  41. return (
  42. <div className="clearfix">
  43. <Upload
  44. action={globalConfig.context + '/api/admin/jtBusiness/uploadPicture'}
  45. data={{ sign: 'jt_business_picture'}}
  46. listType="picture-card"
  47. fileList={fileList}
  48. onPreview={this.handlePreview}
  49. onChange={this.handleChange}
  50. >
  51. {fileList.length >=1 ? null : uploadButton}
  52. </Upload>
  53. <Modal maskClosable={false} visible={previewVisible} footer={null} onCancel={this.handleCancel}>
  54. <img alt="example" style={{ width: '100%' }} src={previewImage} />
  55. </Modal>
  56. </div>
  57. );
  58. }
  59. });
  60. const BusinessCategory=Form.create()(React.createClass({
  61. loadData(pageNo) {
  62. this.state.data = [];
  63. this.setState({
  64. loading: true,
  65. page:pageNo,
  66. });
  67. $.ajax({
  68. method: "get",
  69. dataType: "json",
  70. crossDomain: false,
  71. url: globalConfig.context + '/api/admin/jtBusiness/category/list',
  72. data: {
  73. pageNo: pageNo || 1,
  74. pageSize: this.state.pagination.pageSize,
  75. name:this.state.nameSearch, //品类名称
  76. layer:this.state.layerSearch,//组织层级
  77. },
  78. success: function (data) {
  79. let theArr = [];
  80. if (!data.data || !data.data.list) {
  81. if (data.error && data.error.length) {
  82. message.warning(data.error[0].message);
  83. };
  84. } else {
  85. for (let i = 0; i < data.data.list.length; i++) {
  86. let thisdata = data.data.list[i];
  87. theArr.push({
  88. key: i,
  89. id: thisdata.id,//品类ID
  90. sort:thisdata.sort,//品类序号
  91. number: thisdata.number,//品类编号
  92. module:thisdata.module?thisdata.module.toString():undefined,
  93. name: thisdata.name,//品类名称
  94. layer:thisdata.layer,
  95. superId:thisdata.superId,
  96. layerName: thisdata.layerName,//品类层级
  97. superName: thisdata.superName,//上级品类
  98. });
  99. };
  100. this.state.pagination.current = data.data.pageNo;
  101. this.state.pagination.total = data.data.totalCount;
  102. };
  103. this.setState({
  104. dataSource: theArr,
  105. pagination: this.state.pagination
  106. });
  107. }.bind(this),
  108. }).always(function () {
  109. this.setState({
  110. loading: false
  111. });
  112. }.bind(this));
  113. },
  114. getInitialState() {
  115. return {
  116. searchMore: true,
  117. selectedRowKeys: [],
  118. pictureUrl: [],
  119. selectedRows: [],
  120. loading: false,
  121. pagination: {
  122. defaultCurrent: 1,
  123. defaultPageSize: 10,
  124. showQuickJumper: true,
  125. pageSize: 10,
  126. onChange: function (page) {
  127. this.loadData(page);
  128. this.setState({
  129. selectedRowKeys: [],
  130. })
  131. }.bind(this),
  132. showTotal: function (total) {
  133. return '共' + total + '条数据';
  134. }
  135. },
  136. columns: [
  137. {
  138. title: '品类编号',
  139. dataIndex: 'number',
  140. key: 'number',
  141. }, {
  142. title: '品类名称',
  143. dataIndex: 'name',
  144. key: 'name',
  145. }, {
  146. title: '品类层级',
  147. dataIndex: 'layerName',
  148. key: 'layerName'
  149. }, {
  150. title: '上级品类',
  151. dataIndex: 'superName',
  152. key: 'superName',
  153. render:(text)=>{
  154. return text?text:'超级品类'
  155. }
  156. },{
  157. title:'操作',
  158. dataIndex: 'superName1',
  159. key: 'superName1',
  160. render:(text,recard)=>{
  161. return (
  162. <div>
  163. {recard.layer<2&&<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?recard.module.toString():'undefined'
  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. let rowItem = this.state.selectedRowKeys[0];
  227. let data = this.state.dataSource ||[];
  228. if (data.length) {
  229. deletedIds.push(data[rowItem].id);
  230. }
  231. this.setState({
  232. selectedRowKeys: [],
  233. loading: deletedIds.length > 0
  234. });
  235. $.ajax({
  236. method: "post",
  237. dataType: "json",
  238. crossDomain: false,
  239. url: globalConfig.context + "/api/admin/jtBusiness/category/delete",
  240. data: {
  241. id: deletedIds[0]
  242. }
  243. }).done(function (data) {
  244. if (!data.error.length) {
  245. message.success('删除成功!');
  246. this.setState({
  247. loading: false,
  248. });
  249. } else {
  250. message.warning(data.error[0].message);
  251. };
  252. this.loadData(this.state.page)
  253. }.bind(this));
  254. },
  255. addClick() {
  256. alert(1)
  257. this.state.RowData = {};
  258. this.setState({
  259. visible: true,
  260. addFirst:0,
  261. name:'',
  262. superId:'',
  263. module:"1"
  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?((this.state.recrdAdd.layer)+1):'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. {typeModule.map(item=>{
  447. return <Select.Option key={item.value} value={item.value}>{item.key}</Select.Option>
  448. })}
  449. </Select>:<span>{getTypeModule(recrdAdd.module)}</span>}
  450. </FormItem>
  451. </div>
  452. <div className="clearfix">
  453. <FormItem
  454. labelCol={{ span: 7 }}
  455. wrapperCol={{ span: 12 }}
  456. label="上级品类"
  457. >
  458. <span>{this.state.addFirst?recrdAdd.name:'超级品类'}</span>
  459. </FormItem>
  460. </div>
  461. <FormItem wrapperCol={{ span: 12, offset: 7 }}>
  462. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  463. <Button className="set-submit" type="ghost" onClick={this.handleCancel} style={{marginLeft:'15px'}}>取消</Button>
  464. </FormItem>
  465. </Spin>
  466. </Form >
  467. </Modal>
  468. </div>
  469. <div className="patent-desc">
  470. <Modal maskClosable={false} visible={this.state.editvisible}
  471. onOk={this.checkPatentProcess} onCancel={this.edithandleCancel}
  472. width='600px'
  473. title='编辑品类'
  474. footer=''
  475. className="admin-desc-content">
  476. <Form layout='horizontal' onSubmit={this.edithandleSubmit} id="demand-form">
  477. <Spin spinning={this.state.loading}>
  478. <div className="clearfix">
  479. <FormItem
  480. labelCol={{ span: 7 }}
  481. wrapperCol={{ span: 12 }}
  482. label="品类名称" >
  483. <Input placeholder="组织名称" value={this.state.name}
  484. onChange={(e)=>{this.setState({name:e.target.value})}}/>
  485. </FormItem>
  486. </div>
  487. <div className="clearfix">
  488. <FormItem
  489. labelCol={{ span: 7 }}
  490. wrapperCol={{ span: 12 }}
  491. label="上级品类"
  492. >
  493. <span>{theData.superName?theData.superName:'超级品类'}</span>
  494. </FormItem>
  495. </div>
  496. <div className="clearfix">
  497. <FormItem
  498. labelCol={{ span: 7 }}
  499. wrapperCol={{ span: 12 }}
  500. label="业务品类图标" >
  501. <PicturesWall
  502. fileList={this.getPictureUrl}
  503. pictureUrl={this.state.pictureUrl}
  504. visible={this.props.visible}
  505. />
  506. </FormItem>
  507. </div>
  508. <div className="clearfix">
  509. <FormItem
  510. labelCol={{ span: 7 }}
  511. wrapperCol={{ span: 12 }}
  512. label="品类序号"
  513. >
  514. <span>{theData.sort}</span>
  515. </FormItem>
  516. </div>
  517. <div className="clearfix">
  518. <FormItem
  519. labelCol={{ span: 7 }}
  520. wrapperCol={{ span: 12 }}
  521. label="品类层级"
  522. >
  523. <span>{theData.layerName}</span>
  524. </FormItem>
  525. </div>
  526. <FormItem
  527. labelCol={{ span: 7 }}
  528. wrapperCol={{ span: 12 }}
  529. label="所属模块" >
  530. <span>{getTypeModule(theData.module)}</span>
  531. </FormItem>
  532. <div className="clearfix">
  533. <FormItem
  534. labelCol={{ span: 7 }}
  535. wrapperCol={{ span: 12 }}
  536. label="品类编号"
  537. >
  538. <span>{theData.number}</span>
  539. </FormItem>
  540. </div>
  541. <div className="clearfix" >
  542. <FormItem
  543. labelCol={{ span: 7 }}
  544. wrapperCol={{ span: 12 }}
  545. label="创建人"
  546. >
  547. <span>超级管理员</span>
  548. </FormItem>
  549. </div>
  550. <div className="clearfix">
  551. <FormItem
  552. labelCol={{ span: 7 }}
  553. wrapperCol={{ span: 12 }}
  554. label="创建时间"
  555. >
  556. <span>{this.state.createTime}</span>
  557. </FormItem>
  558. </div>
  559. <FormItem wrapperCol={{ span: 12, offset: 7 }}>
  560. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  561. <Button className="set-submit" type="ghost" onClick={this.edithandleCancel} style={{marginLeft:'100px'}}>取消</Button>
  562. </FormItem>
  563. </Spin>
  564. </Form >
  565. </Modal>
  566. </div>
  567. </div>
  568. </div>
  569. );
  570. }
  571. }));
  572. export default BusinessCategory;