<template>
  <page-header-wrapper>
    <a-card>
      <JeepaySearchForm v-if="$access('ENT_UR_ROLE_SEARCH')" :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="dateTime" />
        </a-form-item>
        <jeepay-text-up v-model:value="data.searchData['mchNo']" v-if="props.configMode != 'mch'" :placeholder="'用户号/名称/手机号'" />

        <!--        <jeepay-text-up v-model:value="vdata.searchData['mchServiceName']" :placeholder="'服务商号/服务商名称'" />-->

        <jeepay-text-up  v-model:value="data.searchData['applyId']"  :placeholder="'商户号/商户名称'"  />
        <jeepay-text-up   v-model:value="data.searchData['storeId']"  :placeholder="'门店名称/门店编号'"  />
        <jeepay-text-up   v-model:value="data.searchData['ifCode']"  :placeholder="'支付通道'"  />
        <jeepay-text-up   v-model:value="data.searchData['isvNo']"  :placeholder="'渠道名称/渠道号'"  />
        <jeepay-text-up   v-model:value="data.searchData['routeId']"  :placeholder="'策略/策略ID'"  />

        <a-form-item label="" class="table-search-item">
          <a-select v-model:value="data.searchData['payTypeValue']" placeholder="支付方式">
            <a-select-option value="">全部</a-select-option>
            <a-select-option value="WECHAT">微信</a-select-option>
            <a-select-option value="ALIPAY">支付宝</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="" class="table-search-item">
          <a-select v-model:value="data.searchData['settleType']" placeholder="结算类型">
            <a-select-option value="">全部</a-select-option>
            <a-select-option value="D0">D0</a-select-option>
            <a-select-option value="D1">D1</a-select-option>
            <a-select-option value="T1">T1</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>
        </a-form-item>
      </JeepaySearchForm>

      <!-- 列表渲染 -->
      <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 #topBtnSlot>
          <div>
            <a-button  v-if="$access('ENT_ROUTE_MANAGE_ADD')"  type="primary"   class="mg-b-30"  @click="addFunc()"  >  <plus-outlined /> 新建  </a-button>
          </div>
        </template>
        <template #bodyCell="{column,record}">

          <template v-if="column.key === 'payType'">
            <span v-if="record.payType.indexOf('WECHAT') !== -1" >微信</span>
            <span v-if="record.payType.indexOf('ALIPAY') !== -1" >、支付宝</span>
          </template>
          <template v-if="column.key === 'amtRange'">
            <div style="color:#1965FF;" @click="remarkFunc(record,1)" v-if="props.configMode == 'mch'">
              <span>{{ (record.amtRange[0] / 100).toFixed(2) }}</span>
              <span class="rule-span">~</span>
              <span>{{ (record.amtRange[1] / 100).toFixed(2) }}</span>
              <EditOutlined  />
            </div>
            <div  v-else>
              <span>{{ (record.amtRange[0] / 100).toFixed(2) }}</span>
              <span class="rule-span">~</span>
              <span>{{ (record.amtRange[1] / 100).toFixed(2) }}</span>
            </div>

          </template>

          <template v-if="column.key === 'timeRange'">
            <div style="color:#1965FF;" @click="remarkFunc(record,2)"  v-if="props.configMode == 'mch'">
              <span>{{record.timeRange[0] }}</span>
              <span class="rule-span">~</span>
              <span>{{ record.timeRange[1]}}</span>
              <EditOutlined  />
            </div>
            <div v-else>
              <span>{{record.timeRange[0] }}</span>
              <span class="rule-span">~</span>
              <span>{{ record.timeRange[1]}}</span>
            </div>
          </template>

          <template v-if="column.key === 'routeName'">
            <a-tooltip  class="my-tooltip" overlayClassName="tooltip-box-name">
              <template #title>
                <span>策略名称：{{record.routeName}}</span><br>
                <span>策略ID：{{record.routeId}}</span>
              </template>
              <div class="my-tooltip-title-box"> {{record.routeName}}</div>
            </a-tooltip>
          </template>
          <template v-if="column.key === 'isvName'">
            <a-tooltip  class="my-tooltip" overlayClassName="tooltip-box-name">
              <template #title>
                <span>渠道名称：{{record.isvName}}</span><br>
                <span>渠道号：{{record.isvNo}}</span>
              </template>
              <div class="my-tooltip-title-box"> {{record.isvName}}</div>
            </a-tooltip>
          </template>
          <template v-if="column.key === 'applyId'">
            <a-tooltip  class="my-tooltip" overlayClassName="tooltip-box-name">
              <template #title>
                <span>商户名称：{{record.mchShortName}}</span><br>
                <span>商户号：{{record.applyId}}</span>
              </template>
              <div class="my-tooltip-title-box"> {{record.mchShortName}}</div>
            </a-tooltip>
          </template>
          <template v-if="column.key === 'storeId'">
            <a-tooltip  class="my-tooltip" overlayClassName="tooltip-box-name">
              <template #title>
                <span>门店名称：{{record.storeName}}</span><br>
                <span>门店编号：{{record.storeId}}</span>
              </template>
              <div class="my-tooltip-title-box"> {{record.storeName}}</div>
            </a-tooltip>
          </template>
          <template v-if="column.key === 'state'">
            <JeepayTableColState :state="record.state" :show-switch-type="true" :on-change="(state) => { return updateState(record, state)}" />
          </template>
          <template v-if="column.key === 'routeState'">
            <a-badge v-if="record.routeState == 0" status="error" text="不路由门店" />
            <a-badge v-if="record.routeState == 1" status="success" text="启用门店" />

            <a-tooltip  :title="record.remark" v-if="record.routeState == 0">
              <info-circle-outlined style="color: #FF0000;margin-left: 10px"/>
            </a-tooltip>

          </template>
          <template v-if="column.key === 'op'">
            <!-- 操作列插槽 -->
            <JeepayTableColumns>
              <a-button  type="link" @click="detailFunc(record)">详情</a-button>
              <a-button v-if="$access('ENT_ROUTE_MANAGE_EDIT')" type="link" @click="editFunc(record)">修改</a-button>
              <a-button v-if="$access('ENT_ROUTE_MANAGE_DEL')"  type="link"  style="color: red" @click="delFunc(record.storeId)">解绑</a-button>
            </JeepayTableColumns>
          </template>
        </template>
      </JeepayTable>
    </a-card>

    <a-modal v-model:visible="vdata.showPreRouteModal" :title="vdata.addTitle" width="30%" :confirmLoading="vdata.preRouteModalLoading" @ok="preRouteHandleOkFunc">
      <a-form
          ref="infoFormModel"
          :model="vdata.saveObject"
          layout="vertical"
          :rules="rules"
          style="padding-bottom:50px"
      >
        <a-row justify="space-between" >
          <!--          <a-col :span="24">-->
          <!--                  <a-form-item label="选择应用" name="appId">-->
          <!--                    <a-select v-model:value="vdata.saveObject.appId" placeholder="请选择应用" show-search @change="handleAppIdChange" @search="handleAppIdSearch"  :filter-option="false">-->
          <!--                      <a-select-option v-for="d in vdata.filteredApplyInfoList" :key="d.appId" v-model:value="d.appId">-->
          <!--                        {{ d.appName }} - {{ d.appId }}-->
          <!--                      </a-select-option>-->
          <!--                    </a-select>-->
          <!--                  </a-form-item>-->
          <!--          </a-col>-->
          <!--          <a-col :span="24">-->
          <!--            <a-form-item  label="选择商户" name="applyId">-->
          <!--              <a-select-->
          <!--                  v-model:value="vdata.saveObject.applyId"-->
          <!--                  placeholder="选择商户"-->
          <!--                  show-search-->
          <!--                  label-in-value-->
          <!--                  :filter-option="false"-->
          <!--                  @change="handleMchApplyChange"-->
          <!--                  @search="handleMchApplySearch"-->
          <!--                  :getPopupContainer="(triggerNode) => triggerNode.parentElement"-->
          <!--              >-->
          <!--                <a-select-option v-for="(item, index) in vdata.filteredMchApplyList" :key="index" :value="item.applyId">-->
          <!--                  {{ item.mchShortName }} - {{ item.applyId }} -  {{ item.ifName }}-->
          <!--                </a-select-option>-->
          <!--              </a-select>-->
          <!--            </a-form-item>-->
          <!--          </a-col>-->
          <a-col :span="24">
            <a-form-item  label="选择策略" name="routeId">
              <a-select
                  v-model:value="vdata.saveObject.routeId"
                  placeholder="选择策略"
                  show-search
                  label-in-value
                  :filter-option="false"
                  @search="handleRouteSearch"
                  @change="handleRouteChange"
                  :getPopupContainer="(triggerNode) => triggerNode.parentElement"
              >
                <!--                  @change="handleRouteChange"-->
                <a-select-option v-for="(item, index) in vdata.filteredRouteInfoList" :key="index" :value="item.routeId">
                  {{ item.name }} - [{{ item.routeId }}]
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :span="24" style="margin:10px 0px">
            <a-form-item label="关联门店" name="storeIdList">
              <a-textarea v-if="vdata.saveObject.storeName" v-model:value="vdata.saveObject.storeName"
                          disabled />
              <a-button v-if="vdata.addTitle == '新建'" style="margin-top: 5px" type="primary" @click="showStoreIdSelectPackageModel">{{
                  vdata.isAdd ?
                      '选择绑定门店' : '重新绑定门店' }}</a-button>
            </a-form-item>
          </a-col>
          <!--          <a-col :span="24">-->
          <!--            <a-form-item  label="选择门店" name="storeId">-->
          <!--              <a-select-->
          <!--                  v-model:value="vdata.saveObject.storeId"-->
          <!--                  placeholder="选择门店"-->
          <!--                  show-search-->
          <!--                  label-in-value-->
          <!--                  :filter-option="false"-->
          <!--                  @search="handleStoreSearch"-->
          <!--                  :getPopupContainer="(triggerNode) => triggerNode.parentElement"-->
          <!--              >-->
          <!--                <a-select-option v-for="(item, index) in vdata.filteredStoreInfoList" :key="index" :value="item.value">-->
          <!--                  {{ item.storeName }} - {{ item.storeId }} - {{ item.ifName }}-->
          <!--                </a-select-option>-->
          <!--              </a-select>-->
          <!--            </a-form-item>-->
          <!--          </a-col>-->

        </a-row>

        <div class="drawer-btn-center">
          <a-button :style="{ marginRight: '8px' }" @click="onClose">
            <close-outlined />
            取消
          </a-button>
          <a-button type="primary" :loading="vdata.confirmLoading" @click="handleOkFunc">
            <check-outlined />
            保存
          </a-button>
        </div>
      </a-form>

    </a-modal>


    <a-modal v-model:visible="vdata.showSaveRouteModal" :title="vdata.addTitle" width="30%" :confirmLoading="vdata.preSaveRouteModalLoading" @ok="handleSaveOkFunc">
      <a-form
          ref="infoSaveFormModel"
          :model="vdata.detailInfo"
          layout="vertical"
          :rules="rules"
          style="padding-bottom:50px"
      >
        <a-row justify="space-between" >

          <a-col :span="24" style="margin:10px 0px" v-if="vdata.detailInfo.savetype == 2">
            <a-form-item label="支付交易时间" name="time">
              <div  class="con-flex-div" >
                <a-time-picker class="con-flex-span"  v-model:value="vdata.detailInfo.timeRange1" format="HH:mm" />
                <span class="rule-span">至</span>
                <a-time-picker class="con-flex-span"  v-model:value="vdata.detailInfo.timeRange2" format="HH:mm" />
              </div>
            </a-form-item>
          </a-col>
          <a-col :span="24" style="margin:10px 0px" v-if="vdata.detailInfo.savetype == 1">
                        <a-form-item label="支付金额范围" name="amtRange">
                          <div  class="con-flex-div" >
                            <a-input-number class="con-flex-span"  addon-after="元" :min="0.01" :precision="2"  v-model:value="vdata.detailInfo.amtRange1" placeholder="请输入最小金额"/>
                            <span class="rule-span">至</span>
                            <a-input-number class="con-flex-span"  addon-after="元" :min="0.01" :precision="2"  v-model:value="vdata.detailInfo.amtRange2"  placeholder="请输入最大金额"/>
                          </div>
                        </a-form-item>
          </a-col>

        </a-row>

        <div class="drawer-btn-center">
          <a-button :style="{ marginRight: '8px' }" @click="onSaveClose">
            <close-outlined />
            取消
          </a-button>
          <a-button type="primary" :loading="vdata.confirmLoading" @click="handleSaveOkFunc">
            <check-outlined />
            保存
          </a-button>
        </div>
      </a-form>

    </a-modal>



    <JeepayModelStoreList style="margin-top: -45px !important; " v-if="jeepayModelStoreListFlag" ref="jeepayModelStoreListFlag"
                          @selectFinishFunc="selectStoreIdFinishProductFunc" />
  </page-header-wrapper>
