<template>

  <div v-show=" vdata.tableType == 'table' " style="display: grid;width: 100%;">
    <div class="box-top" style="display: flex;width: 100%;" v-if="$access('ENT_MCH_TRANSFER_OVERVIEW_WALLET') || $access('ENT_MCH_TRANSFER_OVERVIEW_VIRTUA')">
      <a-card style="width: 48%; margin-bottom: 20px;margin-right: 2%" v-if="$access('ENT_MCH_TRANSFER_OVERVIEW_WALLET')" >
        <div class="title" style="display: flex;width: 100%;position: relative;">
          <div style="width: 100%;display: flex" class="title-div-box">
            <p>商户钱包</p>
            <span  class="title-div-box-span">
              <a-popover placement="bottom">
                <template #title><span>资金安全有保障</span></template>
                <template #content>
                  <p>根据《非银行支付机构客户备付金存管办法》、《关于支付机构客户备付金全部集中交存有关事官的通知》 </p>
                  <p>您的收款资金将全部由支付通道存放于中国人民银行。任何单位和个人不得挪用、占用、借用客户备付金，请知悉。 </p>
                </template>
               <SafetyOutlined style="padding: 0 2px"/>资金安全有保障
              </a-popover>
            </span>
          </div>
<!--                    <div style="width: 50%;text-align: right;margin-right: 10px;margin-bottom: 10px;color: #729ED5">明细</div>-->
        </div>
        <div class="items-box-wallet" v-if="vdata.visibleWallet">
          <div class="items">
            <div class="items-zhong">
              <div class="item  items-price">
                <div style="display: flex">
                  <p class="item-title">可用余额</p>
                  <a-tooltip class="tooltip">
                    <template #title>可用金额可用于转账、提现等用途</template>
                    <i class="bi bi-info-circle" />
                  </a-tooltip>
                </div>
                <p class="item-detail">411251561</p>
              </div>
              <div class="item  items-price">
                <div style="display: flex">
                  <p class="item-title">不可用余额</p>
                  <a-tooltip class="tooltip">
                    <template #title>通常为未到结算周期、提现申请中或违规冻结的资金。</template>
                    <i class="bi bi-info-circle" />
                  </a-tooltip>
                </div>
                <p class="item-sub">1651651</p>
              </div>
            </div>
          </div>
          <div class="items-bottom items-bottom-operate">
            <div class="operate" @click="accountFunc(1)" v-if="$access('ENT_MCH_TRANSFER_OVERVIEW_WALLET_RECHARGE')">
              <a-button >充值</a-button>
            </div>
            <div class="operate" @click="accountFunc(2)" v-if="$access('ENT_MCH_TRANSFER_OVERVIEW_WALLET_CASE')" >
              <a-button >提现</a-button>
            </div>
