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

import {UPCLOUD_RDC_TMS_BMS_SERVICE } from '@/config/serviceSettings.js'

const bms=UPCLOUD_RDC_TMS_BMS_SERVICE


// //分页查询接口重试日志 GET
export const mainTableInfoUrl = bms + '/ar_closeAccount/findList'


export const mainViewUrl = bms + '/ar_closeAccount/detail'



//费用结算-费用信息
export const feeListUrl = bms + '/ar_closeAccount/feeList'
//费用结算-派车单
export const loadingBillUrl = bms + '/ar_closeAccount/find_loading'
//费用结算-费用日志
export const findListForLogUrl = bms + '/ar_closeAccount/findListForLog'

//详情
export const detailUrl = bms + '/ar_closeAccount/detail'


//费用结算弹框-列表查询 POST
export const settlementManagementUrl = bms + '/ar_closeAccount/findList'




//费用提交
export const auditSubmit = (_this, data) => {

  let confirmLoading = true
  return new Promise((resolve) => {
    _this.$confirm({
      title: '是否审核通过?',
      confirmLoading,
      onOk(clear) {
        confirmLoading = true
        return request({
          url: bms + '/ar_closeAccount/audit',
          method: 'post',
          data: data,
        })
          .then((response) => {
            if (response.success) {
              clear()
              _this.clearChildrenTableAll()
              _this.$refs.mainTable.reload()
              _this.$message.success(response.message)
            } else {
              _this.$exception(response)
            }
            setTimeout(() => {
              confirmLoading = false
            }, 1000)
            return resolve(response)
          })
          .catch((response) => {
            confirmLoading = false
          })
      },
    })
  })
}
//作废

export const cancellationSubmit = (_this, data) => {
  let confirmLoading = true
  return new Promise((resolve) => {
    _this.$confirm({
      title: '是否作废?',
      confirmLoading,
      onOk(clear) {
        confirmLoading = true
        return request({
          url: bms + '/ar_closeAccount/invalid',
          method: 'post',
          params: {id:data},
        })
          .then((response) => {
            if (response.success) {
              clear()
              _this.clearChildrenTableAll()
              _this.$refs.mainTable.reload()
              _this.$message.success(response.message)
            } else {
              _this.$exception(response)
            }
            setTimeout(() => {
              confirmLoading = false
            }, 1000)
            return resolve(response)
          })
          .catch((response) => {
            confirmLoading = false
          })
      },
    })
  })
}

//详情
export const getDetail = (_this, data) => {
  return request({
    url: detailUrl,
    method: 'post',
    params: data,
  })
    .then((response) => {
      if (response.success) {
          _this.detailData=response.data
      } else {
        _this.$exception(response)
      }
    })
    .finally((response) => {
      _this.loading=false
    })
}


//修改
export const updateSubmit = (_this, data, _clear) => {
  let confirmLoading = true

  return new Promise((resolve) => {
    _this.$confirm({
      title: '是否修改保存?',
      confirmLoading,
      onOk(clear) {
        confirmLoading = true
        return request({
          url: bms +'/ar_closeAccount/update',
          method: 'post',
          data,
        }).then((response) => {
          _this.inMoneyVisible=false;

            if (response.success) {
              clear()
              _this.clearChildrenTableAll()
              _this.$refs.mainTable.reload()
              _this.$message.success(response.message)
            } else {
              _this.$exception(response)
            }
            return resolve(response)
          }).finally((response) => {
            confirmLoading = false
            _this.inMoneyVisible=false;

            clear()
            _clear()
          })
      },
    })
  })
}
