<template>
  <a-modal
    v-model:visible="vdata.showModal"
    title="确认重新分账?"
    :confirm-loading="vdata.btnLoading"
    :closable="false"
    @ok="handleOkFunc"
    @cancel="handleCancel"
  >
    <br>
    <p style="color:red">提示：重新分账将按照订单维度重新发起（仅限分账失败订单）。</p>
    <br>
    <a-form-item label="是否重新订单金额" name="recalAmount">
      <a-radio-group v-model:value="vdata.isResendAndRecalAmount">
        <a-radio :value="0">不重新计算</a-radio>
        <a-radio :value="1">重新计算</a-radio>
      </a-radio-group>
    </a-form-item>
  </a-modal>
</template>
<script lang="ts" setup>
import { $resendDivision } from '@/api/manage'
import { reactive, ref, getCurrentInstance, inject } from 'vue'

const { $infoBox, $access } = getCurrentInstance()!.appContext.config.globalProperties
// eslint-disable-next-line no-unused-vars


const vdata : any = reactive({
  showModal: false,
  recordIds: null,
  isResendAndRecalAmount: 0,
  btnLoading: false,
})

// 预览函数
let searchFunc : any = inject('searchFunc')


// 确认请求： 重新发起分账 
function handleOkFunc() {
  vdata.btnLoading = true
  $resendDivision(vdata.recordIds.join(','), vdata.isResendAndRecalAmount).then(res => {

      $infoBox.message.warning('请等待接口最新状态')
      if(searchFunc){
        searchFunc()
      }

      vdata.showModal = false

    }).finally(() => {
      vdata.btnLoading = false
    })
}


// 弹层取消
function  handleCancel (e) {
  vdata.showModal = false
}

// 
function show(recordIds) {
  vdata.btnLoading = false
  vdata.isResendAndRecalAmount = 0
  vdata.recordIds = recordIds
  vdata.showModal = true

}

defineExpose({show})
</script>
