
import { session } from '/@/utils/Memory';
import { defHttp } from '/@/utils/http/axios';

enum Api {
    GetFlowInfoDB = '/base-center/flow/getFlowInfoDB',//查询待办业务
    GetFlowInfoYB = '/base-center/flow/getFlowInfoYB',//查询待办业务
}

export const updateExamine = (params) => {
    params.rows = params.pageSize;
    delete params.pageSize;
    if (params.checkStatus == 1) {//代办
        delete params.checkStatus;
        statistics(true)
        return updateQueryTaskInfoPage(params)
    } else {//已办
        delete params.checkStatus;
        statistics(false)
        return updateQueryTaskYbInfoPage(params)
    }
};

export const statistics = (type) => {
    var ajax = type ? updateQueryTaskInfoPage : updateQueryTaskYbInfoPage;
    ['MR', 'ER', 'DR', 'SR'].map(i => {
        ajax({ page: 1, rows: 1000, serviceType: i }).then((r) => {
            var d = document.querySelector(`#scsh${i}`);
            if (d?.innerText && r) {
                d.innerText = r.items.length;
            }
        }).catch((error) => {
            console.log(error)
        })
    })
}



/**
 * @description: 查询待办的业务信息
 * @param: page:页数              must
 * @param: rows:每页数据条数       must
 * @param: keyStr:模糊查询关键字
 * @param: userId:用户id
 */
export const updateQueryTaskInfoPage = (params) => {
    // params['rows'] = params?.pageSize ? params?.pageSize : 10
    params.shtype = "2";
    // params.serviceType = "MR";//"MR,SR,ER,DR,interface"
    params.userId = session.getItem('userId')
    return new Promise<void>((resolve) => {
        defHttp.post({ url: Api.GetFlowInfoDB, params: params }).then((res) => {
            const result = res.resp_code === 0 ? res.datas : []
            result.items = result.pageData;
            resolve(result)
        })
    })
};
/**
 * @description: 查询已办的业务信息
 * @param: page:页数              must
 * @param: rows:每页数据条数       must
 * @param: keyStr:模糊查询关键字
 * @param: userId:用户id
 */
export const updateQueryTaskYbInfoPage = (params) => {
    // params['rows'] = params?.pageSize ? params?.pageSize : 10
    params.shtype = "2";
    // params.serviceType = "MR";//"MR,SR,ER,DR,interface"//mr是地图资源，dr是文件，er场景，sr组件
    params.userId = session.getItem('userId')
    return new Promise<void>((resolve) => {
        defHttp.post({ url: Api.GetFlowInfoYB, params: params }).then((res) => {
            const result = res.resp_code === 0 ? res.datas : [];
            result.items = result.pageData;
            resolve(result)
        })
    })
};