<!--            <div class="operate" @click="accountFunc(3)" v-if="$access('ENT_MCH_TRANSFER_OVERVIEW_WALLET_CASE')">-->
<!--              <a-button >转账</a-button>-->
<!--            </div>-->
            <div class="operate" @click="accountFunc(4)" v-if="$access('ENT_MCH_TRANSFER_OVERVIEW_WALLET_LOG')">
              <a-button >明细</a-button>
            </div>
          </div>
        </div>
        <div class="items-box-wallet" v-if="!vdata.visibleWallet">

          <div class="items">
            <div class="items-zhong-img">
              <div class="item-img">
                <div>
                  <img src="https://syb-manage.oss-cn-hangzhou.aliyuncs.com/price.png" >
                </div>
                <p class="item-img-title">资金管理</p>
                <p class="item-img-detail">备付金账户托管安全有保障 </p>
              </div>
              <div class="item-img">
                <div>
                  <img src="https://syb-manage.oss-cn-hangzhou.aliyuncs.com/tongji.png" >
                </div>
                <p class="item-img-title">税筹优化</p>
                <p class="item-img-detail">空中分账不落地规避二清 </p>
              </div>
              <div class="item-img">
                <div>
                  <img src="https://syb-manage.oss-cn-hangzhou.aliyuncs.com/jb.png" >
                </div>
                <p class="item-img-title">灵活结算</p>
                <p class="item-img-detail">余额转账自动提现更方便 </p>
              </div>
            </div>
          </div>

          <div class="items-bottom-img" v-if="$access('ENT_MCH_TRANSFER_OVERVIEW_WALLET_OPEN')">
            <div class="operate" @click="productFunc(11)">
              <a-button >立即开通</a-button>
            </div>
          </div>
        </div>
      </a-card>
      <a-card style="width: 48%; margin-bottom: 20px;" v-if="$access('ENT_MCH_TRANSFER_OVERVIEW_VIRTUA')">
        <div class="title" style="display: flex;width: 100%">
          <div style="width: 50%" class="title-div-box"><p>虚拟银行</p></div>
          <!--          <div style="width: 50%;text-align: right;margin-right: 10px;margin-bottom: 10px;color: #729ED5">明细</div>-->
        </div>
        <div class="items-box-wallet" v-if="vdata.visibleVirtually">
          <div class="items">
            <div class="items-zhong">
              <div class="item  items-price">
                <div style="display: flex">
                  <p class="item-title">可用余额</p>
                  <a-tooltip class="tooltip">
                    <template #title>可用金额可用于转账、提现等用途</template>
                    <i class="bi bi-info-circle" />
                  </a-tooltip>
                </div>
                <p class="item-detail">411251561</p>
              </div>
              <div class="item  items-price">
                <div style="display: flex">
                  <p class="item-title">不可用余额</p>
                  <a-tooltip class="tooltip">
                    <template #title>通常为未到结算周期、提现申请中或违规冻结的资金。</template>
                    <i class="bi bi-info-circle" />
                  </a-tooltip>
                </div>
                <p class="item-sub">1651651</p>
              </div>
            </div>
          </div>
          <div class="items-bottom items-bottom-operate">
            <div class="operate" @click="accountFunc(1)" v-if="$access('ENT_MCH_TRANSFER_OVERVIEW_VIRTUAL_BANK_RECHARGE')">
              <a-button >充值</a-button>
            </div>
            <div class="operate" @click="accountFunc(2)" v-if="$access('ENT_MCH_TRANSFER_OVERVIEW_VIRTUAL_BANK_CASE')">
              <a-button >提现</a-button>
            </div>
            <div class="operate" @click="accountFunc(3)" v-if="$access('ENT_MCH_TRANSFER_OVERVIEW_WALLET_ACCOUNT')">
              <a-button >转账</a-button>
            </div>
            <div class="operate" @click="accountFunc(4)" v-if="$access('ENT_MCH_TRANSFER_OVERVIEW_VIRTUAL_BANK_LOG')">
              <a-button >明细</a-button>
            </div>
          </div>
        </div>
        <div class="items-box-wallet" v-if="!vdata.visibleVirtually">

          <div class="items">
            <div class="items-zhong-img">
              <div class="item-img">
                <div>
                  <img src="https://syb-manage.oss-cn-hangzhou.aliyuncs.com/price.png" >
                </div>
                <p class="item-img-title">线上开通</p>
                <p class="item-img-detail">虚拟对公户无需上门极速开通 </p>
              </div>
              <div class="item-img">
                <div>
                  <img src="https://syb-manage.oss-cn-hangzhou.aliyuncs.com/tongji.png" >
                </div>
                <p class="item-img-title">资金管理</p>
                <p class="item-img-detail">多渠道收单资金一站式管理 </p>
              </div>
              <div class="item-img">
                <div>
                  <img src="https://syb-manage.oss-cn-hangzhou.aliyuncs.com/jb.png" >
                </div>
                <p class="item-img-title">税筹优化</p>
                <p class="item-img-detail">空中分账不落地资金灵活结算 </p>
              </div>
            </div>
          </div>

          <div class="items-bottom-img" v-if="$access('ENT_MCH_TRANSFER_OVERVIEW_VIRTUAL_BANK_OPEN')">
            <div class="operate" @click="productFunc(10)">
              <a-button >立即开通</a-button>
            </div>
          </div>
        </div>
      </a-card>
    </div>
    <div class="box-top" style="display: flex;width: 100%;flex-wrap: wrap;"   v-if="$access('ENT_MCH_TRANSFER_OVERVIEW_REFUND') || $access('ENT_MCH_TRANSFER_OVERVIEW_MARKE')">
      <div  v-for="(item, index) in vdata.accountList" :key="index" style="width: 48%; margin-bottom: 20px;margin-right: 2%">
        <a-card  v-if="item.statusOpen"  >
          <div class="title" style="display: flex;width: 100%;margin: 16px 0 0 20px">
            <div style="width: 50%" ><p>{{ item.typeNameDesc }}
              <a-popover placement="top">
                <template #content>
                  <a href='https://opendocs.alipay.com/common/02kipk?pathHash=0d20b438' target="_blank">密钥生成方式</a>
                </template>
                <question-circle-outlined style="font-size: 15px" />
              </a-popover>
            </p></div>
            <div class="tooltip_so" @click="getEarlyFunc(item)" v-if="item.prompt">
              预警设置
            </div>
          </div>
          <div class="items-box-wallet" v-if="vdata.visibleRefund">
            <div class="items">
              <div class="items-zhong">
                <div class="item  items-price">
                  <div style="display: flex">
                    <p class="item-title">可用余额</p>
                    <a-tooltip class="tooltip">
                      <template #title>可用金额可用于转账、提现等用途</template>
                      <i class="bi bi-info-circle" />
                    </a-tooltip>
                  </div>
                  <p class="item-detail">{{ (item.balacne / 100).toFixed(2) }}</p>
                </div>
                <div class="item  items-price">
                  <div style="display: flex">
                    <p class="item-title">不可用余额</p>
                    <a-tooltip class="tooltip">
                      <template #title>通常为未到结算周期、提现申请中或违规冻结的资金。</template>
                      <i class="bi bi-info-circle" />
                    </a-tooltip>
                  </div>
                  <p class="item-sub">{{ (item.freeze / 100).toFixed(2) }}</p>
                </div>
              </div>
            </div>
            <div class="items-bottom">
              <div class="operate" @click="accountFunc(1)" v-if="item.recharge">
                <a-button >充值</a-button>
              </div>
              <div class="operate" @click="accountFunc(2,item.type)" v-if="item.case">
                <a-button >提现</a-button>
              </div>
              <div class="operate" @click="accountFunc(3)" v-if="item.account">
                <a-button >转账</a-button>
              </div>
              <div class="operate" @click="accountFunc(4)" v-if="item.log">
                <a-button >明细</a-button>
              </div>
            </div>
          </div>
          <div class="items-box-wallet" v-if="!vdata.visibleRefund">
            <div class="items">
              <div class="items-zhong-img">
                <div class="item-img">
                  <div>
                    <img src="https://syb-manage.oss-cn-hangzhou.aliyuncs.com/price.png" >
                  </div>
                  <p class="item-img-title">资金管理</p>
                  <p class="item-img-detail">备付金账户托管安全有保障 </p>
                </div>
                <div class="item-img">
                  <div>
                    <img src="https://syb-manage.oss-cn-hangzhou.aliyuncs.com/tongji.png" >
                  </div>
                  <p class="item-img-title">税筹优化</p>
                  <p class="item-img-detail">空中分账不落地规避二清 </p>
                </div>
                <div class="item-img">
                  <div>
                    <img src="https://syb-manage.oss-cn-hangzhou.aliyuncs.com/jb.png" >
                  </div>
                  <p class="item-img-title">灵活结算</p>
                  <p class="item-img-detail">余额转账自动提现更方便 </p>
                </div>
              </div>
            </div>

            <div class="items-bottom-img">
              <div class="operate" @click="accountFunc(5)">
                <a-button>立即开通</a-button>
              </div>
            </div>
          </div>
        </a-card>
      </div>
    </div>
  </div >

  <EarlySave ref="infoEarlySave" :callbackFunc="searchFunc" @itemRender="itemEarlySave" />


    <SybProductDeatil configMode="mch"  v-show=" vdata.tableType == 'detail' " ref="nextProductDeatilRef" @itemRender="itemRenderSave" />


    <SybProductSign configMode="mch"  v-show=" vdata.tableType == 'sign' " ref="nextProductSignRef" @itemRender="itemRenderSave"/>
