businessCategory.jsx 23 KB

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