index.tsx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import Tables from "@/components/Tables"
  2. import { useAjax } from "@/Hook/useAjax"
  3. import { getCropWechatApi, sysCropWechatApi } from "@/services/launchAdq/createAd"
  4. import { CheckOutlined, SyncOutlined } from "@ant-design/icons"
  5. import { Button, Input, message, Modal, Space, Tooltip } from "antd"
  6. import React, { useEffect, useState } from "react"
  7. import style from '../goodsModal/index.less'
  8. import columns from "./tableConfig"
  9. /**
  10. * 获取客服组
  11. * @returns
  12. */
  13. interface Props {
  14. onChange?: (data: any) => void,
  15. data: any
  16. }
  17. const CustomerServiceModal: React.FC<Props> = (props) => {
  18. /************************/
  19. const { data: data1, onChange } = props
  20. const [tableData, setTableData] = useState<any[]>([])//table数据
  21. const [selectAdz, setSelectAdz] = useState<number>(1) // 选择广告主
  22. const [selectCrop, setSelectCrop] = useState<number>(1) // 选择按钮
  23. const [data, setData] = useState<any>(JSON.parse(JSON.stringify(data1)))
  24. const [visible, setVisible] = useState<boolean>(false)
  25. const [sysVisible, setSysVisible] = useState<boolean>(false)
  26. const [corpId, setCorpId] = useState<string>('')
  27. const [notConfigured, setNotConfigured] = useState<any>([])
  28. const getCropWechat = useAjax((params) => getCropWechatApi(params))
  29. const sysCropWechat = useAjax((params) => sysCropWechatApi(params))
  30. /************************/
  31. useEffect(() => {
  32. setData(data1)
  33. }, [data1])
  34. /** 未配置账户获取 */
  35. useEffect(() => {
  36. setNotConfigured(() => data.filter((item: { data: { cropList: any[] }[] }) => item?.data?.some((item: { cropList: any[] }) => item?.cropList?.length === 0)))
  37. }, [data])
  38. useEffect(() => {
  39. if (data?.length > 0) {
  40. getList([data[selectAdz - 1].adAccountId])
  41. } else {
  42. setTableData([])
  43. }
  44. }, [selectAdz])
  45. // 获取客服组列表
  46. const getList = (params: number[]) => {
  47. getCropWechat.run(params).then(res => {
  48. if (res && Object.keys(res)?.indexOf(params[0].toString()) !== -1) {
  49. setTableData(res[params[0]]?.map((item: { groupId: string }) => ({ ...item, id: item.groupId })))
  50. } else {
  51. setTableData([])
  52. }
  53. })
  54. }
  55. const handleOk = () => {
  56. onChange && onChange(data)
  57. setVisible(false)
  58. }
  59. /** 设置选中广告主 */
  60. const handleSelectAdz = (value: number, item: any) => {
  61. if (value === selectAdz) {
  62. return
  63. }
  64. setSelectAdz(value)
  65. setSelectCrop(1)
  66. }
  67. /** 设置选中广告主 */
  68. const handleSelectCrop = (value: number, item: any) => {
  69. if (value === selectCrop) {
  70. return
  71. }
  72. setSelectCrop(value)
  73. }
  74. /** 表格选折 */
  75. const onChangeTable = (selectedRowKeys: React.Key[], selectedRows: any) => {
  76. let newData = JSON.parse(JSON.stringify(data))
  77. newData[selectAdz - 1].data[selectCrop - 1].cropList = selectedRows
  78. setData([...newData])
  79. }
  80. /** 同步 */
  81. const handleSys = () => {
  82. if (corpId) {
  83. console.log(data[selectAdz - 1].id, corpId);
  84. sysCropWechat.run({ accountId: data[selectAdz - 1].id, corpId: corpId }).then(res => {
  85. if (res) {
  86. getList([data[selectAdz - 1].adAccountId])
  87. message.success('同步成功')
  88. setSysVisible(false)
  89. }
  90. })
  91. } else {
  92. message.error('请输入企业微信ID')
  93. }
  94. }
  95. return <div>
  96. <Button type="link" size="small" onClick={() => setVisible(true)} style={{ fontSize: 12 }}>{data1.some((item: { data: { cropList: any[] }[] }) => item?.data?.some((item: { cropList: any[] }) => item?.cropList?.length > 0)) ? '修改客服' : '配置客服'}</Button>
  97. {visible && <Modal
  98. title={<Space>
  99. <span>客服组</span>
  100. <Button size="small" onClick={() => { setSysVisible(true) }} type='link'>同步客服组</Button>
  101. </Space>}
  102. visible={visible}
  103. footer={<Space>
  104. <Button onClick={() => setVisible(false)}>取消</Button>
  105. {notConfigured?.length > 0 ? <Tooltip title={`${notConfigured?.map((item: { adAccountId: string }) => item.adAccountId)?.toString()}下按钮未全部配置客服`}>
  106. <Button type="primary">确定</Button>
  107. </Tooltip> : <Button type="primary" onClick={handleOk}>确定</Button>}
  108. </Space>}
  109. width={1100}
  110. onCancel={() => setVisible(false)}
  111. className={style.SelectPackage}
  112. bodyStyle={{ padding: '0 10px 0 10px' }}
  113. >
  114. <div className={style.content}>
  115. <div className={style.left}>
  116. <h4 className={style.title}>媒体账户</h4>
  117. {data?.map((item: { adAccountId: number, id: number }, index: number) => (
  118. <div key={index} onClick={() => { handleSelectAdz(index + 1, item) }} className={`${style.accItem} ${selectAdz === index + 1 && style.select} `}>
  119. {item?.adAccountId}
  120. {data[index]?.data?.every((item: { cropList: any[] }) => item?.cropList?.length > 0) && <CheckOutlined style={{ color: '#1890ff' }} />}
  121. </div>))}
  122. </div>
  123. <div className={style.left}>
  124. <h4 className={style.title}>企微按钮</h4>
  125. {data[selectAdz - 1].data?.map((item: { name: number }, index: number) => (
  126. <div key={index} onClick={() => { handleSelectCrop(index + 1, item) }} className={`${style.accItem} ${selectCrop === index + 1 && style.select} `}>
  127. <div>按钮{index + 1}<span style={{ fontSize: 12 }}>({item.name})</span></div>
  128. {data[selectAdz - 1]?.data[index]?.cropList?.length > 0 && <CheckOutlined style={{ color: '#1890ff' }} />}
  129. </div>))}
  130. </div>
  131. <div className={style.right}>
  132. <Space style={{ marginBottom: 10 }} align="end">
  133. <Button icon={<SyncOutlined />} type='link' loading={getCropWechat?.loading} onClick={() => { getList([data[selectAdz - 1].adAccountId]) }}></Button>
  134. </Space>
  135. <Tables
  136. columns={columns()}
  137. dataSource={tableData}
  138. size="small"
  139. loading={getCropWechat?.loading}
  140. scroll={{ y: 300 }}
  141. bordered
  142. rowSelection={{
  143. type: 'radio',
  144. selectedRowKeys: data[selectAdz - 1]?.data[selectCrop - 1]?.cropList?.map((item: any) => item?.id?.toString()),
  145. onChange: onChangeTable
  146. }}
  147. />
  148. </div>
  149. </div>
  150. </Modal>}
  151. {/* 输入企业微信ID同步 */}
  152. {sysVisible && <Modal title="输入企业微信ID同步" visible={sysVisible} onOk={handleSys} onCancel={() => setSysVisible(false)} okText='同步' confirmLoading={sysCropWechat.loading}>
  153. <Input value={corpId} onChange={(e) => setCorpId(e.target.value)} placeholder='输入企业微信ID同步' />
  154. </Modal>}
  155. </div>
  156. }
  157. export default React.memo(CustomerServiceModal)