import request from '@/utils/request'
import { exportExcel } from '@/utils/filedown'
function clearCache() {
  request({
    url: 'http://47.244.232.78/api/Customer/ClareCaches',
    method: 'post'
  })
  request({
    url: 'http://120.24.149.148/api/Customer/ClareCaches',
    method: 'post'
  })
}

export function _getCustomer(id) {
  return request({
    url: '/Customer/getCustomer',
    method: 'get',
    params: { id }
  })
}
export function _editCustomer(data) {
  var r = request({
    url: '/Customer/EditCustomer',
    method: 'post',
    data: data
  })
  clearCache()
  return r
}
export function _addCustomer(data) {
  var r = request({
    url: '/Customer/AddCustomer',
    method: 'post',
    data: data
  })
  clearCache()
  return r
}

export function _queryPager(data) {
  return request({
    url: '/Customer/QueryPager',
    method: 'post',
    timeout: 20 * 1000,
    data
  })
}

export function _disable(id) {
  var r = request({
    url: '/Customer/Disable',
    method: 'post',
    timeout: 20 * 1000,
    params: { id }
  })
  clearCache()
  return r
}

export function _enable(id) {
  var r = request({
    url: '/Customer/Enable',
    method: 'post',
    timeout: 20 * 1000,
    params: { id }
  })
  clearCache()
  return r
}

export function _getSalesmanUsers() {
  return request({
    url: '/Customer/GetSalesmanUsers',
    method: 'get',
    timeout: 20 * 1000
  })
}

export function _outCustomer(data) {
  exportExcel('http://120.24.149.148/api/Customer/OutCustomer', data, 'post')
}

export function _startAgentIOSS(id) {
  var r = request({
    url: '/Customer/StartAgentIOSS',
    method: 'post',
    timeout: 20 * 1000,
    params: { id }
  })
  clearCache()
  return r
}

export function _stopAgentIOSS(id) {
  var r = request({
    url: '/Customer/StopAgentIOSS',
    method: 'post',
    timeout: 20 * 1000,
    params: { id }
  })
  clearCache()
  return r
}

export function _startReceiving(id) {
  var r = request({
    url: '/Customer/StartReceiving',
    method: 'post',
    timeout: 20 * 1000,
    params: { id }
  })
  clearCache()
  return r
}

export function _stopReceiving(id) {
  var r = request({
    url: '/Customer/StopReceiving',
    method: 'post',
    timeout: 20 * 1000,
    params: { id }
  })
  clearCache()
  return r
}
export function _startConvertUSDToEur(id) {
  var r = request({
    url: '/Customer/StartConvertUSDToEur',
    method: 'post',
    timeout: 20 * 1000,
    params: { id }
  })
  clearCache()
  return r
}

export function _stopConvertUSDToEur(id) {
  var r = request({
    url: '/Customer/StopConvertUSDToEur',
    method: 'post',
    timeout: 20 * 1000,
    params: { id }
  })
  clearCache()
  return r
}

export function _getAllBranchCompanyCustomers() {
  return request({
    url: '/Customer/getAllBranchCompanyCustomers',
    method: 'get'
  })
}

export function _getCustomerRatings() {
  return request({
    url: '/Customer/_getCustomerRatings',
    method: 'get'
  })
}
export function _updateWeightCoefficient(WeightCoefficient,Ids) {
  return request({
    url: '/Customer/_updateWeightCoefficient',
    method: 'post',
    params:{WeightCoefficient:WeightCoefficient,Ids:Ids}
  })
}

/**
 * 账期列表
 * @returns
 */
export function _getAccountPeriod(id) {
  return request({
    url: '/customer/GetAccountPeriod',
    method: 'get',
    params: { id }
  })
}

/**
 * 更新账期
 * @returns
 */
export function _updateAccountPeriod(data) {
  return request({
    url: '/customer/UpdateAccountPeriod',
    method: 'post',
    data
  })
}
