option-group.vue 1.78 KB
Newer Older
wangcong committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
<style lang="less" scoped>
.option-group {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-size: .75rem;

  .option-group-data {
    width: 100%;
    height: 100%;
    overflow: auto;
  }

  .option {
    width: 100%;
    float: left;
    min-height: 30px;
  }

  .option-title {
    width: calc(~'100% - 24px');
    float: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .option-title-span {
    width: calc(~'100% - 5px');
    float: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .option-checkbox {
    float: left;
    width: 20px;
    margin-right: 4px;
  }
}
</style>
<template>
  <div class="option-group">
    <div
      v-if="hasData"
      class="option-group-data"
    >
      <div
        class="option"
        v-for="(item, index) in data"
        :key="item.code"
      >
        <div class="option-checkbox">
          <Checkbox
            :value="item._checked"
            @on-change="selectCancel(item)"
          />
        </div>
        <div class="option-title">
          <Tooltip :content="showTitle(item, index)">
            <span class="option-title-span">{{showTitle(item, index)}}</span>
          </Tooltip>
        </div>
        <div style="clear:both"></div>
      </div>
    </div>
    <div
      class="no-data"
      v-else
    >
      {{"暂无数据"}}
    </div>
  </div>
</template>
<script>
export default {
  props: {
    data: {
      type: Array,
      default: () => [],
    },
  },
  computed: {
    hasData: {
      get: function () {
        return this.data && this.data.length > 0
      },
    },
  },
  methods: {
    showTitle(item, index) {
      return item.name + '(' + item.code + ')'
    },
    selectCancel(item) {
      this.$emit('on-change', item)
    },
  },
}
</script>