<template>
  <page-header-wrapper>
    <a-card>
      <JeepaySearchForm  :searchConditionNum="6" :searchFunc="searchFunc" :resetFunc="() => { data.searchData= {} }">
        <a-form-item label="" class="table-search-item">
          <JeepayDateRangePicker  ref="dateRangePicker"  v-model:value="data.searchData['queryDateRange']"  customDateRangeType="date" />
        </a-form-item>
        <jeepay-text-up v-model:value="data.searchData['mchUserName']" v-if="props.configMode =='mgr'" :placeholder="'用户号/名称/手机号'" />

<!--        <jeepay-text-up v-model:value="data.searchData['subjectId']" :placeholder="'项目Id'" />-->
        <jeepay-text-up v-model:value="data.searchData['accountName']" :placeholder="'支付宝名称/账号'" />
        <jeepay-text-up v-model:value="data.searchData['transChannelMchNo']" :placeholder="'记账本ID'" />
        <a-form-item label="" class="table-search-item">
          <a-select v-model:value="data.searchData['signState']" placeholder="签约状态">
            <a-select-option value="">全部</a-select-option>
            <a-select-option :value="0">已签约</a-select-option>
            <a-select-option :value="1">签约中</a-select-option>
            <a-select-option :value="2">未签约</a-select-option>
            <a-select-option :value="3">已解约</a-select-option>
            <a-select-option :value="4">解约中</a-select-option>
            <!--            <a-select-option :value="5">暂存</a-select-option>-->
            <a-select-option :value="6">已解约</a-select-option>
            <!--            <a-select-option :value="7">未知</a-select-option>-->
          </a-select>
        </a-form-item>
        <a-form-item label="" class="table-search-item">
          <a-select v-model:value="data.searchData['state']" placeholder="状态">
            <a-select-option value="">全部</a-select-option>
            <a-select-option :value="1">启用</a-select-option>
            <a-select-option :value="0">禁用</a-select-option>
            <a-select-option :value="2">审核中</a-select-option>
<!--            <a-select-option :value="3">禁用</a-select-option>-->
          </a-select>
        </a-form-item>
      </JeepaySearchForm>

<!--      :tableExportFunc="tableExportFunc"-->
      <!-- 列表渲染 -->
      <JeepayTable
        ref="infoTable"
        :init-data="true"
        :req-table-data-func="reqTableDataFunc"
        :statisticsIsShow="false"
        :table-columns="tableColumns"
        :search-data="data.searchData"
        row-key="sysUserId"
        @btnLoadClose="data.btnLoading=false"
      >
        <template #statistics v-if="props.configMode == 'mgr'">
          <div class="statistics-list">
            <div v-for="(item, index) in count" :key="index" class="item">
              <div v-if="item.type == 'line'" class="line" />
              <div class="title">{{ item.title }}</div>
              <div v-if="item.title" class="amount" :style="{color: item.textColor}">
                <span class="amount-num">{{ item.content }}</span>
              </div>
            </div>
          </div>
        </template>
        <template #topBtnSlot>
          <div>
            <a-button
              type="primary"
              class="mg-b-30"
              @click="addFunc"
              v-if="props.configMode == 'mch'"
            >
              <plus-outlined />
              新建
            </a-button>
          </div>
        </template>
        <template #headerCell="{ column }">
          <span v-if="column.tooltipTitle">
            {{ column.title }}
            <a-tooltip :title="column.tooltipTitle"><info-circle-outlined /></a-tooltip>
          </span>
        </template>
        <template #bodyCell="{column,record}">
          <template v-if="column.key === 'bankCardDayMax'">
             <div  v-if="record.signState == 0">
               <b v-if="props.configMode == 'mgr'"  @click="getCardDayMax(record)"><a>{{ (record.bankCardDayMax / 100).toFixed(2)??0 }}</a></b>
               <span v-else  >{{ (record.bankCardDayMax / 100).toFixed(2)??0 }}</span>
               <reload-outlined  style="color: #1890ff; margin-left: 10px;font-size: 16px"  @click="getReloadState(record,1)" />
             </div>
            <div v-else> </div>
          </template>
          <template v-if="column.key === 'zfbDayMax'">
            <div  v-if="record.signState == 0">
               <b v-if="props.configMode == 'mgr'"  @click="getCardDayMax(record)"><a>{{ (record.zfbDayMax / 100).toFixed(2)??0 }}</a></b>
               <span v-else >{{ (record.zfbDayMax / 100).toFixed(2)??0 }}</span>
              <reload-outlined  style="color: #1890ff; margin-left: 10px;font-size: 16px"  @click="getReloadState(record,1)" />

            </div>
            <div v-else> </div>
          </template>
          <template v-if="column.key === 'accountBookBalance'">

            {{ (record.accountBookBalance / 100).toFixed(2)??0 }}
