<template>
  <div class="app-container">
    <el-form
      ref="queryRef"
      :model="queryParams"
      :inline="true"
      label-width="100px"
    >
      <el-form-item
        label="药品名称："
        prop="searchKey"
      >
        <el-input
          v-model="queryParams.searchKey"
          placeholder="编码/序号/药品名称"
          clearable
          style="width: 200px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item
        label="供应商："
        prop="supplierId"
      >
        <el-select
          v-model="queryParams.supplierId"
          placeholder=""
          clearable
          style="width: 150px"
        >
          <el-option
            v-for="supplierList in supplierListOptions"
            :key="supplierList.value"
            :label="supplierList.label"
            :value="supplierList.value"
          />
        </el-select>
      </el-form-item>
    </el-form>

    <el-row
      :gutter="10"
      class="mb8"
    >
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Search"
          @click="handleQuery"
        >
          查询
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <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="medicationSaleList"
      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"
        width="100"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="fixmedinsCode"
        label="定点编码"
        align="center"
        prop="fixmedinsCode"
        width="120"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="fixmedinsName"
        label="定点名称"
        align="center"
        prop="fixmedinsName"
        width="120"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="ybOrgNo"
        label="医疗目录编码"
        align="center"
        prop="ybOrgNo"
        width="150"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="ypName"
        label="药品通用名称"
        align="center"
        prop="ypName"
        width="150"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="ybNo"
        label="药品69码"
        align="center"
        prop="ybNo"
        width="150"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="categoryCode"
        label="药品类型"
        align="center"
        prop="categoryCode"
        width="120"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="doseFromCode"
        label="药品剂型"
        align="center"
        prop="doseFromCode"
        width="120"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="totalVolume"
        label="药品规格"
        align="center"
        prop="totalVolume"
        width="150"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="minUnitSum"
        label="最小包装数量"
        align="center"
        prop="minUnitSum"
        width="150"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="minUnitCode"
        label="最小包装单位"
        align="center"
        prop="minUnitCode"
        width="150"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="supplyName"
        label="生产企业"
        align="center"
        prop="supplyName"
        width="150"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="lotNumber"
        label="批准文号"
        align="center"
        prop="lotNumber"
        width="150"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="annualSales"
        label="年度销售量（盒/瓶/支）"
        align="center"
        prop="annualSales"
        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="medicationSaleDetails">
import {getMedicationSaleDetails,} from './statisticalManagent';

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

const medicationSaleList = 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,
    busNo: undefined,
    name: undefined,
    medicationDefId: undefined,
    department: undefined,
    purposeLocationId: undefined,
    categoryType: undefined,
    supplierId: undefined,
    occurrenceTimeSTime: undefined,
    occurrenceTimeETime: undefined,
  },
  rules: {},
});

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

function getPharmacyCabinetLists() {
  getPharmacyCabinetList().then((response) => {
    locationIdList.value = response.data;
  });
  getInboundInit().then((response) => {
    supplierListOptions.value = response.data.supplierListOptions;
  });
}
/** 导出按钮操作 */
function handleExport() {
  proxy.$download.downloadGet(
    'report-manage/inbound/excel-out',
    {
      ...queryParams.value,
    },
    `dict_${new Date().getTime()}.xlsx`
  );
}
/** 查询调拨管理项目列表 */
function getList() {
  loading.value = true;
  getMedicationSaleDetails(queryParams.value).then((res) => {
    loading.value = false;
    medicationSaleList.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>
