<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">{{ item.itemName }}</span>
            <span class="price">￥{{ item.unitPrice }}元</span>
            <span class="code">{{ item.itemSocialCode }}</span>
            <span class="unit">
              <el-input-number v-model="item.selectedNum" min="1"></el-input-number>
                <span style="line-height: 30px;margin-left: 10px">{{ item.unit }}</span>
            </span>
            <span class="delete">
                <el-button @click="deleteItem(item.id)">
                  <el-icon><CircleClose/></el-icon>
                </el-button>
              </span>
          </li>
        </ul>
      </div>
      <div class="search">
        <div class="search-input">
          <SearchInput
              :request-api="serviceSearchApi"
              :show-config="serviceShowConfig"
              @selectedCallBack="serviceSelect"
              :placeholder="'请输入项目名称'"
          >
          </SearchInput>
        </div>
        <span style="margin-right: 24px">￥{{ list.reduce((acc, cur) => acc + cur.unitPrice*cur.selectedNum, 0) }}元</span></div>
    </div>
  </Panel>
</template>
<script setup lang="ts">
import Panel from "@/components/common/Panel.vue";
import {CircleClose} from '@element-plus/icons-vue'
import SearchInput from "@/components/SearchInput.vue";

const serviceSearchApi = "item/search";
const serviceShowConfig = [
  {
    label: "服务名称",
    prop: "itemName",
  },
  {
    label: "服务医保码",
    prop: "itemSocialCode",
  },
  {
    label: "售价",
    prop: "unitPrice",
  },
]
const serviceSelect = (row: any) => {
  row.selectedNum = 1
  list.value.push(row)
}

const list = defineModel<any[]>({default: () => []});
const deleteItem = (id: any) => {
  list.value = list.value.filter((item) => item.id !== id);
};
</script>

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

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

    .item {
      height: 64px;
      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: 64px;
      }

      .name {
        flex: 1;
        margin-left: 10px;
        border-right: 1px solid #EAEAEC;
        height: 100%;
        line-height: 64px;
      }

      .code {
        flex: 1;
        margin-left: 10px;
        border-right: 1px solid #EAEAEC;
        height: 100%;
        line-height: 64px;
      }

      .price {
        height: 100%;
        width: 200px;
        line-height: 64px;
        border-right: 1px solid #EAEAEC;
        text-align: center;
      }

      .delete {
        height: 100%;
        width: 50px;
        line-height: 64px;
        text-align: center;
      }
    }
  }

  .search {
    height: 64px;
    border-top: 1px solid #EAEAEC;
    display: flex;
    align-items: center;

    .search-input {
      height: 100%;
      flex: 1;
    }
  }
}
</style>