import fetch from '@/utils/fetch'

/**
 * 配送管理
 * @param {} param0
 */
// 获取（司机，品种，供应商，工地）数据列表
export const getData = (data_type) => fetch('/admin/order/get_data', {data_type}, 'POST')

/**
 * 获取中转站列表
 * @Author   Sophy
 * @DateTime 2020-11-02T15:21:45+0800
 */
export const getTransitList = () => fetch('/admin/order/get_transit', {}, 'POST')

// 新增配送单
export const createDelivery = ({
  order_pattern,
  transit_id,
  driver_id,
  product_type,
  delivery_no,
  variety_num,
  over_ton,
  order_ton,
  supplier_id,
  site_id,
  order_receipt
}) => fetch('/admin/order/create_delivery', {
  order_pattern,
  transit_id,
  driver_id,
  product_type,
  delivery_no,
  variety_num,
  over_ton,
  order_ton,
  supplier_id,
  site_id,
  order_receipt
}, 'POST')

// 配送单列表
export const listDelivery = ({
  page,
  page_len,
  order_num,
  driver_name,
  driver_account,
  start_time,
  end_time,
  supplier_name,
  site_name,
  order_status
}) => fetch('/admin/order/list_delivery', {
  page,
  page_len,
  order_num,
  driver_name,
  driver_account,
  start_time,
  end_time,
  supplier_name,
  site_name,
  order_status
}, 'POST')

// 配送单详情
export const detailDelivery = (delivery_id) => fetch('/admin/order/detail_delivery', { delivery_id }, 'POST')

// 录入信息
export const saveDelivery = ({
  delivery_id,
  over_ton,
  order_ton,
  base_fee,
  sale_fee,
  post_fee,
  return_fee
}) => fetch('/admin/order/save_delivery', {
  delivery_id,
  over_ton,
  order_ton,
  base_fee,
  sale_fee,
  post_fee,
  return_fee
}, 'POST')

// 配送单列表
export const tinyDelivery = ({
  page,
  page_len,
  order_num,
  // delivery_id,
  driver_name,
  driver_account,
  // driver_phone,
  start_time,
  end_time,
  supplier_name,
  // transit_name,
  // variety_num,
  site_name,
  // product_type,
  // order_ton,
  // over_ton,
  // post_fee,
  // create_time
  enterprise_id,
}) => fetch('/admin/order/tiny_delivery', {
  page,
  page_len,
  order_num,
  // delivery_id,
  driver_name,
  driver_account,
  // driver_phone,
  start_time,
  end_time,
  supplier_name,
  // transit_name,
  // variety_num,
  site_name,
  // product_type,
  // order_ton,
  // over_ton,
  // post_fee,
  // create_time
  enterprise_id,
}, 'POST')

// 录入运费
export const savePost = ({
  detail_id,
  post_fee
}) => fetch('/admin/order/save_post', {
  detail_id,
  post_fee
}, 'POST')

// 新增配送单价
export const createPostCash = ({
  transit_id,
  supplier_id,
  site_id,
  cash_fee,
  post_note,
  start_time,
  end_time
}) => fetch('/admin/order/create_post_cash', {
  transit_id,
  supplier_id,
  site_id,
  cash_fee,
  post_note,
  start_time,
  end_time
}, 'POST')

// 配送单价列表
export const listPostCash = ({
  page,
  page_len,
  supplier_name,
  site_name
}) => fetch('/admin/order/list_post_cash', {
  page,
  page_len,
  supplier_name,
  site_name
}, 'POST')

// 配送单价详情
export const detailPostCash = (post_id) => fetch('/admin/order/detail_post_cash', {post_id}, 'POST')

// 编辑配送单价
export const updatePostCash = ({
  transit_id,
  supplier_id,
  site_id,
  cash_fee,
  post_note,
  start_time,
  end_time,
  post_id
}) => fetch('/admin/order/update_post_cash', {
  transit_id,
  supplier_id,
  site_id,
  cash_fee,
  post_note,
  start_time,
  end_time,
  post_id
}, 'POST')


/**
 * 财务管理-司机
 */