</template>
<script setup lang="ts">
import {
  API_URL_MCH_APPLYMENT_LIST,
  req,
  reqLoad,
  API_URL_STATISTIC,
  API_URL_MCH_STORE_LIST,
  API_URL_ROUTE_MANAGE_LIST,
  API_URL_MCH_APPS,
  API_URL_PAY_ORDER_ROUTE_LIST,
  API_URL_ROUTE_MANAGE_DEL,
  API_URL_ROUTE_MANAGE_ADD,
  API_URL_ROUTE_MANAGE_SAVE, API_URL_PAY_ORDER_ROUTE_DEL
} from '@/api/manage'
import {reactive, ref, getCurrentInstance, onMounted, nextTick} from 'vue'
import fileDownload from "js-file-download";
import {message} from "ant-design-vue";
import moment from 'moment';
import { useRouter, useRoute } from 'vue-router'
import dayjs from "dayjs";
const router = useRouter() //这是全部路由

const props = defineProps({
  configMode: { type: String, default: '' },   // 模式
})

const { $infoBox, $access, $hasAgentEnt } = getCurrentInstance()!.appContext.config.globalProperties


const tableColumns = reactive([
  {key:'applyId', title: '商户信息',   dataIndex: 'applyId' },
  {key:'storeId', title: '门店信息', dataIndex: 'storeId' },
  {key:'ifName', title: '支付通道', dataIndex: 'ifName', },
  {key:'isvName', title: '支付渠道', dataIndex: 'isvName', },
  {key:'routeName', title: '策略名称', dataIndex: 'routeName', },
  {key:'state', title: '启用状态', dataIndex: 'state', },
  {key:'payType', title: '支付方式', dataIndex: 'payType', },
  {key:'amtRange', title: '金额范围', dataIndex: 'amtRange', },
  {key:'timeRange', title: '交易时间', dataIndex: 'timeRange' },
  // {key:'failNum', title: '连续失败笔数', dataIndex: 'failNum', },
  // {key:'succRate', title: '支付成功率', dataIndex: 'succRate', },
  {key:'settleType', title: '结算类型', dataIndex: 'settleType', },
  {key:'routeState', title: '策略状态', dataIndex: 'routeState', },
  {key:'createdAt', title: '创建时间', dataIndex: 'createdAt', },
  {key: 'op',title: '操作',   fixed: 'right',align: 'center' }
])

