<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.typeId)">修改</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" />
    <!-- 详情页面组件  -->
    <InfoDetail ref="infoDetail" :callback-func="searchFunc" />

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

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

const infoDetail = ref()
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_PRODUCT_TYPE_LIST, params)
  // console.log(tablList)
  // return req.list(tablList);
}
function searchFunc() { // 点击【查询】按钮点击事件
  infoTable.value.refTable(true)
}

function addFunc() { // 业务通用【新增】 函数
  infoAddTypeEdit.value.show()
}
function editFunc(recordId: any) { // 业务通用【修改】 函数
  infoAddTypeEdit.value.show(recordId)
}

function mchConfigFunc(recordId: any) { // 配置 函数
  mchConfigRef.value.show(recordId)
}

function detailFunc(recordId: any) { // 商户详情页
  infoDetail.value.show(recordId)
}
// 删除商户
function delFunc(recordId: any) {
  $infoBox.confirmDanger('确认删除？', '该操作将删除分类', () => {
    reqLoad.delById(API_URL_PRODUCT_TYPE_SAVE, recordId).then((res: any) => {
      infoTable.value.refTable(true)
      queryFunc()
      $infoBox.message.success('删除成功')
    })
  })
}
function mchAppConfig(recordId: any) { // 应用配置
  router.push({
    path: '/apps',
    query: { mchNo: recordId }
  })
}
function mchStoreConfig(recordId: any) { // 门店管理
  router.push({
    path: '/store',
    query: { mchNo: recordId }
  })
}
function mchReceiverGroupConfig(recordId: any) { // 账号分组管理
  router.push({
    path: '/divisionReceiverGroup',
    query: { mchNo: recordId }
  })
}
function mchReceiverConfig(recordId: any) { // 账号管理
  router.push({
    path: '/divisionReceiver',
    query: { mchNo: recordId }
  })
}
function mchQrCodeConfig(recordId: any) { // 静态码管理
  router.push({
    path: '/qrc',
    query: { mchNo: recordId }
  })
}
function speakerConfig(recordId: any) { // 云喇叭管理
  router.push({
    path: '/speaker/device',
    query: { mchNo: recordId }
  })
}
function printerConfig(recordId: any) { // 云打印管理
  router.push({
    path: '/printer/device',
    query: { mchNo: recordId }
  })
}
function posConfig(recordId: any) { // pos管理
  router.push({
    path: '/pos/device',
    query: { mchNo: recordId }
  })
}
function autoPosConfig(recordId: any) { // 智能pos管理
  router.push({
    path: '/auto/pos',
    query: { mchNo: recordId }
  })
}
function cdKeyConfig(recordId: any) { // 收银插件管理
  router.push({
    path: '/plugin/cdkey',
    query: { mchNo: recordId }
  })
}

function toMchApplymentPage(recordId) {
  router.push({
    path: '/applyments',
    query: { mchNo: recordId }
  })
}

function channelAccountConfig(recordId) {
  router.push({
    path: '/channel/account',
    query: { mchNo: recordId }
  })
}

function isvOperationAuth(recordId) {
  isvOperationAuthRef.value.show(recordId)
}

const { $mittBus } = getCurrentInstance()!.appContext.config.globalProperties;

function newAdd() {
  $mittBus.emit('specialrouter',{type:4,index:0},)
}
</script>
