<script setup lang="ts">
import {onMounted, ref} from 'vue'
import {post} from "@/utils/request";

const emit = defineEmits(['selected', 'close'])
const handleSelectionChange = (val: any) => {
  list.value = val
}
const datalist = ref<any>([])
const initData = () => {
  post('item/list', {page: 1, size: 20}).then((res: any) => {
    datalist.value = res.list
  })
}
const list = ref<any>([])
const isOk = () => {
  emit('selected', list.value)
  close()
}
const close = () => {
  list.value = []
  datalist.value = []
  emit('close')
}
onMounted(() => {
  initData()
})
</script>

<template>
  <el-table :data="datalist" style="width: 100%" @selection-change="handleSelectionChange">
    <el-table-column prop="itemSocialCode" label="医保码编码" width="200"
                     :show-overflow-tooltip="true" type="selection"></el-table-column>
    <el-table-column prop="itemName" label="项目名称"></el-table-column>
    <el-table-column prop="unit" label="单位"></el-table-column>
    <el-table-column prop="purchaseUnitPrice" label="原价"></el-table-column>
    <el-table-column prop="unitPrice" label="售价"></el-table-column>
  </el-table>
  <div>
    <el-pagination
        background
        layout="prev, pager, next"
        :total="datalist.length"
        :page-size="20"
        @current-change="initData"
    >
    </el-pagination>
    <div class="page_btn_list">
      <el-button type="primary" @click="isOk">确定</el-button>
      <el-button type="primary" @click="close">取消</el-button>
    </div>
  </div>
</template>

<style scoped lang="scss">

</style>