const infoTable = ref()
const infoFormModel = ref()
const infoSaveFormModel = ref()

const jeepayModelStoreListFlag = ref()

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

let count:any = ref([]) // 数据统计数组
let vdata : any = reactive({
  saveData:{} as any,
  detailInfo:[] as any,
  filteredApplyInfoList:[] as any,
  filteredRouteInfoList:[]  as any,
  applyList:[] as any,
  storeList:[] as any,
  mchApplyList:[] as any,
  filteredMchApplyList:[] as any,
  filteredStoreInfoList:[] as any,
  saveObject:{} as any,
  addTitle:"",
  visible:false,
  showRechargeModal:false,
  rechargeModalLoading: false,  // loading
  rechargeObject: {}, // 预审核结果

  showPreRouteModal: false,  // 是否显示预审核弹层
  preRouteModalLoading: false,  // loading
  preRouteResult: {}, // 预审核结果

  showSaveRouteModal: false,  // 是否显示预审核弹层
  preSaveRouteModalLoading: false,  // loading
  preSaveRouteResult: {}, // 预审核结果

})

onMounted(() => {

  if(useRoute().query.routeId !== undefined){
    data.searchData['routeId'] = useRoute().query.routeId

  }
  if(useRoute().query.storeId !== undefined){
    data.searchData['storeId'] = useRoute().query.storeId

  }
  setTimeout(()=>{
    searchFunc()
  },500)
})
const rules = reactive({
  routeId: [{ required: true, message: '请选择策略', trigger: 'blur' }],
  storeIdList: [{ required: true, message: '请选择关联门店', trigger: 'blur' }],
})
// 请求table接口数据
async function reqTableDataFunc(params){
  // reqTableCountFunc(params)
  let res = await req.list(API_URL_ROUTE_MANAGE_LIST, params);
  //  for (let i = 0; i < res.records.length; i++) {
  //    res.records[i]['timeRange1'] = moment(res.records[i].timeRange[0], 'HH:mm')
  //    res.records[i]['timeRange2'] = moment(res.records[i].timeRange[1], 'HH:mm')
  // }
  return res
}

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 () { // 业务通用【新增】 函数
                      // getMchApps()
                      // getStoreList()
  vdata.addTitle = "新建"
  getRouteList()
  vdata.saveObject.storeName = []
  vdata.saveObject.storeIdList = []
  vdata.showPreRouteModal = true

}

