<template>
  <div class="app-container">
    <el-form
      ref="queryRef"
      :model="queryParams"
      :inline="true"
      label-width="150px"
    >
      <el-form-item
        label="项目名称："
        prop="searchKey"
      >
        <el-input
          v-model="queryParams.name"
          placeholder="项目名称"
          clearable
          style="width: 200px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item
        label="医疗机构名称："
        prop="searchKey"
      >
        <el-input
          v-model="queryParams.medinsName"
          placeholder="医疗机构名称"
          clearable
          style="width: 200px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
    </el-form>

    <el-row
      :gutter="10"
      class="mb8"
    >
      <el-col :span="1.5">
        <!-- v-hasPermi="['system:user:import']" -->
        <el-button
          type="primary"
          plain
          icon="Search"
          @click="handleQuery"
        >
          查询
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <!-- v-hasPermi="['system:user:export']" -->
        <el-button
          type="warning"
          plain
          icon="CircleClose"
          @click="handleClear"
        >
          重置
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
        >
          导出
        </el-button>
      </el-col>
    </el-row>

    <el-table
      v-loading="loading"
      :data="collectionRateList"
      height="calc(100vh - 300px)"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        type="selection"
        width="50"
        align="center"
      />
      <el-table-column
        key="name"
        label="项目名称"
        align="center"
        prop="name"
        width="200"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="medinsName"
        label="医疗机构名称"
        align="center"
        prop="medinsName"
        width="200"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="drugGenname"
        label="药品通用名"
        align="center"
        prop="drugGenname"
        width="200"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="collectionRate"
        label="30天回款率（%）"
        align="center"
        prop="collectionRate"
        width="200"
        :show-overflow-tooltip="true"
      />
    </el-table>
    <pagination
      v-show="total > 0"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      :total="total"
      @pagination="getList"
    />
  </div>
</template>

<script setup name="thirtyDayCollectionRate">
import {getThirtyDayCollectionRate} from './statisticalManagent';

const { proxy } = getCurrentInstance();
const route = useRoute();
const collectionRateList = ref([]);
const loading = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);

const data = reactive({
  form: {},
  queryParams: {
    pageNo: 1,
    pageSize: 10,
    searchKey: undefined,
    name: undefined,
    medinsName: undefined
  },
  rules: {},
});

const { queryParams} = toRefs(data);

/** 导出按钮操作 */
function handleExport() {
  proxy.$download.downloadGet(
    'report-manage/inbound/excel-out',
    {
      ...queryParams.value,
    },
    `dict_${new Date().getTime()}.xlsx`
  );
}
/** 查询调拨管理项目列表 */
function getList() {
  loading.value = true;
  getThirtyDayCollectionRate(queryParams.value).then((res) => {
    loading.value = false;
    collectionRateList.value = res.data.records;
    total.value = res.data.total;
  });
}

// 监听路由变化
watch(
  () => route.query,
  (newQuery) => {
    // 如果路由中包含指定参数，则使用这些参数进行查询
    if (
      newQuery.name ||
      newQuery.medinsName
    ) {
      // 设置查询参数
      if (newQuery.name) {
        queryParams.value.name = newQuery.name;
      }
       // 设置查询参数
      if (newQuery.medinsName) {
        queryParams.value.medinsName = newQuery.medinsName;
      }
      // 执行查询
      getList();
    }
  },
  { immediate: true }
);

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

/** 清空条件按钮操作 */
function handleClear() {
  // 清空查询条件
  queryParams.value.name = '';
  queryParams.value.medinsName = '';
  proxy.resetForm('queryRef');
  getList();
}

/** 选择条数  */
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

getList();
</script>
<style scoped>
.custom-tree-node {
  display: flex;
  align-items: center;
}

.title {
  font-weight: bold;
  font-size: large;
  margin-bottom: 10px;
}
</style>
