<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="70"
          :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: "productName",
    label: "产品",
    align: "center",
  },
  {
    prop: "customName",
    label: "客户",
    align: "center",
  },
  {
    prop: "occurrenceDate",
    label: i18n.t("code.occurrenceDate"),
    align: "center",
    filter: timeFormatter,
  },
  {
    prop: "D1",
    label: "D1",
    align: "center",
  },
  {
    prop: "D2",
    label: "D2",
    align: "center",
  },
  {
    prop: "D3",
    label: "D3",
    align: "center",
  },
  {
    prop: "D4",
    label: "D4",
    align: "center",
  },
  {
    prop: "D5",
    label: "D5",
    align: "center",
  },
  {
    prop: "D6",
    label: "D6",
    align: "center",
  },
  {
    prop: "D7",
    label: "D7",
    align: "center",
  },
  {
    prop: "D8",
    label: "D8",
    align: "center",
  },
];
const tableBtn = [
  {
    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",
        },
      ],
    };
  },
  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>