function detailFunc(record){
  router.push({
    path:'/tradeRouteRotation',
    query:{storeId:record.storeId}
  })
}
function editFunc (record) { // 业务通用【修改】 函数
  getRouteList()
  vdata.showPreRouteModal = true
  vdata.addTitle = "编辑"
  vdata.saveObject.routeId = record.routeId
  vdata.saveObject.storeIdList = [record.storeId]
  vdata.saveObject.storeName = [record.storeName]
}


function delFunc(recordId){
  $infoBox.confirmDanger(
      "确认解绑？",
      "",
      () => {
        return req
            .delById(API_URL_ROUTE_MANAGE_DEL, recordId)
            .then((res) => {
              $infoBox.message.success("解绑成功！");
              infoTable.value.refTable(false);
            })
            .catch((err) => {});
      },
      () => {
        console.log(1111);
      }
  );
}



function onCopySuccess () {
  $infoBox.message.success('复制成功')
}
// 预审核结果
function rechargeHandleOkFunc(){

  if(!vdata.rechargeResult.state){
    return $infoBox.message.error('请选择审核结果')
  }

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

  vdata.rechargeModalLoading = true

}
function rechargeFunc(record){
  vdata.showRechargeModal = true
}


// 显示弹层
function showPreRouteModalFunc (recordId) {

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

  vdata.showPreRouteModal = true
  vdata.preRouteResult = { applyId: recordId }
}
// 预审核结果
function preRouteHandleOkFunc(){

  if(!vdata.preRouteResult.state){
    return $infoBox.message.error('请选择审核结果')
  }

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

  vdata.preRouteModalLoading = true

}

