vouchers.jsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. import React from 'react';
  2. import { Icon, Button, Input, Select, Spin, Table, message, DatePicker ,Modal,Form} from 'antd';
  3. import $ from 'jquery/src/ajax';
  4. import moment from 'moment';
  5. import NewDesc from '@/administration/messagePush/messageIn/messageDesc';
  6. import '@/account/demand/techDemand.less';
  7. import '@/administration/news/news.less';
  8. import {getCouponCome,getCouponAuthState} from '@/tools.js';
  9. import {couponCome} from '@/dataDic.js';
  10. const DemandList = React.createClass({
  11. loadData(pageNo) {
  12. this.state.data = [];
  13. this.setState({
  14. selectedRowKeys:[],
  15. page:pageNo,
  16. loading: true
  17. });
  18. $.ajax({
  19. method: "get",
  20. dataType: "json",
  21. crossDomain: false,
  22. url: globalConfig.context + "/open/api/user/voucher/selectList",
  23. data: {
  24. pageNo: pageNo || 1,
  25. pageSize: this.state.pagination.pageSize,
  26. name: this.state.name, //券面名称
  27. },
  28. success: function (data) {
  29. let theArr = [];
  30. if (!data.data || !data.data.list) {
  31. if (data.error && data.error.length) {
  32. message.warning(data.error[0].message);
  33. };
  34. } else {
  35. for (let i = 0; i < data.data.list.length; i++) {
  36. let thisdata = data.data.list[i];
  37. theArr.push({
  38. key: i,
  39. id: thisdata.id,
  40. name: thisdata.name,//券面名称
  41. source:thisdata.source,//券面来源
  42. money:thisdata.money,//面额
  43. durationDay: thisdata.durationDay, //活动期限
  44. activeState: thisdata.activeState, //抵用券状态
  45. });
  46. };
  47. };
  48. this.state.pagination.current = data.data.pageNo;
  49. this.state.pagination.total = data.data.totalCount;
  50. if(data.data&&data.data.list&&!data.data.list.length){
  51. this.state.pagination.current=0;
  52. this.state.pagination.total=0;
  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. validityPeriodDate: [],
  69. releaseDate: [],
  70. visitModul:false,
  71. selectedRowKeys: [],
  72. selectedRows: [],
  73. loading: false,
  74. pagination: {
  75. defaultCurrent: 1,
  76. defaultPageSize: 10,
  77. showQuickJumper: true,
  78. pageSize: 10,
  79. onChange: function (page) {
  80. this.loadData(page);
  81. }.bind(this),
  82. showTotal: function (total) {
  83. return '共' + total + '条数据';
  84. }
  85. },
  86. columns: [
  87. {
  88. title: '劵面名称',
  89. dataIndex: 'name',
  90. key: 'name',
  91. },
  92. {
  93. title: '面额(元)',
  94. dataIndex: 'money',
  95. key: 'money',
  96. //render: text => { return text&&text.length>16?text.substr(0,16)+'...':text}
  97. },
  98. {
  99. title: '抵用券有效期(天)',
  100. dataIndex: 'durationDay',
  101. key: 'durationDay'
  102. },
  103. {
  104. title: '抵用券来源',
  105. dataIndex: 'source',
  106. key: 'source',
  107. render: text => { return getCouponCome(text); }
  108. },
  109. {
  110. title: '抵用券状态',
  111. dataIndex: 'activeState',
  112. key: 'activeState',
  113. render: text => { return getCouponAuthState(text); }
  114. }
  115. ],
  116. dataSource: [],
  117. searchTime: [,]
  118. };
  119. },
  120. //抵用券停用
  121. block(){
  122. let id;
  123. for(let idx = 0; idx < this.state.selectedRows.length; idx++) {
  124. let rowItem = this.state.selectedRows[idx];
  125. if(rowItem.id) {
  126. id=rowItem.id;
  127. };
  128. };
  129. this.setState({
  130. loading:true
  131. });
  132. $.ajax({
  133. method: "post",
  134. dataType: "json",
  135. crossDomain: false,
  136. url: globalConfig.context + "/open/api/user/voucher/update",
  137. data: {
  138. id:id,
  139. activeState:"0"
  140. }
  141. }).done(function (data) {
  142. if (!data.error.length) {
  143. message.success('该劵已停用');
  144. this.loadData(this.state.page)
  145. } else {
  146. message.warning(data.error[0].message);
  147. };
  148. this.setState({
  149. loading: false,
  150. });
  151. }.bind(this));
  152. },
  153. //进入页面
  154. componentWillMount() {
  155. this.loadData();
  156. },
  157. //新增抵用券
  158. newSubmit(e) {
  159. e.preventDefault();
  160. if(!this.state.newName) {
  161. message.warning('请填写券面名称');
  162. return false;
  163. };
  164. if(!this.state.source) {
  165. message.warning('请确认券的来源');
  166. return false;
  167. };
  168. if(!this.state.money) {
  169. message.warning('请填写券面金额');
  170. return false;
  171. };
  172. if(!this.state.durationDay) {
  173. message.warning('请填写使用期限');
  174. return false;
  175. };
  176. $.ajax({
  177. method: "POST",
  178. dataType: "json",
  179. crossDomain: false,
  180. url: globalConfig.context + "/open/api/user/voucher/save",
  181. data: {
  182. name:this.state.newName,//抵用券名称
  183. source:this.state.source,//抵用券来源
  184. money:this.state.money,//抵用券面额
  185. durationDay:this.state.durationDay,//抵用券使用期限
  186. limitUse:0,//是否限定,在这里固定传0
  187. }
  188. }).done(function (data) {
  189. if (!data.error.length) {
  190. message.success('新增成功!');
  191. this.setState({
  192. loading: false,
  193. visitModul:false
  194. });
  195. // if(this.state.pagination.total%10==1){
  196. // this.loadData((this.state.page)-1);
  197. // }else{
  198. this.loadData(this.state.page);
  199. // }
  200. } else {
  201. message.warning(data.error[0].message);
  202. };
  203. }.bind(this));
  204. },
  205. //点击整行
  206. // tableRowClick(record, index) {
  207. // this.state.RowData = record;
  208. // this.setState({
  209. // visitModul: true
  210. // });
  211. // },
  212. addClick() {
  213. this.state.RowData = {};
  214. this.setState({
  215. visitModul: true
  216. });
  217. },
  218. closeDesc(e, s) {
  219. this.state.showDesc = e;
  220. if (s) {
  221. this.loadData(this.state.page);
  222. };
  223. },
  224. //详情打开
  225. visitOk(e) {
  226. this.setState({
  227. visitModul: false
  228. });
  229. },
  230. //详情关闭
  231. visitCancel(e) {
  232. this.state.fileList = [];
  233. this.setState({
  234. visitModul: false,
  235. });
  236. },
  237. search() {
  238. this.loadData();
  239. },
  240. reset() {
  241. this.state.name = '';
  242. this.loadData();
  243. },
  244. searchSwitch() {
  245. this.setState({
  246. searchMore: !this.state.searchMore
  247. });
  248. },
  249. render() {
  250. const rowSelection = {
  251. selectedRowKeys: this.state.selectedRowKeys,
  252. onChange: (selectedRowKeys, selectedRows) => {
  253. this.setState({
  254. selectedRows: selectedRows.slice(-1),
  255. selectedRowKeys: selectedRowKeys.slice(-1)
  256. });
  257. }
  258. };
  259. const FormItem = Form.Item;
  260. const { RangePicker } = DatePicker;
  261. const hasSelect = this.state.selectedRowKeys.length;
  262. const formItemLayout = {
  263. labelCol: { span: 6 },
  264. wrapperCol: { span: 14 },
  265. };
  266. const hasSelected = this.state.selectedRowKeys.length > 0;
  267. return (
  268. <div className="user-content" >
  269. <div className="content-title">
  270. <span>通用券管理</span>
  271. </div>
  272. <div className="user-search">
  273. <Button type="primary" onClick={this.addClick} style={{float:'right'}}>新增通用劵<Icon type="plus" /></Button>
  274. <Input placeholder="劵面名称"
  275. value={this.state.name}
  276. onChange={(e) => { this.setState({ name: e.target.value }); }} />
  277. <Button type="primary" onClick={this.search}>搜索</Button>
  278. <Button onClick={this.reset}>重置</Button>
  279. <Button type="primary" onClick={this.block} disabled={!hasSelected}>停用<Icon type="plus" /></Button>
  280. </div>
  281. <div className="patent-table">
  282. <Spin spinning={this.state.loading}>
  283. <Table columns={this.state.columns}
  284. dataSource={this.state.dataSource}
  285. rowSelection={rowSelection}
  286. pagination={this.state.pagination}
  287. onRowClick={this.tableRowClick} />
  288. </Spin>
  289. </div>
  290. <NewDesc
  291. data={this.state.RowData}
  292. showDesc={this.state.showDesc}
  293. closeDesc={this.closeDesc} />
  294. <Modal
  295. className="customeDetails"
  296. footer=''
  297. title="新增抵用券"
  298. width='600px'
  299. visible={this.state.visitModul}
  300. onOk={this.visitOk}
  301. onCancel={this.visitCancel}
  302. >
  303. <Form layout="horizontal" onSubmit={this.newSubmit} id="demand-form">
  304. <Spin spinning={this.state.loading}>
  305. <div className="clearfix" >
  306. <FormItem
  307. {...formItemLayout}
  308. label="劵面名称"
  309. >
  310. <Input placeholder="券面名称" value={this.state.newName} onChange={(e) => {
  311. this.setState({ newName: e.target.value }) }} />
  312. </FormItem>
  313. <FormItem
  314. {...formItemLayout}
  315. label="关联项目"
  316. >
  317. <Input placeholder="请输入关联项目关键字" value={this.state.source} style={{width:'80%'}} onChange={(e) => {
  318. this.setState({ source: e.target.value }) }} />
  319. <span>搜索</span>
  320. </FormItem>
  321. <FormItem
  322. {...formItemLayout}
  323. label="面额"
  324. >
  325. <Input placeholder="面额" style={{width:'95%'}} value={this.state.money} onChange={(e) => {
  326. this.setState({ money: e.target.value }) }} /> 元
  327. </FormItem>
  328. <FormItem
  329. {...formItemLayout}
  330. label="使用期限"
  331. >
  332. <Input placeholder="使用期限" style={{width:'95%'}} value={this.state.durationDay} onChange={(e) => {
  333. this.setState({ durationDay: e.target.value }) }} /> 天
  334. </FormItem>
  335. </div>
  336. <Button className="setSubmit" type="primary" htmlType="submit" style={{marginLeft:'150px'}}>保存</Button>
  337. <Button type="ghost" onClick={this.visitCancel} style={{marginLeft:'100px'}}>取消</Button>
  338. </Spin>
  339. </Form>
  340. </Modal>
  341. </div>
  342. );
  343. }
  344. });
  345. export default DemandList;