<script setup lang="ts">
import { reactive, ref, onMounted, toRaw } from 'vue';
import { PageContainer } from 'antdv-pro-layout';
import { ProModal } from 'antdv-pro-modal';
import { message, Modal, Form, TableColumnsType } from 'ant-design-vue/es';
import { SizeType } from 'ant-design-vue/es/config-provider';
import { MenuInfo } from 'ant-design-vue/es/menu/src/interface';
import UploadModal from '@/components/UploadModal/index.vue';
import useNeStore from '@/store/modules/ne';
import useI18n from '@/hooks/useI18n';
import {
  addPCFRule,
  delPCFRule,
  editPCFRule,
  exportPCFRule,
  importPCFRule,
  listPCFRule,
} from '@/api/neData/pcf';
import { getPCFRule } from '@/api/ne/neConfig';
import { uploadFileToNE } from '@/api/tool/file';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
import { saveAs } from 'file-saver';
import { currentCoreUid } from '@/hooks/useCoreUid';
const { t } = useI18n();
const neStore = useNeStore();
/**网元参数 */
let neOtions = ref<Record<string, any>[]>([]);

/**表单中多选的OPTION */
const pcfRuleOption = ref<Record<string, any[]>>({
  pccRules: [],
  sessionRules: [],
  qosTemplate: [],
  headerEnrichTemplate: [],
  serviceAreaRestriction: [],
});

/**查询参数 */
let queryParams = reactive({
  /**核心网标识 */
  coreUid: currentCoreUid(),
  /**网元标识 */
  neUid: undefined,
  /**移动编号 */
  imsi: '',
  /**号码 */
  msisdn: '',
  /**当前页数 */
  pageNum: 1,
  /**每页条数 */
  pageSize: 20,
});

/**查询参数重置 */
function fnQueryReset() {
  queryParams = Object.assign(queryParams, {
    imsi: '',
    msisdn: '',
  });
  fnGetList();
}

/**表格状态类型 */
type TabeStateType = {
  /**加载等待 */
  loading: boolean;
  /**紧凑型 */
  size: SizeType;
  /**搜索栏 */
  seached: boolean;
  /**记录数据 */
  data: object[];
  /**勾选记录 */
  selectedRowKeys: (string | number)[];
};

/**表格状态 */
let tableState: TabeStateType = reactive({
  loading: false,
  size: 'small',
  seached: true,
  data: [],
  selectedRowKeys: [],
});

/**表格字段列 */
let tableColumns = ref<TableColumnsType>([
  {
    title: 'IMSI',
    dataIndex: 'imsi',
    sorter: (a: any, b: any) => Number(a.imsi) - Number(b.imsi),
    align: 'left',
    width: 150,
  },
  {
    title: 'MSISDN',
    dataIndex: 'msisdn',
    sorter: (a: any, b: any) => Number(a.msisdn) - Number(b.msisdn),
    align: 'left',
    width: 150,
  },
  {
    title: 'SAR',
    dataIndex: 'sar',
    align: 'left',
    width: 150,
  },
  {
    title: 'RFSP',
    dataIndex: 'rfsp',
    align: 'left',
    width: 50,
  },
  {
    title: 'QoS Video',
    dataIndex: 'qosVideo',
    align: 'left',
    width: 100,
  },
  {
    title: 'QoS Audio',
    dataIndex: 'qosAudio',
    align: 'left',
    width: 100,
  },
  {
    title: 'Online Billing', // 在线计费
    dataIndex: 'online',
    align: 'left',
    width: 120,
    customRender(opt) {
      const status = +opt.value;
      return status ? 'Enable' : 'Disable';
    },
  },
  {
    title: 'Offline Billing', // 离线计费
    dataIndex: 'offline',
    align: 'left',
    width: 120,
    customRender(opt) {
      const status = +opt.value;
      return status ? 'Enable' : 'Disable';
    },
  },
  {
    title: 'PCC Rules',
    dataIndex: 'pccRules',
    align: 'left',
    resizable: true,
    width: 200,
    minWidth: 100,
    maxWidth: 300,
  },
  {
    title: 'SESS Rules',
    dataIndex: 'sessRules',
    align: 'left',
    resizable: true,
    width: 200,
    minWidth: 100,
    maxWidth: 300,
  },
  {
    title: 'HDR Enrich',
    dataIndex: 'hdrEnrich',
    align: 'left',
    width: 150,
  },
  {
    title: 'UE Policy',
    dataIndex: 'uePolicy',
    align: 'left',
  },
  {
    title: t('common.operate'),
    key: 'imsi',
    align: 'left',
    width: 150,
    fixed: 'right',
  },
]);

