<!--
 * @Author: zwq
 * @Date: 2023-01-04 10:29:40
 * @LastEditors: zwq
 * @LastEditTime: 2023-01-06 09:54:57
 * @Description: 
-->
<template>
  <el-card shadow="never" class="aui-card--fill">
    <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="80"
        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" />
    </base-dialog>
  </el-card>
</template>

<script>
import AddOrUpdate from "./components/unitList-add";
import basicPage from "@/mixins/basic-page";

const tableProps = [
  {
    prop: "date",
    label: "日期",
  },
  {
    prop: "name",
    label: "姓名",
  },
  {
    prop: "sex",
    label: "性别",
  },
  {
    prop: "age",
    label: "年龄",
  },
  {
    prop: "address",
    label: "地址",
  },
];
const tableBtn = [
  {
    type: "edit",
    btnName: "编辑",
  },
  {
    type: "delete",
    btnName: "删除",
  },
];
export default {
  mixins: [basicPage],
  data() {
    return {
      urlOptions: {
        getDataListURL: "/basic/unit/page",
        deleteURL: "/basic/unit",
        statusUrl: "/basic/unit/status",
        exportUrl: "/basic/unit/export",
      },
      tableProps,
      tableBtn,
      tableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          sex: "男",
          id:111,
          age: 18,
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          sex: "男",
          age: 18,
          address: "上海市普陀区金沙江路 1517 弄",
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          sex: "男",
          age: 18,
          address: "上海市普陀区金沙江路 1519 弄",
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          sex: "男",
          age: 18,
          address: "上海市普陀区金沙江路 1516 弄",
        },
      ],
      formConfig: [
        {
          type: "input",
          label: "名称",
          placeholder: "请输入名称",
          param: "xm1",
        },
        {
          type: "input",
          label: "编码",
          placeholder: "请输入编码",
          param: "xm2",
        },
        {
          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.xm1 = val.xm1;
          this.listQuery.xm2 = val.xm2;
          this.listQuery.page = 1;
          this.getDataList();
          break;
        case "add":
          this.addOrEditTitle = '新增'
          this.addOrUpdateVisible = true;
          this.addOrUpdateHandle()
          break;
        default:
          console.log(val)
       }
    },
  },
};
</script>
