You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
4.0 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. import React, { FC, useEffect, useMemo, useRef, useState } from "react";
  2. import clientApi from "@/package/SimpleTrade/api/client";
  3. import MyTable from "@/components/MyTable";
  4. import { Button, Input, Modal, notification, Select } from "antd";
  5. import { copy, splitAddress } from "@/utils";
  6. import { CopyOutlined } from "@ant-design/icons";
  7. const UserList: FC = () => {
  8. const [currentItem, setCurrentItem] = useState({} as any)
  9. const [isModalOpen, setIsModalOpen] = useState(false)
  10. const [lv, setLv] = useState(0);
  11. const tableRefs = useRef<any>()
  12. const options = useMemo(() => [
  13. { value: 0, label: 'R' },
  14. { value: 1, label: 'G' },
  15. { value: 2, label: 'G1' },
  16. { value: 3, label: 'G2' },
  17. { value: 4, label: 'G3' },
  18. { value: 5, label: 'G4' },
  19. { value: 6, label: 'G5' },
  20. ], [])
  21. const columns = [
  22. {
  23. title: '邮箱',
  24. dataIndex: 'email'
  25. },
  26. {
  27. title: '地址',
  28. dataIndex: 'address',
  29. render: (address) => (
  30. <div style={{ display: 'flex', alignItems: 'center' }}>
  31. <div>{splitAddress(address, 5)}</div>
  32. <div style={{ marginLeft: 5, cursor: 'pointer' }} onClick={() => copy(address)}>
  33. <CopyOutlined />
  34. </div>
  35. </div>
  36. )
  37. },
  38. {
  39. title: 'A账号',
  40. dataIndex: 'a_mt4_login'
  41. },
  42. {
  43. title: 'A仓余额',
  44. dataIndex: 'a_mt4_balance'
  45. },
  46. {
  47. title: 'A仓订单数量',
  48. dataIndex: 'a_product'
  49. },
  50. {
  51. title: 'B账号',
  52. dataIndex: 'b_mt4_login'
  53. },
  54. {
  55. title: 'B仓余额',
  56. dataIndex: 'b_mt4_balance'
  57. },
  58. {
  59. title: 'B仓订单数量',
  60. dataIndex: 'b_product'
  61. },
  62. {
  63. title: '手数',
  64. dataIndex: 'volume'
  65. },
  66. {
  67. title: '级别',
  68. dataIndex: 'level',
  69. render: (level) => (
  70. <div>{options[level] ? options[level].label : level}</div>
  71. )
  72. },
  73. {
  74. title: '保险开关',
  75. dataIndex: 'insurance',
  76. render: (status) => (
  77. <div>{status === 1 ? '开' : '关'}</div>
  78. )
  79. },
  80. {
  81. title: '邀请码',
  82. dataIndex: 'invite_code'
  83. },
  84. {
  85. title: '推荐人',
  86. dataIndex: 'referrer'
  87. },
  88. {
  89. title: '操作',
  90. dataIndex: 'operations',
  91. align: 'center',
  92. key: Date.now(),
  93. render: (text, record) => {
  94. return (
  95. <div>
  96. <Button type="primary" className="btn" size="small" onClick={() => {
  97. setCurrentItem(record)
  98. setIsModalOpen(true)
  99. setLv(record.level)
  100. }}></Button>
  101. </div>
  102. )
  103. }
  104. }
  105. ]
  106. // 搜索栏配置项
  107. const searchConfigList = [
  108. {
  109. key: 'name',
  110. slot: <Input placeholder="用户名" allowClear />,
  111. initialValue: ''
  112. }
  113. ]
  114. const setLevel = async () => {
  115. if (currentItem.level === lv) {
  116. notification.error({
  117. message: '设置等级相同',
  118. })
  119. return;
  120. }
  121. let res: any = await clientApi.up_levle({
  122. level: lv,
  123. invite_code: currentItem.invite_code
  124. })
  125. if (res.code === 0) {
  126. notification.success({
  127. message: '设置成功'
  128. })
  129. setIsModalOpen(false)
  130. tableRefs.current?.update()
  131. }
  132. }
  133. const handleChange = (_, e) => {
  134. setLv(e.value)
  135. }
  136. useEffect(() => {
  137. if (!isModalOpen) {
  138. setCurrentItem({})
  139. setLv(0)
  140. }
  141. }, [isModalOpen])
  142. return (
  143. <div>
  144. <MyTable
  145. ref={tableRefs}
  146. columns={columns}
  147. apiFun={clientApi.user_list}
  148. searchConfigList={searchConfigList}
  149. rowKey="invite_code"
  150. />
  151. <Modal
  152. title="设置等级"
  153. visible={isModalOpen}
  154. onOk={setLevel}
  155. onCancel={() => setIsModalOpen(false)}
  156. >
  157. {
  158. isModalOpen && (
  159. <Select
  160. defaultValue={currentItem.level || 0}
  161. options={options}
  162. style={{ width: '100%' }}
  163. onChange={handleChange}
  164. />
  165. )
  166. }
  167. </Modal>
  168. </div>
  169. )
  170. };
  171. export default UserList;