// 司机账款列表
// export const listDriverOrder = ({
//   page,
//   page_len,
//   driver_name,
//   driver_account
// }) => fetch('/admin/order/list_driver_order', {
//   page,
//   page_len,
//   driver_name,
//   driver_account
// }, 'POST')
// 改成按负责人收费，接口已改20201103
export const listDriverOrder = ({
  page,
  page_len,
  head_name
}) => fetch('/admin/order/list_head_post', {
  page,
  page_len,
  head_name
}, 'POST')

// 结算运费
export const saveDriverOrder = ({
  head_id,
  order_fee,
  order_note
}) => fetch('/admin/order/save_head_order', {
  head_id,
  order_fee,
  order_note
}, 'POST')

// 运费明细
export const listDriverTiny = ({
  page,
  page_len,
  head_id,
  head_name,
  // delivery_id,
  // driver_name,
  // driver_account,
  start_time,
  end_time,
  enterprise_id
}) => fetch('/admin/order/list_head_order', {
  page,
  page_len,
  head_id,
  head_name,
  start_time,
  end_time,
  enterprise_id
}, 'POST')

// 编辑运费
export const updateDriverOrder = ({
  order_id,
  order_fee
}) => fetch('/admin/order/update_head_order', {
  order_id,
  order_fee
}, 'POST')

// 运费利润
export const listProfit = ({
  page,
  page_len,
  driver_name,
  driver_account
}) => fetch('/admin/order/list_profit', {
  page,
  page_len,
  driver_name,
  driver_account
}, 'POST')

// 新增运费成本
export const saveCost = ({
  cost_id,
  driver_id,
  date_time,
  cost_name,
  cost_count,
  cost_unit,
  order_fee,
  order_note
}) => fetch('/admin/order/save_cost', {
  cost_id,
  driver_id,
  date_time,
  cost_name,
  cost_count,
  cost_unit,
  order_fee,
  order_note
}, 'POST')

// 运费成本列表
export const listCost = ({
  page,
  page_len,
  driver_id
}) => fetch('/admin/order/list_cost', {
  page,
  page_len,
  driver_id
}, 'POST')

//运费成本详情
export const detailCost = ({
  cost_id,
  enterprise_id
}
  
) => fetch('/admin/order/detail_cost', {cost_id,enterprise_id}, 'POST')

// 运费成本删除
export const deleteCost = (cost_id) => fetch('/admin/order/delete_cost', {cost_id}, 'POST')

// 运费利润凭证查询
export const detailCredential = (cost_id) => fetch('/admin/order/detail_credential', {cost_id}, 'POST')

// 导出-司机账款
export const exportDriverOrder = ({
  driver_account
}) => fetch('/admin/order/export_driver_order', {
  driver_account
}, 'POST')

// 导出-运费明细
export const exportDriverTiny = ({
  driver_account,
  delivery_id,
  start_time,
  end_time
}) => fetch('/admin/order/export_driver_tiny', {
  driver_account,
  delivery_id,
  start_time,
  end_time
}, 'POST')

// 导出-运费利润
export const exportProfit = ({
  driver_account
}) => fetch('/admin/order/export_profit', {
  driver_account
}, 'POST')



/**
 * 财务管理-客户
 */
// 新增销项票
export const createSell = ({
  sell_num,
  client_id,
  product_type,
  variety_num,
  sell_ton,
  sell_fee,
  ticket_time,
  order_fee
}) => fetch('/admin/order/create_sell', {
  sell_num,
  client_id,
  product_type,
  variety_num,
  sell_ton,
  sell_fee,
  ticket_time,
  order_fee
}, 'POST')

// 销项票管理列表
export const listSell = ({
  page,
  page_len,
  sell_num,
  client_company,
  start_time,
  end_time
}) => fetch('/admin/order/list_sell', {
  page,
  page_len,
  sell_num,
  client_company,
  start_time,
  end_time
}, 'POST')

// 应付订单管理
export const listClientAccept = ({
  page,
  page_len,
  site_name,
  man_phone,
  order_num,
  account_flag,
  start_time,
  end_time
}) => fetch('/admin/order/list_client_accept', {
  page,
  page_len,
  site_name,
  man_phone,
  order_num,
  account_flag,
  start_time,
  end_time
}, 'POST')

// 配送单详情
export const detailClientOrder = (delivery_id) => fetch('/admin/order/detail_client_order', {delivery_id}, 'POST')

