excel.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <div class="excelData" :style="{ height: height, overflow: 'auto' }">
  3. <el-empty v-if="!data.length" description="暂无数据" />
  4. <el-checkbox-group size="small" v-model="excelCheckIds" v-if="showCheckbox" @change="funCheckChange">
  5. <el-checkbox :class="{'!bg-[rgb(236,245,255)]': currentId === item.id}" size="small"
  6. class="hover:bg-[rgb(245,247,250)] !mr-0 py-[3px]" :label="item.id" v-for="item in data"
  7. :key="item.name">
  8. <span
  9. class="whitespace-nowrap cursor-pointer font-bold text-[12px] align-middle inline-flex items-center"
  10. @click.stop="funExcelChange(item)">
  11. <el-icon>
  12. <Document />
  13. </el-icon>{{ item.name }}
  14. </span>
  15. </el-checkbox>
  16. </el-checkbox-group>
  17. <div v-else>
  18. <div class="excelDataNoCheck" v-for="item in data" :key="item.name"
  19. :class="{'!bg-[rgb(236,245,255)]': currentId === item.id}" @click="funExcelChange(item)">
  20. <el-icon>
  21. <Document />
  22. </el-icon>{{ item.name }}
  23. </div>
  24. </div>
  25. </div>
  26. </template>
  27. <script>
  28. export default {
  29. props: {
  30. data: {
  31. type: Array,
  32. default: () => {
  33. return [];
  34. },
  35. },
  36. height: {
  37. type: String,
  38. default: () => {
  39. return '';
  40. },
  41. },
  42. showCheckbox: {
  43. type: Boolean,
  44. default: () => {
  45. return false;
  46. },
  47. },
  48. checkIds: {
  49. type: Array,
  50. default: () => {
  51. return [];
  52. },
  53. },
  54. },
  55. data() {
  56. return {
  57. excelCheckIds: [],
  58. currentId: ''
  59. }
  60. },
  61. watch: {
  62. checkIds(newVal, oldVal) {
  63. this.excelCheckIds = newVal
  64. }
  65. },
  66. methods: {
  67. funExcelChange(obj) {
  68. this.currentId = obj.id
  69. this.$emit('excelChange', obj)
  70. },
  71. funCheckChange(checkArr) {
  72. this.$emit('checkChange', {
  73. checkArr,
  74. data: this.data
  75. }) //抛出当前选择checkIds, 和当前的childs数据项
  76. }
  77. }
  78. }
  79. </script>
  80. <style lang="less">
  81. .excelData {
  82. .excelDataNoCheck {
  83. font-size: 14px;
  84. color: #b7b7b7;
  85. line-height: 25px;
  86. height: 25px;
  87. cursor: pointer;
  88. .el-icon {
  89. margin-right: 5px;
  90. color: #504bb5;
  91. }
  92. }
  93. .excelDataNoCheck:hover {
  94. background-color: #504bb5;
  95. color: #fff;
  96. }
  97. }
  98. </style>