<!--
数据安全级别表码列表
@Author: linqian
@Date: 2021-03-31 15:30:
-->
<template>
  <div>
    <!-- 搜索栏 -->
    <search-bar :conditionForm="conditionForm" @submitSearch="receiveSearch"></search-bar>
    <!-- 操作栏 -->
    <operate-bar :pageOptList="pageOptList" @submitPageOpt="receviceOpt"></operate-bar>
    <!-- 列表 -->
    <new-table
      ref="table"
      :tableUrl="dataSecLevTableUrl"
      :tableHeader="safeLevelForm"
      :condition="condition"
      :tableOptList="tableOptList"
      @submitTableOpt="receviceOpt"
    >
    </new-table>
  </div>
</template>

<script>
import { dataSecLevTableUrl, getDataSecLevDetail, saveDataSecLev, delDataSecLev } from '@/api/data-auth';
import { safeLevelCodeSyncUrl } from '@/api/sync';
import { safeLevelForm, tableOptList, pageOptList } from './DataConfig';
import newTable from '@/components/new-table';
import searchBar from '@/components/search-bar';
import operateBar from '@/components/operate-bar';
import { searchOpt, importOpt, syncOpt, addEditOpt } from '@/mixins/page-opt';
import { dataSafeLevelImportUrl } from '@/api/import';
const area = ['500px', '400px'];
const labelWidth = '120px';
export default {
  components: { searchBar, operateBar, newTable },
  mixins: [searchOpt, importOpt, syncOpt, addEditOpt],
  data() {
    return {
      conditionForm: [
        {
          label: '数据安全级别',
          name: 'secName',
          op: 'like',
          value: '',
          component: 'ElInput'
        }
      ],
      tableOptList: tableOptList.slice(1, 3),
      pageOptList,
      dataSecLevTableUrl,
      safeLevelForm
    };
  },
  computed: {},
  methods: {
    async receviceOpt(opt, row) {
      const otherParams = {
        config: safeLevelForm,
        labelWidth,
        area
      };
      if (opt == '新增') {
        this.handleOpenEditForm('新增', 'add', otherParams);
      } else if (opt == '修改') {
        const detailInfo = await this.getDetail(row.id);
        this.handleOpenEditForm('编辑', 'update', { ...otherParams, detailInfo });
      } else if (opt == '删除') {
        this.handleDelete(row);
      } else if (opt == '同步') {
        this.handleSync(safeLevelCodeSyncUrl);
      } else if (opt == '导入') {
        this.handleImport(dataSafeLevelImportUrl, 'dataSec', '数据安全级别表码导入');
      }
    },
    /**
     * 获取详情
     */
    getDetail(id) {
      return new Promise((resolve) => {
        getDataSecLevDetail(id).then((res) => {
          resolve(res.data.content);
        });
      });
    },
    /**
     * 删除
     */
    handleDelete(row) {
      this.$dgConfirm(`是否确定删除这条数据！`, '提示', {}).then(() => {
        delDataSecLev(row.id).then((res) => {
          this.$message.success('删除成功!');
          this.handleSearch();
        });
      });
    },
    /**
     * @description: 保存表单
     * @param { 表单数据 } form
     * @param { 新增还是编辑 } type
     * @param { 弹框 } layer
     */
    saveForm(form, type, layer) {
      saveDataSecLev(form)
        .then((res) => {
          this.$message.success('保存成功!');
          layer.close(layer.dialogIndex);
          this.handleSearch();
        })
        .catch((error) => {
          this.$message.error(error);
        });
    }
  },
  created() {},
  mounted() {}
};
</script>

<style lang='scss'>
@import url('./index.scss');
</style>