<template>
  <Panel :title="'服务项目'">
    <div class="content">
      <div class="list">
          <ul>
            <li class="item" v-for="(item, index) in list" :key="index">
              <span class="index">{{ index + 1 }}</span>
              <span class="name"> <el-popover
                  width="485"
                  @show="show(item)"
                  @hide="hide"
              >
                <template #reference>
                  {{ item.itemName }}
                </template>
                <div class="detail">
                  <div style="display: flex;justify-content: space-between">
                    <div style="font-size: 18px;font-weight: 500;color: #000">{{ itemInfo.name }}[{{ chrgitm_lv[itemInfo.chrgitmLv as keyof typeof chrgitm_lv || '-'] || '-' }}]</div>
                    <div>￥{{ item.unitPrice }}/{{item.unit }}</div>
                  </div>
                  <div style="display: flex;justify-content: space-between">
                    <div>限制条件:{{ itemInfo.lmtUsedFlag == 0 ? '否' : itemInfo.lmtUsedFlag == 1 ? '是' : '-'}}</div>
                    <div> 医保码:{{item.itemSocialCode||'-'}}</div>
                  </div>
                </div>
              </el-popover>
              </span>
              <span class="unit">{{item.selectedNum}}{{ item.selectedUnit }}</span>
              <span class="price">￥{{ item.selectedPrice }}元</span>
            </li>
          </ul>
      </div>
      <div class="search">
        <span style="margin-left: 24px">合计</span>
        <span style="margin-right: 24px">￥{{ list.reduce((acc, cur) => acc + cur.selectedNum*cur.selectedPrice, 0) }}元</span>
      </div>
    </div>
  </Panel>
</template>
<script setup lang="ts">
import Panel from "@/components/common/Panel.vue";
import {ref} from "vue";
import {post} from "@/utils/request.ts";
import chrgitm_lv from "@/assets/config/directory/chrgitmLv.json"

const list = defineModel<any[]>({default: () => []});
const itemInfo = ref<any>({});
const show = (item:any) => {
  post('social/directory/getItemByCode',{code:item.itemSocialCode}).then((res:any)=>{
    itemInfo.value = res
  })
}
const hide = () => {
  itemInfo.value = {}
}
</script>

<style scoped lang="scss">
.content {
  display: flex;
  flex-direction: column;

  .list {
    flex: 1;
    min-height: 0;

    .item {
      height: 30px;
      border-top: 1px solid #EAEAEC;
      display: flex;
      align-items: center;
      justify-content: space-between;
      .index{
        height: 100%;
        width: 50px;
        text-align: center;
        border-right: 1px solid #EAEAEC;
        line-height: 30px;
      }
      .name{
        flex: 1;
        margin-left: 10px;
        border-right: 1px solid #EAEAEC;
        height: 100%;
        line-height: 30px;
      }
      .code{
        flex: 1;
        margin-left: 10px;
        border-right: 1px solid #EAEAEC;
        height: 100%;
        line-height: 30px;
      }
      .unit{
        width: 60px;
        margin-left: 10px;
        border-right: 1px solid #EAEAEC;
        height: 100%;
        line-height: 30px;
        text-align: center;
      }
      .price{
        height: 100%;
        width: 200px;
        line-height: 30px;
        border-right: 1px solid #EAEAEC;
        text-align: center;
      }
    }
  }

  .search {
    height: 64px;
    border-top: 1px solid #EAEAEC;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
}
</style>