function historyFunc(record){
  vdata.visible = true
}
function  updateState (recordId, state) { // 【更新状态】

  const title = state === 1 ? '确认[启用]？' : '确认[停用]？'
  return new Promise<void>((resolve, reject) => {
    $infoBox.confirmDanger(title, '', () => {
          return reqLoad.updateById(API_URL_ROUTE_MANAGE_SAVE, recordId.storeId, { state: state }).then(res => {
            searchFunc()
            resolve()
          }).catch(err => reject(err))
        },
        () => {
          reject(new Error())
        })
  })
}


function setAqfRouteInfo(e){
  vdata.showPreRouteModal = false
}


//商户

function onClose(){
  vdata.showPreRouteModal = false
}
function handleOkFunc(){
  infoFormModel.value.validate().then(valid=>{
    vdata.loading = true // 打开按钮上的 loading
    vdata.confirmLoading = true // 显示loading
    if(vdata.addTitle == '新建'){
      req.add(API_URL_ROUTE_MANAGE_ADD, vdata.saveObject).then(res => {
        message.success('新增成功')
        vdata.showPreRouteModal = false
        vdata.loading = false
        vdata.confirmLoading = false
        infoTable.value.refTable(true)
      }).catch((res) => {
        vdata.confirmLoading = false
      })

    }else{
      req.updateById(API_URL_ROUTE_MANAGE_SAVE, vdata.saveObject.storeIdList[0],vdata.saveObject).then(res => {
        message.success('修改成功')
        vdata.showPreRouteModal = false
        vdata.loading = false
        vdata.confirmLoading = false
        infoTable.value.refTable(true)
      }).catch(res => { vdata.confirmLoading = false })
    }

  })
}

