vouchers.jsx 14 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/messageOut/selectContent';
  6. import '@/account/demand/techDemand.less';
  7. import '@/administration/news/news.less';
  8. import {getCouponCome,getCouponAuthState} from '@/tools.js';
  9. const DemandList = React.createClass({
  10. loadData(pageNo) {
  11. this.setState({
  12. selectedRowKeys:[],
  13. page:pageNo,
  14. loading: true,
  15. visibleSel:false,
  16. selData:{}
  17. });
  18. $.ajax({
  19. method: "get",
  20. dataType: "json",
  21. crossDomain: false,
  22. url: globalConfig.context + "/api/user/voucher/selectList",
  23. data: {
  24. pageNo: pageNo || 1,
  25. pageSize: this.state.pagination.pageSize,
  26. name: this.state.nameSearch, //券面名称
  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. data:{},
  72. selectedRowKeys: [],
  73. selectedRows: [],
  74. loading: false,
  75. pagination: {
  76. defaultCurrent: 1,
  77. defaultPageSize: 10,
  78. showQuickJumper: true,
  79. pageSize: 10,
  80. onChange: function (page) {
  81. this.loadData(page);
  82. }.bind(this),
  83. showTotal: function (total) {
  84. return '共' + total + '条数据';
  85. }
  86. },
  87. columns: [
  88. {
  89. title: '劵面名称',
  90. dataIndex: 'name',
  91. key: 'name',
  92. render: text => { return text&&text.length>16?text.substr(0,16)+'...':text}
  93. },
  94. {
  95. title: '数量(枚)',
  96. dataIndex: 'money',
  97. key: 'money',
  98. },
  99. {
  100. title: '抵用券有效期(天)',
  101. dataIndex: 'durationDay',
  102. key: 'durationDay'
  103. },
  104. {
  105. title: '抵用券来源',
  106. dataIndex: 'source',
  107. key: 'source',
  108. render: text => { return getCouponCome(text); }
  109. },
  110. {
  111. title: '抵用券状态',
  112. dataIndex: 'activeState',
  113. key: 'activeState',
  114. render: text => { return getCouponAuthState(text); }
  115. }
  116. ],
  117. dataSource: [],
  118. searchTime: [,]
  119. };
  120. },
  121. //抵用券停用
  122. block(){
  123. let id;
  124. for(let idx = 0; idx < this.state.selectedRows.length; idx++) {
  125. let rowItem = this.state.selectedRows[idx];
  126. if(rowItem.id) {
  127. id=rowItem.id;
  128. };
  129. };
  130. this.setState({
  131. loading:true
  132. });
  133. $.ajax({
  134. method: "post",
  135. dataType: "json",
  136. crossDomain: false,
  137. url: globalConfig.context + "/api/user/voucher/update",
  138. data: {
  139. id:id,
  140. activeState:"0"
  141. }
  142. }).done(function (data) {
  143. if (!data.error.length) {
  144. message.success('该劵已停用');
  145. this.loadData(this.state.page)
  146. } else {
  147. message.warning(data.error[0].message);
  148. };
  149. this.setState({
  150. loading: false,
  151. });
  152. }.bind(this));
  153. },
  154. //进入页面
  155. componentWillMount() {
  156. this.loadData();
  157. },
  158. selContent(){
  159. this.setState({
  160. visibleSel:true,
  161. selData:{
  162. url:'/portal/service/jtProject/list',
  163. privateProject:0,
  164. auditStatus:2
  165. }
  166. })
  167. },
  168. //新增抵用券
  169. newSubmit(e) {
  170. e.preventDefault();
  171. this.props.form.validateFields((err, values) => {
  172. if(!err){
  173. if(!this.state.objTitle){
  174. message.warning('请选择关联项目!');
  175. return;
  176. }
  177. if(!this.state.money){
  178. message.warning('请输入金额!');
  179. return;
  180. }
  181. if(!this.state.durationDay){
  182. message.warning('请输入使用期限!');
  183. return;
  184. }
  185. $.ajax({
  186. method: "POST",
  187. dataType: "json",
  188. crossDomain: false,
  189. url: globalConfig.context + "/api/user/voucher/save",
  190. data: {
  191. name:values.name,//抵用券名称
  192. source:4,//抵用券来源
  193. money:this.state.money,//抵用券面额
  194. durationDay:this.state.durationDay,//抵用券使用期限
  195. limitUse:1,//是否限定,在这里固定传0
  196. limitProjectId:this.state.objData.id
  197. }
  198. }).done(function (data) {
  199. if (!data.error.length) {
  200. message.success('新增成功!');
  201. this.setState({
  202. loading: false,
  203. visitModul:false
  204. });
  205. this.loadData(this.state.page);
  206. } else {
  207. message.warning(data.error[0].message);
  208. };
  209. }.bind(this));
  210. }
  211. })
  212. },
  213. addClick() {
  214. this.props.form.resetFields();
  215. this.setState({
  216. money:'',
  217. durationDay:'',
  218. visitModul: true,
  219. limitProjectId:'',
  220. objTitle:'',
  221. });
  222. },
  223. closeDesc(e, s) {
  224. this.state.showDesc = e;
  225. if (s) {
  226. this.loadData(this.state.page);
  227. };
  228. },
  229. //详情打开
  230. visitOk(e) {
  231. this.setState({
  232. visitModul: false
  233. });
  234. },
  235. //详情关闭
  236. visitCancel(e) {
  237. this.setState({
  238. visitModul: false,
  239. });
  240. },
  241. search() {
  242. this.loadData();
  243. },
  244. reset() {
  245. this.state.nameSearch = '';
  246. this.loadData();
  247. },
  248. searchSwitch() {
  249. this.setState({
  250. searchMore: !this.state.searchMore
  251. });
  252. },
  253. //搜索渲染值
  254. visFun(state,data){
  255. if(state){
  256. this.setState({
  257. visibleSel:false,
  258. objData:data,
  259. objTitle:data.name
  260. });
  261. }else{
  262. this.setState({
  263. visibleSel:false,
  264. })
  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 { getFieldDecorator } = this.props.form;
  278. const FormItem = Form.Item;
  279. const formItemLayout = {
  280. labelCol: { span: 6 },
  281. wrapperCol: { span: 12 },
  282. };
  283. let theData = this.state.data||{};
  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.nameSearch}
  294. onChange={(e) => { this.setState({ nameSearch: 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.selData}
  310. visible={this.state.visibleSel}
  311. visFun={this.visFun.bind(this)} />
  312. <Modal
  313. className="customeDetails"
  314. footer=''
  315. title="新增抵用券"
  316. width='600px'
  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 {...formItemLayout} label="劵面名称">
  325. {getFieldDecorator('name', {
  326. rules: [ { required: true, message: '此项为必填项!' } ],
  327. initialValue: theData.name
  328. })(<Input placeholder="请输入劵面名称." maxLength={200}/>)}
  329. </FormItem>
  330. <FormItem
  331. {...formItemLayout}
  332. label={<span><strong style={{color:'#f00'}}> * </strong>关联项目</span>}
  333. >
  334. <span>{this.state.objTitle}</span>
  335. <Button
  336. onClick={this.selContent.bind(this)}
  337. type="primary"
  338. style={{marginLeft:10}}>搜索</Button>
  339. </FormItem>
  340. <div className="clearfix">
  341. <FormItem
  342. {...formItemLayout}
  343. label={<span><strong style={{color:'#f00'}}> * </strong>数量</span>}>
  344. <div><InputNumber value={this.state.money}
  345. formatter={(value)=>value}
  346. parser={(val)=>parseInt(val)||0}
  347. onChange={(e)=>{this.setState({money:e})}} min={0} max={999999} step={0
  348. } placeholder="输入数量."/><span> 枚</span></div>
  349. </FormItem>
  350. <FormItem
  351. {...formItemLayout}
  352. label={<span><strong style={{color:'#f00'}}> * </strong>使用期限</span>}>
  353. <div><InputNumber value={this.state.durationDay}
  354. onChange={(e)=>{this.setState({durationDay:e})}}
  355. min={0} max={9999} step={0}
  356. formatter={(value)=>value}
  357. parser={(val)=>parseInt(val)||0}
  358. placeholder="输入天数"/><span> 天</span></div>
  359. </FormItem>
  360. </div>
  361. </div>
  362. <Button className="setSubmit" type="primary" htmlType="submit" style={{marginLeft:140,marginBottom:20}}>保存</Button>
  363. <Button type="ghost" onClick={this.visitCancel} style={{marginLeft:50}}>取消</Button>
  364. </Spin>
  365. </Form>
  366. </Modal>
  367. </div>
  368. );
  369. }
  370. });
  371. export default Form.create()(DemandList);