// /**分页查询接口重试日志 */
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
// 待排计划单分页查询 POST
export const mainTableInfoUrl = business + '/transport_plan_bill/plan_bill_page'


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


export const exportUrls = {
  allUrl: business + '/transport_plan_bill/export',
  currentUrl: business + '/transport_plan_bill/exportPage',
  selectUrl: business + '/transport_plan_bill/exportSelected',
  ids:[]

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


//订单修改 保存
export const mainSaveData = (_this, data,st) => {
  let url
  let title='是否保存计划单?'

  if (st == 2) {
    data.planBillNo=null
    url = business + '/transport_plan_bill/save'
  } else if (st == 3) {
    url = business + '/transport_plan_bill/update'
  }

  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)
          }
          return resolve(response)
        }).finally((response) => {
            _this.load = false
             confirmLoading = false
         })

      },
    })
  })
}

// 计划单运单明细详情查询 POST
export const getChildrenShipbill = (_this, data) => {
  _this.visible = true
  return request({
    url: business + '/transport_plan_bill/plan_bill_detail_view',
    method: 'post',
    data:{
      planBillId:data.planBillId
    },
  }).then((response,reject) => {
    if (response.success) {
      //_this.$set(data,'_children',response.data)
    //  data.children=response.data
       // return response.data

        // _this.$message.success(response.message)
          return response.data
      } else {
        _this.$exception(response)
      }
    })
    .finally((response) => {
      _this.visible = false

    })
}

export const deleteMainItem = (context, data) => {
  let confirmLoading=true
  return new Promise(resolve => {
    context.$confirm({
      title: '确认是否删除!',
      confirmLoading,
      onOk(clear) {
        confirmLoading = true
        return request({
          url: business + '/transport_plan_bill/delete',
          method: 'post',
          data
        }).then(response => {
          if (response.success) {
            clear()
            context.$refs.mainTable.reload()
          } else {
            context.$exception(response)
          }
          return resolve(response)
        }).finally(() => {
          confirmLoading=false
        })
      }
    })
  })
}