/**表格字段列排序 */
let tableColumnsDnd = ref<TableColumnsType>([]);

/**表格分页器参数 */
let tablePagination = reactive({
  /**当前页数 */
  current: 1,
  /**每页条数 */
  pageSize: 20,
  /**默认的每页条数 */
  defaultPageSize: 20,
  /**指定每页可以显示多少条 */
  pageSizeOptions: ['10', '20', '50', '100'],
  /**只有一页时是否隐藏分页器 */
  hideOnSinglePage: false,
  /**是否可以快速跳转至某页 */
  showQuickJumper: true,
  /**是否可以改变 pageSize */
  showSizeChanger: true,
  /**数据总数 */
  total: 0,
  showTotal: (total: number) => t('common.tablePaginationTotal', { total }),
  onChange: (page: number, pageSize: number) => {
    tablePagination.current = page;
    tablePagination.pageSize = pageSize;
    queryParams.pageNum = page;
    queryParams.pageSize = pageSize;
    // fnGetList();
  },
});

/**表格紧凑型变更操作 */
function fnTableSize({ key }: MenuInfo) {
  tableState.size = key as SizeType;
}

/**表格多选 */
function fnTableSelectedRowKeys(keys: (string | number)[]) {
  tableState.selectedRowKeys = keys;
}

/**对话框对象信息状态类型 */
type ModalStateType = {
  /**新增框或修改框是否显示 */
  openByEdit: boolean;
  /**标题 */
  title: string;
  /**表单数据 */
  from: Record<string, any>;
  /**是否批量操作 */
  isBatch: boolean;
  /**操作类型 */
  type: 'delete' | 'add' | 'update';
  /**确定按钮 loading */
  confirmLoading: boolean;
};

/**对话框对象信息状态 */
let modalState: ModalStateType = reactive({
  openByEdit: false,
  title: '用户策略',
  from: {
    num: undefined,
    imsi: '',
    msisdn: '',
    qosAudio: '',
    pccRules: undefined,
    rfsp: 0,
    uePolicy: '',
    sessRules: undefined,
    sar: '',
    hdrEnrich: '',
    qosVideo: '',
  },
  isBatch: false,
  type: 'add',
  confirmLoading: false,
});

/**对话框内表单属性和校验规则 */
const modalStateFrom = Form.useForm(
  modalState.from,
  reactive({
    num: [
      {
        required: true,
        message: t('views.neData.common.batchNum'),
      },
    ],
    imsi: [{ required: true, message: t('views.neData.common.imsiPlease') }],
    msisdn: [
      { required: true, message: t('views.neData.common.msisdnPlease') },
    ],
  })
);

/**
 * 对话框弹出显示为 新增或者修改
 * @param noticeId 网元id, 不传为新增
 */
function fnModalVisibleByEdit(row?: Record<string, any>) {
  const neUid = queryParams.neUid || '-';
  const coreUid = queryParams.coreUid || '-';
  getPCFRule(coreUid, neUid)
    .then((data: any) => {
      pcfRuleOption.value = data;
    })
    .finally(() => {
      modalState.isBatch = false;
      if (!row) {
        modalStateFrom.resetFields(); //重置表单
        modalState.title = t('views.neData.pcfSub.addTitle');
        modalState.openByEdit = true;
        modalState.type = 'add';
      } else {
        Object.assign(modalState.from, row);

        // 处理多选框数据
        let pccRules = row.pccRules;
        if (!pccRules) {
          pccRules = [];
        } else if (pccRules.includes('|')) {
          pccRules = pccRules.split('|');
        } else {
          pccRules = [pccRules];
        }
        modalState.from.pccRules = pccRules;
        // 处理多选框数据
        let sessRules = row.sessRules;
        if (!sessRules) {
          sessRules = [];
        } else if (sessRules.includes('|')) {
          sessRules = sessRules.split('|');
        } else {
          sessRules = [sessRules];
        }
        modalState.from.sessRules = sessRules;

        // 打开对话框
        modalState.title = t('views.neData.pcfSub.updateTitle', {
          imsi: row.imsi,
        });
        modalState.openByEdit = true;
        modalState.type = 'update';
      }
    });
}