function handleMchApplyChange(e){
  vdata.saveObject.mchApplyId = e.value
  getStoreList()
}

const handleMchApplySearch = (value) => {
  vdata.filteredMchApplyList = [];
  // getApplyList(value)
};
function getApplyList(value='' as any){
  req.list(API_URL_MCH_APPLYMENT_LIST,{'autoConfigMchAppId':vdata.saveObject.appId,'mchApplyName':value, 'pageSize': 100000,'state':99 }).then(res => {
    vdata.filteredMchApplyList = res.records
    vdata.mchApplyList = res.records
  })
}


const handleRouteSearch = (value) => {
  vdata.filteredStoreInfoList = [];
  vdata.storeList = [];
  getRouteList(value)
};
const handleRouteChange = (e) => {
  console.log(e,'valuevalue')
  vdata.saveObject.routeId = e.value
};

function getRouteList(value ='' as any){
  req.list(API_URL_PAY_ORDER_ROUTE_LIST,{ 'name':value,'pageSize': 100000}).then(res => {
    vdata.filteredRouteInfoList = res.records
  })
}

const handleStoreSearch = (value) => {
  vdata.filteredStoreInfoList = [];
  vdata.storeList = [];
  getStoreList(value)
};

function getStoreList(value ='' as any){
  req.list(API_URL_MCH_STORE_LIST,{ 'storeName':value,'pageSize': 100000}).then(res => {
    vdata.filteredStoreInfoList = res.records
    vdata.storeList = res.records
  })
}
getMchApps()
const handleAppIdChange = (value) => {
  vdata.filteredMchApplyList = [];
  vdata.saveObject.applyId = ''
  vdata.saveObject.storeId = ''
  getApplyList()
};
const handleAppIdSearch = (value) => {
  vdata.filteredApplyInfoList = [];
  vdata.applyList = [];
  getMchApps(value)
};
function getMchApps(value ='' as any){
  req.list(API_URL_MCH_APPS, { 'pageSize': 100000,state:1 ,appName:value}).then(res => {
    vdata.applyList =  res.records
    vdata.filteredApplyInfoList = res.records
  })
}

