appointPut.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { useAjax } from "@/Hook/useAjax"
  2. import { addAccountUserApi, cutPutApi } from "@/services/operating/accountyyb"
  3. import { Form, message, Modal, Select } from "antd"
  4. import React, { useEffect, useState } from "react"
  5. interface Props {
  6. allOfMember: any
  7. onChange?: () => void
  8. onClose?: () => void
  9. visible?: boolean,
  10. value?: any[]
  11. }
  12. /**
  13. * 指派
  14. * @param props
  15. * @returns
  16. */
  17. const AppointPut: React.FC<Props> = (props) => {
  18. /*******************************/
  19. const { onChange, onClose, visible, allOfMember, value = [] } = props
  20. const [userAll, setUserAll] = useState([])
  21. const [form] = Form.useForm();
  22. const addAccountUser = useAjax((params) => addAccountUserApi(params))
  23. /*******************************/
  24. useEffect(() => {
  25. if (value.length === 1) {
  26. console.log('value--->', value[0].accountUsers?.map((item: any) => item.putUserId));
  27. form.setFieldsValue({ putUserIds: value[0].accountUsers?.map((item: any) => item.putUserId) })
  28. }
  29. }, [value])
  30. /** 获取组员 */
  31. useEffect(() => {
  32. (async function () {
  33. let res = allOfMember?.data || await allOfMember.run()
  34. if (res?.data) {
  35. let useAll: any = []
  36. res?.data?.forEach((item: any) => {
  37. let obj = {
  38. key: item.userId,
  39. label: item.nickname
  40. }
  41. useAll.push(obj)
  42. })
  43. setUserAll(useAll)
  44. }
  45. })()
  46. }, [])
  47. const handleOk = () => {
  48. form.validateFields().then(values => {
  49. addAccountUser.run({ ...values, accountIds: value.map((item: { accountId: number }) => item.accountId) }).then(res => {
  50. message.success('指派成功')
  51. onChange?.()
  52. })
  53. })
  54. }
  55. return <Modal
  56. title="指派投放助理"
  57. open={visible}
  58. onOk={handleOk}
  59. onCancel={() => onClose?.()}
  60. confirmLoading={addAccountUser.loading}
  61. >
  62. <Form
  63. form={form}
  64. labelCol={{ span: 4 }}
  65. colon={false}
  66. initialValues={{}}
  67. >
  68. <Form.Item label={<strong>组员</strong>} name='putUserIds' rules={[{ required: true, message: '请选择分组' }]}>
  69. <Select
  70. placeholder='请选择组员'
  71. showSearch
  72. mode="multiple"
  73. filterOption={(input: string, option: any) => {
  74. return option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
  75. }}
  76. >
  77. {userAll?.map((item: { key: string, label: number }) => <Select.Option value={item.key} key={item.key}>{item.label}</Select.Option>)}
  78. </Select>
  79. </Form.Item>
  80. </Form>
  81. </Modal>
  82. }
  83. export default React.memo(AppointPut)