import { Select } from 'antd'
import React from 'react'
import { useModel } from 'umi'
//当前账号所有公众号筛选Select
function WxSelect(props: { mode?: 1 | 2, isAll?: boolean }) {
    const { mode = 2,isAll = true } = props
    const { state: { filterWxs, selectWx }, dispatch } = useModel('useOperating.useWxGroupList')
    const { getList } = useModel(isAll ? 'useOperating.useBdMedia' : 'useOperating.useBdMediaPup')
    return <Select
        showSearch
        style={{ width: '100%', marginTop: 15 }}
        placeholder="关联公众号"
        optionFilterProp="children"
        onChange={(value) => {
            dispatch({ type: 'selectWx', params: { selectWx: value } });
            if (mode === 1) {
                getList({mpId:value})
            }
        }}
        mode={mode === 1 ? undefined : 'multiple'}
        allowClear
        filterOption={(input, option) =>
            option?.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
        }
        value={selectWx}
    >
        {
            filterWxs?.map((item: any) => {
                // console.log(item)
                return <Select.Option value={item?.id} key={item?.id}>{item?.nickName}</Select.Option>
            })
        }
    </Select>
}
export default WxSelect