import request from '@/utils/request'
import requestMessage from '@/utils/request_message'
import { createService } from '@/utils/createRequest'
import { getCurrentDateTime } from '@/utils'
import { exportExcelData } from '@/utils/filedown'
const requestDS = createService(process.env.VUE_APP_DS_API)
const requestClient = createService(process.env.VUE_APP_CLIENT_API)

export function _updateESBOnline(data) {
  return request({
    url: '/order/UpdateESBOnline',
    method: 'post',
    data
  })
}

export function _loadOrder(params) {
  return request({
    url: '/order/LoadOrderInfo',
    method: 'get',
    params
  })
}

export function _createOrder(data) {
  return request({
    url: '/Order/Create',
    method: 'post',
    data
  })
}


export function RecoverOrderStatus(data) {
  return request({
    url: '/Order/RecoverOrderStatus',
    method: 'post',
    data
  })
}

/**
 * 重新申请ESB单号
 * @returns
 */
export function _getHomeReGetLabel(systemNo) {
  return requestMessage({
    baseURL: 'https://wms.xingyunyi.cn/api',
    url: '/order/ReGetLabel',
    method: 'post',
    params: { systemNo }
  })
}

/**
 * 邮政单号提前上网
 * @returns
 */
export function _getTrackingMoreAddESB(transferNumber) {
  return requestMessage({
    baseURL: 'http://wms.xingyunyi.cn/api',
    url: '/TrackingMore/AddESB',
    method: 'post',
    params: { transferNumber }
  })
}

/**
 * 获取取订单信息
 * @param {*} data
 * @returns
 */
export function _getLoadOrderInfo(number) {
  return request({
    url: '/order/GetOrderInfo',
    method: 'post',
    params: { number }
  })
}

/**
 * 扣费接口
 * @param {*} data
 * @returns
 */
export function _SetOrderFee(data) {
  return request({
    url: '/order/SetOrderFee',
    method: 'post',
    data
  })
}

/**
 * 获取是否新旧客户
 * @param {*} data
 * @returns
 */
export function GetIsNewCustomer(CustomerId) {
  return request({
    url: '/finance/CheackIsNewFee',
    timeout: 60000,
    method: 'get',
    params: { CustomerId }
  })
}

/**
 * 新客户费用试算
 * @param {*} data
 * @returns
 */
export function NewCalculatorAll(data) {
  return request({
    url: '/finance/ComputeAllProducts',
    method: 'get',
    params: { coutryCode: data.CountryCode, weight: data.Weight, length: data.L, width: data.W, height: data.H, CustomerId: data.CustomerId }
  })
}

/**
 * 兼容旧版费用试算
 * @param {*} data
 * @returns
 */
export function OldCalculator(data) {
  return requestClient({
    url: '/finance/Calculator',
    method: 'post',
    data
  })
}


/**
 * 变更17服务商
 * @returns
 */
export function _updateChange17TrackingInfo(data) {
  return request({
    baseURL: 'http://wms.xingyunyi.cn/api',
    url: '/TrackingMore/Change17TrackingInfo',
    method: 'post',
    data
  })
}
const requestWms = createService('https://wms.xingyunyi.cn/api', true)
/**
 * 获取上门取件预报列表
 * @param {*} data
 * @returns
 */
export function GetScanFormPager(data) {
  return requestWms({
    url: '/order/GetScanFormPager',
    method: 'post',
    data,
    timeout: 30 * 1000
  })
}

/**
 * 明细
 * @param {*} data
 * @returns
 */
export function GetScanFormDetailsPager(data) {
  return requestWms({
    url: '/order/GetScanFormDetailsPager',
    method: 'post',
    data,
    timeout: 30 * 1000
  })
}

/**
 * 提交上门取件预报
 * @param {*} params
 * @returns
 */
export function AddScanform(data) {
  return requestWms({
    url: '/order/Scanform',
    method: 'post',
    data
  })
}




/**
 *
 * @param {*} data
 * @returns
 */
export function _GetNewFee(data) {
  return request({
    url: '/order/GetNewFee',
    method: 'post',
    data
  })
}


/**
 * 保存列表结果
 * @param {*} data
 * @returns
 */
export function _SaveNewFee(data) {
  return request({
    url: '/order/SaveNewFee',
    method: 'post',
    data
  })
}

/**
 * 保存列表结果后显示的数据
 * @param {*} data
 * @returns
 */
export function _GetCustomerWeightSupplementary(data) {
  return request({
    url: '/order/GetCustomerWeightSupplementary',
    method: 'post',
    data
  })
}

/**
 * 查询明细分页数据
 * @param {*} groupId
 * @returns
 */
export function _GetDetail(groupId) {
  return request({
    url: '/order/GetDetail',
    method: 'get',
    params: { groupId }
  })
}

/**
 * 上传费用
 * @param {*} data
 * @returns
 */
export function _UpdateSupplementaryGroup(GroupId) {
  return request({
    url: '/order/UpdateSupplementaryGroup',
    method: 'post',
    params: { GroupId }
  })
}

/**
 * 实重表格数据导出
 * @param {*} data
 * @returns
 */
export function _DoloadUpdateWeightViewFile(data) {
  return request({
    url: '/order/DoloadUpdateWeightViewFile',
    method: 'post',
    timeout: 60 * 1000,
    responseType: 'blob',
    headers:{ 'Content-Type': 'application/json; application/octet-stream'},
    data
  })
  .then((res)=>{
    const fileName = getCurrentDateTime()
    exportExcelData(res, fileName + '上传实重')
  })
}