</template>

<script lang="ts" setup>
import { message } from 'ant-design-vue'
import {$getMainUserInfo, req, reqLoad, API_MCH_PAY_ACCOUNT, API_URL_PRODUCT_START_LIST} from '@/api/manage'
import { ref, onMounted, reactive, getCurrentInstance } from 'vue'
import EarlySave from "@/views/transfer/EarlySave.vue";
import ProductDeatil from "@/views/product/productDeatil.vue";
import ProductSign from "@/views/product/productSign.vue";
import { useRouter, useRoute } from 'vue-router'
const router = useRouter() //这是全部路由

const { $infoBox, $access } = getCurrentInstance()!.appContext.config.globalProperties // 获取全局函数
const infoTable = ref()
const infoEarlySave = ref()
const nextProductDeatilRef = ref();
const nextProductSignRef = ref();
const vdata = reactive({
  tableType:'table',
  visibleWallet:false,
  visibleVirtually:false,
  visibleRefund:true,
  visibleMarketing:true,
  accountList:[] as any,//账户信息
})

console.log($access('ENT_MCH_TRANSFER_OVERVIEW_REFUND'),'ENT_MCH_TRANSFER_OVERVIEW_REFUND')


function accountFunc(type,index=0){
  switch (type){
    case 1:
      router.push({
        path:'/fundRecharge'
      })
    break;
    case 2:
      router.push({
        path:'/fundWithdrawal',
        query:{index:index}
      })
      break;
    case 3:
      // router.push({
      //   path:'/doTransfer'
      // })
      message.error("暂未开通此功能")
      break;
    case 4:
      router.push({
        path:'/fundLog'
      })
      break;
  }

  // message.error("暂未开通此功能")

}
function  updateState (type) { // 【更新状态】


}

