<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__user">
      <search-bar :formConfigs="formConfig" ref="searchBarForm" @headBtnClick="buttonClick" />
      <base-table
        :table-props="tableProps"
        :page="listQuery.page"
        :limit="listQuery.limit"
        :table-data="tableData"
      >
        <method-btn
          v-if="tableBtn.length"
          slot="handleBtn"
          :width="150"
          :label="$t('handle')"
          :method-list="tableBtn"
          @clickBtn="handleClick"
        />
      </base-table>
      <pagination
        :limit.sync="listQuery.limit"
        :page.sync="listQuery.page"
        :total="listQuery.total"
        @pagination="getDataList"
      />
      <!-- 弹窗, 新增 / 修改 -->
    <add-or-update
      v-if="addOrUpdateVisible"
      ref="addOrUpdate"
      @successSubmit="getDataList"
    ></add-or-update>
    </div>
  </el-card>
</template>

<script>
import AddOrUpdate from './components/interpretationScheme-add'
import basicPage from '@/mixins/basic-page'
import i18n from "@/i18n";

const tableProps = [
  {
    prop: "name",
    label: i18n.t("role.name"),
  },
  {
    prop: "code",
    label: i18n.t("params.paramCode"),
  },
]
const tableBtn = [
  {
    type: "edit",
    btnName: i18n.t("edit"),
  },
  {
    type: "delete",
    btnName: i18n.t("delete"),
  },
];
export default {
  mixins: [basicPage],
  data() {
    return {
      urlOptions: {
        getDataListURL: '/qualityPlanning/myInterpretationScheme/page',
        deleteURL: '/qualityPlanning/myInterpretationScheme',
        exportUrl: '/qualityPlanning/myInterpretationScheme/export'
      },
      tableProps,
      tableBtn,
      tableData: [],
      formConfig: [
        {
          type: "input",
          label: i18n.t("role.name"),
          placeholder: i18n.t("placeholder.name"),
          param: "name",
        },
        {
          type: "input",
          label: i18n.t("params.paramCode"),
          placeholder: i18n.t("placeholder.code"),
          param: "code",
        },
        {
          type: "button",
          btnName: i18n.t("query"),
          name: "search",
          color: "primary",
        },
        {
          type: "button",
          btnName: i18n.t("add"),
          name: "add",
          color: "primary",
          plain: true,
        },
        {
          type: "button",
          btnName: i18n.t("export"),
          name: "export",
          color: "primary",
          plain: true,
        },
      ],
    };
  },
  components: {
    AddOrUpdate,
  },
  methods: {
    //search-bar点击
    buttonClick(val) {
      switch (val.btnName) {
        case "search":
          this.listQuery.name = val.name;
          this.listQuery.code = val.code;
          this.listQuery.page = 1;
          this.getDataList();
          break;
        case "add":
          this.addOrEditTitle = this.$t('add');
          this.addOrUpdateVisible = true;
          this.addOrUpdateHandle()
          break;
        case "export":
          this.exportHandle('判读方案')
          break;
        default:
          console.log(val)
       }
    },
  },
};
</script>
