<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <el-card shadow="hover">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="120px">
            <el-form-item label="管理机构" prop="manageCom">
              <el-select v-model="queryParams.manageCom" clearable placeholder="请输入保单管理机构">
                <template #header>
                  <el-input v-model="likeName" placeholder="可根据机构编码或名称模糊查询" @input="filterByManageCom"></el-input>
                </template>
                <el-option v-for="dict in filteredManagecom" :key="dict.value" :label="dict.value + '-' + dict.label" :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="收入支出户类型" prop="bankType">
              <el-select v-model="queryParams.bankType" placeholder="请输入收入支出户类型">
                <el-option v-for="dict in bls_bank_type" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
            <el-row>
              <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-row>
          </el-form>
        </el-card>
      </div>
    </transition>
    <el-card shadow="never">
      <el-table v-loading="loading" :data="collectionBankList">
        <el-table-column label="SAP机构" align="center" prop="sapInstitution" />
        <el-table-column label="SAP开户行" align="center" prop="sapBankCode" />
        <el-table-column label="账户户名" align="center" prop="bankAccountName" width="300px" />
        <el-table-column label="开户行" align="center" prop="bankCode" width="280px">
          <template #default="scope">
            <dict-tag :options="sys_bank_code" :value="scope.row.bankCode" />
          </template>
        </el-table-column>
        <el-table-column label="银行账号" align="center" prop="bankAccount" width="250px" />

        <el-table-column label="归属机构" align="center" prop="manageCom" width="300px">
        </el-table-column>
        <el-table-column label="是否委托专户" align="center" prop="isEntrust" width="200px" >
          <template #default="scope">
            <dict-tag :options="sys_yes_no" :value="scope.row.isEntrust" />
          </template>
        </el-table-column>

        <el-table-column label="银行类型" align="center" prop="bankType" width="100px">
          <template #default="scope">
            <dict-tag :options="bls_bank_type" :value="scope.row.bankType" />
          </template>
        </el-table-column>
        <el-table-column label="账户标记" align="center" prop="bankFlag" width="100px"> </el-table-column>
      </el-table>
      <pagination v-show="total > 0" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" :total="total" @pagination="getList" />
    </el-card>
  </div>
</template>
<script setup lang="ts">
import {getBussnessData, getCollectionBank} from "@/api/bfs/busnessQury/costBalance";

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { sys_managecom, bls_bank_type, sys_bank_code, sys_yes_no } = toRefs<any>(proxy?.useDict('sys_managecom', 'bls_bank_type', 'sys_bank_code', 'sys_yes_no'));

const total = ref(0);
const showSearch = ref(true);
const loading = ref(false);
const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    manageCom: undefined,
    bankType: undefined
  },
  rules: {}
});
const { queryParams, rules } = toRefs(data);
const likeName = ref('');
const filteredManagecom = ref([]);
const queryFormRef = ref<ElFormInstance>();
const collectionBankList = ref([]);

/** 模糊查询 */
const filterByManageCom = () => {
  if (likeName.value) {
    filteredManagecom.value = sys_managecom.value.filter((item) => {
      return item.label.includes(likeName.value) || item.value.includes(likeName.value);
    });
  } else {
    filteredManagecom.value = sys_managecom.value;
  }
};

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

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  queryParams.value.pageNum = 1;
};

const getList = async () => {
  loading.value = true;
  const res = await getCollectionBank(queryParams.value);
  collectionBankList.value = res.rows;
  total.value = res.total;
  loading.value = false;
  filteredManagecom.value = sys_managecom.value;
};

onMounted(() => {
  getList();
});
</script>

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