<!--            <transaction-outlined v-if="record.signState == 0"  @click="rechargeFunc(record)"  style="font-size: 16px; padding-left: 5px;color: #1965FF" />-->
<!--            <DollarOutlined />-->
            <WalletOutlined  @click="rechargeFunc(record)" v-if="record.signState == 0"  style="font-size: 16px; padding-left: 5px;color: #1965FF" />
            <reload-outlined  v-if="record.transChannelMchNo" style="color: #1890ff; margin-left: 10px" @click="getReloadState(record,1)" />
          </template>


          <template v-if="column.key === 'transChannelMchNo'">
            <a-popover placement="top" style="background: #0c2640 !important;">
              <template #content  style="background: #ff0 !important;">
                <p>记账本ID：{{ record.transChannelMchNo}}</p>
                <p>记账的外卡卡号：{{ record.extCardInfoJson.cardNo}}</p>
                <p>记账的外卡户名：{{ record.extCardInfoJson.bankAccName}}</p>
                <p>记账的外卡支行 ：{{ record.extCardInfoJson.cardBranch}}</p>
                <p>记账的外卡开户行 ：{{ record.extCardInfoJson.cardBank}}</p>
                <p>记账的外卡开户地址 ：{{ record.extCardInfoJson.cardLocation}}</p>
                <p>记账的外卡联行号 ：{{ record.extCardInfoJson.cardDeposit}}</p>
                <p>记账的外卡状态 ：{{ record.extCardInfoJson.status == 'A'?'正常':"异常"}}</p>
              </template>
              <div class="my-tooltip-title-box"><a >{{record.transChannelMchNo}}</a></div>
            </a-popover>
          </template>
          <template v-if="column.key === 'accountName'">

              <a-tooltip  overlayClassName="tooltip-box-name">
                <template #title>
                  <span>企业支付宝名称：{{record.accountName}}</span><br>
                  <span>企业支付宝账号：{{record.account}}</span>
                </template>
                <div class="my-tooltip-title-box"><a > {{record.accountName}}</a></div>
              </a-tooltip>
          </template>
          <template v-if="column.key === 'state'">
            <a-badge v-if="record.state == 0" status="error" text="禁用" />
            <a-badge v-if="record.state == 1" status="processing" text="启用" />
            <a-badge v-if="record.state == 2" status="warning" text="审核中" />
<!--            <a-badge v-if="record.state == 3" status="blue" text="审核通过" />-->
<!--            <a-badge v-if="record.state == 4" status="error" text="通过驳回" />-->
            <a-tooltip  :title="record.remark" v-if="record.state == 0">
              <info-circle-outlined style="color: #FF0000;margin-left: 5px"/>
            </a-tooltip>
          </template>

          <template v-if="column.key === 'signState'">
            <a-badge v-if="record.signState == 0" status="blue" text="已签约" />
            <a-badge v-if="record.signState == 1" status="processing" text="签约中" />
            <a-badge v-if="record.signState == 2" status="warning" text="未签约" />
            <a-badge v-if="record.signState == 3" status="error" text="已解约" />

            <link-outlined v-if="record.signState != 0 && record.signState != 3"  @click="getSignState(record)"  style="font-size: 16px; padding-left: 5px;color: #1965FF" />
            <reload-outlined v-if="record.signState == 1" style="color: #1890ff; margin-left: 10px" @click="getReloadState(record)" />
<!--            <a-badge v-if="record.signState == 4" status="error" text="解约中" />-->
<!--            <a-badge v-if="record.signState == 5" status="error" text="暂存" />-->
<!--            <a-badge v-if="record.signState == 6" status="error" text="暂停" />-->
<!--            <a-badge v-if="record.signState == 7" status="error" text="未知" />-->
          </template>

          <template v-if="column.key === 'op'">
            <!-- 操作列插槽 -->
            <JeepayTableColumns>
              <a-button  type="link" v-if="props.configMode =='mgr' && record.state == 2" @click="showPreAuditModalFunc(record)">审核</a-button>
