import { getUserId } from '@/services/bus/account';
import { queryCustomerInfo } from '@/services/go/ermcp/qhj';
import { QueryCustomerInfoReq } from "@/services/go/ermcp/qhj/interface";

// 查询类型 1:未提交(网上开户表) 2:待审核(网上开户表) 3:正常 4:停用
export function handleSearch(querytype: 1 | 2 | 3 | 4, queryTable: Function) {
    let cache: any = null;
    function search(value: any) {
        const { includesub, name, nickname, userid, userinfotype } = value;
        const param: QueryCustomerInfoReq = {
            // includesub,     // 是否包含子级 1-包含
            querytype,  // 查询类型 1:未提交(网上开户表) 2:待审核(网上开户表) 3:正常 4:停用
            customername: name[0],  // 客户名称(模糊匹配)
            nickname: nickname[0],     // 昵称(模糊匹配)
            userinfotype: userinfotype[0] ? userinfotype[0] : 0,
            userid: userid[0] ? userid[0] : getUserId()
        };
        (includesub !== undefined) && (param.includesub = includesub)
        cache = param
        queryTable(queryCustomerInfo, param);
    }
    function update() {
        if (cache) {
            search(cache)
        } else {
            queryTable(queryCustomerInfo, { querytype, userid: getUserId() });
        }
    }
    return { search, update }
}
