index.jsx 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import React, { useState, useEffect } from 'react';
  2. import { PageHeaderWrapper } from '@ant-design/pro-layout';
  3. import { Form, Pagination, Card, Button, Icon, Tooltip, message, notification, Modal, Table } from 'antd';
  4. import router from 'umi/router';
  5. import moment from 'moment';
  6. import className from 'classnames';
  7. import Cell from '../../../components/Cell';
  8. import styles from './style.less';
  9. import { fetch, apis } from '../../../utils/request';
  10. import request from '../../../utils/request';
  11. import AuthButton from '@/components/AuthButton';
  12. function header(props) {
  13. // 获取初始化数据
  14. const [ data, setData ] = useState({})
  15. useEffect(() => {
  16. getList({ pageNum: 1, pageSize: 10 });
  17. },[])
  18. // 查询列表
  19. const getList = (params) => {
  20. request({ ...apis.channel.list, params: { ...params } }).then((data) => {
  21. console.log(data)
  22. setData(data)
  23. })
  24. }
  25. // 提交事件
  26. const handleSubmit = (e, props) => {
  27. e.preventDefault();
  28. props.form.validateFields((err, values) => {
  29. if (!err) {
  30. getList({ pageNum: 1, pageSize: 10, ...values })
  31. }
  32. });
  33. }
  34. const changePageNum = (pageNumber) => {
  35. getList({ pageNum: pageNumber, pageSize: 10 })
  36. }
  37. // 跳转到编辑资讯
  38. const toEditNews = (id) => () => {
  39. router.push({
  40. pathname: '/channel/edit',
  41. query: {
  42. id
  43. },
  44. });
  45. }
  46. const changeNewsStatus = (row, newsId) => () => {
  47. const title = row.status === 0 ? '确定启用吗': '停用后,此账号将无法登录渠道代理商后台'
  48. Modal.confirm({
  49. title: title,
  50. okText: '确认',
  51. cancelText: '取消',
  52. onOk() {
  53. if(row.status === 0){
  54. request({ ...apis.channel.put, urlData: { id: newsId }, data: { ...row, status: 1 } }).then((data) => {
  55. message.info('操作成功!')
  56. getList({ pageNum: 1, pageSize: 10 });
  57. }).catch((err) => {
  58. console.log(err)
  59. message.info(err.msg || err.message)
  60. })
  61. }else{
  62. request({ ...apis.channel.put, urlData: { id: newsId }, data: { ...row, status: 0 } }).then((data) => {
  63. message.info('操作成功!')
  64. getList({ pageNum: 1, pageSize: 10 });
  65. }).catch((err) => {
  66. console.log(err)
  67. message.info(err.msg || err.message)
  68. })
  69. }
  70. }
  71. });
  72. }
  73. /**
  74. *
  75. *
  76. * @param {*} props
  77. * @returns
  78. */
  79. const columns = [
  80. {
  81. title: '渠道代理',
  82. dataIndex: 'channelProxyName',
  83. key: 'channelProxyName',
  84. align: 'center',
  85. },
  86. {
  87. title: '账号名',
  88. dataIndex: 'userName',
  89. key: 'userName',
  90. align: 'center',
  91. render: (x, row) => <span>{row.userName === null || row.userName === '' ? row.channelTel : row.userName}</span>,
  92. },
  93. {
  94. title: '小程序总数',
  95. dataIndex: 'appMaxNum',
  96. key: 'appMaxNum',
  97. align: 'center',
  98. },
  99. {
  100. title: '现有小程序',
  101. dataIndex: 'appCurrentNum',
  102. key: 'appCurrentNum',
  103. align: 'center',
  104. render: (appCurrentNum) => <span>{appCurrentNum === 0 || appCurrentNum == null ? 0 : appCurrentNum}</span>,
  105. },
  106. {
  107. title: '服务到期时间',
  108. dataIndex: 'expireDate',
  109. key: 'expireDate',
  110. align: 'center',
  111. render: (x, row) => <><span>{`${moment(row.expireDate).format('YYYY-MM-DD')}`}</span></>,
  112. },
  113. {
  114. title: '状态',
  115. dataIndex: 'status',
  116. key: 'status',
  117. align: 'center',
  118. render: (status) => <span>{status === 1 ? '启动' : '停用'}</span>,
  119. },
  120. {
  121. title: '操作',
  122. dataIndex: 'handle',
  123. key: 'handle',
  124. align: 'center',
  125. render: (x, row) => (
  126. <>
  127. <AuthButton name="admin.taNewsType.id.delete" noRight={null}>
  128. <span style={{ color: '#EF273A', marginRight: '20px', cursor: 'pointer' }} onClick={changeNewsStatus(row, row.channelId)}>
  129. {row.status == 1 ? '停用' : '启用'}<Icon type="shopping-cart" className={styles.shoppingCart} />
  130. </span>
  131. </AuthButton>
  132. <AuthButton name="admin.taNewsType.id.put" noRight={null}>
  133. <span style={{ color: '#FF925C', cursor: 'pointer' }} onClick={toEditNews(row.channelId)}>
  134. 编辑<Icon type="form" className={styles.edit} />
  135. </span>
  136. </AuthButton>
  137. </>
  138. ),
  139. },
  140. ];
  141. function handleReset() {
  142. props.form.resetFields();
  143. getList({ pageNum: 1, pageSize: 10 })
  144. }
  145. const { getFieldDecorator } = props.form
  146. return (
  147. <>
  148. <AuthButton name="admin.taNewsType.post" noRight={null}>
  149. <Button type="danger" className={styles.addBtn} onClick={toEditNews()}>新增</Button>
  150. </AuthButton>
  151. <Table rowKey="newsType" dataSource={data.records} columns={columns} pagination={false} />
  152. <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
  153. <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={changePageNum} current={data.current}/>
  154. </div>
  155. </>
  156. )
  157. }
  158. const WrappedHeader = Form.create({ name: 'header' })(header);
  159. export default WrappedHeader