/**
 * 对话框弹出确认执行函数
 * 进行表达规则校验
 */
function fnModalOk() {
  const from = JSON.parse(JSON.stringify(modalState.from));
  const neUid = queryParams.neUid || '-';
  const coreUid = queryParams.coreUid || '-';
  from.rfsp = Number(from.rfsp) || 0;
  // 处理多选框数据
  let pccRules = modalState.from.pccRules;
  if (Array.isArray(pccRules)) {
    pccRules = pccRules.join('|');
  } else {
    pccRules = '';
  }
  from.pccRules = pccRules;
  // 处理多选框数据
  let sessRules = modalState.from.sessRules;
  if (Array.isArray(sessRules)) {
    sessRules = sessRules.join('|');
  } else {
    sessRules = '';
  }
  from.sessRules = sessRules;

  // 必要字段校验
  let validateArr = ['imsi', 'msisdn'];
  if (modalState.isBatch) {
    validateArr.push('num');
    if (modalState.type === 'delete') {
      validateArr = ['num', 'imsi'];
    }
  }

  modalStateFrom
    .validate(validateArr)
    .then(e => {
      modalState.confirmLoading = true;
      const hide = message.loading(t('common.loading'), 0);

      // 根据类型选择函数
      let result: any = null;
      if (modalState.isBatch) {
        if (modalState.type === 'add') {
          result = addPCFRule({
            coreUid: coreUid,
            neUid: neUid,
            num: from.num,
            paramData: from,
          });
        }
        if (modalState.type === 'update') {
          result = editPCFRule({
            coreUid: coreUid,
            neUid: neUid,
            num: from.num,
            paramData: from,
          });
        }
        if (modalState.type === 'delete') {
          result = delPCFRule({
            coreUid: coreUid,
            neUid: neUid,
            num: from.num,
            imsi: from.imsi,
          });
        }
      } else {
        if (modalState.type === 'add') {
          result = addPCFRule({
            coreUid: coreUid,
            neUid: neUid,
            num: 0,
            paramData: from,
          });
        }
        if (modalState.type === 'update') {
          result = editPCFRule({
            coreUid: coreUid,
            neUid: neUid,
            num: 0,
            paramData: from,
          });
        }
      }

      result
        .then((res: any) => {
          if (res.code === RESULT_CODE_SUCCESS) {
            if (modalState.isBatch) {
              let okTip = '';
              if (modalState.type === 'add') {
                okTip = res.data;
              }
              if (modalState.type === 'update') {
                okTip = res.data;
              }
              if (modalState.type === 'delete') {
                okTip = t('common.msgSuccess', { msg: modalState.title });
              }
              message.success({
                content: okTip,
                duration: 5,
              });
            } else {
              message.success({
                content: t('common.msgSuccess', { msg: modalState.title }),
                duration: 3,
              });
            }

            fnModalCancel();
            fnGetList();
          } else {
            message.error({
              content: `${res.msg}`,
              duration: 3,
            });
          }
        })
        .finally(() => {
          hide();
          modalState.confirmLoading = false;
        });
    })
    .catch(e => {
      message.error(t('common.errorFields', { num: e.errorFields.length }), 3);
    });
}

/**
 * 对话框弹出关闭执行函数
 * 进行表达规则校验
 */
function fnModalCancel() {
  modalState.type = 'add';
  modalState.isBatch = false;
  modalState.openByEdit = false;
  modalStateFrom.resetFields();
}

/**
 * 对话框弹出显示为 批量操作
 * @param type 类型
 */
function fnModalVisibleByBatch(type: 'delete' | 'add' | 'update') {
  const neUid = queryParams.neUid || '-';
  const coreUid = queryParams.coreUid || '-';
  getPCFRule(coreUid, neUid)
    .then((data: any) => {
      pcfRuleOption.value = data;
      console.log(data);
    })
    .finally(() => {
      modalStateFrom.resetFields(); //重置表单
      modalState.isBatch = true;
      modalState.from.num = 1;
      modalState.type = type;
      if (type === 'add') {
        modalState.title = t('views.neData.common.batchAddText');
        modalState.openByEdit = true;
      }
      if (type === 'update') {
        modalState.title = t('views.neData.common.batchUpdateText');
        modalState.openByEdit = true;
      }
      if (type === 'delete') {
        modalState.title = t('views.neData.common.batchDelText');
        modalState.openByEdit = true;
      }
    });
}