<!--              <a-button   type="link" @click="editFunc(record)">修改</a-button>-->
              <a-button   type="link" @click="rechargeFunc(record)" v-if="record.signState == 0">充值</a-button>
              <a-button   type="link" @click="historyFunc(record,0)">充值明细</a-button>
              <a-button   type="link" @click="historyFunc(record,1)">结算明细</a-button>
              <a-button   type="link" @click="taskSettleFunc(record)" v-if="record.signState == 0">提现</a-button>
              <a-button   type="link" @click="unsignFunc(record)"  style="color:red;" v-if="record.signState == 0">解约</a-button>
              <a-button   type="link" @click="delFunc(record)" style="color:red;" v-if="record.signState == 0">删除</a-button>
            </JeepayTableColumns>
          </template>
        </template>
      </JeepayTable>
    </a-card>

    <a-modal v-model:visible="vdata.showRechargeModal" title="充值余额" width="30%" :confirmLoading="vdata.rechargeModalLoading" @ok="rechargeHandleOkFunc">
      <a-form layout="vertical">
          <a-form-item label="充值类型" name="type">
            <a-radio-group v-model:value="vdata.rechargeObject['type']">
              <a-radio :value="1">扫码充值</a-radio>
              <a-radio :value="2">汇款充值</a-radio>
            </a-radio-group>
            <span class="jeepay-tip-text">  请使用查看 <a  href="https://shouyinbei.yuque.com/rv7pt7/ly9al3/rdn9tvz0q9nxbrup" target="_blank">充值流程 </a> </span>

          </a-form-item>
        <div v-if="vdata.rechargeObject.type == 1">
          <a-form-item label="充值金额：" required>
           <div style="display: grid">
             <a-input-number addon-after="元" :min="1" :max="100" :precision="0" v-model:value="vdata.rechargeObject['transAmount']" placeholder="请输入" />
             <span class="jeepay-tip-text">  请使用 <a >{{vdata.rechargeObjectInfo.accountName}} {{vdata.rechargeObjectInfo.account}}</a> 企业支付宝进行充值</span>
           </div>
          </a-form-item>

          <a-form-item label="备注" required style="width: 80%">
            <a-textarea
                v-model:value="vdata.rechargeObject.remark"
                placeholder="请输入备注"
                :auto-size="{ minRows: 3, maxRows: 5 }"
            />
          </a-form-item>
        </div>

        <div v-if="vdata.rechargeObject.type == 2" class="transChannelMchNo-box">

            <a-descriptions>
              <a-descriptions-item label="资金记账本ID">
                <div style="margin-bottom: auto">{{ vdata.rechargeObjectInfo.transChannelMchNo}}</div>
                <div style="margin-top:-4px">
                  <a-button v-clipboard:copy="vdata.rechargeObjectInfo.transChannelMchNo" v-clipboard:success="() => $infoBox.message.success('复制成功')" type="link">
                    <template #icon><copy-outlined /></template>
                     复制
                  </a-button>
                </div>
              </a-descriptions-item>
            </a-descriptions>
            <a-descriptions>
              <a-descriptions-item label="记账的外卡卡号">
                <div style="margin-bottom: auto">{{ vdata.rechargeObjectInfo.extCardInfoJson.cardNo}}</div>
                <div style="margin-top:-4px">
                  <a-button v-clipboard:copy="vdata.rechargeObjectInfo.extCardInfoJson.cardNo" v-clipboard:success="() => $infoBox.message.success('复制成功')" type="link">
                    <template #icon><copy-outlined /></template>
                    复制
                  </a-button>
                </div>
              </a-descriptions-item>
            </a-descriptions>
            <a-descriptions>
              <a-descriptions-item label="记账的外卡户名">
                <div style="margin-bottom: auto">{{ vdata.rechargeObjectInfo.extCardInfoJson.bankAccName}}</div>
                <div style="margin-top:-4px">
                  <a-button v-clipboard:copy="vdata.rechargeObjectInfo.extCardInfoJson.bankAccName" v-clipboard:success="() => $infoBox.message.success('复制成功')" type="link">
                    <template #icon><copy-outlined /></template>
                    复制
                  </a-button>
                </div>
              </a-descriptions-item>
            </a-descriptions>
          <a-descriptions>
            <a-descriptions-item label="记账的外卡支行">
              <div style="margin-bottom: auto">{{ vdata.rechargeObjectInfo.extCardInfoJson.cardBranch}}</div>
              <div style="margin-top:-4px">
                <a-button v-clipboard:copy="vdata.rechargeObjectInfo.extCardInfoJson.cardBranch" v-clipboard:success="() => $infoBox.message.success('复制成功')" type="link">
                  <template #icon><copy-outlined /></template>
                  复制
                </a-button>
              </div>
            </a-descriptions-item>
          </a-descriptions>
          <a-descriptions>
            <a-descriptions-item label="记账的外卡开户行">
              <div style="margin-bottom: auto">{{ vdata.rechargeObjectInfo.extCardInfoJson.cardBank}}</div>
              <div style="margin-top:-4px">
                <a-button v-clipboard:copy="vdata.rechargeObjectInfo.extCardInfoJson.cardBank" v-clipboard:success="() => $infoBox.message.success('复制成功')" type="link">
                  <template #icon><copy-outlined /></template>
                  复制
                </a-button>
              </div>
            </a-descriptions-item>
          </a-descriptions>
          <a-descriptions>
            <a-descriptions-item label="记账的外卡开户地址">
              <div style="margin-bottom: auto">{{ vdata.rechargeObjectInfo.extCardInfoJson.cardLocation}}</div>
              <div style="margin-top:-4px">
                <a-button v-clipboard:copy="vdata.rechargeObjectInfo.extCardInfoJson.cardLocation" v-clipboard:success="() => $infoBox.message.success('复制成功')" type="link">
                  <template #icon><copy-outlined /></template>
                  复制
                </a-button>
              </div>
            </a-descriptions-item>
          </a-descriptions>
          <a-descriptions>
            <a-descriptions-item label="记账的外卡联行号">
              <div style="margin-bottom: auto">{{ vdata.rechargeObjectInfo.extCardInfoJson.cardDeposit}}</div>
              <div style="margin-top:-4px">
                <a-button v-clipboard:copy="vdata.rechargeObjectInfo.extCardInfoJson.cardDeposit" v-clipboard:success="() => $infoBox.message.success('复制成功')" type="link">
                  <template #icon><copy-outlined /></template>
                  复制
                </a-button>
              </div>
            </a-descriptions-item>
          </a-descriptions>
          <a-descriptions>
            <a-descriptions-item label="记账的外卡状态">
              {{ vdata.rechargeObjectInfo.extCardInfoJson.status == 'A'?'正常':"异常"}}
            </a-descriptions-item>
          </a-descriptions>

        </div>
      </a-form>
    </a-modal>
    <a-modal v-model:visible="vdata.showPreAuditModal" title="审核记账本" width="30%" :confirmLoading="vdata.preAuditModalLoading" @ok="preAuditHandleOkFunc">
      <a-form layout="vertical">
        <a-form-item label="企业支付宝名称：">
          <a-input  v-model:value="vdata.preAuditResult['accountName']" placeholder="请输入" :disabled="true" />
        </a-form-item>
        <a-form-item label="企业支付宝账号：">
          <a-input v-model:value="vdata.preAuditResult['account']" placeholder="请输入" :disabled="true" />
        </a-form-item>
        <a-form-item label="签约账号：">
          <a-input v-model:value="vdata.preAuditResult.succResParameter.alipay_logon_id" :disabled="true"  />
        </a-form-item>

        <a-form-item label="处理结果：">
          <a-radio-group v-model:value="vdata.preAuditResult.state">
            <a-radio :value="1">通过</a-radio>
            <a-radio :value="0">驳回</a-radio>
          </a-radio-group>
        </a-form-item>

        <a-form-item v-if="vdata.preAuditResult.state == 0" label="原因：">
          <a-textarea v-model:value="vdata.preAuditResult.applyErrorInfo" :rows="3" />
        </a-form-item>
      </a-form>
    </a-modal>

    <a-modal v-model:visible="vdata.showLimitModal" title="编辑限额" width="30%" :confirmLoading="vdata.LimitModalLoading" @ok="limitHandleOkFunc">
      <a-form layout="vertical">
        <a-form-item label="支付宝单日限额：" name="zfbDayMax">
          <a-input  v-model:value="vdata.recordInfo['zfbDayMax']" placeholder="请输入"  />
        </a-form-item>
        <a-form-item label="支付宝单月限额：" name="zfbMonthMax">
          <a-input  v-model:value="vdata.recordInfo['zfbMonthMax']" placeholder="请输入"  />
        </a-form-item>

        <a-form-item label="银行卡单日限额：" name="bankCardDayMax">
          <a-input v-model:value="vdata.recordInfo.bankCardDayMax"  />
        </a-form-item>

        <a-form-item label="银行卡单月限额：" name="bankCardMonthMax">
          <a-input v-model:value="vdata.recordInfo.bankCardMonthMax" />
        </a-form-item>


        <a-form-item v-if="vdata.preAuditResult.state == 0" label="原因：">
          <a-textarea v-model:value="vdata.preAuditResult.applyErrorInfo" :rows="3" />
        </a-form-item>
      </a-form>
    </a-modal>

    <!-- 新增 / 修改 页面组件  -->
    <SybAqfAddOrEdit ref="infoAddOrEdit" :configMode="props.configMode" :callback-func="searchFunc" />
    <a-drawer
        v-model:visible="vdata.visible"
        title="流水记录"
        :closable="true"
        :body-style="{ paddingBottom: '80px' }"
        :drawer-style="{ backgroundColor: '#f0f2f5' }"
        width="85%"
        @close="vdata.visible = false"
    >
      <SybAqfHistoryPanel :configMode="props.configMode" ref="sybAqfHistoryPanelDrawerRef"  />

    </a-drawer>
  </page-header-wrapper>