getAccount()
function  getAccount(){

  req.list(API_MCH_PAY_ACCOUNT,{}).then(res => {
    let list = [] as any;
     res.forEach((item)=>{
      console.log(item,'itemitem')
        if(item.type != 3 && item.type != 2){
          list.push(item)
        }
    })
    console.log(list,'listlistlist')
    let accountList  = list
    for (let i=0;i<accountList.length;i++){
      accountList[i].prompt = false
      accountList[i].open = false
      accountList[i].log = false
      accountList[i].case = false
      accountList[i].recharge = false
      accountList[i].account = false
      accountList[i].statusOpen = false
      if(i == 0){
        if($access('ENT_MCH_TRANSFER_OVERVIEW_REFUND')){
          accountList[i].statusOpen = true
        }
        console.log($access('ENT_MCH_TRANSFER_OVERVIEW_MARKE_PROMPT'),'ENT_MCH_TRANSFER_OVERVIEW_MARKE_PROMPT')
         if($access('ENT_MCH_TRANSFER_OVERVIEW_REFUND_PROMPT')){
           accountList[i].prompt = true
         }
        if($access('ENT_MCH_TRANSFER_OVERVIEW_REFUND_ACCOUNT')){
          accountList[i].account = true
        }
        if($access('ENT_MCH_TRANSFER_OVERVIEW_REFUND_CASE')){
          accountList[i].case = true
        }
        if($access('ENT_MCH_TRANSFER_OVERVIEW_REFUND_LOG')){
          accountList[i].log = true
        }
        if($access('ENT_MCH_TRANSFER_OVERVIEW_REFUND_OPEN')){
          accountList[i].open = true
        }
        if($access('ENT_MCH_TRANSFER_OVERVIEW_REFUND_RECHARGE')){
          accountList[i].recharge = true
        }
      }
      if(i == 1){
        if($access('ENT_MCH_TRANSFER_OVERVIEW_MARKE')){
          accountList[i].statusOpen = true
        }
        if($access('ENT_MCH_TRANSFER_OVERVIEW_MARKE_PROMPT')){
          accountList[i].prompt = true
        }
        if($access('ENT_MCH_TRANSFER_OVERVIEW_MARKE_ACCOUNT')){
          accountList[i].account = true
        }
        if($access('ENT_MCH_TRANSFER_OVERVIEW_MARKE_CASE')){
          accountList[i].case = true
        }
        if($access('ENT_MCH_TRANSFER_OVERVIEW_MARKE_LOG')){
          accountList[i].log = true
        }
        if($access('ENT_MCH_TRANSFER_OVERVIEW_MARKE_OPEN')){
          accountList[i].open = true
        }
        if($access('ENT_MCH_TRANSFER_OVERVIEW_MARKE_RECHARGE')){
          accountList[i].recharge = true
        }
      }

      if(i == 2){
        accountList[i].prompt = true
        accountList[i].open = true
        accountList[i].log = true
        accountList[i].case = true
        accountList[i].recharge = true
        accountList[i].account = true
        accountList[i].statusOpen = true
      }
    }
       vdata.accountList = accountList
      console.log(vdata.accountList,'accountListaccountList')
  })
}

