import request from '@/utils/request';

import { UPCLOUD_RDC_TMS_BUSINESS_SERVICE } from '@/config/serviceSettings.js'
import qs from 'qs'
const serviceName = UPCLOUD_RDC_TMS_BUSINESS_SERVICE
const business = UPCLOUD_RDC_TMS_BUSINESS_SERVICE

// 单号扫描查询
export const View = (data) => {
  return request.post(serviceName + '/scan_dispatch/view', qs.stringify(data), {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}
export const queryShipbillByLoadingBill = () => {

}
//装车扫描
export const loadingScan = (_this, data) => {
  _this.loading=true

  return request({
    url: business + '/scanDispatch/scanBill',
    method: 'post',
    data,
  }).then((response) => {
    if (response.success) {
    } else {
     // _this.$exception(response)
    }
    return response
  }).finally(() => {
    _this.loading = false
    _this.$nextTick(() => {
      _this.$refs?.scanInput?.focus();
      let form = _this.form();
      form.resetFields()
    })

  })
}

export const scanDispatch_dispatch = (_this, data) => {

  let confirmLoading = false;
  return new Promise((resolve) => {
    _this.$confirm({
      title:'是否直接派车',
      confirmLoading,
      onOk(clear) {
        confirmLoading = true
        return request({
          url: business + '/scanDispatch/dispatch',
          method: 'post',
          data,
        })
          .then((response) => {
            close()
            _this.visible = false
            if (response.success) {
              clear()
              _this.$message.success(response.message)
            } else {
              _this.$exception(response)
            }

            return resolve(response)
          })
          .catch((response) => {
            _this.visible = false
            confirmLoading = false
          })
      },
    })
  })
}