<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="Back"
          @click="handleBack"
          
          >返回列表</el-button
        >
      </el-col>
      <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">
        <el-button
          type="warning"
          plain
          icon="CircleClose"
          @click="handleClear"
          
          >重置</el-button
        >
      </el-col> -->
    </el-row>

    <el-table
      v-loading="loading"
      :data="purchaseinventoryList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="50" align="center" />
      <!-- <el-table-column label="组" align="center" width="60">
        <template #default="scope">
          <div v-if="groupMarkers[scope.$index] === '┏'">┏</div>
          <div v-if="groupMarkers[scope.$index] === '┗'">┗</div>
          <div v-if="groupMarkers[scope.$index] === '┃'">┃</div>
        </template>
      </el-table-column> -->
      <el-table-column
        label="处方号"
        align="center"
        key="prescriptionNo"
        prop="prescriptionNo"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="请求人"
        align="center"
        key="requesterId_dictText"
        prop="requesterId_dictText"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="请求时间"
        align="center"
        key="requestTime"
        prop="requestTime"
        :show-overflow-tooltip="true"
        width="160px"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.requestTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="医嘱名称"
        align="center"
        key="adviceName"
        prop="adviceName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="规格"
        align="center"
        key="volume"
        prop="volume"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="产品批号"
        align="center"
        key="lotNumber"
        prop="lotNumber"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="请求数量" align="center" prop="">
        <template #default="scope">
          <span>
            {{ scope.row.quantity ? scope.row.quantity + ' ' + scope.row.unitCode_dictText : '' }}
          </span>
        </template>
      </el-table-column>
      <!-- <el-table-column
        label="请求单位"
        align="center"
        key="unitCode_dictText"
        prop="unitCode_dictText"
        :show-overflow-tooltip="true"
      /> -->
      <el-table-column label="请求状态" align="center" prop="" width="80">
        <template #default="scope">
          <el-tag v-if="scope.row.statusEnum == 2" type="success">已签发</el-tag>
          <el-tag v-else-if="!scope.row.requestId && scope.row.statusEnum == 1" type="warning"
            >待保存</el-tag
          >
          <el-tag v-else-if="scope.row.statusEnum == 1" type="primary">待签发</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="用法"
        align="center"
        key="methodCode_dictText"
        prop="methodCode_dictText"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="使用频次"
        align="center"
        key="rateCode_dictText"
        prop="rateCode_dictText"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="单次剂量" align="center" prop="">
        <template #default="scope">
          <span>
            {{ scope.row.dose ? scope.row.dose + ' ' + scope.row.doseUnitCode_dictText : '' }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="总价" align="center" prop="" header-align="center" width="99">
        <template #default="scope">
          <span style="text-align: center">
            {{ scope.row.totalPrice ? Number(scope.row.totalPrice).toFixed(2) + ' 元' : '-' }}
          </span>
        </template>
      </el-table-column>
      <el-table-column
        label="收费状态"
        align="center"
        key="chargeStatus_enumText"
        prop="chargeStatus_enumText"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="收费状态" align="center" prop="" width="80">
        <template #default="scope">
          <el-tag v-if="scope.row.chargeStatus == 2" type="success">{{scope.row.chargeStatus_enumText}}</el-tag>
          <el-tag v-else-if="!scope.row.requestId && scope.row.chargeStatus == 1" type="warning"
            >{{scope.row.chargeStatus_enumText}}</el-tag>
          <el-tag v-else-if="scope.row.statusEnum == 1" type="primary">{{scope.row.chargeStatus_enumText}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="发药药房/耗材房/执行科室" align="center" prop="" width="179">
        <template #default="scope">
          <span v-if="!scope.row.isEdit">
            {{ scope.row.positionName }}
          </span>
        </template>
      </el-table-column>
      <el-table-column
        label="用药天数"
        align="center"
        key="dispensePerDuration"
        prop="dispensePerDuration"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="诊断定义名称"
        align="center"
        key="conditionDefinitionName"
        prop="conditionDefinitionName"
        :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="historicalPrescriptionDetail">
import {
   getPrescriptionDetail
} from "./api";

const { proxy } = getCurrentInstance();

const props = defineProps({

  typeDetail: {
    type: String,
    required: false,
  },
  prescriptionNo:{
    type: String,
    required: false,
  }
});

const prescriptionNo = ref('')
const typeDetail = ref('2')
const purchaseinventoryList = ref([]);
const loading = ref(false);
const occurrenceTime = ref([])
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const supplyTypeOptions = ref(undefined); 
const supplyStatusOptions = ref(undefined);
const groupMarkers = ref([]);
const data = reactive({
  form: {},
  queryParams: {
    pageNo: 1,
    pageSize: 10,
  },
  rules: {},
});
watch(
  () => props,
  (newValue) => {
    typeDetail.value = newValue.typeDetail;
    getList();
  },
  { immdiate: true, deep: true }
);
const emits = defineEmits(['handleBack']);
const { queryParams, form, rules } = toRefs(data);

function handleBack(){
  typeDetail.value = '1'
  emits("handleBack", typeDetail.value);
}


/** 查询调拨管理项目列表 */
function getList() {
  loading.value = true;
//   props.prescriptionNo = ""
   getPrescriptionDetail(props.prescriptionNo).then((res) => {
    loading.value = false;
    if(res.data&&res.data.length>0){
        purchaseinventoryList.value = res.data
    }
  });
}

/** 搜索按钮操作 */
function handleQuery() {
    queryParams.value.pageNo = 1;
    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;
}


</style>