<template>
  <page-header-wrapper>
    <a-card>
      <JeepaySearchForm v-if="$access('ENT_PC_WAY_SEARCH')" :searchFunc="searchFunc" :resetFunc="() => { vdata.searchData = {} }">
        <jeepay-text-up v-model:value="vdata.searchData['wayCode']" :placeholder="'支付方式代码'" />
        <jeepay-text-up v-model:value="vdata.searchData['wayName']" :placeholder="'支付方式名称'" />
      </JeepaySearchForm>
      <!-- 展开与收起分割线 -->
      <!-- 列表渲染 -->
      <JeepayTable
        ref="infoTable"
        :initData="true"
        :reqTableDataFunc="reqTableDataFunc"
        :tableColumns="tableColumns"
        :searchData="vdata.searchData"
        rowKey="wayCode"
        @btnLoadClose="vdata.btnLoading=false"
      >
        <template #topBtnSlot>
          <a-button v-if="$access('ENT_PC_WAY_ADD')" type="primary" class="mg-b-30" @click="addFunc"><plus-outlined />新建</a-button>
        </template>
        <template #bodyCell="{column,record}">
          <template v-if="column.key == 'wayCode'">
            <b>{{ record.wayCode }}</b>
          </template>
          <template v-if="column.key == 'op'">
            <a v-if="$access('ENT_PC_WAY_EDIT')" style="padding-right: 15px; padding-left: 10px;" @click="editFunc(record.wayCode)">修改</a>
            <a v-if="$access('ENT_PC_WAY_DEL')" style="color: red" @click="delFunc(record.wayCode)">删除</a>
          </template>
        </template>
      </JeepayTable>
    </a-card>

    <!-- 新增页面组件  -->
    <InfoAddOrEdit ref="infoAddOrEdit" :callbackFunc="searchFunc" />
  </page-header-wrapper>
</template>
<script lang="ts" setup>
import { API_URL_PAYWAYS_LIST, req } from '@/api/manage'
import InfoAddOrEdit from './AddOrEdit.vue'
import {reactive,ref,getCurrentInstance} from 'vue'
// eslint-disable-next-line no-unused-vars
const { $infoBox,$access } = getCurrentInstance()!.appContext.config.globalProperties

const tableColumns = reactive([
  {
    key: 'wayCode', // key为必填项，用于标志该列的唯一
    
    title: '支付方式代码',
    scopedSlots: { customRender: 'wayCodeSlot' }
  },
  {
    key: 'wayName',
    title: '支付方式名称',
    dataIndex: 'wayName'
  },
  {
    key: 'op',
    title: '操作',
    fixed: 'right',
    align: 'center',
    scopedSlots: { customRender: 'opSlot' }
  }
])


    const infoTable =ref()
    const infoAddOrEdit = ref()
    const vdata = reactive ({
      tableColumns: tableColumns,
      searchData: {},
      btnLoading: false
    })


    // 请求table接口数据
   function reqTableDataFunc(params){
      return req.list(API_URL_PAYWAYS_LIST, params)
    }

 function   searchFunc (isToFirst = false) { // 点击【查询】按钮点击事件
      vdata.btnLoading = true
      infoTable.value.refTable(isToFirst)
    }

   function addFunc () { // 业务通用【新增】 函数
      infoAddOrEdit.value.show()
    }

   function editFunc (wayCode) { // 业务通用【修改】 函数
      infoAddOrEdit.value.show(wayCode)
    }

  function  delFunc(wayCode) {
   
      $infoBox.confirmDanger('确认删除？', '', () => {
        req.delById(API_URL_PAYWAYS_LIST, wayCode).then(res => {
          $infoBox.message.success('删除成功！')
          infoTable.value.refTable(false)
        })
      })
    }
</script>