/**
 * 记录删除
 * @param imsi 网元编号ID
 */
function fnRecordDelete(imsi: string) {
  const neUid = queryParams.neUid || '-';
  const coreUid = queryParams.coreUid || '-';
  if (!coreUid || !neUid) return;
  let imsiMsg = imsi;
  if (imsi === '0') {
    imsiMsg = `${tableState.selectedRowKeys[0]}... ${tableState.selectedRowKeys.length}`;
    imsi = tableState.selectedRowKeys.join(',');
  }

  Modal.confirm({
    title: t('common.tipTitle'),
    content: t('views.neData.pcfSub.delSure', { imsi: imsiMsg }),
    onOk() {
      const hide = message.loading(t('common.loading'), 0);
      delPCFRule({
        coreUid: coreUid,
        neUid: neUid,
        imsi: imsi,
      })
        .then(res => {
          if (res.code === RESULT_CODE_SUCCESS) {
            message.success({
              content: `${t('common.operateOk')}`,
              duration: 3,
            });
          } else {
            message.error({
              content: `${res.msg}`,
              duration: 3,
            });
          }
        })
        .finally(() => {
          hide();
          fnGetList();
        });
    },
  });
}

/**列表导出 */
function fnExportList(type: string) {
  const neUid = queryParams.neUid || '-';
  const coreUid = queryParams.coreUid || '-';
  if (!coreUid || !neUid) return;
  const hide = message.loading(t('common.loading'), 0);
  exportPCFRule({
    coreUid: coreUid,
    neUid: neUid,
    fileType: type,
  })
    .then(res => {
      if (res.code === RESULT_CODE_SUCCESS) {
        message.success({
          content: t('common.msgSuccess', { msg: t('common.export') }),
          duration: 3,
        });
        saveAs(res.data, `PCFRlue_${neUid}_${Date.now()}.${type}`);
      } else {
        message.error({
          content: `${res.msg}`,
          duration: 3,
        });
      }
    })
    .finally(() => {
      hide();
    });
}

/**查询列表, pageNum初始页数 */
function fnGetList(pageNum?: number) {
  if (tableState.loading) return;
  tableState.loading = true;
  if (pageNum) {
    queryParams.pageNum = pageNum;
    tablePagination.current = pageNum;
  }
  listPCFRule(toRaw(queryParams)).then(res => {
    if (res.code === RESULT_CODE_SUCCESS) {
      // 取消勾选
      if (tableState.selectedRowKeys.length > 0) {
        tableState.selectedRowKeys = [];
      }
      tablePagination.total = res.data.length;
      tableState.data = res.data;
    } else {
      tableState.data = [];
    }
    tableState.loading = false;
  });
}

/**对话框表格信息导入对象信息状态类型 */
type ModalUploadImportStateType = {
  /**是否显示 */
  open: boolean;
  /**标题 */
  title: string;
  /**是否上传中 */
  loading: boolean;
  /**上传结果信息 */
  msg: string;
  /**含失败信息 */
  hasFail: boolean;
};

/**对话框表格信息导入对象信息状态 */
let uploadImportState: ModalUploadImportStateType = reactive({
  open: false,
  title: t('components.UploadModal.uploadTitle'),
  loading: false,
  msg: '',
  hasFail: false,
});

/**对话框表格信息导入弹出窗口 */
function fnModalUploadImportOpen() {
  uploadImportState.msg = '';
  uploadImportState.loading = false;
  uploadImportState.open = true;
}

/**对话框表格信息导入关闭窗口 */
function fnModalUploadImportClose() {
  uploadImportState.open = false;
  fnGetList();
}

