import { axios } from '@/utils/request'
import { UPCLOUD_RDC_TMS_BUSINESS_SERVICE, UPCLOUD_RDC_TMS_MAINDATA_SERVICE } from '@/config/serviceSettings.js'
const serviceName = UPCLOUD_RDC_TMS_BUSINESS_SERVICE
import qs from 'qs'

// 主表地址
export const listRemoteUrl = {
  url: serviceName + '/pending_dispatch/page',
  method: 'post',
}

// 商品表地址
export const page_detail_item = {
  url: serviceName + '/pending_dispatch/detail/list',
  method: 'post',
}

// 商品表地址（不带分页）
export const split_detail_list = {
  url: serviceName + '/pending_dispatch/split/detail/list',
  method: 'post',
}

// 通过商品查包裹
export const page_package_item = {
  url: serviceName + '/pending_dispatch/detail/package',
  method: 'post',
}

// 包裹表地址
export const page_detail_package = {
  url: serviceName + '/pending_dispatch/package/list',
  method: 'post',
}

// 通过包裹查商品
export const page_item_package = {
  url: serviceName + '/pending_dispatch/package/detail',
  method: 'post',
}

// 查询运单明细
export const viewUrl = (data) => {
  return axios.post(serviceName + "/pending_dispatch/pending_dispatch_view", qs.stringify(data), {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

// 热力图站点信息查询
export const shipbill_hot_map = (data) => {
  return axios.post(serviceName + '/pending_dispatch/shipbill_hot_map', data)
}

// 待调度中转
export const Transit = (data) => {
  return axios.post(serviceName + '/pending_dispatch/transit', data)
}

// 待调度撤销
export const Revoke = (data) => {
  return axios.post(serviceName + '/pending_dispatch/revoke', data)
}

// 待调度按商品拆分
export const goods_split = (data) => {
  return axios.post(serviceName + '/pending_dispatch/goods_split', data)
}

// 策略拆分
export const smart_split = (data) => {
  return axios.post(serviceName + '/pending_dispatch/smart_split', data)
}

// 智能拆分(选择策略)
export const smart_split_strategy = (data) => {
  return axios.post(serviceName + '/pending_dispatch/smart_split_strategy', data)
}

// 策略调度
export const carrier_dispatch_strategy = (data) => {
  return axios.post(serviceName + '/pending_dispatch/carrier_dispatch_strategy', data)
}

// 商品表地址（不带分页）
export const getItemListNoPage = (data) => {
  return axios.post(serviceName + '/pending_dispatch/split/detail/list', data)
}

// 根据商品ID查询单位重量体积
export const getItemVolumeWeight = (data) => {
  return axios.post(UPCLOUD_RDC_TMS_MAINDATA_SERVICE + '/item/by/itemId', data)
}

// 系统分组-查询
export const sys_group_query = (data) => {


  return axios.post(serviceName + '/pending_dispatch/sys_group_query_new', data)
}

// 策略中转
export const smart_transfer = (data) => {
  return axios.post(serviceName + '/pending_dispatch/smart_transfer', data)
}

// 调度前运单地图站点信息查询
export const shipbill_map = (data) => {
  return axios.post(serviceName + '/pending_dispatch/shipbill_map', data)
}

//查询承运商策略
export const query_dispatch_strategy = (data) => {
  return axios.post(serviceName + '/pending_dispatch/query_dispatch_strategy', data)
}
export const match_line = (data) => {
  return axios.post(serviceName + '/pending_dispatch/match_line', data)
}

// 定位
export const Location = (context, data) => {
  let confirmLoading = false
  return new Promise((resolve) => {
    context.$confirm({
      title: '是否定位?',
      confirmLoading,
      onOk(clear) {
        confirmLoading = true
        return axios({
          url: UPCLOUD_RDC_TMS_MAINDATA_SERVICE + '/common/shipbill/location',
          method: 'post',
          data,
        })
          .then((response) => {
            if (response.success) {
              clear()
              context.onSearch();
            } else {
              context.$exception(response)
            }
            confirmLoading = false
            return resolve(response)
          })
          .catch((error) => {
            confirmLoading = false
          })
      },
    })
  })
};


// 计划调度的分组查询接口


