wt-label.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <div class="flex flex-wrap flex-center">
  3. <div v-if="tags.length >= 2" class="flex flex-center flex-justify-start">
  4. <div class="tag flex flex-center" v-for="i in tags" :key="i.id">
  5. {{ i.dictValue }}
  6. <el-icon class="ml-10" @click="remove(i)" v-if="!disabled">
  7. <CircleCloseFilled />
  8. </el-icon>
  9. </div>
  10. </div>
  11. <el-icon
  12. size="30"
  13. class="padding-left padding-right"
  14. color="#A3773D"
  15. @click="show = true"
  16. v-if="!disabled"
  17. >
  18. <CirclePlusFilled />
  19. </el-icon>
  20. <el-dialog v-model="show" width="500" title="选择标签">
  21. <div class="flex flex-center">
  22. <el-select v-model="form.tag1" class="mr-10" placeholder="请选择">
  23. <el-option
  24. v-for="item in options"
  25. :key="item.dictKey"
  26. :label="item.dictValue"
  27. :value="item.dictKey"
  28. />
  29. </el-select>
  30. <el-select v-model="form.tag2" placeholder="请选择">
  31. <el-option
  32. v-for="item in options1"
  33. :key="item.dictKey"
  34. :label="item.dictValue"
  35. :value="item.dictKey"
  36. />
  37. </el-select>
  38. </div>
  39. <div class="full-width flex flex-center flex-justify-end mt-20">
  40. <el-button type="primary" plain @click="show = false">取 消</el-button>
  41. <el-button type="primary" @click="submit">确 定</el-button>
  42. </div>
  43. </el-dialog>
  44. </div>
  45. </template>
  46. <script>
  47. export default {
  48. props: {
  49. // 初始化id
  50. ids: {
  51. type: Array,
  52. default: () => {
  53. return null
  54. }
  55. },
  56. // 是否可以编辑
  57. disabled: {
  58. type: Boolean,
  59. default: false
  60. }
  61. },
  62. data() {
  63. return {
  64. show: false,
  65. tags: [],
  66. form: {
  67. tag1: '',
  68. tag2: ''
  69. },
  70. options: [],
  71. options1: []
  72. }
  73. },
  74. created() {
  75. this.init()
  76. },
  77. methods: {
  78. init() {
  79. this.$api.common.dicList({ code: 'edit_task_type' }).then(res => {
  80. if (res.code === 200) {
  81. this.options = res.data.map(ele => {
  82. ele.type = 'tags'
  83. return ele
  84. })
  85. if (this.ids.length > 0) {
  86. const tmp = this.options.find(ele => ele.id === this.ids[0])
  87. if (tmp) {
  88. this.tags.push(tmp)
  89. }
  90. }
  91. }
  92. })
  93. this.$api.common.dicList({ code: 'edit_task' }).then(res => {
  94. if (res.code === 200) {
  95. this.options1 = res.data.map(ele => {
  96. ele.type = 'category'
  97. return ele
  98. })
  99. if (this.ids.length > 1) {
  100. const tmp = this.options1.find(ele => ele.id === this.ids[1])
  101. this.tags.push(tmp)
  102. }
  103. }
  104. })
  105. },
  106. submit() {
  107. this.tags = [
  108. this.options.find(ele => ele.dictKey === this.form.tag1),
  109. this.options1.find(ele => ele.dictKey === this.form.tag2)
  110. ]
  111. this.show = false
  112. this.form = {}
  113. this.$emit('submit', this.tags)
  114. },
  115. remove(res) {
  116. this.tags = this.tags.filter(ele => ele.id !== res.id)
  117. const tmps = this.tags.map(ele => ele.id).join(',')
  118. this.$emit('submit', tmps)
  119. }
  120. }
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. .tag {
  125. min-width: 60px;
  126. height: 20px;
  127. border-radius: 20px;
  128. background-color: #a3773d;
  129. padding: 2px 10px;
  130. margin: 0 5px;
  131. color: white;
  132. }
  133. </style>