// /**分页查询接口重试日志 */
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 + '/appointment/shipbill_page'
export const mainTableNextInfoUrl = business + '/appointment/consignee_page'
export const shipbillTableUrl = business + '/appointment/shipper_page'
export const confirmShipbillTableUrl = business + '/appointment/confirm_shipbill'


export const mainTableShipperInfoUrl = business + '/appointment/loading_shipbill'
export const goodsTableUrl = business + '/appointment/loading_shipbill_detail'
export const packageTableUrl = business + '/appointment/loading_shipbill_package'
export const advancedQueryUrl = business + '/appointment/advanced_query_shipbill'
//派车单查询
export const loadingbillQueryUrl = business + '/appointment/loadingbill_page'



export const exportUrls = {
  allUrl: business + '/appointment/export_all_shipbill',
  currentUrl: business + '/appointment/export_page_shipbill',
  selectUrl: business + '/appointment/export_select_line_shipbill',
  ids:[]

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

//系统参数配置查询
export const getSysConfig = (_this, data) => {
  return request({
    url: serviceName + '/sysParamConfig/queryPage',
    method: 'post',
    data: { pageSize: 10, pageNum: 1 },
  }).then((response) => {
    if (response.success) {
      _this.sysConfig = response.data
    } else {
      _this.$exception(response)
    }

    //  return resolve(response)
  })
}
//装车扫描
export const loadingScan = (_this, data) => {
  return request({
    url: business + '/' + _this.$props.portName + '/loading_scan',
    method: 'post',
    data,
  }).then((response) => {
    if (response.success) {
    } else {
      _this.$exception(response)
    }
    return response
  })
}

export const loading_confirm = (_this, data) => {
  let confirmLoading = true
  let title = '派车作业全部完成，确认装车?'
  if (data.notScannedShipbillIds.length > 0) {
    title = `派车单【${data.loadingBillId}】中存在未扫描的运单：${data.notScannedShipbillIds.join(',')}，是否装车！`
  }

  return new Promise((resolve) => {
    _this.$confirm({
      title,
      confirmLoading,
      onOk(clear) {
        confirmLoading = true
        return request({
          url: business + '/' + _this.$props.portName + '/loading_confirm',
          method: 'post',
          data,
        })
          .then((response) => {
            close()
            _this.visible = false
            if (response.success) {
              clear()
              _this.$message.success(response.message)
            } else {
              _this.$exception(response)
            }
            setTimeout(() => {
              confirmLoading = false
            }, 1000)
            return resolve(response)
          })
          .catch((response) => {
            _this.visible = false
            confirmLoading = false
          })
      },
    })
  })
}

// 提货预约查询 POST
export const queryAppointment= (_this, data) => {
  return request({
    url: business + '/appointment/pick_up_appointment',
    method: 'post',
    data,
  })
}

export const appointment_confirm = (_this, data) => {
  let confirmLoading = true
  return new Promise((resolve) => {
    _this.$confirm({
      title: '是否预约确认?',
      confirmLoading,
      onOk(clear) {
        confirmLoading = true

        return request({
          url: business + '/appointment/pick_up_appointment_confirm',
          method: 'post',
          data,
        })
          .then((response) => {
            if (response.success) {
              clear()
              _this.$message.success('预约提交成功，请等待审核!')
              setTimeout(() => {
                _this.onBack('main',null,true)
              }, 1000)
            } else {
              _this.$exception(response)
            }
            setTimeout(() => {
              confirmLoading = false
            }, 1000)
            return resolve(response)
          })
          .catch((response) => {
            confirmLoading = false
          })
      }
    })
  })
}