</template>
<script setup lang="ts">
import {
  req,
  reqLoad,
  $exportExcel,
  exportExcelUrl,
  API_URL_STATISTIC,
  API_URL_PAY_AQF_LIST,
  API_URL_PAY_AQF_DEL,
  API_URL_PAY_AQF_AGREEMENT_UNSIGN,
  API_URL_PAY_AQF_SAVE,
  $getAqfApisignUrl,
  $getAqfApiTransPage,
  $getAqfApiAlipayFundAccountbookQuery, $getAqfState, $getApiTransferConfigQuota
} from '@/api/manage'
import { useUserStore } from '@/store/modules/user'
import { reactive,ref,getCurrentInstance} from 'vue'
import fileDownload from "js-file-download";
import {message} from "ant-design-vue";
import { useRouter, useRoute } from 'vue-router'
const router = useRouter() //这是全部路由

const props = defineProps({
  configMode: { type: String, default: '' },   // 模式
})
const userStore = useUserStore()
const { $infoBox, $access, $hasAgentEnt } = getCurrentInstance()!.appContext.config.globalProperties


const tableColumns = reactive([
  // {key:'id', title: '账户ID',   dataIndex: 'id' },
  // {key:'subjectName', title: '项目名称',   dataIndex: 'subjectName' },
  {key:'accountName', title: '企业支付宝', dataIndex: 'accountName', },
  {key:'transChannelMchNo', title: '记账本信息', dataIndex: 'transChannelMchNo',align: 'center', },
  {key:'accountBookBalance', title: '记账本余额', dataIndex: 'accountBookBalance',align: 'center', },
  {key:'signState', title: '签约状态', dataIndex: 'signState',align: 'center', },
  {key:'state', title: '启用状态', dataIndex: 'state',align: 'center', },
  {key:'zfbDayMax', title: '支付宝限额', tooltipTitle: '单日支付宝剩余限额', dataIndex: 'zfbDayMax',align: 'center', },
  {key:'bankCardDayMax', title: '银行卡限额', tooltipTitle: '单日银行卡剩余限额',dataIndex: 'bankCardDayMax',align: 'center', },
  // {key:'name', title: '备注', dataIndex: 'name',align: 'center'},
  {key:'createdTime', title: '创建时间', dataIndex: 'createdTime', },
  {key: 'op',title: '操作',   fixed: 'right',align: 'center' }
])

