coupon.jsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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/admin/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. submission(record){
  122. this.setState({
  123. loading:true
  124. });
  125. $.ajax({
  126. method: "get",
  127. dataType: "json",
  128. crossDomain: false,
  129. url: globalConfig.context + "/api/admin/message/sendMessage",
  130. data: {
  131. messageId:record.id,
  132. }
  133. }).done(function (data) {
  134. if (!data.error.length) {
  135. message.success('推送成功.');
  136. this.setState({
  137. loading: false,
  138. });
  139. this.loadData(this.state.page)
  140. } else {
  141. message.warning(data.error[0].message);
  142. };
  143. }.bind(this));
  144. },
  145. //抵用券停用
  146. block(){
  147. let id;
  148. for(let idx = 0; idx < this.state.selectedRows.length; idx++) {
  149. let rowItem = this.state.selectedRows[idx];
  150. if(rowItem.id) {
  151. id=rowItem.id;
  152. };
  153. };
  154. this.setState({
  155. loading:true
  156. });
  157. $.ajax({
  158. method: "post",
  159. dataType: "json",
  160. crossDomain: false,
  161. url: globalConfig.context + "/open/api/admin/voucher/update",
  162. data: {
  163. id:id,
  164. activeState:"0"
  165. }
  166. }).done(function (data) {
  167. if (!data.error.length) {
  168. message.success('该劵已停用');
  169. this.loadData(this.state.page)
  170. } else {
  171. message.warning(data.error[0].message);
  172. };
  173. this.setState({
  174. loading: false,
  175. });
  176. }.bind(this));
  177. },
  178. //进入页面
  179. componentWillMount() {
  180. this.loadData();
  181. },
  182. //新增抵用券
  183. newSubmit(e) {
  184. e.preventDefault();
  185. if(!this.state.newName) {
  186. message.warning('请填写券面名称');
  187. return false;
  188. };
  189. if(!this.state.source) {
  190. message.warning('请确认券的来源');
  191. return false;
  192. };
  193. if(!this.state.money) {
  194. message.warning('请填写券面金额');
  195. return false;
  196. };
  197. if(!this.state.durationDay) {
  198. message.warning('请填写使用期限');
  199. return false;
  200. };
  201. $.ajax({
  202. method: "POST",
  203. dataType: "json",
  204. crossDomain: false,
  205. url: globalConfig.context + "/open/api/admin/voucher/save",
  206. data: {
  207. name:this.state.newName,//抵用券名称
  208. source:this.state.source,//抵用券来源
  209. money:this.state.money,//抵用券面额
  210. durationDay:this.state.durationDay,//抵用券使用期限
  211. limitUse:0,//是否限定,在这里固定传0
  212. }
  213. }).done(function (data) {
  214. if (!data.error.length) {
  215. message.success('新增成功!');
  216. this.setState({
  217. loading: false,
  218. visitModul:false
  219. });
  220. // if(this.state.pagination.total%10==1){
  221. // this.loadData((this.state.page)-1);
  222. // }else{
  223. this.loadData(this.state.page);
  224. // }
  225. } else {
  226. message.warning(data.error[0].message);
  227. };
  228. }.bind(this));
  229. },
  230. //点击整行
  231. // tableRowClick(record, index) {
  232. // this.state.RowData = record;
  233. // this.setState({
  234. // visitModul: true
  235. // });
  236. // },
  237. addClick() {
  238. this.state.RowData = {};
  239. this.setState({
  240. visitModul: true
  241. });
  242. },
  243. closeDesc(e, s) {
  244. this.state.showDesc = e;
  245. if (s) {
  246. this.loadData(this.state.page);
  247. };
  248. },
  249. //详情打开
  250. visitOk(e) {
  251. this.setState({
  252. visitModul: false
  253. });
  254. },
  255. //详情关闭
  256. visitCancel(e) {
  257. this.state.fileList = [];
  258. this.setState({
  259. visitModul: false,
  260. });
  261. },
  262. search() {
  263. this.loadData();
  264. },
  265. reset() {
  266. this.state.name = '';
  267. this.loadData();
  268. },
  269. searchSwitch() {
  270. this.setState({
  271. searchMore: !this.state.searchMore
  272. });
  273. },
  274. render() {
  275. const rowSelection = {
  276. selectedRowKeys: this.state.selectedRowKeys,
  277. onChange: (selectedRowKeys, selectedRows) => {
  278. this.setState({
  279. selectedRows: selectedRows.slice(-1),
  280. selectedRowKeys: selectedRowKeys.slice(-1)
  281. });
  282. }
  283. };
  284. const FormItem = Form.Item;
  285. const { RangePicker } = DatePicker;
  286. const hasSelect = this.state.selectedRowKeys.length;
  287. const formItemLayout = {
  288. labelCol: { span: 6 },
  289. wrapperCol: { span: 14 },
  290. };
  291. const hasSelected = this.state.selectedRowKeys.length > 0;
  292. return (
  293. <div className="user-content" >
  294. <div className="content-title">
  295. <span>通用券管理</span>
  296. </div>
  297. <div className="user-search">
  298. <Button type="primary" onClick={this.addClick} style={{float:'right'}}>新增通用劵<Icon type="plus" /></Button>
  299. <Input placeholder="劵面名称"
  300. value={this.state.name}
  301. onChange={(e) => { this.setState({ name: e.target.value }); }} />
  302. <Button type="primary" onClick={this.search}>搜索</Button>
  303. <Button onClick={this.reset}>重置</Button>
  304. <Button type="primary" onClick={this.block} disabled={!hasSelected}>停用<Icon type="plus" /></Button>
  305. </div>
  306. <div className="patent-table">
  307. <Spin spinning={this.state.loading}>
  308. <Table columns={this.state.columns}
  309. dataSource={this.state.dataSource}
  310. rowSelection={rowSelection}
  311. pagination={this.state.pagination}
  312. onRowClick={this.tableRowClick} />
  313. </Spin>
  314. </div>
  315. <NewDesc
  316. data={this.state.RowData}
  317. showDesc={this.state.showDesc}
  318. closeDesc={this.closeDesc} />
  319. <Modal
  320. className="customeDetails"
  321. footer=''
  322. title="新增抵用券"
  323. width='600px'
  324. visible={this.state.visitModul}
  325. onOk={this.visitOk}
  326. onCancel={this.visitCancel}
  327. >
  328. <Form layout="horizontal" onSubmit={this.newSubmit} id="demand-form">
  329. <Spin spinning={this.state.loading}>
  330. <div className="clearfix" >
  331. <FormItem
  332. {...formItemLayout}
  333. label="劵面名称"
  334. >
  335. <Input placeholder="券面名称" value={this.state.newName} onChange={(e) => {
  336. this.setState({ newName: e.target.value }) }} />
  337. </FormItem>
  338. <FormItem
  339. {...formItemLayout}
  340. label="优惠券来源"
  341. >
  342. <Select placeholder="优惠券来源" value={this.state.source}
  343. onChange={(e)=>{this.setState({source:e})}}>
  344. {
  345. couponCome.map(function (item) {
  346. return <Select.Option key={item.value} >{item.key}</Select.Option>
  347. })
  348. }
  349. </Select>
  350. </FormItem>
  351. <FormItem
  352. {...formItemLayout}
  353. label="面额"
  354. >
  355. <Input placeholder="面额" style={{width:'95%'}} value={this.state.money} onChange={(e) => {
  356. this.setState({ money: e.target.value }) }} /> 元
  357. </FormItem>
  358. <FormItem
  359. {...formItemLayout}
  360. label="使用期限"
  361. >
  362. <Input placeholder="使用期限" style={{width:'95%'}} value={this.state.durationDay} onChange={(e) => {
  363. this.setState({ durationDay: e.target.value }) }} /> 天
  364. </FormItem>
  365. </div>
  366. <Button className="setSubmit" type="primary" htmlType="submit" style={{marginLeft:'150px'}}>保存</Button>
  367. <Button type="ghost" onClick={this.visitCancel} style={{marginLeft:'100px'}}>取消</Button>
  368. </Spin>
  369. </Form>
  370. </Modal>
  371. </div>
  372. );
  373. }
  374. });
  375. export default DemandList;