coupon.jsx 13 KB

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