const infoTable = ref()
const infoAddOrEdit =ref()
const sybAqfHistoryPanelDrawerRef = ref()

let data : any = reactive ({
  tableColumns: tableColumns,
  searchData: {queryDateRange: '' } as any,
  btnLoading: false
})

let count:any = ref([]) // 数据统计数组
let vdata : any = reactive({
  visible:false,
  transChannelMchNo:"",
  recordInfo:{} as any,
  showLimitModal:false,
  LimitModalLoading:false,
  showRechargeModal:false,
  rechargeModalLoading: false,  // loading
  rechargeObject: {}, // 预审核结果
  rechargeObjectInfo: {}, // 预审核结果

  showPreAuditModal: false,  // 是否显示预审核弹层
  preAuditModalLoading: false,  // loading
  preAuditResult: {}, // 预审核结果
})

    // 请求table接口数据
function reqTableDataFunc(params){
  params.transIfCode = 'aliaqf'
  params.subjectType = 'FQ'
  if(props.configMode == 'mgr'){
    reqTableCountFunc(params)
  }
  return req.list(API_URL_PAY_AQF_LIST, params)
}

function reqTableCountFunc(params: any) {
  params.method = 'transaction'
  req.list(API_URL_STATISTIC + '/total', params).then(res => {
    count.value = [
      {title: '总成交金额', symbol: 'add', textColor: '#1A66FF', content: ((res.totalSuccAmt) / 100).toFixed(2)},
      {type: 'line'},
      {title: '总成交笔数', content: (res.totalSuccNum)},
      // {type: 'line'},
      // {title: '总退款金额', symbol: 'sub', content: ((res.totalRefundAmt) / 100).toFixed(2)},
      // {type: 'line'},
      // {title: '总退款笔数', content: (res.totalRefundNum)},
    ]
  })
}
    function searchFunc() { // 点击【查询】按钮点击事件
      data.btnLoading = true // 打开查询按钮的loading
      infoTable.value.refTable(true)
    }

    function addFunc () { // 业务通用【新增】 函数
      infoAddOrEdit.value.show()
    }
