<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__user">
      <search-bar :formConfigs="formConfig" ref="searchBarForm" @headBtnClick="buttonClick">
        <el-badge :value="5" class="item">
          <el-button type="primary" size="small" @click="searchsClick">条件搜索</el-button>
        </el-badge>
      </search-bar>
      <base-table
        :table-props="tableProps"
        :page="listQuery.page"
        :limit="listQuery.limit"
        :table-data="tableData"
      >
        <method-btn
          v-if="tableBtn.length"
          slot="handleBtn"
          :width="100"
          :label="$t('handle')"
          :method-list="tableBtn"
          @clickBtn="handleClick"
        />
      </base-table>
      <pagination
        :limit.sync="listQuery.limit"
        :page.sync="listQuery.page"
        :total="listQuery.total"
        @pagination="getDataList"
      />
      <!-- 弹窗, 条件搜索-->
      <base-dialog
        :dialogTitle="searchsTitle"
        :dialogVisible="searchsVisible"
        @cancel="searchsCancel"
        @confirm="searchsConfirm"
        :before-close="searchsCancel"
      >
        <searchs ref="searchsRef" @refreshDataList="searchsSubmit"></searchs>
      </base-dialog>
      <!-- 弹窗, 新增 / 修改 -->
      <base-dialog
        :dialogTitle="addOrEditTitle"
        :dialogVisible="addOrUpdateVisible"
        @cancel="handleCancel"
        @confirm="handleConfirm"
        :before-close="handleCancel"
        width=80%
      >
        <add-or-update ref="addOrUpdate" @refreshDataList="successSubmit"></add-or-update>
      </base-dialog>
    </div>
  </el-card>
</template>

<script>
import AddOrUpdate from "./components/eightDisciplineList-detail";
import Searchs from "./components/searchs";
import basicPage from "@/mixins/basic-page";
import codeFilter from "@/filters/code-filter";
import { timeFormatter } from "@/filters/code-filter";
import i18n from "@/i18n";

const tableProps = [
  {
    prop: "title",
    label: i18n.t("code.title"),
    align: "center",
  },
  {
    prop: "code",
    label: i18n.t("code.code"),
    align: "center",
  },
  {
    prop: "eightDisciplineType",
    label: i18n.t("code.eightDisciplineType"),
    align: "center",
    filter: codeFilter("eightDisciplineType"),
  },
  {
    prop: "occurrenceDate",
    label: i18n.t("code.occurrenceDate"),
    align: "center",
    filter: timeFormatter,
  },
  {
    prop: "description",
    label: i18n.t("code.description"),
    align: "center",
  },
  {
    prop: "examineStatus",
    label: i18n.t("code.examineStatus"),
    align: "center",
    filter: codeFilter("examineStatus"),
  },
];
const tableBtn = [
  {
    type: "delete",
    btnName: i18n.t("delete"),
  },
  {
    type: "detail",
    btnName: "详情",
  },
];

export default {
  mixins: [basicPage],
  data() {
    return {
      urlOptions: {
        getDataListURL: "/code/startEightDiscipline/eight/page",
        deleteURL: "/code/startEightDiscipline",
      },
      tableProps,
      tableBtn,
      tableData: [],
      formConfig: [
        {
          type: "button",
          btnName: "搜索",
          name: "search",
          color: "primary",
        },
        {
          type: "button",
          btnName: i18n.t("export"),
          name: "export",
          color: "primary",
          plain: true,
        },
      ],
    };
  },
  components: {
    AddOrUpdate,
    Searchs,
  },
  methods: {
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      this.$http
        .post(this.urlOptions.getDataListURL, this.listQuery)
        .then(({ data: res }) => {
          this.dataListLoading = false;
          if (res.code !== 0) {
            this.tableData = [];
            this.listQuery.total = 0;
            return this.$message.error(res.msg);
          }
          this.tableData = res.data.list;
          this.listQuery.total = res.data.total;
        })
        .catch(() => {
          this.dataListLoading = false;
        });
    },
    //search-bar点击
    searchsClick() {
      this.searchsTitle = "条件搜索";
      this.searchsHandle();
    },
    buttonClick(val) {
      switch (val.btnName) {
        case "search":
          this.listQuery = {};
          this.listQuery.page = 1;
          this.listQuery.limit = 10;
          this.listQuery.total = 1;
          this.getDataList();
          break;
        case "export":
          this.exportHandle("工厂管理");
          break;
        default:
          console.log(val);
      }
    },
    otherMethods(val) {
      this.addOrEditTitle = "详情";
      this.addOrUpdateVisible = true;
      this.addOrUpdateHandle(val.data.id);
    },
  },
};
</script>
