zhuguifei
2025-04-28 442928123f63ee497d766f9a7a14f0a6ee067e25
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<template>
  <div>
    <template v-for='(tag, index) in tags'>
      <a-tooltip :key='tag' :title='tag'>
        <a-tag :key='tag' :closable='true' @close='() => handleClose(tag)'>
          {{ tag }}
        </a-tag>
      </a-tooltip>
 
    </template>
    <a-input
      v-if='inputVisible'
      ref='input'
      type='text'
      size='small'
      :style="{ width: '78px' }"
      :value='inputValue'
      @change='handleInputChange'
      @blur='handleInputConfirm'
      @keyup.enter='handleInputConfirm'
    />
    <a-tag v-else style='background: #fff; borderStyle: dashed;' @click='showInput'>
      <a-icon type='plus' />
      新增
    </a-tag>
  </div>
</template>
 
<script>
import { deleteAction, getAction, postAction } from '@api/manage'
 
export default {
  name: 'CondTag',
  props: {
    currSelectedTyp: {
      type: Object,
      required: true
    },
    type: {
      type: Number,
      required: true
    }
  },
  watch: {
    currSelectedTyp: {
      immediate: true,
      handler(val) {
        this.queryCondList()
 
      }
    }
  },
  data() {
    return {
      tags: [],
      inputVisible: false,
      inputValue: '',
      records:[],
      url: {
        addCond: '/lims/testing/cond/add',
        editCond: '/lims/testing/cond/edit',
        delCond: '/lims/testing/cond/delete',
        listCond: '/lims/testing/cond/list'
      }
    }
  },
  mounted() {
  },
  methods: {
    handleClose(removedTag) {
      const tag =  this.records.filter(tag => tag.cond === removedTag)
      this.handleDel(tag[0].id)
 
    },
 
    showInput() {
      this.inputVisible = true
      this.$nextTick(function() {
        this.$refs.input.focus()
      })
    },
 
    handleInputChange(e) {
      this.inputValue = e.target.value
    },
 
    handleInputConfirm() {
      const inputValue = this.inputValue
      /*  let tags = this.tags;
        if (inputValue && tags.indexOf(inputValue) === -1) {
          tags = [...tags, inputValue];
        }
      console.log(tags);*/
      let tags = this.tags;
      if (inputValue && tags.indexOf(inputValue) === -1) {
        this.handleAdd(inputValue)
      }
      Object.assign(this, {
        // tags,
        inputVisible: false,
        inputValue: ''
      })
    },
    queryCondList() {
      let params = Object.assign({}, {
        standardId: this.currSelectedTyp.standardId,
        categoryId: this.currSelectedTyp.pid,
        typeId: this.currSelectedTyp.id,
        type:this.type
      })
      if (!params.standardId || !params.categoryId || !params.typeId) {
        this.$message.warning('参数错误!')
        return false
      }
      getAction(this.url.listCond, params).then(res => {
        if (res.success) {
          //this.$message.success(res.message)
          this.tags = []
          this.records =  res.result.records
          this.records.forEach(item => {
            if (item.cond) {
              this.tags.push(item.cond)
            }
          })
 
        }
      })
    },
    handleAdd(value) {
      let params = Object.assign({}, {
        standardId: this.currSelectedTyp.standardId,
        categoryId: this.currSelectedTyp.pid,
        typeId: this.currSelectedTyp.id,
        type: this.type,
        cond: value
      })
      postAction(this.url.addCond, params).then(res => {
        if (res.success) {
          this.$message.success(res.message)
          this.queryCondList()
        }
      })
    },
    handleDel(id) {
      deleteAction(this.url.delCond,{id:id}).then(res=>{
        if(res.success){
          this.$message.success(res.message)
          this.queryCondList()
        }
      })
 
    }
  }
}
</script>
 
<style scoped>
 
</style>