<template>
  <el-main>
    <!-- 搜索栏 -->
    <el-form
      class="el-search-form"
      :model="listParm"
      label-width="80px"
      :inline="true"
      size="mini"
    >
      <el-form-item class="item-search">
        <el-input
          v-model="listParm.titleName"
          placeholder="请输入标题名称"
        />
      </el-form-item>
      <el-form-item class="item-search">
        <el-select
          v-model="listParm.currencyCode"
          placeholder="请选择币种"
          :clearable="true"
        >
          <el-option
            v-for="item in currencyList"
            :key="item.value"
            :label="`${item.value}(${item.label})`"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          :loading="customerRateList.loading"
          :icon="Search"
          @click="searchBtn"
        >
          搜索
        </el-button>
        <el-button
          :loading="customerRateList.loading"
          class="reset-btn"
          :icon="RefreshRight"
          @click="resetBtn"
        >
          重置
        </el-button>
        <el-button
          v-permission="['sys:customercurrencyrate:add']"
          type="primary"
          :icon="Plus"
          @click="addBtn"
        >
          新增
        </el-button>
      </el-form-item>
    </el-form>
    <!-- 表格 -->
    <el-table
      :height="tableHeight"
      :data="customerRateList.list"
      stripe
    >
      <el-table-column
        prop="titleName"
        label="名称"
      />
      <el-table-column
        prop="currencyCode"
        label="币种"
      />
      <el-table-column
        prop="currencyRate"
        label="汇率"
      />
      <el-table-column
        prop="startDate"
        label="生效起始时间"
      >
        <template #default="scope">
          {{ timeFiltering(scope.row.startDate) }}
        </template>
      </el-table-column>
      <el-table-column
        prop="endDate"
        label="生效结束时间"
      >
        <template #default="scope">
          {{ timeFiltering(scope.row.endDate) }}
        </template>
      </el-table-column>
      <el-table-column
        prop="createUserName"
        label="操作人员"
      />
      <el-table-column
        prop="createTime"
        label="操作时间"
      />
      <el-table-column
        label="操作"
        width="350"
      >
        <template #default="scope">
          <el-button
            v-permission="['sys:customercurrencyrate:edit']"
            type="primary"
            size="mini"
            :icon="Edit"
            @click="editBtn(scope.row)"
          >
            编辑
          </el-button>
          <el-button
            v-permission="['sys:customercurrencyrate:delete']"
            type="danger"
            size="mini"
            :icon="Delete"
            @click="deleteBtn(scope.row.rateVersionId)"
          >
            删除
          </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>
  <!-- 新增、编辑弹框 -->
  <!-- <AddandEditCustomerRate
    ref="adCurrencyRateRef"
    @save="save"
  /> -->
  <AddEditCustomerRateV2
    ref="adCurrencyRateRef"
    @save-customer-rate="save"
  />
</template>
<script setup lang="ts">
import { onBeforeMount } from 'vue';
import { Search, Edit, Plus, Setting, RefreshRight, Delete } from '@element-plus/icons-vue';
import userCustomerRateTable from '@/composables/customerrate/userCustomerRateTable';
import useCustomerRate from '@/composables/customerrate/userCustomerRate';
import AddandEditCustomerRate from './AddandEditCustomerRate.vue';
import AddEditCustomerRateV2 from './AddEditCustomerRateV2.vue';
import timeFiltering from '@/utils/timeFiltering';
import useResizeHeight from '@/hooks/useResizeHeight';
import { useCurrencyStore } from '@/store/currency';

// 基础数据
const store = useCurrencyStore()

//表格列表
const { currencyList, listParm, customerRateList, getCustomerRateList, sizeChange, currentChange, searchBtn, resetBtn } = userCustomerRateTable(store)
//新增、编辑
const { addBtn, editBtn, deleteBtn, adCurrencyRateRef, save } = useCustomerRate(getCustomerRateList)
// 表格自适应屏幕高度
const { tableHeight } = useResizeHeight()
</script>
   
<style lang="scss">
.el-search-form {
  width: 100%;

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