function  submitApp(productId){
  router.push({
    path:'/product/productDeatil',
    query:{'productId':productId}
  })
}
function searchFunc () {
  // vdata.btnLoading = true
  infoTable.value.refTable(true)
}
function getEarlyFunc(data){
  infoEarlySave.value.show(data)
}
function productFunc (recordId) {
   vdata.tableType = "detail"
  nextProductDeatilRef.value.show(recordId)
  // router.push({
  //   path:'/product/productDeatil',
  //   query:{productId:recordId}
  // })
}
function itemEarlySave(e){
  getAccount()
}
function  itemRenderSave(e){
  if(e.type == 1){
    vdata.tableType = e.table
    nextProductSignRef.value.show(e.productId)
  }
  if(e.type == 2){
    vdata.tableType = e.table
    nextProductSignRef.value.show(e.productId)
  }
  if(e.type == 3){
    req.add(API_URL_PRODUCT_START_LIST, e).then(data => {
      $infoBox.message.success(data)
      setTimeout(() => {
        router.push({
          path: '/productLog'
        })
      }, 1000)
    })
  }
  if(e.type == 4){
    // window.location.href=  "/apps"
    router.push({
      path:'/apps'
    })
  }
}

// Promise.all([getStatisticsData()])
Promise.all([])
</script>
<style lang="less" scoped>
.title {
  box-sizing: border-box;
  //padding: 16px 0 0px 20px;
  margin-bottom: 30px;
  border-bottom: 1px solid #e8e8e8;
  p {
    //font-weight: bold;
    font-size: 18px;
    letter-spacing: 0.07em;
    color: #000;
  }
}

.items {
  margin: 30px 0;
  display: flex;
  justify-content: space-around;
  .item {
    margin-bottom: 20px;
    padding: 10px 100px !important;
    p {
      font-weight: 500;
      margin: 0;
    }
    .item-title {
      font-size: 14px;
      letter-spacing: 0.05em;
      padding-right: 5px;
      color: #737980;
    }
    .item-detail,
    .item-sub {
      font-size: 25px;
      color: var(--ant-primary-color);
    }
    .item-sub {
      color: #000000 !important;
    }
  }
}
.tooltip {
  &:hover {
    cursor: pointer;
  }
}
.statistics-list .item .title-count {
  color: #808080;
  margin-bottom: 10px;
}

.operate {
  display: flex;
  justify-content: center;
  align-items: center;
  //width: 100px;
  margin: 10px 5px 5px 10px;
  height: 38px;
  border-radius:10px;
  //margin-top: 15px;
  button{
    border-radius:5px;
  }
  p {
    font-size: 13px;
    letter-spacing: 0.02em;
    color: #fff;
  }
}
.items-bottom{
  margin-bottom: 20px;
  display: flex;
  justify-content: left;
}
.items-zhong{
  display: flex;
  padding-top: 10px;
}
.items-zhong-img{
  display: flex;
  img{
    width: 55px;
    height: 55px;
  }
}
.item-img{
  align-items: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin: 0 30px !important;
}
.item-img-title{
  color: #666;
  font-family: PingFangSC-Medium;
  font-size: 14px;
  line-height: 14px;
  margin: 17px auto 9px;
}
.item-img-detail{
  color: #666;
  font-family: PingFangSC-Regular;
  font-size: 12px;
  line-height: 10px;
  transform: scale(.83);
}

.items-bottom-img{
  margin-bottom: 20px;
  display: flex;
  justify-content: center;
  button{
    background: #1890ff;
    color: #ffffff !important;
  };
}
.tooltip_so{
  width: 50%;
  text-align: right;
  margin-right: 30px;
  margin-bottom: 10px;
  color: rgb(22, 119, 255)
}
.items-bottom-operate{
  margin-bottom: unset !important;
}
.title-div-box{
  margin: 16px 0 0 20px;
}
.title-div-box-span{
  background: rgb(224, 240, 255);
  position: absolute;
  left: 101px;
  top: 20px;
  font-size: 12px;
  border-radius: 5px;
  padding: 3px 10px;
  color: rgb(67, 126, 194);
}
</style>
<style lang="less">
.tooltip_class {
  min-width: 250px  !important;
}
</style>
