<template>
  <div busNo="app-container">
    <el-form
      ref="queryRef"
      style="margin-top:20px;margin-left:20px;"
      :model="queryParams"
      :inline="true"
      label-width="90px"
    >
      <el-form-item label="收费时间：">
        <el-date-picker
          v-model="occurrenceTime"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width: 300px"
          value-format="YYYY-MM-DD"
        />
      </el-form-item>
      <el-form-item
        label="科室："
        prop="departmentId"
      >
        <el-select
          v-model="queryParams.departmentId"
          placeholder=""
          clearable
          style="width: 150px"
        >
          <el-option
            v-for="supplyStatus in getDepartmentOptions"
            :key="supplyStatus.id"
            :label="supplyStatus.name"
            :value="supplyStatus.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item
        label="医生："
        prop="doctorId"
      >
        <el-select
          v-model="queryParams.doctorId"
          placeholder=""
          clearable
          style="width: 150px"
        >
          <el-option
            v-for="supplyStatus in issuerOptions"
            :key="supplyStatus.id"
            :label="supplyStatus.name"
            :value="supplyStatus.id"
          />
        </el-select>
      </el-form-item>
    </el-form>

    <el-row
      :gutter="10"
      bus-no="mb8"
      style="margin-left:20px;margin-right:0px;margin-bottom:5px"
    >
      <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-row>

    <el-table
      v-loading="loading"
      style="padding:0 20px;width:100%"
      :data="purchaseinventoryList"
      :span-method="arraySpanMethod"
      @selection-change="handleSelectionChange"
    >
      <!-- :summary-method="getSummaries"
      show-summary 每页单独合计-->
      <el-table-column
        type="selection"
        align="center"
      />
      <el-table-column
        key="busNo"
        label="门诊号"
        align="center"
        prop="busNo"

        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="name"
        label="姓名"
        align="center"
        prop="name"
    
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="departmentName"
        label="科室"
        align="center"
        prop="departmentName"
  
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="clinicalName"
        label="项目"
        align="center"
        prop="clinicalName"

        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="doctorName"
        label="挂号医生"
        align="center"
        prop="doctorName"
      
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="payeeName"
        label="收费人"
        align="center"
        prop="payeeName"
       
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="number"
        label="数量"
        align="center"
        prop="number"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="price"
        label="单价"
        align="center"
        prop="price"
       
        :show-overflow-tooltip="true"
      />
      <el-table-column
        key="totalPrice"
        label="金额"
        align="center"
        prop="totalPrice"
     
        :show-overflow-tooltip="true"
      /> 
     
      <el-table-column
        key="chargeTime"
        label="时间"
        align="center"
        prop="chargeTime"
       
        :show-overflow-tooltip="true"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.chargeTime) }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      :total="total"
      @pagination="getList()"
    />
    <el-row
      :gutter="10"
      bus-no="mb8"
      style="
        margin-top: 10px;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        margin-left:0px;margin-right:0px;padding:0 20px;
      "
    >
      <el-col :span="3">
        <span>制单人：{{ userStore.name }}</span>
      </el-col>
    </el-row>
  </div>
</template>

<script setup name="registrationFeeDetails">
import {getDepartmentList, getReportRegisterInit, getReportRegisterPage} from "./statisticalManagent";
import useUserStore from "@/store/modules/user";

const userStore = useUserStore();

const { proxy } = getCurrentInstance();
const totalAmount = ref(0);
// const {
//   item_category_code,
//   hosp_lv
// } = proxy.useDict(
//   "item_category_code",
//   "hosp_lv"
// );
const purchaseinventoryListAll = ref([])
const xiaojiTotal = ref([])

const currentCategory =  ref(null);
const rowSpan = ref(1)
const issuerOptions = ref([])
const payeeOptions = ref([])
const inventoryOptions = ref([])
const clinicalTypeOptions = ref([]);
const purchaseinventoryList = ref([]);

const loading = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const occurrenceTime = ref([]);
const payeeNameOptions = ref([]); 
const getDepartmentOptions = ref([])

const data = reactive({
  form: {},
  queryParams: {
    pageNo: 1,
    pageSize: 10,
    departmentId: undefined, 
    doctorId:undefined, 
    registerTimeSTime:undefined,
    registerTimeETime:undefined,
  },
  rules: {},
});

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


function getPharmacyCabinetLists() {
  getReportRegisterInit().then((response)=>{
    issuerOptions.value = response.data.doctorOptions
  })
  getDepartmentList().then((response) => {
    getDepartmentOptions.value = response.data // 科室
  })
}
/** 查询调拨管理项目列表 */
function getList() { 
  loading.value = true;
  console.log(queryParams.value,"queryParams.value")
  getReportRegisterPage(queryParams.value).then((res) => {
    purchaseinventoryList.value = res.data.records||[]
    purchaseinventoryList.value.map(k=>{
      k.number = k.number?(k.number+k.quantityUnit_dictText):0
      k.price = k.price?k.price.toFixed(2):"0.00"
      // k.totalPrice = k.totalPrice?("¥"+k.totalPrice.toFixed(2)):"¥0.00"
      k.totalPrice = k.totalPrice?k.totalPrice.toFixed(2):"0.00"
    })
    total.value = res.data.total;
    loading.value = false
  });
}
  
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.chargeTimeSTime =
    occurrenceTime.value && occurrenceTime.value.length == 2
      ? occurrenceTime.value[0] + " 00:00:00"
      : "";
  queryParams.value.chargeTimeETime =
    occurrenceTime.value && occurrenceTime.value.length == 2
      ? occurrenceTime.value[1] + " 23:59:59"
      : "";
  queryParams.value.pageNo = 1;
  getList();
}

/** 清空条件按钮操作 */
function handleClear() {
  // 清空查询条件
  occurrenceTime.value = ""
  queryParams.value.chargeTimeSTime = ""
  queryParams.value.chargeTimeETime = ""
  proxy.resetForm("queryRef");
  getList();
}

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


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

.pagination-container{
    margin-right: 20px;
}
</style>