appointPut.tsx 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { useAjax } from "@/Hook/useAjax"
  2. import { oceanengine_adAccount_configOperationUser } from "@/services/toutiao/ttAccountManage"
  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 = null } = props
  20. const [userAll, setUserAll] = useState([])
  21. const [form] = Form.useForm();
  22. const addAccountUser = useAjax((params) => oceanengine_adAccount_configOperationUser(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. console.log(values, value)
  50. addAccountUser.run({ ...values, accountId: value?.accountId }).then(res => {
  51. message.success('指派成功')
  52. onChange?.()
  53. })
  54. })
  55. }
  56. console.log("userAll===>",userAll)
  57. return <Modal
  58. title="指派投放助理"
  59. visible={visible}
  60. onOk={handleOk}
  61. onCancel={() => onClose?.()}
  62. confirmLoading={addAccountUser.loading}
  63. >
  64. <Form
  65. form={form}
  66. labelCol={{ span: 4 }}
  67. colon={false}
  68. initialValues={{operationUserIds:value?.operationUserList?.map((item: { userId: any }) => item.userId)}}
  69. >
  70. <Form.Item label={<strong>组员</strong>} name='operationUserIds' rules={[{ required: true, message: '请选择分组' }]}>
  71. <Select
  72. placeholder='请选择组员'
  73. allowClear
  74. showSearch
  75. mode="multiple"
  76. filterOption={(input: string, option: any) => {
  77. return option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
  78. }}
  79. >
  80. {userAll?.map((item: { key: string, label: number }) => <Select.Option value={item.key} key={item.key}>{item.label}</Select.Option>)}
  81. </Select>
  82. </Form.Item>
  83. </Form>
  84. </Modal>
  85. }
  86. export default React.memo(AppointPut)