// /**分页查询接口重试日志 */
import request from '@/utils/request'

import { UPCLOUD_RDC_TMS_MAINDATA_SERVICE, UPCLOUD_RDC_TMS_BUSINESS_SERVICE } from '@/config/serviceSettings.js'
const business = UPCLOUD_RDC_TMS_BUSINESS_SERVICE

const serviceName = UPCLOUD_RDC_TMS_MAINDATA_SERVICE
export const mainTableInfoUrl = business + '/allShipbill/queryAllShipbillPage'
export const advancedQueryUrl = business + '/allShipbill/advanced_query_shipbill'
//销售单
export const sellQueryUrl = business + '/allShipbill/query_sell'
//发货单信息查询
export const shipQueryUrl = business + '/allShipbill/query_ship'
export const evaluateQueryUrl = business + '/allShipbill/query_evaluation'
//备货等待信息
export const stockingQueryUrl = business + '/allShipbill/query_stocking_waiting'
// 关闭信息查询 POST
export const closingQueryUrl = business + '/allShipbill/query_closing'


export const goodsTableUrl = business + '/allShipbill/listItemDetailData'
export const packageTableUrl = business + '/allShipbill/listPackageData'

//点运单修改查询的接口
export const mainViewUrl = business + '/shipbill/view_id'
// /allShipbill/adjust

//运输管理——所有运单控制层/客户反馈
export const feedBack = (_this, data, close) => {
  let confirmLoading = true
  request({
    url: business + '/allShipbill/feedBack',
    method: 'post',
    data,
  })
    .then((response) => {
      close()
      if (response.success) {
        _this.visible = false
        _this.$message.success(response.message)
      } else {
        _this.$exception(response)
      }

      return resolve(response)
    })
    .catch((response) => {

    })
}
//运输管理——所有运单控制层/异常登记
export const abnormalRegister = (_this, data, close) => {
  return request({
    url: business + '/allShipbill/abnormalRegister',
    method: 'post',
    data,
  })
    .then((response) => {
      close()
      if (response.success) {
        _this.visible = false
        _this.$message.success(response.message)
      } else {
        _this.$exception(response)
      }
      return resolve(response)
    })
    .catch((response) => {
    })
}
export const exportUrls = {
  allUrl: business + '/allShipbill/export',
  currentUrl: business + '/allShipbill/exportPage',
  selectUrl: business + '/allShipbill/exportSelected',
  ids:[]

}
export const printUrl = business + '/allShipbill/print'


//订单修改 保存
export const mainSaveData = (_this, data) => {
  let url = business + '/allShipbill/adjust'
  let title='是否保存订单商品?'
  if (_this.title === '关闭运单') {
    url = business + '/allShipbill/close';
    title = '是否关闭运单';
  }

  let confirmLoading = true
  return new Promise((resolve) => {
    _this.$confirm({
      title,
      confirmLoading,
      onOk(clear) {
        confirmLoading = true
        _this.load = true
        return request({
          url,
          method: 'post',
          data,
        }) .then((response) => {
          if (response.success) {
            clear()
            _this.$message.success(response.message)
          } else {
            _this.$exception(response)
          }
          _this.load = false
          confirmLoading = false
          return resolve(response)
        })
          .catch((response) => {
            confirmLoading = false
         })

      },
    })
  })
}

//关联运单
export const getTreeShipbill = (_this, data) => {
  const { originalShipbillId,shipbillId}=data
  _this.visible = true
  return request({
    url: business + '/allShipbill/related_shipbill',
    method: 'post',
    data:{
      originalShipbillId:originalShipbillId||shipbillId,
      shipbillId
    },
  })
    .then((response,reject) => {
      if (response.success) {
        // _this.$message.success(response.message)
      } else {
        _this.$exception(response)
      }
      return response

    })
    .finally((response) => {
      _this.visible = false

    })
}
