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

import { UPCLOUD_RDC_TMS_BUSINESS_SERVICE, UPCLOUD_RDC_TMS_MAINDATA_SERVICE } from '@/config/serviceSettings.js';
const business = UPCLOUD_RDC_TMS_BUSINESS_SERVICE
export const mainTableInfoUrl = business + '/pending_dispatch/planDispatchGroupQuery'

// 系统分组-查询
export const queryPlanDispatchGroup = (data) => {
  return request.post(mainTableInfoUrl, data)
}

export const getCarData = (context, plateNumber) => {
  return request({
    url: UPCLOUD_RDC_TMS_MAINDATA_SERVICE + '/vehicle/popup',
    method: 'post',
    data: {
      plateNumber,
      pageNum: 1, pageSize: 10

    },
  }).then((response) => {
    if (response.success) {
      return response.data?.list[0] ?? null
    } else {
      context.$exception(response);
      return null

    }
  })
    .finally((error) => {
    });
};
///调度管理-待调度控制层/调度
export const dataSubmit = (_this, data) => {
  let confirmLoading = true
  const { volumeRercen, weightRercent } = data[0].loadingBillHeaderVO
  let title='是否调度该配载单?'

  if (Number(volumeRercen)>=1||Number(weightRercent)>=1) {
    title = '当前车辆装载率已满！'+title

  }

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




///调度管理-待调度控制层/调度并审核

export const dataSubmitReview = (_this, data) => {
  let confirmLoading = true
  const { volumeRercen, weightRercent } = data[0].loadingBillHeaderVO
  let title='是否调度并审核该配载单?'

  if (Number(volumeRercen)>=1||Number(weightRercent)>=1) {
    title = '当前车辆装载率已满！'+title

  }


  return new Promise((resolve) => {
    _this.$confirm({
      title,
      confirmLoading,
      onOk() {
        confirmLoading = true
        return request({
          url: business + '/pending_dispatch/plan_dispatch_review',
          method: 'post',
          data,
        })
          .then((response) => {
            if (response.success) {
              _this.$message.success(response.message)
            } else {
              _this.$exception(response)
            }
            setTimeout(() => {
              confirmLoading = false
            }, 100)
            return resolve(response)
          })
          .catch((response) => {
            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: {
      isDispatch: 1,
      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 getPendingDispatch = (_this, data) => {
  return request({
    url: business + '/pending_dispatch/plan_dispatch_loading_statistics',
    method: 'post',
    data,
  }).then((response, reject) => {
    if (response.success) {
      return response.data
    } else {
      _this.$exception(response)
    }
  })
}

export const sys_group_query = (_this, data) => {
  return request({
    url: business + '/pending_dispatch/plan_dispatch_loading_statistics',
    method: 'post',
    data,
  }).then((response, reject) => {
    if (response.success) {
      return response.data
    } else {
      _this.$exception(response)
    }
  })
}

