<template>
  <div class="card-import">
    <qm-low-form :fields="fields"> </qm-low-form>
    <a-table :data-source="tableData" :columns="columns" size="middle" bordered>
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'operation'">
          <qm-button type="link" @click="editRow(record)">修改</qm-button>
          <qm-button type="link" @click="deleteRow(record)">删除</qm-button>
        </template>
      </template>
    </a-table>
    <AddCardDialog
      v-model="showAddDialog"
      v-if="showAddDialog"
      :cur-row="curRow"
    ></AddCardDialog>
  </div>
</template>
<script name="CardImport" lang="ts" setup>
import { ref } from "vue";
import AddCardDialog from "./AddCardDialog.vue";
import type { TableColumnsType } from "@qmth/ui";

const showAddDialog = ref(false);
const curRow = ref(null);
const editRow = (row: any) => {
  curRow.value = row;
  showAddDialog.value = true;
};
const fields = ref([
  {
    type: "buttons",
    children: [
      {
        text: "导入卡格式",
        attrs: {
          style: { marginLeft: 0 },
        },
      },
      {
        text: "新增卡格式",
        attrs: {
          type: "default",
          onClick: () => {
            showAddDialog.value = true;
          },
        },
      },
    ],
  },
]);
const tableData = ref([{ a: 1, b: 2, c: 3, d: 4, e: 5 }]);
const columns: TableColumnsType = [
  {
    title: "序号",
    dataIndex: "index",
    key: "index",
    width: 100,
    customRender: ({ index }) => `${index + 1}`,
  },
  {
    title: "科目",
    dataIndex: "a",
  },
  {
    title: "属性",
    dataIndex: "b",
  },
  {
    title: "张数",
    dataIndex: "c",
  },
  {
    title: "备注",
    dataIndex: "d",
  },
  {
    title: "更新时间",
    dataIndex: "e",
  },
  {
    title: "操作",
    key: "operation",
    width: 300,
  },
];
const deleteRow = (row: any) => {
  window.$confirm({
    title: () => "系统通知",
    content: () => "请确认是否立即删除？",
    onOk() {
      //todo 执行删除接口
    },
  });
};
</script>
<style lang="less" scoped>
.card-import {
  padding: 0 20px 20px 20px;
}
</style>
