index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <div class="tips-wrapper">
  3. <span>
  4. <el-tag
  5. v-for="item in value"
  6. :key="item"
  7. closable
  8. size="small"
  9. type="info"
  10. @close="() => tabClose(item)">
  11. {{ item }}
  12. </el-tag>
  13. </span>
  14. <span class="add-tag" @click="addTag">打标</span>
  15. <!-- 弹窗 -->
  16. <div v-if="visible" class="tag_dialogbox">
  17. <div class="box">
  18. <div class="title">
  19. <span class="line" />
  20. <span class="name">设置标签</span>
  21. <i class="el-icon-close icon" @click="visible = false" />
  22. </div>
  23. <div class="body">
  24. <div class="tag-from_item">
  25. <div class="tag-from__label">标签:</div>
  26. <div class="tag-from__content">
  27. <el-select
  28. ref="select"
  29. v-model="tagSelectValue"
  30. style="width: 100%;"
  31. multiple
  32. remote
  33. filterable
  34. allow-create
  35. default-first-option
  36. :placeholder="placeholder"
  37. :remote-method="remoteMethod"
  38. @click.stop
  39. @change="change"
  40. >
  41. <el-option
  42. v-for="(item, itemIndex) in options"
  43. :key="itemIndex"
  44. :label="item"
  45. :value="item"
  46. >
  47. {{ item }}
  48. </el-option>
  49. </el-select>
  50. </div>
  51. </div>
  52. </div>
  53. <div class="footer">
  54. <el-button size="small" @click="close">取消</el-button>
  55. <el-button size="small" type="primary" @click="ok">确定</el-button>
  56. </div>
  57. </div>
  58. <div class="bg" />
  59. </div>
  60. </div>
  61. </template>
  62. <script>
  63. import Clickoutside from 'element-ui/src/utils/clickoutside'
  64. import { desDecryptId } from '@/utils/crypto-js.js'
  65. import { taskGetTag } from '@/api/common'
  66. // import Modal from '@/components/modal'
  67. export default {
  68. name: 'Tag',
  69. // components: { Modal },
  70. directives: { Clickoutside },
  71. props: {
  72. value: {
  73. required: false,
  74. type: Array,
  75. default: () => []
  76. },
  77. type: {
  78. required: false,
  79. type: String,
  80. default: () => ''
  81. },
  82. placeholder: {
  83. required: false,
  84. type: String,
  85. default: () => '请选择标签'
  86. }
  87. },
  88. data() {
  89. return {
  90. visible: false,
  91. isAddTag: true,
  92. options: [],
  93. tagSelectValue: [],
  94. tagValue: []
  95. }
  96. },
  97. methods: {
  98. change() {
  99. this.tagSelectValue = Array.from(new Set(this.tagSelectValue))
  100. this.options = Array.from(new Set([...this.options, ...this.tagSelectValue]))
  101. },
  102. close() {
  103. this.visible = false
  104. },
  105. tabClose(item) {
  106. const newTagValue = [...this.value].filter(elm => elm !== item)
  107. this.$emit('input', newTagValue)
  108. this.$emit('change', newTagValue)
  109. },
  110. ok() {
  111. this.$emit('input', this.tagSelectValue)
  112. this.$emit('change', this.tagSelectValue)
  113. this.close()
  114. },
  115. addTag() {
  116. this.remoteMethod()
  117. this.tagSelectValue = Array.from(new Set(this.value))
  118. this.options = Array.from(new Set([...this.options, ...this.value]))
  119. this.visible = true
  120. },
  121. remoteMethod(searchTag = '') {
  122. if (!this.$route.query.bizId) return
  123. // const bizId_id = analysisBizId_id(this.$route.query.bizId)
  124. // const bizId_id = window.localStorage.getItem('bizId')
  125. const bizId_id = desDecryptId(this.$route.query.bizId).replace(/_.*/, '')
  126. console.log(bizId_id)
  127. taskGetTag({
  128. type: this.type,
  129. searchTag,
  130. bizId: bizId_id
  131. }).then(res => {
  132. if (res.code === 200) {
  133. this.options = res.data.map(elm => elm.tag)
  134. }
  135. })
  136. }
  137. }
  138. }
  139. </script>
  140. <style scoped lang="less">
  141. .tips-wrapper {
  142. display: inline-block;
  143. }
  144. /deep/ .el-select__tags {
  145. max-width: calc(100% - 100px) !important;
  146. }
  147. .el-tag {
  148. margin-left: 5px;
  149. user-select: none;
  150. }
  151. .add-tag {
  152. color: #00a0ff;
  153. margin-left: 10px;
  154. cursor: pointer;
  155. }
  156. /deep/ .el-select {
  157. /deep/ .el-input__inner {
  158. border: 1px solid rgba(220, 223, 230) !important;
  159. }
  160. }
  161. .tag_dialogbox {
  162. .box {
  163. position: fixed;
  164. top:20vh;
  165. left: calc(50% - 250px);
  166. width: 500px;
  167. min-height: 180px;
  168. // overflow: auto;
  169. background: #fff;
  170. z-index: 1000;
  171. border-radius: 4px;
  172. display: flex;
  173. flex-direction: column;
  174. box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  175. .title {
  176. padding: 5px 0px 5px 18px;
  177. // border-bottom: 1px solid #eee;
  178. position: relative;
  179. .line {
  180. display: inline-block;
  181. width: 4px;
  182. height: 18px;
  183. background: #409eff;
  184. border-radius: 1px;
  185. vertical-align: text-top;
  186. }
  187. .name {
  188. margin-left: 6px;
  189. color: rgba(0,0,0,.85);
  190. font-weight: 500;
  191. font-size: 16px;
  192. line-height: 22px;
  193. word-wrap: break-word;
  194. }
  195. .icon {
  196. position: absolute;
  197. top: 20px;
  198. right: 20px;
  199. font-size: 16px;
  200. color: #909399;
  201. cursor: pointer;
  202. }
  203. }
  204. .body {
  205. padding: 15px 20px;
  206. color: #606266;
  207. font-size: 14px;
  208. word-break: break-all;
  209. // height: calc(80vh - 118px);
  210. overflow: auto;
  211. .tag-from .el-form-item__content {
  212. width: calc(100% - 100px);
  213. }
  214. .tag-from_item{
  215. display: flex;
  216. .tag-from__label {
  217. width: 50px;
  218. }
  219. .tag-from__content {
  220. flex: 1;
  221. /deep/.el-input__inner {
  222. border: 1px solid #c0c4cc!important;
  223. }
  224. }
  225. }
  226. }
  227. .footer {
  228. padding: 0 20px 15px;
  229. text-align: right;
  230. // border-top: 1px solid #eee;
  231. background: #fff;
  232. }
  233. }
  234. .bg {
  235. background: rgba(000, 000, 000, 0.5);
  236. position: fixed;
  237. top: 0;
  238. left: 0;
  239. bottom: 0;
  240. right: 0;
  241. z-index: 100;
  242. }
  243. }
  244. </style>