assignUser.tsx 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { useAjax } from "@/Hook/useAjax"
  2. import { getRoleUserListApi } from "@/services/gameData"
  3. import { gameServerAssignApi } from "@/services/gameData/roleOperate"
  4. import { Form, Modal, Radio, Select, message } from "antd"
  5. import React, { useEffect, useState } from "react"
  6. interface Props {
  7. assignType: 'GAME_SERVER_ASSIGN_CUSTOMER' | 'GAME_SERVER_ASSIGN_GS'
  8. initialValues?: any
  9. visible?: boolean
  10. onChange?: () => void
  11. onClose?: () => void
  12. }
  13. /**
  14. * 批量指派
  15. * @returns
  16. */
  17. const AssignUser: React.FC<Props> = ({ visible, onChange, onClose, assignType, initialValues = {} }) => {
  18. /***************************/
  19. const [list, setList] = useState<any[]>([])
  20. const [form] = Form.useForm()
  21. const getRoleUserList = useAjax((params) => getRoleUserListApi(params))
  22. const gameServerAssign = useAjax((params) => gameServerAssignApi(params))
  23. /***************************/
  24. useEffect(() => {
  25. if (assignType) {
  26. getRoleUserList.run({ authType: assignType === 'GAME_SERVER_ASSIGN_CUSTOMER' ? 'CUSTOMER' : 'GS' }).then(res => {
  27. if (res) {
  28. setList(Object.keys(res)?.map(key => ({ userId: key, nickname: res[key] })))
  29. }
  30. })
  31. } else {
  32. setList([])
  33. }
  34. }, [assignType])
  35. const handleOk = async () => {
  36. let validate = await form.validateFields()
  37. gameServerAssign.run({ ...validate, idList: initialValues.idList, assignType }).then(res => {
  38. if (res) {
  39. message.success('指派成功')
  40. onChange?.()
  41. }
  42. })
  43. }
  44. return <Modal
  45. title={<strong>指派{assignType === 'GAME_SERVER_ASSIGN_CUSTOMER' ? '客服' : 'GS'}</strong>}
  46. visible={visible}
  47. onCancel={onClose}
  48. onOk={handleOk}
  49. >
  50. <Form
  51. name="basicAssignUser"
  52. form={form}
  53. autoComplete="off"
  54. initialValues={initialValues}
  55. layout="vertical"
  56. >
  57. <Form.Item
  58. label={<strong>{assignType === 'GAME_SERVER_ASSIGN_CUSTOMER' ? '客服' : 'GS'}</strong>}
  59. name="assignUserIdList"
  60. rules={[{ required: true, message: `请选择${assignType === 'GAME_SERVER_ASSIGN_CUSTOMER' ? '客服' : 'GS'}` }]}
  61. >
  62. <Select
  63. loading={getRoleUserList.loading}
  64. mode="multiple"
  65. showSearch
  66. style={{ width: '100%' }}
  67. allowClear
  68. placeholder={`请选择${assignType === 'GAME_SERVER_ASSIGN_CUSTOMER' ? '客服' : 'GS'}`}
  69. filterOption={(input, option) =>
  70. (option?.children as any)?.toLowerCase().indexOf(input.toLowerCase()) >= 0
  71. }
  72. >
  73. {list.map((item: any) => <Select.Option value={item.userId} key={item.userId}>{item.nickname}</Select.Option>)}
  74. </Select>
  75. </Form.Item>
  76. </Form>
  77. </Modal>
  78. }
  79. export default React.memo(AssignUser)