function taskSettleFunc(record){
  $infoBox.confirmDanger('提现？', '请前往 “发起结算” 页面结算到指定账户', () => {

    router.push({ path: '/taskSettleList' })
  },() => {
    console.log(1111)
  })
}
    function editFunc (recordId) { // 业务通用【修改】 函数
      infoAddOrEdit.value.show(recordId)
    }


function getCardDayMax(record){
  vdata.recordInfo = record
  vdata.recordInfo.zfbDayMax = (record.zfbDayMax / 100).toFixed(2)
  vdata.recordInfo.zfbMonthMax = (record.zfbMonthMax / 100).toFixed(2)
  vdata.recordInfo.bankCardDayMax = (record.bankCardDayMax / 100).toFixed(2)
  vdata.recordInfo.bankCardMonthMax = (record.bankCardMonthMax / 100).toFixed(2)
  vdata.showLimitModal = true
}
    function onCopySuccess () {
      $infoBox.message.success('复制成功')
    }
// 预审核结果
function rechargeHandleOkFunc(){

  if(vdata.rechargeObject.type == 2){
    return false;
  }

  if(!vdata.rechargeObject.transAmount){
    return $infoBox.message.error('请输入金额')
  }

  if(!vdata.rechargeObject.remark){
    return $infoBox.message.error('请输入备注')
  }

  vdata.rechargeModalLoading = true
  $getAqfApiTransPage(vdata.rechargeObject.id,vdata.rechargeObject.transAmount,vdata.rechargeObject.remark).then((res) => {
    vdata.showPreAuditModal = false
    window.open(res)
    infoTable.value.refTable(true)
    vdata.rechargeModalLoading = false
  }).finally(() => {
    vdata.rechargeModalLoading = false
  })

}
function rechargeFunc(record){
  vdata.showRechargeModal = true
  record.remark = ''
  vdata.rechargeObject = record
  vdata.rechargeObjectInfo = record
}


// 显示弹层
function showPreAuditModalFunc (record) {

  vdata.copyInfoSourceApplyId = '' // 清空副本信息

  vdata.showPreAuditModal = true
  record.succResParameter = JSON.parse(record.succResParameter)
  console.log(record,'recordrecord')
  vdata.preAuditResult = record
}
// 预审核结果
function limitHandleOkFunc(){

  vdata.limitModalLoading = true
  // vdata.preAuditResult.applyId vdata.preAuditResult
  $getApiTransferConfigQuota({
    transSubjectId:vdata.recordInfo.id,
    zfbDayMax:vdata.recordInfo.zfbDayMax*100,
    zfbMonthMax:vdata.recordInfo.zfbMonthMax*100,
    bankCardDayMax:vdata.recordInfo.bankCardDayMax*100,
    bankCardMonthMax:vdata.recordInfo.bankCardMonthMax*100
  }).then((res) => {
    vdata.showLimitModal = false
    vdata.limitModalLoading = false
    $infoBox.message.success('处理完成')
    infoTable.value.refTable(true)
  }).finally(() => {
    vdata.limitModalLoading = false
  })

}

