levelSet.jsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. import React from 'react';
  2. import { Icon, Button, Input, Spin, Table, message, Modal, Tabs, InputNumber, Checkbox, Select } from 'antd';
  3. import ajax from 'jquery/src/ajax/xhr.js';
  4. import $ from 'jquery/src/ajax';
  5. import './userList.less';
  6. const ListAdd = React.createClass({
  7. getInitialState () {
  8. return {
  9. visible: false,
  10. loading: false
  11. };
  12. },
  13. showModal () {
  14. this.setState({
  15. visible: true,
  16. });
  17. },
  18. handleCancel (e) {
  19. this.setState({
  20. visible: false,
  21. });
  22. },
  23. handleOk () {
  24. this.setState({
  25. loading: true
  26. });
  27. $.ajax({
  28. method: "post",
  29. dataType: "json",
  30. crossDomain: false,
  31. url: globalConfig.context + "/api/admin/member/addGradeName",
  32. data: {
  33. gradeName: this.state.lvlName,
  34. memberRank: this.state.level
  35. },
  36. success: function (data) {
  37. if (data.error && data.error.length) {
  38. message.warning(data.error[0].message);
  39. } else {
  40. message.success("添加成功!");
  41. this.state.visible = false;
  42. this.props.refresh(this.state.level);
  43. }
  44. this.setState({
  45. loading: false
  46. })
  47. }.bind(this),
  48. });
  49. },
  50. render () {
  51. const Option = Select.Option;
  52. return (
  53. <div className="patent-desc" style={{ float: 'right', marginRight: '20px' }}>
  54. <Button type="primary" onClick={this.showModal}>添加新等级</Button>
  55. <Modal maskClosable={false}
  56. title="新增用户等级"
  57. visible={this.state.visible}
  58. onCancel={this.handleCancel}
  59. afterClose={() => { this.state.lvlName = undefined; this.state.level = undefined }}
  60. width='400px'
  61. footer={[
  62. <Button key="submit" type="primary" loading={this.state.loading} onClick={this.handleOk}>提交</Button>,
  63. <Button key="back" onClick={this.handleCancel}>返回</Button>
  64. ]}
  65. className="admin-desc-content">
  66. <div className='orgAdd-input'>
  67. <span>会员等级名称:</span>
  68. <Input value={this.state.lvlName} style={{ width: '200px' }}
  69. onChange={(e) => { this.setState({ lvlName: e.target.value }); }} />
  70. </div>
  71. <div className='orgAdd-input'>
  72. <span>会员等级:</span>
  73. <Select value={this.state.level} style={{ width: 120 }}
  74. onChange={(e) => { this.setState({ level: e }) }}>
  75. <Option value="2">2</Option>
  76. <Option value="3">3</Option>
  77. <Option value="4">4</Option>
  78. <Option value="5">5</Option>
  79. </Select>
  80. </div>
  81. </Modal>
  82. </div>
  83. );
  84. }
  85. });
  86. const ListDelete = React.createClass({
  87. getInitialState () {
  88. return {
  89. visible: false,
  90. loading: false
  91. };
  92. },
  93. showModal () {
  94. this.setState({
  95. visible: true,
  96. });
  97. },
  98. handleCancel (e) {
  99. this.setState({
  100. visible: false,
  101. });
  102. },
  103. handleOk () {
  104. this.setState({
  105. loading: true
  106. });
  107. $.ajax({
  108. method: "post",
  109. dataType: "json",
  110. crossDomain: false,
  111. url: globalConfig.context + "/api/admin/member/delGrade",
  112. data: {
  113. id: this.props.rid
  114. },
  115. success: function (data) {
  116. if (data.error && data.error.length) {
  117. message.warning(data.error[0].message);
  118. } else {
  119. message.success("删除成功!");
  120. this.state.visible = false;
  121. this.props.refreshForDel();
  122. }
  123. this.setState({
  124. loading: false
  125. })
  126. }.bind(this),
  127. });
  128. },
  129. render () {
  130. return (
  131. <div className="patent-desc" style={{ float: 'right', marginRight: '20px' }}>
  132. <Button type="ghost" onClick={this.showModal}>删除</Button>
  133. <Modal maskClosable={false}
  134. title="删除用户等级"
  135. visible={this.state.visible}
  136. onCancel={this.handleCancel}
  137. width='400px'
  138. footer={[
  139. <Button key="submit" type="primary" loading={this.state.loading} onClick={this.handleOk}>提交</Button>,
  140. <Button key="back" onClick={this.handleCancel}>返回</Button>
  141. ]} >
  142. <div className="level-tabs-modal">
  143. <p>
  144. <Icon type="exclamation-circle-o" />
  145. <span> 确认要删除该用户等级吗?删除以后不可恢复!</span>
  146. </p>
  147. </div>
  148. </Modal>
  149. </div>
  150. );
  151. }
  152. });
  153. const SetContent = React.createClass({
  154. getInitialState () {
  155. return {
  156. visible: false,
  157. loading: false,
  158. columns: [
  159. {
  160. title: '会员时长',
  161. dataIndex: 'time',
  162. key: 'time',
  163. render: (text, record, index) => {
  164. return <div>
  165. <Input style={{ width: '80px' }}
  166. value={record.time}
  167. onChange={(e) => {
  168. record.time = e.target.value;
  169. this.setState({ dataSource: this.state.dataSource });
  170. }} />
  171. <span style={{ marginLeft: '10px' }}>个月</span>
  172. </div>
  173. }
  174. }, {
  175. title: '金额',
  176. dataIndex: 'money',
  177. key: 'money',
  178. render: (text, record, index) => {
  179. return <div>
  180. <InputNumber step={0.01} min={0}
  181. value={record.money}
  182. onChange={(e) => {
  183. record.money = e;
  184. this.setState({ dataSource: this.state.dataSource });
  185. }} />
  186. <span style={{ marginLeft: '10px' }}>元</span>
  187. </div>
  188. }
  189. }
  190. ],
  191. dataSource: [],
  192. selectedRowKeys: []
  193. };
  194. },
  195. componentWillMount () {
  196. this.state.checked01 = this.props.business.checked01;
  197. this.state.checked02 = this.props.business.checked02;
  198. this.state.checked03 = this.props.business.checked03;
  199. this.state.checked04 = this.props.business.checked04;
  200. this.state.checked05 = this.props.business.checked05;
  201. this.state.checked06 = this.props.business.checked06;
  202. this.state.checked07 = this.props.business.checked07;
  203. this.state.checked08 = this.props.business.checked08;
  204. for (let item in this.props.cost) {
  205. this.state.dataSource.push({
  206. key: this.state.dataSource.length,
  207. time: item,
  208. money: this.props.cost[item]
  209. })
  210. }
  211. },
  212. remove () {
  213. this.state.selectedRowKeys.sort((a, b) => { return b - a });
  214. let theArr = this.state.dataSource.concat();
  215. for (let idx = 0; idx < this.state.selectedRowKeys.length; idx++) {
  216. let dataIndex = this.state.selectedRowKeys[idx];
  217. theArr.map((item, index) => {
  218. if (item.key === dataIndex) {
  219. theArr.splice(index, 1);
  220. }
  221. })
  222. };
  223. this.state.dataSource = [];
  224. for (let i = 0; i < theArr.length; i++) {
  225. let item = theArr[i];
  226. this.state.dataSource.push({
  227. key: i,
  228. time: item.time,
  229. money: item.money
  230. })
  231. };
  232. this.setState({
  233. dataSource: this.state.dataSource,
  234. selectedRowKeys: []
  235. });
  236. },
  237. addNew () {
  238. this.state.dataSource.push({
  239. key: this.state.dataSource.length,
  240. time: '',
  241. money: ''
  242. });
  243. this.setState({
  244. dataSource: this.state.dataSource
  245. })
  246. },
  247. submit () {
  248. this.setState({ loading: true });
  249. let theCost = {};
  250. if (this.state.dataSource.length) {
  251. for (let i = 0; i < this.state.dataSource.length; i++) {
  252. let theMoney = this.state.dataSource[i].money;
  253. let theTime = this.state.dataSource[i].time;
  254. theCost[theTime] = theMoney;
  255. }
  256. };
  257. $.ajax({
  258. method: "post",
  259. dataType: "json",
  260. crossDomain: false,
  261. url: globalConfig.context + "/api/admin/member/addBusinessAndCost",
  262. data: {
  263. id: this.props.rid,
  264. business: JSON.stringify({
  265. "1008": this.state.checked08 ? "1" : "0",
  266. "1007": this.state.checked07 ? "1" : "0",
  267. "1006": this.state.checked06 ? "1" : "0",
  268. "1005": this.state.checked05 ? "1" : "0",
  269. "1004": this.state.checked04 ? "1" : "0",
  270. "1003": this.state.checked03 ? "1" : "0",
  271. "1002": this.state.checked02 ? "1" : "0",
  272. "1001": this.state.checked01 ? "1" : "0",
  273. }),
  274. cost: JSON.stringify(theCost)
  275. },
  276. success: function (data) {
  277. if (data.error && data.error.length) {
  278. message.warning(data.error[0].message);
  279. } else {
  280. message.success("保存成功!");
  281. this.state.visible = false
  282. }
  283. this.setState({
  284. loading: false
  285. })
  286. }.bind(this),
  287. });
  288. },
  289. render () {
  290. const rowSelection = {
  291. type: 'checkbox',
  292. selectedRowKeys: this.state.selectedRowKeys,
  293. onChange: (selectedRowKeys, selectedRows) => {
  294. this.setState({
  295. selectedRows: selectedRows,
  296. selectedRowKeys: selectedRowKeys
  297. });
  298. }
  299. };
  300. const hasSelected = this.state.selectedRowKeys.length > 0;
  301. return (
  302. <Spin spinning={this.state.loading}>
  303. <div className="level-tabs">
  304. <div className="level-tabs-title">
  305. <span>会员等级费用设置</span>
  306. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  307. onClick={this.addNew}>添加<Icon type="plus" /></Button>
  308. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  309. disabled={!hasSelected}
  310. onClick={this.remove}>删除<Icon type="minus" /></Button>
  311. </div>
  312. <Table className="level-tabs-table no-all-select"
  313. columns={this.state.columns}
  314. dataSource={this.state.dataSource}
  315. pagination={false}
  316. rowSelection={rowSelection} />
  317. <div className="level-tabs-title">
  318. <span>会员等级增值服务设置</span>
  319. </div>
  320. <div>
  321. <div className="level-checkbox">
  322. <Checkbox checked={this.state.checked01}
  323. onChange={(e) => { this.setState({ checked01: e.target.checked }) }}>
  324. 科技成果,专家信息定点推送
  325. </Checkbox>
  326. </div>
  327. <div className="level-checkbox">
  328. <Checkbox checked={this.state.checked02}
  329. onChange={(e) => { this.setState({ checked02: e.target.checked }) }}>
  330. 查看专家的联系方式
  331. </Checkbox>
  332. </div>
  333. <div className="level-checkbox">
  334. <Checkbox checked={this.state.checked03}
  335. onChange={(e) => { this.setState({ checked03: e.target.checked }) }}>
  336. 任何业务申请,付费业享受会员专属折扣
  337. </Checkbox>
  338. </div>
  339. <div className="level-checkbox">
  340. <Checkbox checked={this.state.checked04}
  341. onChange={(e) => { this.setState({ checked04: e.target.checked }) }}>
  342. 一对一的技术经纪人服务,进行技术成果媒合服务
  343. </Checkbox>
  344. </div>
  345. <div className="level-checkbox">
  346. <Checkbox checked={this.state.checked05}
  347. onChange={(e) => { this.setState({ checked05: e.target.checked }) }}>
  348. 一对一的科技咨询师服务
  349. </Checkbox>
  350. </div>
  351. <div className="level-checkbox">
  352. <Checkbox checked={this.state.checked06}
  353. onChange={(e) => { this.setState({ checked06: e.target.checked }) }}>
  354. 一对一的专业技术顾问,搜集技术情报,提供研发高参
  355. </Checkbox>
  356. </div>
  357. <div className="level-checkbox">
  358. <Checkbox checked={this.state.checked07}
  359. onChange={(e) => { this.setState({ checked07: e.target.checked }) }}>
  360. 免费参加现场业务培训会
  361. </Checkbox>
  362. </div>
  363. <div className="level-checkbox">
  364. <Checkbox checked={this.state.checked08}
  365. onChange={(e) => { this.setState({ checked08: e.target.checked }) }}>
  366. 免前期费用做科技类扶持资金项目申报
  367. </Checkbox>
  368. </div>
  369. </div>
  370. <div className="level-tabs-save">
  371. <Button type="primary" onClick={this.submit}>保存</Button>
  372. <ListDelete rid={this.props.rid} refreshForDel={this.props.refreshForDel} />
  373. </div>
  374. </div>
  375. </Spin>
  376. );
  377. }
  378. });
  379. const LevelSet = React.createClass({
  380. loadData (pageNo) {
  381. this.setState({
  382. loading: true
  383. });
  384. $.ajax({
  385. method: "get",
  386. dataType: "json",
  387. crossDomain: false,
  388. url: globalConfig.context + "/api/admin/member/selectMemberGrade",
  389. data: {
  390. },
  391. success: function (data) {
  392. let theArr = [];
  393. if (data.error && data.error.length) {
  394. message.warning(data.error[0].message);
  395. } else {
  396. for (let i = 0; i < data.data.length; i++) {
  397. let item = data.data[i];
  398. let theBusiness = {};
  399. theBusiness['checked01'] = (item.business && item.business['1001'] == 1 ? true : false);
  400. theBusiness['checked02'] = (item.business && item.business['1002'] == 1 ? true : false);
  401. theBusiness['checked03'] = (item.business && item.business['1003'] == 1 ? true : false);
  402. theBusiness['checked04'] = (item.business && item.business['1004'] == 1 ? true : false);
  403. theBusiness['checked05'] = (item.business && item.business['1005'] == 1 ? true : false);
  404. theBusiness['checked06'] = (item.business && item.business['1006'] == 1 ? true : false);
  405. theBusiness['checked07'] = (item.business && item.business['1007'] == 1 ? true : false);
  406. theBusiness['checked08'] = (item.business && item.business['1008'] == 1 ? true : false);
  407. theArr.push(
  408. <Tabs.TabPane tab={item.gradeName + '( Lv.' + item.memberRank + ' )'} key={item.memberRank}>
  409. <SetContent business={theBusiness} cost={item.cost || []} rid={item.id} refreshForDel={this.refreshForDel} />
  410. </Tabs.TabPane>
  411. )
  412. };
  413. this.setState({ tabPane: theArr })
  414. }
  415. }.bind(this),
  416. }).always(function () {
  417. this.setState({
  418. loading: false
  419. });
  420. }.bind(this));
  421. },
  422. getInitialState () {
  423. return {
  424. tabPane: [],
  425. activeKey: '1',
  426. loading: false
  427. };
  428. },
  429. componentWillMount () {
  430. this.loadData();
  431. },
  432. refresh (e) {
  433. this.state.activeKey = e;
  434. this.loadData()
  435. },
  436. refreshForDel () {
  437. this.state.activeKey = '1';
  438. this.loadData();
  439. },
  440. tabChange (e) {
  441. this.setState({ activeKey: e });
  442. },
  443. render () {
  444. return (
  445. <div className="user-content" >
  446. <div className="content-title clearfix">
  447. <span>会员等级管理</span>
  448. <ListAdd refresh={this.refresh} />
  449. </div>
  450. <div>
  451. <Tabs activeKey={this.state.activeKey} onChange={this.tabChange}>
  452. {this.state.tabPane}
  453. </Tabs>
  454. </div>
  455. </div >
  456. );
  457. }
  458. });
  459. export default LevelSet;