<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="180"
          :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="addOrEditTitle"
        :dialogVisible="addOrUpdateVisible"
        @cancel="handleCancel"
        @confirm="handleConfirm"
        :before-close="handleCancel"
      >
        <add-or-update ref="addOrUpdate" @successSubmit="successSubmit"></add-or-update>
      </base-dialog>
      <detail v-if="detailVisible" ref="detailRef" @successSubmit="getDataList"></detail>
    </div>
  </el-card>
</template>
<script>
import AddOrUpdate from "./components/toolsType-add";
import Detail from "./components/toolsType-detail";
import basicPage from "@/mixins/basic-page";
import basicFilter from "@/filters/basic-filter";
import i18n from "@/i18n";

const tableProps = [
  {
    prop: "name",
    label: i18n.t("role.name"),
  },
  {
    prop: "code",
    label: i18n.t("params.paramCode"),
  },
  {
    prop: "type",
    label: i18n.t("module.basicData.measureType"),
  },
  {
    prop: "status",
    label: i18n.t("module.basicData.status"),
    filter: basicFilter("status"),
  },
];
const tableBtn = [
  {
    type: "edit",
    btnName: i18n.t("edit"),
  },
  {
    type: "delete",
    btnName: i18n.t("delete"),
  },
  {
    type: "detail",
    btnName: i18n.t("detail"),
  },
  {
    type: "change",
    btnName: "改变状态",
  },
];
export default {
  mixins: [basicPage],
  data() {
    return {
      urlOptions: {
        getDataListURL: "/basic/measureTool/page",
        deleteURL: "/basic/measureTool",
        statusUrl: "/basic/measureTool/status",
        exportUrl: "/basic/measureTool/export",
      },
      detailVisible: false,
      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,
    Detail,
  },
  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.addOrUpdateVisible = true;
          this.addOrUpdateHandle();
          break;
        case "export":
          this.exportHandle("量具管理");
          break;
        default:
          console.log(val);
      }
    },
    otherMethods(val) {
      this.detail(val.data.id);
    },
    detail(id) {
      this.detailVisible = true;
      this.$nextTick(() => {
        this.$refs.detailRef.init(id);
      });
    },
  },
};
</script>
