<template>
  <div>
    <div class="head-container">
      <el-input v-model="searchData.orgName" placeholder="请输入管理单位名称" style="width: 200px"></el-input>
      <el-button @click="getData(1)" style="margin-left: 20px" ghost icon="search" :color="imgColor">查询</el-button>
    </div>
    <el-table :header-cell-style="{backgroundColor: '#f5f7fa',color: '#000',fontSize: '18px',fontWeight: '600'}" :data="basicData" border style="width: 100%;">
      <el-table-column type="index" label="序号" align="center" width="70"/>
      <el-table-column prop="orgName" label="单位名称" align="center"/>
      <el-table-column prop="orgCode" label="单位代码" align="center"/>
    </el-table>
    <el-pagination
      style="left: 40%;margin-top: 6px;"
      background
      :hide-on-single-page="true"
      @current-change="handleCurrentChange"
      :current-page="searchData.pageNo"
      :page-size="searchData.pageSize"
      layout="total, prev, pager, next"
      :total="total"
    />
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { getAction } from '@/api/manage'
import { ElMessage } from 'element-plus'
const searchData = ref({
  pageNo: 1,
  pageSize: 10,
  orgName: undefined
})
const basicData = ref([])
const total = ref(0)
const imgColor = ref()

const getData = async (arg) => {
  if (arg) {
    searchData.value.pageNo = 1
  }
  const res = await getAction(window._CONFIG['serverURL'] + '/org/page', searchData.value)
  if (res.code !== 99200) return ElMessage.error(res.message)
  basicData.value = res.data.records
  total.value = res.data.totalRows - 0
}


const handleCurrentChange =  (val) => {
  searchData.value.pageNo = val
  getData()
}

onMounted(() => {
  if (sessionStorage.getItem('bgColor')) {
    imgColor.value = sessionStorage.getItem('bgColor')
  } else {
    sessionStorage.setItem('bgColor', '#1f8a36')
  }
});

getData()
 
</script>

<style scoped lang="less">
</style>