// 收款明细列表
export const listClientOrder = ({
  page,
  page_len,
  client_company,
  order_type,
  order_note,
  start_time,
  end_time
}) => fetch('/admin/order/list_client_order', {
  page,
  page_len,
  client_company,
  order_type,
  order_note,
  start_time,
  end_time
}, 'POST')

// 收款明细列表new
export const listClientOrderNew = ({
  page,
  page_len,
  client_company,
  order_type,
  order_note,
  start_time,
  end_time
}) => fetch('/admin/order/list_client_order_new', {
  page,
  page_len,
  client_company,
  order_type,
  order_note,
  start_time,
  end_time
}, 'POST')

// 删除收款明细
export const deleteClientAccount = (order_id) => fetch('/admin/order/delete_client_account', {order_id}, 'POST')

// 预收款
export const saveClientAccount = ({
  client_id,
  order_fee,
  order_note,
  order_id
}) => fetch('/admin/order/save_client_account', {
  client_id,
  order_fee,
  order_note,
  order_id
}, 'POST')

// 收款详情
export const detailAccountOrder = (order_id) => fetch('/admin/order/detail_account_order', {order_id}, 'POST')

// 退款明细列表
export const listClientRefund = ({
  page,
  page_len,
  client_company,
  order_type,
  start_time,
  end_time
}) => fetch('/admin/order/list_client_refund', {
  page,
  page_len,
  client_company,
  order_type,
  start_time,
  end_time
}, 'POST')

// 退款明细列表
export const detailClientRefund = ({
  page,
  page_len,
  client_id,
  client_company,
  order_type,
  start_time,
  end_time
}) => fetch('/admin/order/detail_client_refund', {
  page,
  page_len,
  client_id,
  client_company,
  order_type,
  start_time,
  end_time
}, 'POST')

// 入账操作
export const saveClientOrder = ({
  delivery_id,
  order_fee
}) => fetch('/admin/order/save_client_order', {
  delivery_id,
  order_fee
}, 'POST')

// 客户账款
export const listClientAccount = ({
  page,
  page_len,
  client_name,
  client_company,
  account_date,
  enterprise_id
}) => fetch('/admin/order/list_client_account', {
  page,
  page_len,
  client_name,
  client_company,
  account_date,
  enterprise_id
}, 'POST')

// 客户账款-收款明细
export const detailClientAccount = ({
  page,
  page_len,
  client_id,
  client_company,
  order_type,
  start_time,
  end_time
}) => fetch('/admin/order/detail_client_account', {
  page,
  page_len,
  client_id,
  client_company,
  order_type,
  start_time,
  end_time
}, 'POST')

// 开票记录
export const sellAccount = ({
  page,
  page_len,
  client_id,
  sell_num,
  client_company,
  start_time,
  end_time
}) => fetch('/admin/order/sell_account', {
  page,
  page_len,
  client_id,
  sell_num,
  client_company,
  start_time,
  end_time
}, 'POST')

// 修改备注
export const saveNote = ({
  client_id,
  account_note
}) => fetch('/admin/order/save_note', {
  client_id,
  account_note
}, 'POST')

// 查看备注
export const detailNote = (client_id) => fetch('/admin/order/detail_note', {client_id}, 'POST')

// 导出图片列表
export const exportPic = (client_id) => fetch('/admin/order/export_pic', {client_id}, 'POST')

// 退款操作
export const saveClientRefund = ({
  client_id,
  order_note,
  order_fee
}) => fetch('/admin/order/save_client_refund', {
  client_id,
  order_note,
  order_fee
}, 'POST')


/**
 * 财务管理-供应商
 */
// 新增销项票
export const createInput = ({
  input_num,
  supplier_id,
  input_fee,
  input_tax,
  tax_fee,
  ticket_time,
  product_list
}) => fetch('/admin/order/create_input', {
  input_num,
  supplier_id,
  input_fee,
  input_tax,
  tax_fee,
  ticket_time,
  product_list
}, 'POST')

// 进项票列表
export const listInput = ({
  page,
  page_len,
  input_num,
  supplier_name,
  start_time,
  end_time
}) => fetch('/admin/order/list_input', {
  page,
  page_len,
  input_num,
  supplier_name,
  start_time,
  end_time
}, 'POST')

// 进项票产品列表
export const listProduct = (input_id) => fetch('/admin/order/list_product', {input_id}, 'POST')

