<!-- 
/* @name    显示已选择数据组件
 * @authors pen (you@example.org)
 * @date    2022-06-08 
 * @version 1.0.0
 */
 -->
<template>
  <el-popover
    placement="bottom-end"
    width="288"
    trigger="hover"
    v-model="isVisibled"
  >
    <ul>
      <li class="flex li_box li_title">
        <span class="code">编号</span
        ><span class="text">{{ selectDataShowText }}</span
        ><el-link
          @click="allDelete"
          class="delete_all"
          :underline="false"
          type="danger"
          >全部清除</el-link
        >
      </li>
      <li class="flex li_box" v-for="(item, index) in selectData" :key="index">
        <span class="code">{{ index + 1 }}</span>
        <span class="text">{{ item[selectDataField] }}</span>
        <i
          @click="itemDelete(item)"
          class="el-icon-close close_item show_hand common_close"
        ></i>
      </li>
    </ul>
    <el-badge slot="reference" :value="selectData.length" class="item">
      <el-button size="mini" class="choiced_btn"
        >已选中<i
          :class="{
            'el-icon-arrow-down el-icon--right': !isVisibled,
            'el-icon-arrow-up el-icon--right': isVisibled
          }"
        ></i>
      </el-button>
    </el-badge>
  </el-popover>
</template>
<script>
export default {
  name: 'show-choice-data-info',
  props: {
    isShowPop: {
      type: Boolean
    },
    selectData: {
      type: Array,
      default: () => []
    },
    selectDataShowText: String,
    selectDataField: String
  },
  created() {
    this.isVisibled = this.isShowPop
  },
  data() {
    return {
      isVisibled: false
    }
  },
  methods: {
    allDelete() {
      this.$emit('all-delete')
    },
    itemDelete(item) {
      this.$emit('item-delete', item)
    }
  }
}
</script>
<style lang="less" scoped>
ul {
  // display: flex;
  max-height: 366px;
  overflow-y: auto;
  .flex {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .li_title {
    background: #f5f5f5;
  }

  .li_box {
    padding: 10px 0;
    border-bottom: 1px solid #eee;
    // flex:1;
    .code {
      width: 50px;
      text-align: center;
    }
    .text {
      flex: 1;
      margin-left: 20px;
      white-space: nowrap; /*文本强制一行显示*/
      overflow: hidden; /*文本溢出隐藏*/
      text-overflow: ellipsis; /*溢出的文本显示省略号*/
    }
    .delete_all {
      margin-right: 10px;
      width: 56px;
      text-align: right;
      color: #fa5555;
    }
    .close_item {
      margin-right: 10px;
      font-size: 12px;
    }
  }
}
// 关闭按钮样式
.common_close {
  color: #909399;
}
.common_close:hover {
  color: #fff;
  border-radius: 50%;
  padding: 2px;
  background: rgba(0, 0, 0, 0.25);
}
</style>
