<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch">
        <el-card shadow="hover" class="mb-[10px]">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true">
            <el-form-item label="结算单号" prop="settleNo">
              <el-input v-model="queryParams.settleNo" placeholder="请输入结算单号"></el-input>
            </el-form-item>
            <el-form-item label="凭证号" prop="voucherCode">
              <el-input v-model="queryParams.voucherCode" placeholder="请输入凭证号"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
              <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
        </el-card>

        <el-card shadow="never">
          <template #header>
            <el-row :gutter="10" class="mb8">
              <el-col :span="1.5">
                <el-button type="primary" plain @click="syncAll">批量同步</el-button>
              </el-col>
              <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>
          </template>

          <el-table v-loading="loading" :data="tableRows">
            <el-table-column label="序号" type="index" width="50px"></el-table-column>
            <el-table-column label="结算单号" prop="settleNo" />
            <el-table-column label="专家姓名" prop="expertName">
              <template #default="{row}">
                {{ row.expertName || '-' }}
              </template>
            </el-table-column>
            <el-table-column label="项目名称" prop="productName" />
            <el-table-column label="金额" prop="money">
              <template #default="{ row }"> {{ row.money || 0 }}元 </template>
            </el-table-column>
            <el-table-column label="凭证号" prop="voucherCode">
              <template #default="{ row }">
                <el-button type="primary" link>{{ row.voucherCode }}</el-button>
                <!-- <a :href="scope.row.url || ''" :download="row.voucherCode" class="download" target="_blank">{{ row.voucherCode }}</a> -->
              </template>
            </el-table-column>
            <el-table-column label="操作" width="100px">
              <template #default="{ row }">
                <el-button type="primary" link :disabled="row.isSync" @click="Sync">同步</el-button>
              </template>
            </el-table-column>
          </el-table>

          <pagination v-show="page.total > 0" :total="page.total" v-model:page="page.pageNum" v-model:limit="page.pageSize" @pagination="getList" />
        </el-card>
      </div>
    </transition>
  </div>
</template>

<script setup lang="ts">
import { getTableList } from '@/api/expertMoneyConfig/settlementVoucher';
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const showSearch = ref(true);

const page = ref({
  pageNum: 1,
  pageSize: 10,
  total: 0
});
const queryFormRef = ref();
const queryParams = ref<any>({
  settleNo: '',
  voucherCode: ''
});

/** 搜索按钮操作 */
const handleQuery = () => {
  page.value.pageNum = 1;
  getList();
};

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  handleQuery();
};
const tableRows = ref([]);
const loading = ref(false);
const getList = async () => {
  loading.value = true;
  let res = await getTableList({
    ...queryParams.value,
    ...page.value
  }).finally(() => {
    loading.value = false;
  });
  tableRows.value = res.rows;
};
/* 批量同步 */
const syncAll = () => {
  ElNotification({
    title: '提示',
    message: '同步成功',
    type: 'success'
  });
};
/* 同步 */
const Sync = () => {
  ElNotification({
    title: '提示',
    message: '同步成功',
    type: 'success'
  });
};
onMounted(() => {
  getList();
});
</script>