/**对话框表格信息导入上传 */
function fnModalUploadImportUpload(file: File) {
  const neUid = queryParams.neUid || '-';
  const coreUid = queryParams.coreUid || '-';
  if (!neUid || !coreUid) {
    return Promise.reject('Unknown network element');
  }
  const hide = message.loading(t('common.loading'), 0);
  uploadImportState.loading = true;
  // 上传文件
  uploadFileToNE('PCF', neUid, coreUid, file, 3)
    .then(res => {
      if (res.code === RESULT_CODE_SUCCESS) {
        return res.data;
      } else {
        uploadImportState.msg = res.msg;
        uploadImportState.loading = false;
        return '';
      }
    })
    .then((filePath: string) => {
      if (!filePath) return;
      // 文件导入
      return importPCFRule({
        neUid: neUid,
        coreUid: coreUid,
        fileType: 'txt',
        filePath: filePath,
      });
    })
    .then(res => {
      if (!res) return;
      uploadImportState.msg = res.msg;
      const regex = /fail num: (\d+)/;
      const match = res.msg.match(regex);
      if (match) {
        const failNum = Number(match[1]);
        uploadImportState.hasFail = failNum > 0;
      } else {
        uploadImportState.hasFail = false;
      }
    })
    .finally(() => {
      hide();
      uploadImportState.loading = false;
    });
}

/**使其忽略大小写 */
function filterOption(value: any, option: any) {
  return option.value.toUpperCase().indexOf(value.toUpperCase()) >= 0;
}

/**对话框表格信息导入模板 */
function fnModalDownloadImportTemplate() {
  const hide = message.loading(t('common.loading'), 0);

  const baseUrl = import.meta.env.VITE_HISTORY_BASE_URL;
  const templateUrl = `${
    baseUrl.length === 1 && baseUrl.indexOf('/') === 0
      ? ''
      : baseUrl.indexOf('/') === -1
      ? '/' + baseUrl
      : baseUrl
  }/neDataImput`;
  saveAs(
    `${templateUrl}/pcf_template.txt`,
    `import_pcfrule_template_${Date.now()}.txt`
  );

  hide();
}

onMounted(() => {
  // 获取网元网元列表
  neStore.neCascaderOptions.forEach(item => {
    if (item.value === 'PCF') {
      neOtions.value = JSON.parse(JSON.stringify(item.children));
    }
  });
  if (neOtions.value.length === 0) {
    message.warning({
      content: t('common.noData'),
      duration: 2,
    });
    return;
  }
  if (neOtions.value.length > 0) {
    queryParams.neUid = neOtions.value[0].value;
  }

  // 获取列表数据
  fnGetList();
});
</script>

