<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="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" @successSubmit="successSubmit"></add-or-update>
      </base-dialog>
    </div>
  </el-card>
</template>

<script>
import basicPage from "@/mixins/basic-page";
import AddOrUpdate from "./user-add-or-update";
import i18n from "@/i18n";
import sysFilter from '@/filters/sys-filter'
const tableProps = [
  {
    prop: "username",
    label: i18n.t("user.username"),
  },
  {
    prop: "deptName",
    label: i18n.t("user.deptName"),
  },
  {
    prop: "email",
    label: i18n.t("user.email"),
  },
  {
    prop: "mobile",
    label: i18n.t("user.mobile"),
  },
  {
    prop: "gender",
    label: i18n.t("user.gender"),
    filter: sysFilter('sex'),
  },
  {
    prop: "status",
    label: i18n.t("user.status"),
    filter: sysFilter('userStatus'),
  },
  {
    prop: "createDate",
    label: i18n.t("user.createDate"),
  },
];
const tableBtn = [
  {
    type: "edit",
    btnName: "编辑",
  },
  {
    type: "delete",
    btnName: "删除",
  },
];
export default {
  mixins: [basicPage],
  data() {
    return {
      urlOptions: {
        getDataListURL: "/sys/user/page",
        deleteURL: "/sys/user",
        exportUrl: "/sys/user/export",
      },
      tableProps,
      tableBtn,
      formConfig: [
        {
          type: "input",
          label: i18n.t("user.username"),
          placeholder: i18n.t("user.username"),
          param: "username",
        },
        {
          type: "button",
          btnName: "查询",
          name: "search",
          color: "primary",
        },
        {
          type: "button",
          btnName: "新增",
          name: "add",
          color: "primary",
          plain: true,
        },
      ],
    };
  },
  components: {
    AddOrUpdate,
  },
  methods:{
    //search-bar点击
    buttonClick(val) {
      switch (val.btnName) {
        case "search":
          this.listQuery.username = val.username;
          this.listQuery.page = 1;
          this.getDataList();
          break;
        case "add":
          this.addOrEditTitle = '新增'
          this.addOrUpdateVisible = true;
          this.addOrUpdateHandle()
          break;
        default:
          console.log(val)
       }
    },
  }
};
</script>