// 供应商应付订单
export const listSupplierAccept = ({
  page,
  page_len,
  account_flag,
  order_num,
  supplier_name,
  product_type,
  variety_num,
  start_time,
  end_time
}) => fetch('/admin/order/list_supplier_accept', {
  page,
  page_len,
  account_flag,
  order_num,
  supplier_name,
  product_type,
  variety_num,
  start_time,
  end_time
}, 'POST')

// 配送详情
export const detailSupplierOrder = (delivery_id) => fetch('/admin/order/detail_supplier_order', {delivery_id}, 'POST')

// 入账
export const saveSupplierOrder = ({
  delivery_id,
  order_fee
}) => fetch('/admin/order/save_supplier_order', {
  delivery_id,
  order_fee
}, 'POST')

// 付款明细
export const listSupplierOrder = ({
  page,
  page_len,
  supplier_name,
  order_type,
  start_time,
  end_time
}) => fetch('/admin/order/list_supplier_order', {
  page,
  page_len,
  supplier_name,
  order_type,
  start_time,
  end_time
}, 'POST')

// 供应商账款
export const listSupplierAccount = ({
  page,
  page_len,
  supplier_name,
  account_date,
  enterprise_id,
}) => fetch('/admin/order/list_supplier_account', {
  page,
  page_len,
  supplier_name,
  account_date,
  enterprise_id
}, 'POST')

// 供应商账款-付款明细
export const detailSupplierAccount = ({
  page,
  page_len,
  supplier_id,
  supplier_name,
  order_type,
  start_time,
  end_time
}) => fetch('/admin/order/detail_supplier_account', {
  page,
  page_len,
  supplier_id,
  supplier_name,
  order_type,
  start_time,
  end_time
}, 'POST')

// 付款记账-汇款
export const saveDraft = ({
  supplier_id,
  input_time,
  draft_detail,
  draft_num,
  draft_type,
  order_fee,
  output_date,
  expire_date,
  draft_note
}) => fetch('/admin/order/save_draft', {
  supplier_id,
  input_time,
  draft_detail,
  draft_num,
  draft_type,
  order_fee,
  output_date,
  expire_date,
  draft_note
}, 'POST')

// 汇款记账明细
export const listDraft = ({
  page,
  page_len,
  supplier_name,
  draft_type,
  start_time,
  end_time
}) => fetch('/admin/order/list_draft', {
  page,
  page_len,
  supplier_name,
  draft_type,
  start_time,
  end_time
}, 'POST')

// 付款记账-现金
export const saveCash = ({
  supplier_id,
  input_time,
  order_fee,
  cash_date,
  cash_detail,
  cash_fee,
  cash_note
}) => fetch('/admin/order/save_cash', {
  supplier_id,
  input_time,
  order_fee,
  cash_date,
  cash_detail,
  cash_fee,
  cash_note
}, 'POST')

// 现金记账明细
export const listCash = ({
  page,
  page_len,
  supplier_name,
  start_time,
  end_time
}) => fetch('/admin/order/list_cash', {
  page,
  page_len,
  supplier_name,
  start_time,
  end_time
}, 'POST')

/**
 * 首页
 */
// 首页四个总数
export const getIndex = (enterprise_id,s) => fetch('/admin/order/index', {
  enterprise_id,
  s
}, 'POST')

// 客户欠款总预警
export const listDue = ({
  page,
  page_len
}) => fetch('/admin/order/list_due', {
  page,
  page_len
}, 'POST')

/**
 * excel导出
 */
// 导出配送单
export const exportDelivery = ({
  order_num,
  driver_name,
  start_time,
  end_time,
  supplier_name,
  site_name,
  order_status
}) => fetch('/admin/order/export_delivery', {
  order_num,
  driver_name,
  start_time,
  end_time,
  supplier_name,
  site_name,
  order_status
}, 'POST')

// 导出配送明细
export const exportTiny = ({
  order_num,
  driver_name,
  start_time,
  end_time,
  supplier_name,
  site_name
}) => fetch('/admin/order/export_tiny', {
  order_num,
  driver_name,
  start_time,
  end_time,
  supplier_name,
  site_name
}, 'POST')

// 导出客户账款
export const exportClient = ({client_company}) => fetch('/admin/order/export_client', { client_company }, 'POST')

// 导出供应商账款
export const exportSupplier = ({supplier_name}) => fetch('/admin/order/export_supplier', { supplier_name }, 'POST')
