businessCategory.jsx 21 KB

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