businessCategory.jsx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  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 '../content.less';
  7. import { Form,Radio, Icon, Button, Input, Select, Spin, Table, Switch, message, DatePicker, Modal, Upload,Popconfirm,TimePicker } from 'antd';
  8. import {categoryState} from '../../../dataDic.js';
  9. import {getCategoryState} from '../../../tools.js';
  10. const BusinessCategory=Form.create()(React.createClass({
  11. //搜索功能和初始列表加载
  12. loadData(pageNo, apiUrl) {
  13. this.state.data = [];
  14. this.setState({
  15. loading: true
  16. });
  17. let nameText=this.state.SuperArr;
  18. let superText=(this.state.superId)?nameText[parseInt(this.state.superId)].id:"";
  19. $.ajax({
  20. method: "post",
  21. dataType: "json",
  22. crossDomain: false,
  23. url: globalConfig.context + '/open/api/admin/Varieties/vtList',
  24. data: {
  25. pageNo: pageNo || 1,
  26. pageSize: this.state.pagination.pageSize,
  27. cname:this.state.cname, //品类名称
  28. superId:superText,//上级品类编号
  29. layer:this.state.layer,//组织层级
  30. status:this.state.status,//品类状态
  31. },
  32. success: function (data) {
  33. let theArr = [];
  34. if (!data.data || !data.data.list) {
  35. if (data.error && data.error.length) {
  36. message.warning(data.error[0].message);
  37. };
  38. } else {
  39. for (let i = 0; i < data.data.list.length; i++) {
  40. let thisdata = data.data.list[i];
  41. theArr.push({
  42. key: i,
  43. id: thisdata.id,//品类ID
  44. cid: thisdata.cid,//品类编号
  45. cname: thisdata.cname,//品类名称
  46. layer: thisdata.layer,//品类层级
  47. superName: thisdata.superName,//上级品类
  48. status: thisdata.status,//上级品类状态
  49. });
  50. };
  51. this.state.pagination.current = data.data.pageNo;
  52. this.state.pagination.total = data.data.totalCount;
  53. };
  54. this.setState({
  55. dataSource: theArr,
  56. pagination: this.state.pagination
  57. });
  58. }.bind(this),
  59. }).always(function () {
  60. this.setState({
  61. loading: false
  62. });
  63. }.bind(this));
  64. },
  65. getInitialState() {
  66. return {
  67. searchMore: true,
  68. selectedRowKeys: [],
  69. selectedRows: [],
  70. loading: false,
  71. pagination: {
  72. defaultCurrent: 1,
  73. defaultPageSize: 10,
  74. showQuickJumper: true,
  75. pageSize: 10,
  76. onChange: function (page) {
  77. this.loadData(page);
  78. }.bind(this),
  79. showTotal: function (total) {
  80. return '共' + total + '条数据';
  81. }
  82. },
  83. columns: [
  84. {
  85. title: '品类编号',
  86. dataIndex: 'cid',
  87. key: 'cid',
  88. }, {
  89. title: '品类名称',
  90. dataIndex: 'cname',
  91. key: 'cname',
  92. }, {
  93. title: '品类层级',
  94. dataIndex: 'layer',
  95. key: 'layer',
  96. //render: text => { return getAchievementCategory(text); }
  97. }, {
  98. title: '上级品类',
  99. dataIndex: 'superName',
  100. key: 'superName',
  101. },{
  102. title: '品类状态',
  103. dataIndex: 'status',
  104. key: 'status',
  105. render: text => { return getCategoryState(text) }
  106. }
  107. ],
  108. dataSource: [],
  109. };
  110. },
  111. componentWillMount() {
  112. this.selectSuperId();
  113. },
  114. //获取上级品类
  115. selectSuperId() {
  116. this.state.data = []
  117. $.ajax({
  118. method: "get",
  119. dataType: "json",
  120. crossDomain: false,
  121. url: globalConfig.context + "/open/api/admin/Varieties/getSuperList",
  122. data:{
  123. },
  124. success: function (data) {
  125. console.log(data);
  126. let theArr = [];
  127. let thedata=data.data;
  128. if (!thedata) {
  129. if (data.error && data.error.length) {
  130. message.warning(data.error[0].message);
  131. };
  132. thedata = {};
  133. };
  134. var contactIds=[];
  135. //for (let item in data.data) {
  136. for(var i=0;i<data.data.length;i++){
  137. let theData = data.data[i];
  138. theArr.push(
  139. <Select.Option value={i.toString()} key={theData.cname}>{theData.cname}</Select.Option>
  140. );
  141. };
  142. this.setState({
  143. SuperArr:thedata,
  144. contactsOption: theArr,
  145. orderStatusOptions:data.data,
  146. });
  147. }.bind(this),
  148. }).always(function () {
  149. this.loadData();
  150. this.setState({
  151. loading: false
  152. });
  153. }.bind(this));
  154. },
  155. //整行点击
  156. tableRowClick(record, index) {
  157. this.selectSuperId();
  158. this.state.RowData = record;
  159. this.setState({
  160. editvisible: true,
  161. selectedRowKeys:[],
  162. rowId:record.businessId,
  163. });
  164. $.ajax({
  165. method: "get",
  166. dataType: "json",
  167. crossDomain: false,
  168. url: globalConfig.context +"/open/api/admin/Varieties/detailVarieties" ,
  169. data: {
  170. id: record.id
  171. },
  172. success: function (data) {
  173. let theArr = [];
  174. let thisdata = data;
  175. if (!data) {
  176. if (data.error && data.error.length) {
  177. message.warning(data.error[0].message);
  178. };
  179. } else {
  180. theArr.push({
  181. editId: thisdata.id,//每一条记录的ID
  182. editName:thisdata.name,//组织名称
  183. editManagerId:thisdata.managerId,//负责人
  184. editType:thisdata.type,//组织类型
  185. editStatus:thisdata.status,//组织状态
  186. editSuperId:thisdata.superId,//上级组织
  187. editDepNo: thisdata.depNo,//组织编号
  188. editCreateId:thisdata.createId,//创建人
  189. editTime:thisdata.createTime,//创建时间
  190. editRemarks:thisdata.remarks,//组织职能说明
  191. });
  192. };
  193. this.setState({
  194. editId: thisdata.id,//每一条记录的ID
  195. editName:thisdata.name,//组织名称
  196. editManagerId:thisdata.managerId,//负责人
  197. editType:thisdata.type,//组织类型
  198. editStatus:thisdata.status,//组织状态
  199. editSuperId:thisdata.superId,//上级组织
  200. editDepNo: thisdata.depNo,//组织编号
  201. editCreateId:thisdata.createId,//创建人
  202. editTime:thisdata.createTime,//创建时间
  203. editRemarks: thisdata.remarks,//组织职能说明
  204. editDataSource: theArr,
  205. });
  206. }.bind(this),
  207. }).always(function () {
  208. this.setState({
  209. loading: false
  210. });
  211. }.bind(this));
  212. },
  213. //新增一个品类,保存
  214. addhandleSubmit(e){
  215. e.preventDefault();
  216. if(!this.state.categoryName){
  217. message.warning('请输入品类名称');
  218. return false;
  219. }
  220. if(!this.state.upCategory){
  221. message.warning('请选择上级品类');
  222. return false;
  223. }
  224. this.props.form.validateFields((err, values) => {
  225. if (!err) {
  226. this.setState({
  227. loading: true
  228. });
  229. //上级组织字典
  230. let nameText=this.state.SuperArr;
  231. let superText=nameText[parseInt(this.state.upCategory)].id;
  232. $.ajax({
  233. method: "get",
  234. dataType: "json",
  235. crossDomain: false,
  236. url:globalConfig.context + '/open/api/admin/Varieties/addVarieties',
  237. data:{
  238. cname:this.state.categoryName,//组织名称
  239. superId:superText,//上级组织
  240. }
  241. }).done(function (data) {
  242. this.setState({
  243. loading: false
  244. });
  245. if (!data.error.length) {
  246. message.success('新增品类成功!');
  247. this.handleCancel();
  248. this.loadData();
  249. } else {
  250. message.warning(data.error[0].message);
  251. }
  252. }.bind(this));
  253. }
  254. });
  255. },
  256. //整行删除
  257. delectRow() {
  258. let deletedIds = '';
  259. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  260. let rowItem = this.state.selectedRows[idx];
  261. if (rowItem.id) {
  262. deletedIds=rowItem.id;
  263. };
  264. };
  265. this.setState({
  266. selectedRowKeys: [],
  267. loading: deletedIds.length > 0
  268. });
  269. $.ajax({
  270. method: "get",
  271. dataType: "json",
  272. crossDomain: false,
  273. url: globalConfig.context + "/open/api/admin/Varieties/deleteState",
  274. data: {
  275. id: deletedIds
  276. }
  277. }).done(function (data) {
  278. if (!data.error.length) {
  279. message.success('删除成功!');
  280. this.setState({
  281. loading: false,
  282. });
  283. } else {
  284. message.warning(data.error[0].message);
  285. };
  286. this.loadData();
  287. }.bind(this));
  288. },
  289. //整行停用
  290. blockRow() {
  291. let deletedIds = '';
  292. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  293. let rowItem = this.state.selectedRows[idx];
  294. if (rowItem.id) {
  295. deletedIds=rowItem.id;
  296. };
  297. };
  298. this.setState({
  299. selectedRowKeys: [],
  300. loading: deletedIds.length > 0
  301. });
  302. $.ajax({
  303. method: "get",
  304. dataType: "json",
  305. crossDomain: false,
  306. url: globalConfig.context + "/open/api/admin/Varieties/updateStatus",
  307. data: {
  308. id: deletedIds
  309. }
  310. }).done(function (data) {
  311. if (!data.error.length) {
  312. message.success('该品类已成功停用!');
  313. this.setState({
  314. loading: false,
  315. });
  316. } else {
  317. message.warning(data.error[0].message);
  318. };
  319. this.loadData();
  320. }.bind(this));
  321. },
  322. addClick() {
  323. this.state.RowData = {};
  324. this.setState({
  325. visible: true
  326. });
  327. },
  328. editClick() {
  329. this.state.RowData = {};
  330. this.setState({
  331. editvisible: true
  332. });
  333. },
  334. handleCancel() {
  335. this.setState({ visible: false })
  336. },
  337. edithandleCancel() {
  338. this.setState({ editvisible: false })
  339. },
  340. search() {
  341. this.loadData();
  342. },
  343. reset() {
  344. this.state.cname = '';//品类名称清零
  345. this.state.layer = undefined;//品类层级清零
  346. this.state.status = undefined;//品类状态清零
  347. this.state.superId = undefined;//上级品类清零
  348. this.loadData();
  349. },
  350. searchSwitch() {
  351. this.setState({
  352. searchMore: !this.state.searchMore
  353. });
  354. },
  355. render() {
  356. const FormItem = Form.Item
  357. const rowSelection = {
  358. selectedRowKeys: this.state.selectedRowKeys,
  359. onChange: (selectedRowKeys, selectedRows) => {
  360. this.setState({
  361. selectedRows: selectedRows.slice(-1),
  362. selectedRowKeys: selectedRowKeys.slice(-1)
  363. });
  364. }
  365. };
  366. const formItemLayout = {
  367. labelCol: { span: 8 },
  368. wrapperCol: { span: 14 },
  369. };
  370. const { getFieldDecorator } = this.props.form;
  371. const hasSelected = this.state.selectedRowKeys.length > 0;
  372. const { RangePicker } = DatePicker;
  373. return (
  374. <div className="user-content" >
  375. <div className="content-title">
  376. <div className="user-search">
  377. <Input placeholder="业务品类名称" style={{width:'150px',marginRight:'10px',marginBottom:'10px'}}
  378. value={this.state.cname}
  379. onChange={(e) => { this.setState({ cname: e.target.value }); }} />
  380. <Select placeholder="上级品类"
  381. style={{ width:'200px',marginRight:'10px' }}
  382. value={this.state.superId}
  383. onChange={(e) => { this.setState({ superId: e }) }} notFoundContent="未获取到上级品类列表">
  384. {this.state.contactsOption}
  385. </Select>
  386. <Button type="primary" onClick={this.search} style={{marginRight:'10px'}}>搜索</Button>
  387. <Button onClick={this.reset} style={{marginRight:'10px'}}>重置</Button>
  388. <Popconfirm title="是否删除?" onConfirm={this.delectRow} okText="是" cancelText="否">
  389. <Button style={{ background: "#ea0862", border: "none", color: "#fff",marginRight:'10px' ,marginLeft:'10px'}}
  390. disabled={!hasSelected}
  391. >删除<Icon type="minus" />
  392. </Button>
  393. </Popconfirm>
  394. <Popconfirm title="是否停用?" onConfirm={this.blockRow} okText="是" cancelText="否">
  395. <Button style={{ background: "#ea0862", border: "none", color: "#fff",marginRight:'10px' ,marginLeft:'10px'}}
  396. disabled={!hasSelected}
  397. >停用<Icon type="minus" />
  398. </Button>
  399. </Popconfirm>
  400. <span style={{marginRight:'20px'}}>更多搜索 <Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  401. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {display: 'inline-block'}}>
  402. <Select placeholder="品类层级"
  403. style={{ width:'150px',marginRight:'10px' }}
  404. value={this.state.layer}
  405. onChange={(e) => { this.setState({ layer: e }) }}>
  406. <Select.Option value="1" >一级</Select.Option>
  407. <Select.Option value="2" >二级</Select.Option>
  408. <Select.Option value="3" >三级</Select.Option>
  409. <Select.Option value="4" >四级</Select.Option>
  410. <Select.Option value="5" >五级</Select.Option>
  411. <Select.Option value="6" >六级</Select.Option>
  412. </Select>
  413. <Select placeholder="品类状态"
  414. style={{width:'150px',marginRight:'50px'}}
  415. value={this.state.status}
  416. onChange={(e) => { this.setState({ status: e }) }}>
  417. <Select.Option value="0" >正常</Select.Option>
  418. <Select.Option value="1" >停用</Select.Option>
  419. </Select>
  420. </div>
  421. <Button type="primary" className="addButton" onClick={this.addClick} style={{float:'right',marginRight:'200px'}}>新增品类<Icon type="plus" /></Button>
  422. <Button type="primary" className="addButton" onClick={this.editClick}>编辑品类<Icon type="plus" /></Button>
  423. </div>
  424. <div className="patent-table">
  425. <Spin spinning={this.state.loading}>
  426. <Table columns={this.state.columns}
  427. dataSource={this.state.dataSource}
  428. rowSelection={rowSelection}
  429. pagination={this.state.pagination}
  430. onRowClick={this.tableRowClick} />
  431. </Spin>
  432. </div>
  433. <div className="patent-desc">
  434. <Modal maskClosable={false} visible={this.state.visible}
  435. onOk={this.checkPatentProcess} onCancel={this.handleCancel}
  436. width='400px'
  437. title='新增品类'
  438. footer=''
  439. className="admin-desc-content">
  440. <Form horizontal onSubmit={this.addhandleSubmit} id="demand-form">
  441. <Spin spinning={this.state.loading}>
  442. <div className="clearfix">
  443. <FormItem className="half-item"
  444. labelCol={{ span: 7 }}
  445. wrapperCol={{ span: 12 }}
  446. label="品类名称" >
  447. <Input placeholder="品类名称" value={this.state.categoryName} style={{width:'94%'}}
  448. onChange={(e)=>{this.setState({categoryName:e.target.value})}} required="required"/>
  449. <span className="mandatory" style={{color:'red',marginLeft:'5px'}}>*</span>
  450. </FormItem>
  451. </div>
  452. <div className="clearfix">
  453. <FormItem
  454. labelCol={{ span: 7 }}
  455. wrapperCol={{ span: 12 }}
  456. label="上级品类"
  457. >
  458. <Select placeholder="请选择上级品类" value={this.state.upCategory} onChange={(e)=>{this.setState({upCategory:e})}}
  459. notFoundContent="未获取到上级品类列表" style={{width:'94%'}} required="required">
  460. {this.state.contactsOption}
  461. </Select>
  462. <span className="mandatory" style={{color:'red',marginLeft:'5px'}}>*</span>
  463. </FormItem>
  464. </div>
  465. <FormItem wrapperCol={{ span: 12, offset: 7 }}>
  466. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  467. <Button className="set-submit" type="ghost" onClick={this.handleCancel} style={{marginLeft:'50px'}}>取消</Button>
  468. </FormItem>
  469. </Spin>
  470. </Form >
  471. </Modal>
  472. </div>
  473. <div className="patent-desc">
  474. <Modal maskClosable={false} visible={this.state.editvisible}
  475. onOk={this.checkPatentProcess} onCancel={this.edithandleCancel}
  476. width='600px'
  477. title='编辑品类'
  478. footer=''
  479. className="admin-desc-content">
  480. <Form horizontal onSubmit={this.edithandleSubmit} id="demand-form">
  481. <Spin spinning={this.state.loading}>
  482. <div className="clearfix">
  483. <FormItem className="half-item"
  484. labelCol={{ span: 7 }}
  485. wrapperCol={{ span: 12 }}
  486. label="品类名称" >
  487. <Input placeholder="品类名称" />
  488. </FormItem>
  489. </div>
  490. <div className="clearfix">
  491. <FormItem className="half-item"
  492. labelCol={{ span: 7 }}
  493. wrapperCol={{ span: 12 }}
  494. label="品类状态"
  495. >
  496. <Select placeholder="品类状态">
  497. {
  498. categoryState.map(function (item) {
  499. return <Select.Option key={item.value} >{item.key}</Select.Option>
  500. })
  501. }
  502. </Select>
  503. </FormItem>
  504. </div>
  505. <div className="clearfix">
  506. <FormItem
  507. labelCol={{ span: 7 }}
  508. wrapperCol={{ span: 12 }}
  509. label="上级品类"
  510. >
  511. <Select placeholder="上级品类"
  512. value={this.state.lastName}
  513. onChange={this.hundleName}>
  514. {this.state.orderStatusOption}
  515. </Select>
  516. </FormItem>
  517. </div>
  518. <div className="clearfix">
  519. <FormItem className="half-item"
  520. labelCol={{ span: 7 }}
  521. wrapperCol={{ span: 12 }}
  522. label="品类层级"
  523. >
  524. <span>{}</span>
  525. </FormItem>
  526. </div>
  527. <div className="clearfix">
  528. <FormItem className="half-item"
  529. labelCol={{ span: 7 }}
  530. wrapperCol={{ span: 12 }}
  531. label="品类编号"
  532. >
  533. <span>{}</span>
  534. </FormItem>
  535. </div>
  536. <div className="clearfix" >
  537. <FormItem className="half-item"
  538. labelCol={{ span: 7 }}
  539. wrapperCol={{ span: 12 }}
  540. label="创建人"
  541. >
  542. <span>{}</span>
  543. </FormItem>
  544. </div>
  545. <div className="clearfix">
  546. <FormItem className="half-item"
  547. labelCol={{ span: 7 }}
  548. wrapperCol={{ span: 12 }}
  549. label="创建时间"
  550. >
  551. <span>{}</span>
  552. </FormItem>
  553. </div>
  554. <div className="clearfix">
  555. <FormItem className="half-item"
  556. labelCol={{ span: 7 }}
  557. wrapperCol={{ span: 12 }}
  558. label="更新时间" >
  559. <DatePicker placeholder="更新日期" value={moment(this.state.createYear,'YYYY-MM-DD')} onChange={(time) => {this.setState({createYear: time});}}/>
  560. <TimePicker placeholder="更新时间" value={moment(this.state.creatMent, 'HH:mm:ss')} onChange={(time) => { this.setState({creatMent: time}); }}/>
  561. </FormItem>
  562. </div>
  563. <FormItem wrapperCol={{ span: 12, offset: 7 }}>
  564. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  565. <Button className="set-submit" type="ghost" onClick={this.edithandleCancel} style={{marginLeft:'100px'}}>取消</Button>
  566. </FormItem>
  567. </Spin>
  568. </Form >
  569. </Modal>
  570. </div>
  571. </div>
  572. </div>
  573. );
  574. }
  575. }));
  576. export default BusinessCategory;