<!--
 * @Author: 曹捷
 * @Date: 2022-01-11 10:02:53
 * @LastEditors: 曹捷
 * @LastEditTime: 2022-01-19 15:38:03
 * @Description: 过滤已选择
-->
<template>
  <slot></slot>
</template>

<script>
import { provide, computed } from 'vue'
export default {
  props: {
    selectedList: {
      type: Array
    },
    valueName: {
      type: String
    }
  },
  setup ({ selectedList, valueName }) {
    let _computed = {
      selectKeys: computed(() => {
        if (valueName) {
          if (selectedList && selectedList.length > 0) {
            return selectedList.reduce((sumInfo, item) => {
              if (item[valueName]) {
                sumInfo.push(item[valueName])
              }
              return sumInfo
            }, [])
          } else {
            return []
          }
        } else {
          return selectedList
        }
      })
    }
    provide('selectKeys', _computed.selectKeys)
    return {
      ..._computed
    }
  }
}
</script>

<style>
</style>