<template>
  <PageContainer>
    <a-card
      v-show="tableState.seached"
      :bordered="false"
      :body-style="{ marginBottom: '24px', paddingBottom: 0 }"
    >
      <!-- 表格搜索栏 -->
      <a-form :model="queryParams" name="queryParams" layout="horizontal">
        <a-row :gutter="16">
          <a-col :lg="6" :md="12" :xs="24">
            <a-form-item label="PCF" name="neUid ">
              <a-select
                v-model:value="queryParams.neUid"
                :options="neOtions"
                :placeholder="t('common.selectPlease')"
                @change="fnGetList(1)"
              />
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :xs="24">
            <a-form-item label="IMSI" name="imsi">
              <a-input
                v-model:value="queryParams.imsi"
                allow-clear
                :placeholder="t('common.inputPlease')"
              ></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :xs="24">
            <a-form-item label="MSISDN" name="msisdn">
              <a-input
                v-model:value="queryParams.msisdn"
                allow-clear
                :placeholder="t('common.inputPlease')"
              ></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :xs="24">
            <a-form-item>
              <a-space :size="8">
                <a-button type="primary" @click.prevent="fnGetList()">
                  <template #icon>
                    <SearchOutlined />
                  </template>
                  {{ t('common.search') }}
                </a-button>
                <a-button type="default" @click.prevent="fnQueryReset">
                  <template #icon>
                    <ClearOutlined />
                  </template>
                  {{ t('common.reset') }}
                </a-button>
              </a-space>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-card>

    <a-card :bordered="false" :body-style="{ padding: '0px' }">
      <!-- 插槽-卡片左侧侧 -->
      <template #title>
        <a-space :size="8" align="center">
          <a-button type="primary" @click.prevent="fnModalVisibleByEdit()">
            <template #icon>
              <PlusOutlined />
            </template>
            {{ t('common.addText') }}
          </a-button>

          <a-button
            type="default"
            danger
            :disabled="tableState.selectedRowKeys.length <= 0"
            :loading="modalState.confirmLoading"
            @click.prevent="fnRecordDelete('0')"
          >
            <template #icon><DeleteOutlined /></template>
            {{ t('views.neData.common.checkDel') }}
          </a-button>

          <a-dropdown trigger="click">
            <a-button>
              {{ t('views.neData.common.batchOper') }}
              <DownOutlined />
            </a-button>
            <template #overlay>
              <a-menu @click="({ key }:any) => fnModalVisibleByBatch(key)">
                <a-menu-item key="add">
                  <PlusOutlined />
                  {{ t('views.neData.common.batchAddText') }}
                </a-menu-item>
                <a-menu-item key="update">
                  <FormOutlined />
                  {{ t('views.neData.common.batchUpdateText') }}
                </a-menu-item>
                <a-menu-item key="delete">
                  <DeleteOutlined />
                  {{ t('views.neData.common.batchDelText') }}
                </a-menu-item>
              </a-menu>
            </template>
          </a-dropdown>

          <a-button type="dashed" @click.prevent="fnModalUploadImportOpen">
            <template #icon><ImportOutlined /></template>
            {{ t('common.import') }}
          </a-button>
          <a-popconfirm
            placement="topRight"
            :title="t('views.neData.pcfSub.exportTip')"
            ok-text="TXT"
            ok-type="default"
            @confirm="fnExportList('txt')"
          >
            <a-button type="dashed">
              <template #icon><ExportOutlined /></template>
              {{ t('common.export') }}
            </a-button>
          </a-popconfirm>
        </a-space>
      </template>

      <!-- 插槽-卡片右侧 -->
      <template #extra>
        <a-space :size="8" align="center">
          <a-tooltip>
            <template #title>
              {{
                tableState.seached
                  ? t('common.switch.show')
                  : t('common.switch.hide')
              }}
            </template>
            <a-switch
              v-model:checked="tableState.seached"
              :checked-children="t('common.searchBarText')"
              :un-checked-children="t('common.searchBarText')"
              size="small"
            />
          </a-tooltip>
          <TableColumnsDnd
            cache-id="pcfSubData"
            :columns="tableColumns"
            v-model:columns-dnd="tableColumnsDnd"
          ></TableColumnsDnd>
          <a-tooltip>
            <template #title>{{ t('common.reloadText') }}</template>
            <a-button type="text" @click.prevent="fnGetList()">
              <template #icon><ReloadOutlined /></template>
            </a-button>
          </a-tooltip>
          <a-tooltip placement="topRight">
            <template #title>{{ t('common.sizeText') }}</template>
            <a-dropdown placement="bottomRight" trigger="click">
              <a-button type="text">
                <template #icon><ColumnHeightOutlined /></template>
              </a-button>
              <template #overlay>
                <a-menu
                  :selected-keys="[tableState.size as string]"
                  @click="fnTableSize"
                >
                  <a-menu-item key="default">
                    {{ t('common.size.default') }}
                  </a-menu-item>
                  <a-menu-item key="middle">
                    {{ t('common.size.middle') }}
                  </a-menu-item>
                  <a-menu-item key="small">
                    {{ t('common.size.small') }}
                  </a-menu-item>
                </a-menu>
              </template>
            </a-dropdown>
          </a-tooltip>
        </a-space>
      </template>

      <!-- 表格列表 -->
      <a-table
        class="table"
        row-key="imsi"
        :columns="tableColumnsDnd"
        :loading="tableState.loading"
        :data-source="tableState.data"
        :size="tableState.size"
        :pagination="tablePagination"
        :scroll="{ x: tableColumns.length * 150, y: 'calc(100vh - 480px)' }"
        @resizeColumn="(w:number, col:any) => (col.width = w)"
        :row-selection="{
          type: 'checkbox',
          selectedRowKeys: tableState.selectedRowKeys,
          onChange: fnTableSelectedRowKeys,
        }"
      >
        <template #bodyCell="{ column, record }">
          <template v-if="column.key === 'imsi'">
            <a-space :size="8" align="center">
              <a-tooltip>
                <template #title>{{ t('common.editText') }}</template>
                <a-button
                  type="link"
                  @click.prevent="fnModalVisibleByEdit(record)"
                >
                  <template #icon>
                    <FormOutlined />
                  </template>
                </a-button>
              </a-tooltip>
              <a-tooltip>
                <template #title>{{ t('common.deleteText') }}</template>
                <a-button
                  type="link"
                  @click.prevent="fnRecordDelete(record.imsi)"
                >
                  <template #icon>
                    <DeleteOutlined />
                  </template>
                </a-button>
              </a-tooltip>
            </a-space>
          </template>
        </template>
      </a-table>
    </a-card>

    <!-- 新增框或修改框 -->
    <ProModal
      :drag="true"
      :width="520"
      :destroyOnClose="true"
      :keyboard="false"
      :mask-closable="false"
      :open="modalState.openByEdit"
      :title="modalState.title"
      :body-style="{ maxHeight: '600px', 'overflow-y': 'auto' }"
      :confirm-loading="modalState.confirmLoading"
      @ok="fnModalOk"
      @cancel="fnModalCancel"
    >
      <a-form
        name="modalStateFrom"
        layout="horizontal"
        :label-col="{ span: 5 }"
        :labelWrap="true"
      >
        <!--批量删除-->
        <template v-if="modalState.isBatch && modalState.type === 'delete'">
          <a-form-item
            :label="t('views.neData.common.batchNum')"
            name="num"
            v-bind="modalStateFrom.validateInfos.num"
          >
            <a-input-number
              v-model:value="modalState.from.num"
              style="width: 100%"
              :min="1"
              :max="500"
              placeholder="<=500"
            ></a-input-number>
          </a-form-item>
          <a-form-item
            :label="
              modalState.isBatch ? t('views.neData.common.startIMSI') : 'IMSI'
            "
            name="imsi"
            v-bind="modalStateFrom.validateInfos.imsi"
          >
            <a-input
              v-model:value="modalState.from.imsi"
              allow-clear
              :maxlength="64"
              :placeholder="t('common.inputPlease')"
            >
              <template #prefix>
                <a-tooltip placement="topLeft">
                  <template #title>
                    {{ t('views.neData.common.imsiTip') }}<br />
                    {{ t('views.neData.common.imsiTip1') }}<br />
                    {{ t('views.neData.common.imsiTip2') }}<br />
                    {{ t('views.neData.common.imsiTip3') }}
                  </template>
                  <InfoCircleOutlined style="opacity: 0.45; color: inherit" />
                </a-tooltip>
              </template>
            </a-input>
          </a-form-item>
        </template>

        <template v-else>
          <!--批量数-->
          <a-form-item
            v-if="modalState.isBatch"
            :label="t('views.neData.common.batchNum')"
            name="num"
            v-bind="modalStateFrom.validateInfos.num"
          >
            <a-input-number
              v-model:value="modalState.from.num"
              style="width: 100%"
              :min="1"
              :max="500"
              placeholder="<=500"
            ></a-input-number>
          </a-form-item>

          <a-form-item
            :label="
              modalState.isBatch ? t('views.neData.common.startIMSI') : 'IMSI'
            "
            name="imsi"
            v-bind="modalStateFrom.validateInfos.imsi"
          >
            <a-input
              v-model:value="modalState.from.imsi"
              allow-clear
              :maxlength="64"
              :disabled="!modalState.isBatch && modalState.type === 'update'"
              :placeholder="t('common.inputPlease')"
            >
              <template #prefix>
                <a-tooltip placement="topLeft">
                  <template #title>
                    {{ t('views.neData.common.imsiTip') }}<br />
                    {{ t('views.neData.common.imsiTip1') }}<br />
                    {{ t('views.neData.common.imsiTip2') }}<br />
                    {{ t('views.neData.common.imsiTip3') }}
                  </template>
                  <InfoCircleOutlined style="opacity: 0.45; color: inherit" />
                </a-tooltip>
              </template>
            </a-input>
          </a-form-item>
          <a-form-item
            label="MSISDN"
            name="msisdn"
            v-bind="modalStateFrom.validateInfos.msisdn"
          >
            <a-input
              v-model:value="modalState.from.msisdn"
              allow-clear
              :maxlength="16"
              :disabled="!modalState.isBatch && modalState.type === 'update'"
              :placeholder="t('common.inputPlease')"
            >
              <template #prefix>
                <a-tooltip placement="topLeft">
                  <template #title>
                    {{ t('views.neData.common.msisdn') }}
                  </template>
                  <InfoCircleOutlined style="opacity: 0.45; color: inherit" />
                </a-tooltip>
              </template>
            </a-input>
          </a-form-item>

          <a-form-item
            label="PCC Rules"
            name="pccRules"
            :help="t('views.neData.pcfSub.pccRuleTip')"
          >
            <a-select
              v-model:value="modalState.from.pccRules"
              allow-clear
              mode="tags"
              :options="pcfRuleOption.pccRules"
            />
          </a-form-item>
          <a-form-item
            label="SESS Rules"
            name="sessRules"
            :help="t('views.neData.pcfSub.sessRuleTip')"
          >
            <a-select
              v-model:value="modalState.from.sessRules"
              allow-clear
              mode="tags"
              :options="pcfRuleOption.sessionRules"
            />
          </a-form-item>

          <a-form-item
            label="QoS Audio"
            name="qosAudio"
            :help="t('views.neData.pcfSub.qosAudioTip')"
          >
            <a-auto-complete
              v-model:value="modalState.from.qosAudio"
              allow-clear
              :options="pcfRuleOption.qosTemplate"
              :filter-option="filterOption"
            />
          </a-form-item>
          <a-form-item
            label="QoS Video"
            name="qosVideo"
            :help="t('views.neData.pcfSub.qosVideoTip')"
          >
            <a-auto-complete
              v-model:value="modalState.from.qosVideo"
              allow-clear
              :options="pcfRuleOption.qosTemplate"
              :filter-option="filterOption"
            />
          </a-form-item>

          <a-form-item
            label="HDR Enrich"
            name="hdrEnrich"
            :help="t('views.neData.pcfSub.hdrEnrichTip')"
          >
            <a-auto-complete
              v-model:value="modalState.from.hdrEnrich"
              allow-clear
              :options="pcfRuleOption.headerEnrichTemplate"
              :filter-option="filterOption"
            />
          </a-form-item>
          <a-form-item
            label="UE Policy"
            name="uePolicy"
            :help="t('views.neData.pcfSub.uePolicyTip')"
          >
            <a-input
              v-model:value="modalState.from.uePolicy"
              allow-clear
              :maxlength="64"
            >
            </a-input>
          </a-form-item>

          <a-form-item
            label="SAR"
            name="sar"
            :help="t('views.neData.pcfSub.sarTip')"
          >
            <a-auto-complete
              v-model:value="modalState.from.sar"
              allow-clear
              :options="pcfRuleOption.serviceAreaRestriction"
              :filter-option="filterOption"
            />
          </a-form-item>
          <a-form-item
            label="RFSP"
            name="rfsp"
            :help="t('views.neData.pcfSub.rfsfTip')"
          >
            <a-input-number
              v-model:value="modalState.from.rfsp"
              style="width: 100%"
              :min="0"
              :max="255"
              placeholder="0~255"
            >
            </a-input-number>
          </a-form-item>
        </template>
      </a-form>
    </ProModal>

    <!-- 上传导入表格数据文件框 -->
    <UploadModal
      :title="uploadImportState.title"
      :loading="uploadImportState.loading"
      @upload="fnModalUploadImportUpload"
      @close="fnModalUploadImportClose"
      v-model:open="uploadImportState.open"
      :ext="['.txt']"
    >
      <template #default>
        <a-row justify="space-between" align="middle">
          <a-col :span="12"> </a-col>
          <a-col>
            <a-button
              type="link"
              :title="t('views.neData.common.importTemplate')"
              @click.prevent="fnModalDownloadImportTemplate"
            >
              {{ t('views.neData.common.importTemplate') }}
            </a-button>
          </a-col>
        </a-row>
        <a-alert
          :message="uploadImportState.msg"
          :type="uploadImportState.hasFail ? 'warning' : 'info'"
          v-show="uploadImportState.msg.length > 0"
        >
        </a-alert>
      </template>
    </UploadModal>
  </PageContainer>
</template>

<style lang="less" scoped>
.table :deep(.ant-pagination) {
  padding: 0 24px;
}
</style>
