<template>
  <page-header-wrapper>
    <a-card class="table-card">
      <JeepaySearchForm :searchFunc="searchFunc" :resetFunc="() => { vdata.searchData= {} }" searchConditionNum="6">
        <jeepay-text-up v-model:value="vdata.searchData['typeName']" :placeholder="'方案分类'" />
        <!-- <a-form-item label="" class="table-search-item">
          <a-select v-model:value="vdata.searchData['state']" 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>
        </a-form-item> -->
      </JeepaySearchForm>

      <!-- 列表渲染 -->
      <JeepayTable
          ref="infoTable"
          :init-data="true"
          :req-table-data-func="reqTableDataFunc"
          :table-columns="tableColumns"
          :search-data="vdata.searchData"
          row-key="typeName"
          @btnLoadClose="btnLoading=false"
      >
        <template #topBtnSlot>
          <a-button v-if="$access('ENT_MCH_INFO_ADD')" type="primary" @click="addFunc">
            <plus-outlined />新建
          </a-button>
        </template>

        <template #bodyCell="{ column, record }">
          <template v-if="column.key === 'typeName'">
            {{ record.typeName }}
          </template>

          <template v-if="column.key === 'updatedAt'">
            {{ record.updatedAt }}
          </template>
          <template v-if="column.key === 'createdAt'">
            {{ record.createdAt }}
          </template>

          <template v-if="column.key === 'operation'">
            <!-- 操作列插槽 -->
            <JeepayTableColumns>
              <a-button v-if="$access('ENT_MCH_INFO_EDIT')" type="link" @click="editFunc(record)">修改</a-button>
              <a-button v-if="$access('ENT_MCH_INFO_DEL')" type="link" style="color: red" @click="delFunc(record.typeId)">删除</a-button>
            </JeepayTableColumns>
          </template>
        </template>
      </JeepayTable>
    </a-card>
    <!-- 新增页面组件  -->
    <InfoAddTypeEdit ref="infoAddTypeEdit" :callback-func="searchFunc" />

    <!--商户配置  -->
    <!--支付宝代运营授权  -->
  </page-header-wrapper>
</template>
<script setup lang="ts">

import {
  API_URL_PACKAGE_TYPE_DEL,
  API_URL_PACKAGE_TYPE_LIST,
  API_URL_PRODUCT_TYPE_LIST,
  API_URL_PRODUCT_TYPE_SAVE,
  req,
  reqLoad
} from '@/api/manage'
import InfoAddTypeEdit from './save/AddProgrammeTypeEdit.vue'
import { ref, reactive, getCurrentInstance, onMounted } from 'vue'
import router from '@/router'
const { $infoBox,$access, $hasAgentEnt } = getCurrentInstance()!.appContext.config.globalProperties

const infoAddTypeEdit = ref()
const mchConfigRef = ref()
const isvOperationAuthRef = ref()
const infoTable = ref()
let tableColumns = reactive([
  { key: 'typeName', title: '方案分类'},
  { key: 'createdAt', title: '更新日期', dataIndex: 'created_at' },
  { key: 'updatedAt', title: '创建日期', dataIndex: 'update_at' },
  { key: 'operation', title: '操作',  fixed: 'right', align: 'center'}
])


let btnLoading = ref(false)
const vdata = reactive({
  searchData: {} as any
})

function queryFunc () {
  btnLoading.value = true
  infoTable.value.refTable(true)
}
// 请求table接口数据
function reqTableDataFunc(params: any) {
  return req.list(API_URL_PACKAGE_TYPE_LIST, params)
}
function searchFunc () { // 点击【查询】按钮点击事件
  infoTable.value.refTable(true)
}
// 删除商户
function delFunc (recordId: any) {
  $infoBox.confirmDanger('确认删除？', '该操作将删除分类', () => {
    reqLoad.add(API_URL_PACKAGE_TYPE_DEL, {typeId:recordId}).then((res: any) => {
      infoTable.value.refTable(true)
      queryFunc()
      $infoBox.message.success('删除成功')
    })
  })
}
function addFunc () { // 业务通用【新增】 函数
  infoAddTypeEdit.value.show()
}
function editFunc (record: any) { // 业务通用【修改】 函数
  infoAddTypeEdit.value.show(record)
}

</script>
