<!-- 
    TODO 字典 / 币种
 -->
<template>
  <el-main>
    <!-- 搜索栏 -->
    <el-form
      :model="listParm"
      label-width="80px"
      :inline="true"
    >
      <el-form-item class="item-search">
        <el-input
          v-model="listParm.code"
          placeholder="请输入简码"
        />
      </el-form-item>
      <el-form-item class="item-search">
        <el-input
          v-model="listParm.description"
          placeholder="请输入名称"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          :loading="currencyList.loading"
          :icon="Search"
          @click="searchBtn"
        >
          搜索
        </el-button>
        <el-button
          :loading="currencyList.loading"
          class="reset-btn"
          :icon="RefreshRight"
          @click="resetBtn"
        >
          重置
        </el-button>
        <el-button
          v-permission="['sys:currency:add']"
          type="primary"
          :icon="Plus"
          @click="addBtn"
        >
          新增
        </el-button>
      </el-form-item>
    </el-form>
    <!-- 表格 -->
    <el-table
      :height="tableHeight"
      :data="currencyList.list"
      border
      stripe
    >
      <el-table-column
        prop="id"
        label="序号"
      />
      <el-table-column
        prop="code"
        label="简码"
      />
      <el-table-column
        prop="description"
        label="中文名"
      />
      <el-table-column
        prop="symbol"
        label="货币符号"
      />
      <el-table-column
        label="操作"
        width="200"
      >
        <template #default="scope">
          <el-button
            v-permission="['sys:currency:edit']"
            type="primary"
            :icon="Edit"
            @click="editBtn(scope.row)"
          >
            编辑
          </el-button>
          <el-button
            v-permission="['sys:currency: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>
  <!-- 新增、编辑弹框 -->
  <AddandEditCurrency
    ref="adCurrencyRef"
    @save="save"
  />
</template>
<script setup lang='ts' name="currency">
import { ref, onMounted, nextTick } from 'vue';
import { Search, Edit, Plus, Setting, RefreshRight, Delete } from '@element-plus/icons-vue';
import useCurrencyTable from '@/composables/currency/userCurrencyTable';
import useCurrency from '@/composables/currency/userCurrency';
import AddandEditCurrency from './AddandEditCurrency.vue';
import useResizeHeight from '@/hooks/useResizeHeight';

//表格列表
const { listParm, currencyList, getCurrencyList, sizeChange, currentChange, searchBtn, resetBtn } = useCurrencyTable()

//新增、编辑
const { addBtn, editBtn, deleteBtn, adCurrencyRef, save } = useCurrency(getCurrencyList)
// 表格自适应屏幕高度
const { tableHeight } = useResizeHeight()
</script>
<style scoped lang='scss'></style> 