memberList.jsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. import React from 'react';
  2. import $ from 'jquery/src/ajax';
  3. import 'react-quill/dist/quill.bubble.css';
  4. import {Form,Icon,Button,Input,Select,Spin,Table,message,DatePicker,Modal,Upload,Popconfirm,Cascader,InputNumber,Radio} from 'antd';
  5. import {areaSelect, getProvince} from '@/NewDicProvinceList';//省市区
  6. import { getGameState, splitUrl, getprovince, getStatuslist, getLvl} from '@/tools.js';
  7. //主体
  8. const MemberList = Form.create()(
  9. React.createClass({
  10. loadData(pageNo) {
  11. this.state.data = [];
  12. this.setState({
  13. loading: true,
  14. page: pageNo
  15. });
  16. $.ajax({
  17. method: 'get',
  18. dataType: 'json',
  19. crossDomain: false,
  20. url: globalConfig.context + '/api/admin/user/info',
  21. data: {
  22. pageNo: pageNo || 1,
  23. pageSize: this.state.pagination.pageSize,
  24. lvl: this.state.lvlSearch,
  25. mobile: this.state.mobileSearch,
  26. nickname: this.state.nicknameSearch,
  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. mobile: thisdata.mobile,
  41. nickname: thisdata.nickname,
  42. lvl: thisdata.lvl,
  43. status: thisdata.status,
  44. createTimes: thisdata.createTimes,
  45. workUnit: thisdata.workUnit,
  46. });
  47. }
  48. this.state.pagination.current = data.data.pageNo;
  49. this.state.pagination.total = data.data.totalCount;
  50. }
  51. this.setState({
  52. dataSource: theArr,
  53. pagination: this.state.pagination
  54. });
  55. }.bind(this)
  56. }).always(
  57. function() {
  58. this.setState({
  59. loading: false
  60. });
  61. }.bind(this)
  62. );
  63. },
  64. getInitialState() {
  65. return {
  66. loading: false,
  67. flag: true,
  68. totalData:{
  69. mark: false,
  70. },
  71. powerList:[],
  72. pagination: {
  73. defaultCurrent: 1,
  74. defaultPageSize: 10,
  75. showQuickJumper: true,
  76. pageSize: 10,
  77. onChange: function(page) {
  78. this.loadData(page);
  79. this.setState({
  80. selectedRowKeys: []
  81. });
  82. }.bind(this),
  83. showTotal: function(total) {
  84. return '共' + total + '条数据';
  85. }
  86. },
  87. columns: [
  88. {
  89. title: '序号',
  90. dataIndex: 'key',
  91. key: 'key'
  92. },
  93. {
  94. title: '会员',
  95. dataIndex: 'mobile',
  96. key: 'mobile'
  97. },
  98. {
  99. title: '公司',
  100. dataIndex: 'workUnit',
  101. key: 'workUnit',
  102. },
  103. {
  104. title: '姓名',
  105. dataIndex: 'nickname',
  106. key: 'nickname',
  107. },
  108. {
  109. title: '会员级别',
  110. dataIndex: 'lvl',
  111. key: 'lvl',
  112. render:(text,record)=>{
  113. if (text !== undefined) {
  114. let value = '';
  115. this.state.powerList.map((obj)=>{
  116. if (obj.lvlNumber === text) {
  117. value = obj.typeName;
  118. }
  119. })
  120. return value;
  121. }
  122. }
  123. },
  124. {
  125. title: '注册时间',
  126. dataIndex: 'createTimes',
  127. key: 'createTimes'
  128. },
  129. {
  130. title: '状态',
  131. dataIndex: 'status',
  132. key: 'status',
  133. render:(text)=>{
  134. return getStatuslist(text.toString())
  135. }
  136. },
  137. {
  138. title: '排序',
  139. dataIndex: 'memberPrice',
  140. key: 'memberPrice'
  141. },
  142. {
  143. title: '操作',
  144. dataIndex: ' ',
  145. key: ' ',
  146. render:(text,index,record)=>{
  147. return <Button type="primary" onClick={()=>{
  148. this.tableRowClick(record)
  149. }}>修改</Button>
  150. }
  151. },
  152. ],
  153. dataSource: []
  154. };
  155. },
  156. powerList(pageNo) {
  157. $.ajax({
  158. method: 'get',
  159. dataType: 'json',
  160. crossDomain: false,
  161. url: globalConfig.context + '/api/admin/listLvltype',
  162. data: {
  163. pageNo: 1,
  164. pageSize: 99,
  165. },
  166. success: function(data) {
  167. let theArr = [];
  168. if (!data.data || !data.data) {
  169. if (data.error && data.error.length) {
  170. message.warning(data.error[0].message);
  171. }
  172. } else {
  173. for (let i = 0; i < data.data.length; i++) {
  174. let thisdata = data.data[i];
  175. theArr.push({
  176. key: i,
  177. id: thisdata.id,
  178. typeName: thisdata.typeName,
  179. lvlNumber: thisdata.lvlNumber,
  180. });
  181. }
  182. this.state.pagination.current = data.data.pageNo;
  183. this.state.pagination.total = data.data.totalCount;
  184. }
  185. this.setState({
  186. powerList: theArr,
  187. });
  188. }.bind(this)
  189. }).always(
  190. function() {
  191. this.setState({
  192. loading: false
  193. });
  194. }.bind(this)
  195. );
  196. },
  197. componentWillMount() {
  198. this.loadData()
  199. this.powerList()
  200. },
  201. detailes(record) {
  202. this.setState({
  203. loading:true
  204. });
  205. $.ajax({
  206. method: 'get',
  207. dataType: 'json',
  208. crossDomain: false,
  209. url: globalConfig.context + '/api/admin/user/details',
  210. data: {
  211. id: record.id,
  212. },
  213. success: function(data) {
  214. let theArr = [];
  215. let thisdata = data.data;
  216. let ProvinceCityArr = [],
  217. ProvinceS = thisdata.province, //getprovince
  218. citys = thisdata.city,
  219. Areas = thisdata.area;
  220. ProvinceCityArr.push(ProvinceS, citys, Areas);
  221. if (!data.data || !data.data.list) {
  222. if (data.error && data.error.length) {
  223. message.warning(data.error[0].message);
  224. }
  225. }
  226. Object.assign(this.state.totalData,{
  227. postalAddress: thisdata.postalAddress,
  228. contacts: thisdata.contacts,
  229. contactMobile: thisdata.contactMobile,
  230. ProvinceCity: ProvinceCityArr[0] === null?undefined:ProvinceCityArr,
  231. pwds:thisdata.pwds,
  232. },this.state.RowData)
  233. }.bind(this)
  234. }).always(
  235. function() {
  236. this.setState({
  237. loading: false
  238. });
  239. }.bind(this)
  240. );
  241. },
  242. //项目列表整行点击
  243. tableRowClick(record, index) {
  244. this.state.RowData = record;
  245. this.setState({
  246. editvisible: true,
  247. });
  248. this.detailes(record);
  249. },
  250. edithandleCancel(e) {
  251. this.setState({
  252. editvisible: false
  253. },()=>{
  254. this.addReset()
  255. });
  256. },
  257. search() {
  258. this.loadData();
  259. },
  260. add(){
  261. this.setState({
  262. editvisible: true,
  263. flag: false,
  264. });
  265. },
  266. addNew(){
  267. this.setState({
  268. loading:true
  269. });
  270. ["ProvinceCity"].forEach((key)=>{
  271. this.change(key,undefined)
  272. })
  273. $.ajax({
  274. method: 'post',
  275. dataType: 'json',
  276. crossDomain: false,
  277. url: globalConfig.context + (this.state.flag?'/api/admin/user/update':'/api/admin/user/add'),
  278. data: this.state.totalData,
  279. }).done(function(data) {
  280. this.setState({
  281. loading: false
  282. });
  283. if(!data.error.length) {
  284. message.success('保存成功!');
  285. this.cancelAdd()
  286. } else {
  287. message.warning(data.error[0].message);
  288. }
  289. }.bind(this));
  290. },
  291. cancelAdd(){
  292. this.setState({
  293. editvisible: false,
  294. },()=>{
  295. this.setState({
  296. flag:true
  297. })
  298. this.addReset()
  299. });
  300. this.loadData()
  301. },
  302. //新增框的清零
  303. addReset(){
  304. this.setState({
  305. totalData:{},
  306. })
  307. },
  308. //搜索部分的清零
  309. reset() {
  310. this.state.mobileSearch = undefined;
  311. this.state.lvlSearch = undefined;
  312. this.state.nicknameSearch = undefined;
  313. this.loadData();
  314. },
  315. change(key, e, f){
  316. if(f === undefined ){
  317. this.state.totalData[key] = e
  318. this.setState({
  319. totalData:this.state.totalData
  320. })
  321. }else if(typeof(f) === "function"){
  322. this.state.totalData[key] = e
  323. this.setState({
  324. totalData:this.state.totalData
  325. },f)
  326. }
  327. },
  328. render() {
  329. const FormItem = Form.Item;
  330. const rowSelection = {
  331. selectedRowKeys: this.state.selectedRowKeys,
  332. onChange: (selectedRowKeys, selectedRows) => {
  333. this.setState({
  334. selectedRows: selectedRows.slice(-1),
  335. selectedRowKeys: selectedRowKeys.slice(-1)
  336. });
  337. }
  338. };
  339. const empty = [];
  340. let data = this.state.totalData;
  341. return (
  342. <div className="user-content">
  343. <div className="content-title">
  344. <span>会员列表</span>
  345. <div className="user-search">
  346. <Input
  347. placeholder="会员手机号"
  348. style={{ width: '150px', marginRight: '10px', marginBottom: '10px' }}
  349. value={this.state.mobileSearch}
  350. onChange={(e) => {
  351. this.setState({ mobileSearch: e.target.value });
  352. }}
  353. />
  354. <Select value={this.state.lvlSearch} style={{ width: 120 }}
  355. placeholder='请选择级别' onChange={(e)=>{
  356. this.setState({
  357. lvlSearch:e
  358. })
  359. }}>
  360. <Option value={0}>普通会员</Option>
  361. <Option value={1}>A会员</Option>
  362. <Option value={2}>AA会员</Option>
  363. <Option value={3}>AAA会员</Option>
  364. </Select>
  365. <Input
  366. placeholder="姓名"
  367. style={{ width: '150px', marginRight: '10px', marginBottom: '10px' }}
  368. value={this.state.nicknameSearch}
  369. onChange={(e) => {
  370. this.setState({ nicknameSearch: e.target.value });
  371. }}
  372. />
  373. <Button type="primary" onClick={this.search} style={{ marginRight: '10px' }}>
  374. 搜索
  375. </Button>
  376. <Button onClick={this.reset} style={{ marginRight: '10px' }}>
  377. 重置
  378. </Button>
  379. <Button type="primary" onClick={this.add} style={{ marginLeft: '100px'}}>
  380. 新增会员
  381. </Button>
  382. </div>
  383. <div className="patent-table">
  384. <Spin spinning={this.state.loading}>
  385. <Table
  386. columns={this.state.columns}
  387. dataSource={this.state.dataSource}
  388. rowSelection={rowSelection}
  389. pagination={this.state.pagination}
  390. onRowClick={this.tableRowClick}
  391. />
  392. </Spin>
  393. </div>
  394. </div>
  395. <div className="patent-desc">
  396. <Modal
  397. className="customeDetails"
  398. title={this.state.flag?'会员详情':'新增会员'}
  399. width="1000px"
  400. visible={this.state.editvisible}
  401. onOk={this.edithandleCancel}
  402. onCancel={this.state.flag?this.edithandleCancel:this.cancelAdd}
  403. footer=""
  404. >
  405. <Form layout="horizontal" onSubmit={this.edithandleSubmit} id="demand-form">
  406. <Spin spinning={this.state.loading}>
  407. <div className="clearfix">
  408. <FormItem
  409. className="half-item"
  410. labelCol={{ span: 8 }}
  411. wrapperCol={{ span: 12 }}
  412. label="会员"
  413. >
  414. <Input placeholder="请输入会员手机号" value={data.mobile}
  415. onChange={(e)=>{
  416. this.change('mobile',e.target.value)
  417. }} style={{width:'240px'}} />
  418. </FormItem>
  419. <FormItem
  420. className="half-item"
  421. labelCol={{ span: 8 }}
  422. wrapperCol={{ span: 12 }}
  423. label="密码"
  424. >
  425. <Input placeholder="请输入密码" value={data.pwds}
  426. onChange={(e)=>{
  427. this.change('pwds',e.target.value)
  428. }} style={{width:'240px'}} />
  429. </FormItem>
  430. <FormItem
  431. className="half-item"
  432. labelCol={{ span: 8 }}
  433. wrapperCol={{ span: 12 }}
  434. label="姓名"
  435. >
  436. <Input placeholder="请输入姓名" value={data.nickname}
  437. onChange={(e)=>{
  438. this.change('nickname',e.target.value)
  439. }} style={{width:'240px'}} />
  440. </FormItem>
  441. <FormItem
  442. className="half-item"
  443. labelCol={{ span: 8 }}
  444. wrapperCol={{ span: 12 }}
  445. label="公司名称"
  446. >
  447. <Input placeholder="请输入公司名称" value={data.workUnit}
  448. onChange={(e)=>{
  449. this.change('workUnit',e.target.value)
  450. }} style={{width:'240px'}} />
  451. </FormItem>
  452. <FormItem
  453. className="half-item"
  454. labelCol={{ span: 8 }}
  455. wrapperCol={{ span: 12 }}
  456. label="公司地址"
  457. >
  458. <Cascader options={areaSelect()} value={data.ProvinceCity} placeholder="选择城市" style={{width:'95%'}}
  459. onChange={(e)=>{
  460. this.change('ProvinceCity',e)
  461. this.change('province', e[0])
  462. this.change('city', e[1])
  463. this.change('area', e[2])
  464. }} />
  465. </FormItem>
  466. <FormItem
  467. className="half-item"
  468. labelCol={{ span: 8 }}
  469. wrapperCol={{ span: 12 }}
  470. label="详细地址"
  471. >
  472. <Input placeholder="请输入详细地址" value={data.postalAddress}
  473. onChange={(e)=>{
  474. this.change('postalAddress',e.target.value)
  475. }} style={{width:'240px'}} />
  476. </FormItem>
  477. <FormItem
  478. className="half-item"
  479. labelCol={{ span: 8 }}
  480. wrapperCol={{ span: 12 }}
  481. label="联系人"
  482. >
  483. <Input placeholder="请输入联系人" value={data.contacts}
  484. onChange={(e)=>{
  485. this.change('contacts',e.target.value)
  486. }} style={{width:'240px'}} />
  487. </FormItem>
  488. <FormItem
  489. className="half-item"
  490. labelCol={{ span: 8 }}
  491. wrapperCol={{ span: 12 }}
  492. label="联系人电话"
  493. >
  494. <Input placeholder="请输入联系人电话" value={data.contactMobile}
  495. onChange={(e)=>{
  496. this.change('contactMobile',e.target.value)
  497. }} style={{width:'240px'}} />
  498. </FormItem>
  499. <FormItem
  500. className="half-item"
  501. labelCol={{ span: 8 }}
  502. wrapperCol={{ span: 12 }}
  503. label="级别"
  504. >
  505. <Select value={data.lvl} style={{ width: 120 }}
  506. placeholder='请选择级别' onChange={(e)=>{
  507. this.change('lvl',e)
  508. }}>
  509. {this.state.powerList.map((obj)=>{
  510. return <Option value={obj.lvlNumber}>{obj.typeName}</Option>
  511. })}
  512. </Select>
  513. </FormItem>
  514. <FormItem
  515. className="half-item"
  516. labelCol={{ span: 8 }}
  517. wrapperCol={{ span: 12 }}
  518. label="注册时间"
  519. >
  520. <span>{this.state.flag?data.createTimes:new Date().toLocaleDateString()}</span>
  521. </FormItem>
  522. <FormItem
  523. className="half-item"
  524. labelCol={{ span: 8 }}
  525. wrapperCol={{ span: 12 }}
  526. label="账户状态"
  527. >
  528. <Radio.Group onChange={(e)=>{
  529. this.change('status',e.target.value)
  530. }} value={data.status}>
  531. <Radio value={0}>正常</Radio>
  532. <Radio value={1}>注销</Radio>
  533. <Radio value={2}>锁定</Radio>
  534. </Radio.Group>
  535. </FormItem>
  536. <Button type="primary" size="large" onClick={this.addNew} style={{float:'right',marginRight:'80px',marginTop:'20px'}}>保存</Button>
  537. </div>
  538. </Spin>
  539. </Form>
  540. </Modal>
  541. </div>
  542. </div>
  543. );
  544. }
  545. })
  546. );
  547. export default MemberList;