ScenicCheckTag.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <div>
  3. <el-tooltip
  4. v-for="(item,index) in list"
  5. :key="index"
  6. :content="item.name"
  7. placement="top"
  8. effect="dark">
  9. <span
  10. class="stag"
  11. :class="{checked:selected.some(i=>i===item.id)}"
  12. :style="getStyle(item,index)"
  13. @click="handleClick(item)"
  14. >
  15. {{ item.name[0] }}
  16. </span>
  17. </el-tooltip>
  18. </div>
  19. </template>
  20. <script>
  21. export default {
  22. computed: {
  23. list () {
  24. return this.$store.state.app.scenicList
  25. },
  26. scenicColor () {
  27. return this.$store.state.app.scenicColor
  28. }
  29. },
  30. data () {
  31. return {
  32. selected: []
  33. }
  34. },
  35. props: {
  36. value: {
  37. type: Array,
  38. default: () => []
  39. }
  40. },
  41. methods: {
  42. handleClick (item) {
  43. let index = this.selected.findIndex(i => i === item.id)
  44. if (index > -1) {
  45. this.selected.splice(index, 1)
  46. } else {
  47. this.selected.push(item.id)
  48. }
  49. this.$emit('input', this.selected)
  50. this.$emit('change', this.selected)
  51. },
  52. getStyle (item, index) {
  53. let isChecked = this.selected.some(i => i === item.id)
  54. if (isChecked) {
  55. return {
  56. borderColor: this.scenicColor[item.id],
  57. background: this.scenicColor[item.id],
  58. color: '#fff'
  59. }
  60. } else {
  61. return {
  62. borderColor: '#999',
  63. color: '#999'
  64. }
  65. }
  66. }
  67. },
  68. watch: {
  69. value: {
  70. handler (val) {
  71. this.selected = JSON.parse(JSON.stringify(val))
  72. },
  73. immediate: true
  74. }
  75. }
  76. }
  77. </script>
  78. <style lang="scss" scoped>
  79. .stag {
  80. display: inline-block; padding: 2px; margin-bottom: 3px; line-height: 14px; cursor: pointer; border: 1px solid transparent;border-radius: 3px;
  81. }
  82. .stag {
  83. margin-right: 3px;
  84. }
  85. </style>