coupon.jsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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. //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 + "/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 + "/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. this.loadData(this.state.page);
  221. } else {
  222. message.warning(data.error[0].message);
  223. };
  224. }.bind(this));
  225. },
  226. addClick() {
  227. this.state.RowData = {};
  228. this.setState({
  229. newName:'',
  230. source:undefined,
  231. money:'',
  232. durationDay:'',
  233. visitModul: true
  234. });
  235. },
  236. closeDesc(e, s) {
  237. this.state.showDesc = e;
  238. if (s) {
  239. this.loadData(this.state.page);
  240. };
  241. },
  242. //详情打开
  243. visitOk(e) {
  244. this.setState({
  245. visitModul: false
  246. });
  247. },
  248. //详情关闭
  249. visitCancel(e) {
  250. this.state.fileList = [];
  251. this.setState({
  252. visitModul: false,
  253. });
  254. },
  255. search() {
  256. this.loadData();
  257. },
  258. reset() {
  259. this.state.name = '';
  260. this.loadData();
  261. },
  262. searchSwitch() {
  263. this.setState({
  264. searchMore: !this.state.searchMore
  265. });
  266. },
  267. render() {
  268. const rowSelection = {
  269. selectedRowKeys: this.state.selectedRowKeys,
  270. onChange: (selectedRowKeys, selectedRows) => {
  271. this.setState({
  272. selectedRows: selectedRows.slice(-1),
  273. selectedRowKeys: selectedRowKeys.slice(-1)
  274. });
  275. }
  276. };
  277. const FormItem = Form.Item;
  278. const { RangePicker } = DatePicker;
  279. const hasSelect = this.state.selectedRowKeys.length;
  280. const formItemLayout = {
  281. labelCol: { span: 6 },
  282. wrapperCol: { span: 14 },
  283. };
  284. const hasSelected = this.state.selectedRowKeys.length > 0;
  285. return (
  286. <div className="user-content" >
  287. <div className="content-title">
  288. <span>券面管理</span>
  289. </div>
  290. <div className="user-search">
  291. <Button type="primary" onClick={this.addClick} style={{float:'right'}}>新增通用劵<Icon type="plus" /></Button>
  292. <Input placeholder="劵面名称"
  293. value={this.state.name}
  294. onChange={(e) => { this.setState({ name: e.target.value }); }} />
  295. <Button type="primary" onClick={this.search}>搜索</Button>
  296. <Button onClick={this.reset}>重置</Button>
  297. <Button type="primary" onClick={this.block} disabled={!hasSelected}>停用<Icon type="plus" /></Button>
  298. </div>
  299. <div className="patent-table">
  300. <Spin spinning={this.state.loading}>
  301. <Table columns={this.state.columns}
  302. dataSource={this.state.dataSource}
  303. rowSelection={rowSelection}
  304. pagination={this.state.pagination}
  305. onRowClick={this.tableRowClick} />
  306. </Spin>
  307. </div>
  308. <NewDesc
  309. data={this.state.RowData}
  310. showDesc={this.state.showDesc}
  311. closeDesc={this.closeDesc} />
  312. <Modal
  313. className="customeDetails"
  314. footer=''
  315. title="新增通用券"
  316. width='400px'
  317. visible={this.state.visitModul}
  318. onOk={this.visitOk}
  319. onCancel={this.visitCancel}
  320. >
  321. <Form layout="horizontal" onSubmit={this.newSubmit} id="demand-form">
  322. <Spin spinning={this.state.loading}>
  323. <div className="clearfix" >
  324. <FormItem
  325. {...formItemLayout}
  326. label={<span><strong style={{color:'#f00'}}> * </strong>劵面名称</span>}
  327. >
  328. <Input placeholder="券面名称" value={this.state.newName} onChange={(e) => {
  329. this.setState({ newName: e.target.value }) }} />
  330. </FormItem>
  331. <FormItem
  332. {...formItemLayout}
  333. label={<span><strong style={{color:'#f00'}}> * </strong>优惠券来源</span>}
  334. >
  335. <Select placeholder="优惠券来源" value={this.state.source}
  336. onChange={(e)=>{this.setState({source:e})}}>
  337. {
  338. couponCome.map(function (item) {
  339. return <Select.Option key={item.value} >{item.key}</Select.Option>
  340. })
  341. }
  342. </Select>
  343. </FormItem>
  344. <FormItem
  345. {...formItemLayout}
  346. label={<span><strong style={{color:'#f00'}}> * </strong>面额</span>}
  347. >
  348. <InputNumber min={0}
  349. formatter={(value)=>value}
  350. parser={(val)=>parseInt(val)||0}
  351. max={999999} step={0} placeholder="面额" value={this.state.money} onChange={(e) => {
  352. this.setState({ money: e }) }} /> 元
  353. </FormItem>
  354. <FormItem
  355. {...formItemLayout}
  356. label={<span><strong style={{color:'#f00'}}> * </strong>使用期限</span>}
  357. >
  358. <InputNumber min={0} max={9999}
  359. formatter={(value)=>value}
  360. parser={(val)=>parseInt(val)||0}
  361. step={0} placeholder="使用期限" value={this.state.durationDay} onChange={(e) => {
  362. this.setState({ durationDay: e }) }} /> 天
  363. </FormItem>
  364. </div>
  365. <Button className="setSubmit" type="primary" htmlType="submit" style={{marginLeft:'92px'}}>保存</Button>
  366. <Button type="ghost" onClick={this.visitCancel} style={{marginLeft:'40px',marginBottom:20}}>取消</Button>
  367. </Spin>
  368. </Form>
  369. </Modal>
  370. </div>
  371. );
  372. }
  373. });
  374. export default DemandList;