import { request, paramsSerializer } from '@/utils/request.js';

// product-list
export const productListApi = (data) =>
  request({
    url: '/api/admin/tb/product/list',
    params: data,
    // method: 'get',
  });

// dispatch-manage
export const dispatchQueryApi = (data) =>
  request({
    url: '/api/admin/tb/crm/query',
    params: data,
  });
export const dispatchEditApi = (data) =>
  request({
    url: '/api/admin/tb/crm/save',
    data,
  });
export const dispatchDetailApi = (id) =>
  request({
    url: '/api/admin/tb/crm/get',
    params: { id },
    // method: 'get',
  });
export const dispatchDeleteApi = (id) =>
  request({
    url: '/api/admin/tb/crm/delete',
    params: { id },
  });
export const dispatchBatchDisableApi = (crmIds) =>
  request({
    url: '/api/admin/tb/crm/batchDisable',
    params: { crmIds },
    paramsSerializer,
  });
export const dispatchBatchZoneApi = (data) =>
  request({
    url: '/api/admin/tb/crm/batchZone',
    params: data,
  });
export const dispatchCountWaitZoneApi = (data) =>
  request({
    url: '/api/admin/tb/crm/countWaitZone',
    params: data,
    // method: 'get',
  });

// unit-manage
export const serviceUnitQueryApi = (data) =>
  request({
    url: '/api/service/service/unit/page',
    params: data,
  });
export const serviceUnitListApi = (data) =>
  request({
    url: '/api/admin/common/query_service_unit',
    params: data,
    paramsSerializer,
  });
export const serviceUnitEditApi = (data) =>
  request({
    url: '/api/service/service/unit/edit',
    data,
  });
export const serviceUnitPublishApi = (id) =>
  request({
    url: '/api/service/service/unit/publish',
    params: { id },
  });
export const serviceUnitClozeApi = (id) =>
  request({
    url: '/api/service/service/unit/cloze',
    params: { id },
  });
export const serviceUnitRestartApi = (id) =>
  request({
    url: '/api/service/service/unit/restart',
    params: { id },
  });
export const serviceUnitCancelApi = (id) =>
  request({
    url: '/api/service/service/unit/cancel',
    params: { id },
  });

// range-manage
export const serviceScopeQueryApi = (data) =>
  request({
    url: '/api/service/service/scope/page',
    params: data,
  });
export const serviceScopeUnbindCrmQueryApi = (data) =>
  request({
    url: '/api/service/service/scope/unbind/page',
    params: data,
  });
export const serviceScopeSubTotalApi = (data) =>
  request({
    url: '/api/service/service/scope/subTotal',
    params: data,
  });
export const serviceScopeBindBatchApi = (data) =>
  request({
    url: '/api/service/service/scope/bind_batch',
    data,
  });
export const serviceScopeUnbindApi = (crmId) =>
  request({
    url: '/api/service/service/scope/unbind',
    params: { crmId },
  });

// regional-planning
export const serviceRegionQueryApi = (data) =>
  request({
    url: '/api/service/service/region/page',
    params: data,
  });
export const serviceRegionEditApi = (data) =>
  request({
    url: '/api/service/service/region/edit',
    data,
  });
export const serviceRegionRemoveApi = (serviceRegionId) =>
  request({
    url: '/api/service/service/region/remove',
    params: { serviceRegionIdList: serviceRegionId },
    paramsSerializer,
  });

/** v1.1.0 add */
export const getDispatchInfoApi = (params) =>
  request({
    url: '/api/admin/tb/crm/detail/sop/var/info',
    params,
  });
export const getSubSopListApi = (params) =>
  request({
    url: '/api/admin/tb/crm/detail/sop/info',
    params,
  });
//派单明细sop变量保存接口
export const saveProcessVarApi = (data) =>
  request({
    url: '/api/admin/tb/crm/detail/sop/var/save',
    data,
    loading: true,
  });
//创建/编辑派单明细sop接口
export const saveSubSopListApi = (data, isCloud = false) => {
  let url = isCloud
    ? '/api/admin/tb/crm/detail/sop/cloud_mark/save'
    : '/api/admin/tb/crm/detail/sop/save';
  return request({
    url,
    data,
  });
};

//发布
export const subSopPublishApi = (params) =>
  request({
    url: '/api/admin/tb/crm/detail/sop/publish',
    params,
    loading: true,
  });
//删除
export const subSopDeleteApi = (params) =>
  request({
    url: '/api/admin/tb/crm/detail/sop/delete',
    params,
    loading: true,
  });
export const serviceScopeBindNewApi = (data) =>
  request({
    url: '/api/service/service/scope/bind',
    data,
  });

export const getCrmBindInfoApi = (params) =>
  request({
    url: '/api/admin/tb/crm/crm_bind_info',
    params,
  });

export const getAllocationInfoApi = (params) =>
  request({
    url: '/api/admin/user/archives/allocation/info',
    params,
    loading: true,
  });

//人员调配保存
export const saveAllocationInfoApi = (data) =>
  request({
    url: '/api/admin/user/archives/allocation/edit',
    data,
    loading: true,
  });

export const exportPipeiApi = (data) =>
  request({
    url: '/api/admin/tb/crm/receiver/export',
    params: data,
    loading: true,
    download: true,
  });
