<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :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>

    <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="medicationInboundList"
      @selection-change="handleSelectionChange"
      height="calc(100vh - 300px)"
    >
      <el-table-column type="selection" width="50" align="center" />
      <el-table-column
        label="医疗机构代码"
        align="center"
        key="medinsCode"
        prop="medinsCode"
        width="200"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="组织机构名称"
        align="center"
        key="orgCode"
        prop="orgCode"
        width="200"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="国家药品编码(YPID)"
        align="center"
        key="ypNo"
        prop="ypNo"
        width="200"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="院内药品唯一码"
        align="center"
        key="busNo"
        prop="busNo"
        width="200"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="省级药品集中采购平台药品编码"
        align="center"
        key="itemTableText"
        prop="itemTableText"
        width="250"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="产品名称"
        align="center"
        key="productNmae"
        prop="productNmae"
        width="200"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="入库总金额(元)"
        align="center"
        key="totalPrice"
        prop="totalPrice"
        width="200"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="入库数量(最小销售包装单位)"
        align="center"
        key="minUnitSale"
        prop="minUnitSale"
        width="250"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="入库数量(最小制剂单位)"
        align="center"
        key="minDoseQuantity"
        prop="minDoseQuantity"
        width="250"
        :show-overflow-tooltip="true"
      />
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script setup name="medicationInboundDetails">
import {getMedicationInboundDetails,} from './statisticalManagent';

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

const medicationInboundList = 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;
  getMedicationInboundDetails(queryParams.value).then((res) => {
    loading.value = false;
    medicationInboundList.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>
