<template>
  <div class="app-container">
    <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="productUsageDetailsList"
      height="calc(100vh - 300px)"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        type="selection"
        width="50"
        align="center"
      />
      <el-table-column
        key="busNo"
        label="编码"
        align="center"
        prop="busNo"
        :show-overflow-tooltip="true"
        width="110"
      />
      <el-table-column
        key="medName"
        label="药品通用名"
        align="center"
        prop="medName"
        width="200"
        :show-overflow-tooltip="true"
      />
      <!-- itemTable -->
      <el-table-column
        key="productName"
        label="产品名称"
        align="center"
        prop="productName"
        width="140"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="doseFormCode_dictText"
        label="剂型"
        align="center"
        prop="doseFormCode_dictText"
        width="140"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="totalVolume"
        label="规格"
        align="center"
        prop="totalVolume"
        width="120"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="packageUnit"
        label="包装"
        align="center"
        prop="packageUnit"
        width="140px"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="unitCode_dictText"
        label="计价单位"
        align="center"
        prop="unitCode_dictText"
        width="140"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="manufacturerText"
        label="生产企业"
        align="center"
        prop="manufacturerText"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="price"
        label="价格（每盒瓶/元）"
        align="center"
        prop="price"
        width="140"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="isUsed"
        label="是否医保患者使用"
        align="center"
        prop="isUsed"
        width="140"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="insuplcName"
        label="患者参保地"
        align="center"
        prop="insuplcName"
        width="140"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="ybType"
        label="参保类型"
        align="center"
        prop="ybType"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="quantity"
        label="使用数量（片袋支）"
        align="center"
        prop="quantity"
        width="160"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="totalPrice"
        label="使用金额（片袋支）"
        align="center"
        prop="totalPrice"
        width="160"
        :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="productUsageDetails">
import {getReportProductUsageDetails,} from './statisticalManagent';

const { proxy } = getCurrentInstance();
const route = useRoute();

const productUsageDetailsList = ref([]);
const loading = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const approvalTime = ref([]);
const supplierListOptions = ref([]);
const locationIdList = ref([]);

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

const { queryParams, form, rules } = toRefs(data);

/** 查询产品使用情况项目列表 */
function getList() {
  loading.value = true;
  getReportProductUsageDetails(queryParams.value).then((res) => {
    loading.value = false;
    productUsageDetailsList.value = res.data.records;
    total.value = res.data.total;
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.occurrenceTimeSTime =
    approvalTime.value && approvalTime.value.length == 2 ? approvalTime.value[0] + ' 00:00:00' : '';
  queryParams.value.occurrenceTimeETime =
    approvalTime.value && approvalTime.value.length == 2 ? approvalTime.value[1] + ' 23:59:59' : '';
  queryParams.value.pageNo = 1;
  getList();
}

/** 清空条件按钮操作 */
function handleClear() {
  // 清空查询条件
  queryParams.value.occurrenceTimeSTime = '';
  queryParams.value.occurrenceTimeETime = '';
  approvalTime.value = '';
  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>
