var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
//创建服务选择保单接口详细描述
import { requestGet, requestTableList } from '@component/utils';
import { concat, isEmpty, reduce } from 'lodash';
export function getPolicyList(params) {
    const _params = Object.assign({}, params);
    if (_params === null || _params === void 0 ? void 0 : _params.current) {
        _params.pageNum = _params.current;
        Reflect.deleteProperty(_params, 'current');
    }
    function getMapData(params, path) {
        return __awaiter(this, void 0, void 0, function* () {
            const COUNT = 2000;
            try {
                function getData(params) {
                    return requestGet(process.env.REACT_APP_BUSINESS_URL, path, Object.assign(Object.assign({}, params), { pageSize: COUNT }));
                }
                const result = yield getData(params);
                const list = result || [];
                // const pages = result?.pages;
                if (isEmpty(list)) {
                    return [];
                }
                const requestArray = [];
                //
                // for (let i = 1; i < pages; i++) {
                // 	requestArray.push(
                // 		getData({ ...params, pageNum: i + 1 }).then(
                // 			(result) => {
                // 				return result || []
                // 			},
                // 		),
                // 	);
                // }
                return Promise.allSettled(requestArray).then((values) => {
                    return reduce(values, (result, item) => {
                        return concat(result, item.value);
                    }, list);
                });
            }
            catch (e) {
                return [];
            }
        });
    }
    return getMapData(_params, '/policy/choicePolicyLimit').then((data) => {
        if (isEmpty(data)) {
            return {
                success: true,
                total: 0,
                data: [],
            };
        }
        return {
            success: true,
            total: (data === null || data === void 0 ? void 0 : data.length) || 0,
            data: data,
        };
    });
}
//选择保单
export const getPolicyDetail = (params) => {
    return requestGet(process.env.REACT_APP_BUSINESS_URL, 'policy/show', params);
};
//获取一级管理分类列表
export function getIndustryList(params = {}) {
    return requestGet(process.env.REACT_APP_API_URL, '/industry/list', params).then((data) => {
        return data === null || data === void 0 ? void 0 : data.map((item) => {
            return {
                id: item.industryId,
                pId: 0,
                value: item.industryId,
                title: item.industryName,
                label: item.industryName,
                isLeaf: false,
                checkable: false,
            };
        });
    });
}
export const getServiceApply = (params) => {
    return requestTableList(process.env.REACT_APP_SERVICE_URL, `/serviceApply/getServiceObjList`, params);
};