function showStoreIdSelectPackageModel(title) {
  vdata.title = title
  jeepayModelStoreListFlag.value = true
  nextTick(() => {
    jeepayModelStoreListFlag.value.show(vdata.saveObject.storeIdList)
  })
}

function selectStoreIdFinishProductFunc(e) { // 码牌选择完成事件
  jeepayModelStoreListFlag.value = false
  if (!e || e.length <= 0) {
    vdata.saveObject.storeName = ''
    vdata.saveObject.storeIdList = []
    return $infoBox.message.error('请开启要绑定的门店！')
  }
  vdata.saveObject.storeName = ''
  vdata.saveObject.storeIdList = []

  e.forEach((item) => {
    vdata.saveObject.storeName += item.storeName + ','
    vdata.saveObject.storeIdList.push(item.storeId)
  })
  // jeepayModelStoreListFlag.value.close()
}
const getTimeRange1 = (e) =>{
  console.log(e,'getTimeRange1')
}
const getTimeRange2 = (e) =>{
  console.log(e,'getTimeRange2')

}
const getAmtRange = (e) =>{
  console.log(e,'getAmtRangegetAmtRange')

}
function remarkFunc(data,type) {
  vdata.detailInfo = data
  if(type == 1){
    vdata.addTitle = '编辑金额范围'
    vdata.detailInfo.amtRange1 = (data.amtRange[0] / 100).toFixed(2)
    vdata.detailInfo.amtRange2 = (data.amtRange[1] / 100).toFixed(2)
  }else{
    vdata.addTitle = '编辑交易时间'
    vdata.detailInfo.timeRange1 = dayjs(data.timeRange[0], 'HH:mm')
    vdata.detailInfo.timeRange2 = dayjs(data.timeRange[1], 'HH:mm')
  }
  console.log(data.timeRange[0],data.timeRange[1])
  console.log(vdata.detailInfo.timeRange1,vdata.detailInfo.timeRange1,'timeRange2timeRange2timeRange2')
  vdata.detailInfo.savetype = type
  vdata.showSaveRouteModal = true;
}


function onSaveClose(){
  vdata.showSaveRouteModal = false
}
function handleSaveOkFunc(){
  infoSaveFormModel.value.validate().then(valid=>{
    vdata.loading = true // 打开按钮上的 loading
    vdata.confirmLoading = true // 显示loading
    console.log(vdata.detailInfo,'vdatadetailInfo')
    if(vdata.detailInfo.savetype == 1){
      vdata.detailInfo.amtRange = [vdata.detailInfo.amtRange1,vdata.detailInfo.amtRange2]
    }
    if(vdata.detailInfo.savetype == 2){
      vdata.detailInfo.timeRange = [dateFormat(vdata.detailInfo.timeRange1),dateFormat(vdata.detailInfo.timeRange2)]
      delete  vdata.detailInfo.amtRange
    }
    req.updateById(API_URL_ROUTE_MANAGE_SAVE, vdata.detailInfo.storeId,vdata.detailInfo).then(res => {
      message.success('更新成功')
      vdata.showSaveRouteModal = false
      vdata.loading = false
      vdata.confirmLoading = false
      infoTable.value.refTable(true)
    }).catch(res => { vdata.confirmLoading = false })
  })
}
function dateFormat(time) {
  let date = new Date(time);
  let year = date.getFullYear();
  let wk = date.getDay()
  /* 在日期格式中，月份是从0开始的，因此要加0
  * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
  * */
  let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
  let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
  let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
  let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
  let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  let weeks = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
  let week = weeks[wk]
  // 拼接
  return  hours + ":" + minutes;
  // return year + "年" + month + "月" + day + "日" + " " + hours + ":" + minutes + ":" + seconds + ' ' + week;
}
</script>
<style>

.con-flex-div{
  display: flex;
  align-items: center;
  justify-content: space-around;
  width: 100%;
}
.con-flex-span{
  flex: 1 !important;
}
.tb_width_80{
  width: 80% !important;
}

.rule-span{
  padding: 5px 10px;
}
</style>
