<template>
  <div>
    <el-form :model="form" inline>
      <el-form-item label="中心代码">
        <el-input v-model.trim="form.code"></el-input>
      </el-form-item>
      <el-form-item label="中心名称">
        <el-input v-model.trim="form.name"></el-input>
      </el-form-item>
      <el-form-item label="状态">
        <StateSelect v-model="form.enableState"></StateSelect>
      </el-form-item>
      <el-button @click="searchForm">查询</el-button>
      <el-button>新增</el-button>
      <el-button>导入</el-button>
    </el-form>

    <el-table :data="tableData" stripe style="width: 100%;">
      <el-table-column type="selection" width="40" />
      <el-table-column width="55" label="ID">
        <span slot-scope="scope">{{ scope.row.id }}</span>
      </el-table-column>
      <el-table-column width="200" label="机构名称">
        <span slot-scope="scope">{{ scope.row.name }}</span>
      </el-table-column>
      <el-table-column width="200" label="机构代码">
        <span slot-scope="scope">{{ scope.row.code }}</span>
      </el-table-column>
      <el-table-column label="状态">
        <span slot-scope="scope">{{
          scope.row.enable | zeroOneEnableDisableFilter
        }}</span>
      </el-table-column>
      <el-table-column width="100" label="负责人">
        <span slot-scope="scope">{{ scope.row.contactName }}</span>
      </el-table-column>
      <el-table-column width="120" label="联系方式">
        <span slot-scope="scope">{{ scope.row.contactPhone }}</span>
      </el-table-column>
      <el-table-column width="120" label="更新人">
        <span slot-scope="scope">{{ scope.row.updateName }}</span>
      </el-table-column>
      <el-table-column sortable width="170" label="更新时间" prop="updateTime">
      </el-table-column>
      <el-table-column :context="_self" label="操作" width="210">
        <div slot-scope="scope">
          <el-button size="mini" type="primary" plain @click="edit(scope.row)">
            <i class="el-icon-edit"></i> 编辑
          </el-button>
        </div>
      </el-table-column>
    </el-table>
    <div class="page float-right">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-size="pageSize"
        :page-sizes="[10, 20, 50, 100, 200, 300]"
        @size-change="handleSizeChange"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      />
    </div>
  </div>
</template>

<script>
import StateSelect from "@/components/StateSelect";
import { searchOrgs } from "../../../api/system-org";

export default {
  name: "OrgManagement",
  components: {
    StateSelect,
  },
  data() {
    return {
      form: {
        code: "",
        name: "",
        enableState: "",
      },
      tableData: [],
      currentPage: 1,
      pageSize: 10,
      total: 10,
    };
  },
  async created() {},
  methods: {
    async searchForm() {
      this.tableData = (
        await searchOrgs({
          enable: this.form.enableState,
          code: this.form.code,
          name: this.form.name,
          pageNumber: this.currentPage,
          pageSize: this.pageSize,
        })
      ).data.data.records.records;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.searchForm();
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.currentPage = 1;
      this.searchForm();
    },
  },
};
</script>

<style></style>
