more.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. import { Button, Card, Checkbox, Col, Row } from 'antd'
  2. import Modal from 'antd/lib/modal/Modal'
  3. import React, { useCallback, useEffect, useState } from 'react'
  4. import { useModel } from 'umi'
  5. import Left from '@/components/ActionModal/left'
  6. import SelectLeft from '@/components/ActionModal/selectLeft'
  7. import style from './more.less'
  8. import NoFoundPage from '@/pages/empty'
  9. type Props = {
  10. visible: boolean,
  11. hideWx: () => void,
  12. ok: (arr: any[]) => void,
  13. defaultDtat: any[],
  14. isSelect?: boolean
  15. }
  16. //更多选择弹窗
  17. let MoreModal = (props: Props) => {
  18. const { visible, hideWx, ok, defaultDtat, isSelect = false } = props
  19. const { mpAccounts, actionWX, dispatch, actionArr, getDataList, getAllOfMember } = useModel('useOperating.useWxGroupList',
  20. models => ({
  21. mpAccounts: models.state.mpAccounts,
  22. actionWX: models.state.actionWX,
  23. dispatch: models.dispatch,
  24. actionArr: models.state.actionArr,
  25. getDataList: models.getDataList,
  26. getAllOfMember: models.getAllOfMember
  27. }))
  28. const [groupSyncWx, setGroupSyncWx] = useState<any[]>([])//当前组未选中的微信
  29. const [selectState, setSelectState] = useState<{ isAll: boolean, isChecked: boolean }>({ isAll: false, isChecked: false })
  30. const { syncWx, sync, graphicMaterialEdit } = useModel('useOperating.useMaterialContent', model => ({
  31. syncWx: model.syncWx,
  32. sync: model.sync,
  33. graphicMaterialEdit: model.graphicMaterialEdit,
  34. }))
  35. //全选
  36. let allSelect = useCallback(() => {
  37. let isGroupWx: any[] = []//选中的数据
  38. let newActionArr: any[] = []
  39. let fiterMp: any[] = []
  40. mpAccounts?.forEach((mp: { id: number, verifyTypeInfo: number }) => {
  41. if (mp?.verifyTypeInfo !== -1) {//过滤未认证
  42. fiterMp.push(mp)
  43. }
  44. actionArr?.forEach((wx: { id: number }) => {
  45. if (wx.id === mp.id) {
  46. isGroupWx.push(wx)
  47. }
  48. })
  49. })
  50. if (isGroupWx?.length === fiterMp?.length || isGroupWx?.length === fiterMp?.length - groupSyncWx?.length) {//清空
  51. newActionArr = actionArr?.filter((wx: { id: number }) => {
  52. if (isGroupWx.every((groupwx: { id: number }) => wx.id !== groupwx.id)) {
  53. return wx
  54. }
  55. return
  56. })
  57. setSelectState({ isAll: false, isChecked: false })
  58. dispatch({ type: 'setActionArr', params: { actionArr: newActionArr } })
  59. } else {//全选
  60. newActionArr = actionArr?.filter((wx: { id: number }) => {
  61. if (isGroupWx.every((groupwx: { id: number }) => wx.id !== groupwx.id)) {
  62. return wx
  63. }
  64. return
  65. })
  66. newActionArr = [...newActionArr, ...fiterMp]
  67. setSelectState({ isAll: false, isChecked: true })
  68. dispatch({ type: 'setActionArr', params: { actionArr: newActionArr } })
  69. }
  70. }, [selectState, mpAccounts, actionArr, actionWX, groupSyncWx])
  71. //反选
  72. let returnSelct = useCallback(() => {
  73. let isGroupWx: any[] = []
  74. let returnWx: any[] = []
  75. let newActionArr: any[] = []
  76. let fiterMp: any[] = []
  77. mpAccounts?.forEach((mp: { id: number, verifyTypeInfo: number }) => {
  78. if (mp?.verifyTypeInfo !== -1) {//过滤未认证
  79. fiterMp.push(mp)
  80. }
  81. actionArr?.forEach((wx: { id: number }) => {
  82. if (wx.id === mp.id) {
  83. isGroupWx.push(wx)
  84. }
  85. })
  86. })
  87. returnWx = fiterMp?.filter((mp: { id: number }) => {
  88. if (isGroupWx.every((wx: { id: number }) => mp.id !== wx.id)) {
  89. return mp
  90. }
  91. return
  92. })
  93. newActionArr = actionArr?.filter((wx: { id: number }) => {
  94. if (isGroupWx.every((groupwx: { id: number }) => wx.id !== groupwx.id)) {
  95. return wx
  96. }
  97. return
  98. })
  99. if (returnWx.length !== 0 && groupSyncWx.length !== returnWx.length) {//假如选中个数的大于0
  100. setSelectState({ isAll: true, isChecked: true })
  101. } else {//假如等于0
  102. setSelectState({ isAll: false, isChecked: false })
  103. }
  104. if (returnWx.length === fiterMp.length && groupSyncWx.length === 0) {
  105. setSelectState({ isAll: false, isChecked: true })//假如反选值与当前组的个数一样证明全选
  106. }
  107. newActionArr = [...newActionArr, ...returnWx]
  108. dispatch({ type: 'setActionArr', params: { actionArr: newActionArr } })
  109. }, [selectState, mpAccounts, actionArr, actionWX, groupSyncWx])
  110. //每次切换组检测全选状态
  111. useEffect(() => {
  112. let isGroupWx: any[] = []
  113. let groupSyncWx: any[] = []
  114. mpAccounts?.forEach((mp: { id: number }) => {
  115. actionArr?.forEach((wx: { id: number }) => {
  116. if (wx.id === mp.id) {
  117. isGroupWx.push(wx)
  118. }
  119. })
  120. })
  121. setGroupSyncWx(groupSyncWx)
  122. // }
  123. if (isGroupWx?.length === mpAccounts?.length) {
  124. setSelectState({ isAll: false, isChecked: true })
  125. } else {
  126. setSelectState({ isAll: true, isChecked: true })
  127. }
  128. if (isGroupWx?.length === 0) {
  129. setSelectState({ isAll: false, isChecked: false })
  130. }
  131. }, [mpAccounts, actionArr])
  132. //关闭弹窗
  133. let handleCancel = useCallback(() => {
  134. dispatch({ type: 'setActionArr', params: { actionArr: [] } })
  135. hideWx()
  136. }, [])
  137. //确定
  138. let handleOk = useCallback(() => {
  139. ok(actionArr)
  140. dispatch({ type: 'setActionArr', params: { actionArr: [] } })
  141. }, [actionArr])
  142. //选中事件
  143. let action = useCallback((item: any) => {
  144. let isGroupWx: any[] = []//选中的数据
  145. if (actionArr?.some((obj: { appid: number }) => obj.appid === item.appid)) {//删除
  146. let newArr = actionArr?.filter((obj: { appid: number }) => obj.appid !== item.appid)
  147. mpAccounts?.forEach((mp: { id: number }) => {
  148. newArr?.forEach((wx: { id: number }) => {
  149. if (wx.id === mp.id) {
  150. isGroupWx.push(wx)
  151. }
  152. })
  153. })
  154. if (isGroupWx.length === 0) {//假如为空
  155. setSelectState({ isAll: false, isChecked: false })
  156. } else {
  157. setSelectState({ isAll: true, isChecked: true })
  158. }
  159. dispatch({ type: 'setActionArr', params: { actionArr: newArr } })
  160. } else {//添加
  161. let arr = [...actionArr, item]
  162. if (mpAccounts?.every((mp: { id: number }) => arr?.some((wx: { id: number }) => mp.id === wx.id))) {//假如全部存在全选
  163. setSelectState({ isAll: false, isChecked: true })
  164. } else {
  165. setSelectState({ isAll: true, isChecked: true })
  166. }
  167. dispatch({ type: 'setActionArr', params: { actionArr: arr } })
  168. }
  169. }, [actionArr, mpAccounts])
  170. useEffect(() => {
  171. let newArr: any[] = []
  172. if (getDataList?.data) {
  173. getDataList?.data?.forEach((data: { mpAccounts: any }) => {
  174. if(data?.mpAccounts){
  175. newArr = [...data?.mpAccounts]
  176. }
  177. })
  178. }
  179. if (getAllOfMember?.data) {
  180. getAllOfMember?.data?.forEach((data: { value: any }) => {
  181. data?.value?.forEach((mp: { id: number }) => {
  182. if (newArr.every((arr: { id: number }) => mp?.id !== arr.id)) {
  183. newArr.push(mp)
  184. }
  185. })
  186. })
  187. }
  188. }, [getDataList?.data, getAllOfMember?.data, isSelect])
  189. //编辑回填
  190. useEffect(() => {
  191. if (defaultDtat.length > 0) {
  192. dispatch({ type: 'setActionArr', params: { actionArr: defaultDtat } })
  193. }
  194. }, [defaultDtat])
  195. return <>
  196. <Modal
  197. title="批量选择公众号"
  198. width={1040}
  199. visible={visible}
  200. onOk={handleOk}
  201. onCancel={handleCancel}
  202. okText='确定'
  203. cancelText='取消'
  204. destroyOnClose
  205. confirmLoading={syncWx.loading || sync.loading || graphicMaterialEdit.loading}
  206. >
  207. {
  208. actionWX ? <Row className={style.colud} >
  209. <Col >
  210. {isSelect ? <SelectLeft /> : <Left />}
  211. {/* <Left /> */}
  212. </Col>
  213. <Col>
  214. <Card
  215. style={{ height: '420px', overflow: 'hidden', minWidth: 290 }}
  216. title={
  217. <>
  218. <span style={{ marginRight: 10 }}>组下成员</span>
  219. <Checkbox
  220. indeterminate={selectState.isAll}
  221. onChange={allSelect}
  222. checked={selectState.isChecked}
  223. >
  224. <span style={{ fontSize: 12, color: '#999' }}>全选</span>
  225. </Checkbox>
  226. <Button size='small' onClick={returnSelct}>反选</Button>
  227. </>
  228. }
  229. bodyStyle={{ height: 350, overflowY: 'auto' }}
  230. >
  231. <Checkbox.Group style={{ width: '100%', }} >
  232. <Row gutter={[10, 0]}>
  233. {
  234. mpAccounts?.map((item: any) => {
  235. let isAction: any = actionArr?.some((obj: any) => obj?.appid === item?.appid)
  236. return <Col key={item.id} span={24}>
  237. <Checkbox value={item} className={style.box} onClick={() => action(item)} disabled={item?.verifyTypeInfo === -1}>
  238. <div
  239. className={`${isAction ? style.card_action : undefined} ${style.card_box}`}
  240. >
  241. <div
  242. style={{ display: 'flex', alignItems: 'center' }}
  243. >
  244. <img src={item?.headImg || localStorage?.bookImg} className={style.item_img} />
  245. {item.nickName}
  246. </div>
  247. </div>
  248. </Checkbox>
  249. </Col>
  250. })
  251. }
  252. </Row>
  253. </Checkbox.Group>
  254. </Card>
  255. </Col>
  256. <Col>
  257. <Card
  258. style={{ height: 420, overflow: 'hidden', minWidth: 280 }}
  259. title={
  260. <>
  261. <span style={{ marginRight: 10 }}>已勾选</span>
  262. <Button size='small' onClick={() => { dispatch({ type: 'setActionArr', params: { actionArr: [] } }) }}>清空</Button>
  263. </>
  264. }
  265. bodyStyle={{ height: 350, overflowY: 'auto' }}
  266. >
  267. <Checkbox.Group style={{ width: '100%' }} >
  268. <Row gutter={[10, 0]}>
  269. {
  270. actionArr?.map((item: any) => {
  271. let isAction: any = actionArr?.some((obj: any) => obj?.appid === item?.appid)
  272. return <Col key={item.id}>
  273. <Checkbox value={item} className={style.box} onClick={() => action(item)}>
  274. <div
  275. className={`${isAction ? style.card_action : undefined} ${style.card_box}`}
  276. >
  277. <div
  278. style={{ display: 'flex', alignItems: 'center' }}
  279. >
  280. <img src={item?.headImg || localStorage?.bookImg} className={style.item_img} />
  281. {item.nickName}
  282. </div>
  283. </div>
  284. </Checkbox>
  285. </Col>
  286. })
  287. }
  288. </Row>
  289. </Checkbox.Group>
  290. </Card>
  291. </Col>
  292. </Row> : <NoFoundPage />
  293. }
  294. </Modal >
  295. </>
  296. }
  297. export default MoreModal