<template>
    <xc-table :local-data="numberToArray"
              :final-height="getWindowSize.h / 1.2">
        <el-table-column prop="name" label="质控名称"/>
        <el-table-column prop="total" label="总数"/>
        <el-table-column label="操作">
            <template #default="{row}">
                <el-button @click="detailClick(row)" text plain type="primary">详情</el-button>
            </template>
        </el-table-column>
    </xc-table>
</template>

<script setup name='RuleTotal'>
import {
    numberToArray, ruleReturnData, siftData, tabsModel,
} from "@/views/hospitalization/zhu-yuan-yi-sheng/electronic-medical-record/emr_control_rule/rule-store";
import {getWindowSize} from "@/utils/window-size";
import XcTable from "@/components/xiao-chan/xc-table/XcTable.vue";
import {BizException, ExceptionEnum} from "@/utils/BizException";

const detailClick = ({name, total}) => {
    if (total === 0) {
        BizException(ExceptionEnum.MESSAGE_ERROR, "没有指定的病历。")
    }
    let data = [];
    for (let i = 0, len = ruleReturnData.value.details.length; i < len; i++) {
        let item = JSON.parse(JSON.stringify(ruleReturnData.value.details[i]))
        if (item.mapMessage && item.mapMessage[name]) {
            for (let key in item.mapMessage) {
                if (key !== name) {
                    delete item.mapMessage[key]
                }
            }
            item.message = JSON.stringify(item.mapMessage[name])
            data.push(item)
        }
    }
    siftData.value[name] = data;
    tabsModel.value = name;
}

</script>

<style scoped lang="scss">


</style>