// 预审核结果
function preAuditHandleOkFunc(){

  if( (vdata.preAuditResult.state == 0 ) && !vdata.preAuditResult.applyErrorInfo){
    return $infoBox.message.error('请填写拒绝原因')
  }

  vdata.preAuditModalLoading = true
  // vdata.preAuditResult.applyId vdata.preAuditResult
  $getAqfState({
    id:vdata.preAuditResult.id,
    state:vdata.preAuditResult.state,
    remark:vdata.preAuditResult.applyErrorInfo
  }).then((res) => {
    vdata.showPreAuditModal = false
    $infoBox.message.success('处理完成')
    infoTable.value.refTable(true)
  }).finally(() => {
    vdata.preAuditModalLoading = false
  })

}

function historyFunc(record,type){
   // vdata.transChannelMchNo = record.transChannelMchNo
  if(type == 1){
    router.push({
      path:'/taskSettleList',
      query:{bookId:record.transChannelMchNo}
    })
    return false;
  }
   vdata.visible = true
  sybAqfHistoryPanelDrawerRef.value.show(record.transChannelMchNo)
}
function  updateState (recordId, state) { // 【更新状态】

  const title = state === 1 ? '确认[启用]？' : '确认[停用]？'
  return new Promise<void>((resolve, reject) => {
    $infoBox.confirmDanger(title, '', () => {
          return reqLoad.updateById(API_URL_PAY_AQF_SAVE, recordId, { state: state }).then(res => {
            searchFunc()
            resolve()
          }).catch(err => reject(err))
        },
        () => {
          reject(new Error())
        })
  })
}
function getReloadState(record,type = 0){
  if(type == 2){
    $infoBox.message.success('暂无接口')
    // searchFunc() // 更新列表
    return false;
  }
  if(type == 0){
    $infoBox.message.success('状态已更新')
    infoTable.value.refTable(false)
    return false;
  }

  if(type == 1){
    $getAqfApiAlipayFundAccountbookQuery(record.id).then((res) => {

      $infoBox.message.success('更新成功')
      infoTable.value.refTable(false)
    })
    return false;
  }

}
function getSignState(record){


  $infoBox.confirmDanger('请使用 “'+record.accountName+'“ 企业支付宝扫码？', '', () => {
    return  $getAqfApisignUrl(record.id).then((res) => {
      window.open(res)
      infoTable.value.refTable(false)
    }).catch((err) => {
      console.log(1111)
    })
  })
}

function tableExportFunc() {
  return $exportExcel(exportExcelUrl.statistic, Object.assign({}, vdata.searchData, {})).then(res => {
    fileDownload(res.data, '统计.xlsx')
  }).catch((error) => { console.log(error) })
}
function unsignFunc (record) {
  if(record.accountBookBalance != 0){
    $infoBox.message.warn('该记账本余额不为0，请提现后解约')
    return  false
  }
  $infoBox.confirmDanger('确认解约？', '请确认解约该资金账户记账本', () => {
    req.list(API_URL_PAY_AQF_AGREEMENT_UNSIGN, {subId:record.id}).then(res =>   {
      infoTable.value.refTable(false)
      $infoBox.message.success('解约成功')
    }).catch((err) => {
      console.log(1111)
    })
  })
}
function delFunc (record) {
  if(record.signState != 3){
    $infoBox.message.error("请解约该记账本后删除")
    return false;
  }
  $infoBox.confirmDanger('确认删除？', '请确认删除该资金账户', () => {
    req.delById(API_URL_PAY_AQF_DEL, record.id).then(res => {
      infoTable.value.refTable(false)
      $infoBox.message.success('删除成功')
    }).catch((err) => {
      console.log(1111)
    })
  })
}
</script>
<style>
.transChannelMchNo-box{
  background-color: #f5f5f5;
  border-color: #d9d9d9;
  box-shadow: none;
  color: #00000040;
  cursor: not-allowed;
  opacity: 1;
  padding: 15px;
  border-radius: 10px;
}
</style>
