<!-- 
    TODO 字典 / 国家
 -->
<template>
  <el-main>
    <!-- 搜索栏 -->
    <el-form
      class="el-search-form"
      :model="listParm"
      label-width="80px"
      :inline="true"
    >
      <el-form-item class="item-search">
        <el-input
          v-model="listParm.twCode"
          placeholder="请输入二字简码"
        />
      </el-form-item>

      <el-form-item class="item-search">
        <el-input
          v-model="listParm.cnName"
          placeholder="请输入中文名称"
        />
      </el-form-item>
      <el-form-item class="item-search">
        <el-input
          v-model="listParm.enName"
          placeholder="请输入英文名称"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          :loading="countryList.loading"
          :icon="Search"
          @click="searchBtn"
        >
          搜索
        </el-button>
        <el-button
          :loading="countryList.loading"
          class="reset-btn"
          :icon="RefreshRight"
          @click="resetBtn"
        >
          重置
        </el-button>
        <el-button
          v-permission="['sys:country:add']"
          type="primary"
          :icon="Plus"
          @click="addBtn"
        >
          新增
        </el-button>
      </el-form-item>
    </el-form>
    <!-- 表格 -->
    <el-table
      :height="tableHeight"
      :data="countryList.list"
      border
      stripe
    >
      <el-table-column
        prop="id"
        label="编码"
      />
      <el-table-column
        prop="twCode"
        label="二字简码"
      />

      <el-table-column
        prop="cnName"
        label="中文名称"
      />
      <el-table-column
        prop="enName"
        label="英文名称"
      />

      <el-table-column
        label="操作"
        width="200"
      >
        <template #default="scope">
          <el-button
            v-permission="['sys:country:edit']"
            type="primary"
            :icon="Edit"
            @click="editBtn(scope.row)"
          >
            编辑
          </el-button>
          <el-button
            v-permission="['sys:country:delete']"
            type="danger"
            :icon="Delete"
            @click="deleteBtn(scope.row.id)"
          >
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      v-model:current-page="listParm.pageNum"
      :page-sizes="[10, 20, 40, 80, 100]"
      :page-size="listParm.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="listParm.total"
      background
      @size-change="sizeChange"
      @current-change="currentChange"
    />
  </el-main>
  <!-- 新增、编辑弹框 -->
  <AddandEditCountry
    ref="adCountryRef"
    @save="save"
  />
</template>
<script setup lang="ts" name="country">
import { ref, onMounted, nextTick } from 'vue';
import { Search, Edit, Plus, Setting, RefreshRight, Delete } from '@element-plus/icons-vue';
import useCountryTable from '@/composables/country/userCountryTable';
import useCountry from '@/composables/country/userCountry';
import AddandEditCountry from './AddandEditCountry.vue';
import useResizeHeight from '@/hooks/useResizeHeight';

//表格列表
const { listParm, countryList, getCountryList, sizeChange, currentChange, searchBtn, resetBtn } = useCountryTable()

//新增、编辑
const { addBtn, editBtn, deleteBtn, adCountryRef, save } = useCountry(getCountryList)
// 表格自适应屏幕高度
const { tableHeight } = useResizeHeight()
</script>
  
<style lang="scss">
.el-search-form { 
  width: 100%;

  // 将每一行的设置为相对定位 方便后面before after 使用绝对定位来固定位置
  .item-search {
    margin-right: 8px;
  }
}
</style>