<!--
 * @Author: zhp
 * @Date: 2023-01-11 09:24:58
 * @LastEditTime: 2023-07-14 13:53:02
 * @LastEditors: zwq
 * @Description: 
-->
<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__user">
      <SearchBar :formConfigs="formConfig" ref="ruleForm" @headBtnClick="buttonClick"> </SearchBar>
      <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="操作"
          :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" @refreshDataList="successSubmit"></add-or-update>
      </base-dialog>
    </div>
  </el-card>
</template>

<script>
import basicPage from "@/mixins/basic-page";
import AddOrUpdate from "./components/problemType-add";
import available from "./components/available.vue";
import i18n from "@/i18n";
const tableProps = [
  {
    prop: "name",
    label: i18n.t("code.name"),
    align: "center",
  },
  {
    prop: "code",
    label: i18n.t("code.code"),
    align: "center",
  },
  {
    prop: "description",
    label: "描述",
    align: "center",
  },
  {
    prop: "problemStatus",
    label: i18n.t("code.problemStatus"),
    align: "center",
    subcomponent: available,
  },
];
const tableBtn = [
  {
    type: "edit",
    btnName: "编辑",
  },
  {
    type: "delete",
    btnName: "删除",
  },
];
export default {
  mixins: [basicPage],
  components: {
    AddOrUpdate,
  },
  data() {
    return {
      urlOptions: {
        getDataListURL: "/code/problemType/page",
        deleteURL: "/code/problemType",
      },
      tableProps,
      tableBtn,
      formConfig: [
        {
          type: "select",
          label: "状态",
          selectOptions: [
            { id: 1, name: "可用" },
            { id: 0, name: "不可用" },
          ],
          param: "problemStatus",
          defaultSelect: "",
        },
        {
          type: "button",
          btnName: "搜索",
          name: "search",
          color: "primary",
        },
        {
          type: "button",
          btnName: "新增",
          name: "add",
          color: "primary",
        },
      ],
    };
  },
  methods: {
    buttonClick(val) {
      switch (val.btnName) {
        case "search":
          this.listQuery.page = 1;
          this.listQuery.problemStatus = val.problemStatus;
          this.getDataList();
          break;
        case "add":
          this.addOrEditTitle = this.$t("add");
          this.addOrUpdateVisible = true;
          this.addOrUpdateHandle();
          break;
        default:
          console.log(val);
      }
    },
  },
};
</script>
