quanyawei
2024-09-06 75c45150bcc5b1a3b45efe98ce6ec92b7b10aba3
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
<template>
  <div class="editable-cell">
    <div v-if="editable" class="editable-cell-input-wrapper">
 
      <a-select
               style="margin: -5px 0"
               @change="handleChange"
               v-model="selectKey"
           >
             <a-select-option  v-for="(item, key) in dictData" :value="key"  :key="key">
               {{ item }}
             </a-select-option>
      </a-select>
      <a-icon
          type="check"
          class="editable-cell-icon-check"
          @click="check"
      />
    </div>
    <div v-else class="editable-cell-text-wrapper">
      {{ computeValue || ' ' }}
      <a-icon type="edit" class="editable-cell-icon" @click="edit"/>
    </div>
  </div>
</template>
<script lang="tsx">
import {
  Component,
  Prop,
  Vue,
  Emit,
 
} from 'vue-property-decorator';
import * as _ from 'lodash';
import axios from "axios";
 
@Component({})
export default class EditableCell extends Vue {
  private selectKey: any = '1'
  private editable: boolean = false
  @Prop({
    type: String,
    default: ''
  })
  private text: string
 
  @Prop(
      {
        type: Object,
        default: () => {
          return {}
        }
       }
  )
  private dictData: any
 
 
  get computeValue() {
    return this.text
  }
  private created() {
  }
  private handleChange(e: any) {
    const value = e;
    this.selectKey = value;
  }
 
 
  private check() {
    let val = this.dictData[this.selectKey]
    this.editable = false;
    this.$emit('change', val);
    this.$emit('flag', this.editable)
  }
 
  private edit() {
    this.editable = true;
    for (let i in this.dictData) {
      if (this.computeValue === this.dictData[i]) {
        this.selectKey = i
      }
    }
    this.$emit('flag', this.editable)
  }
 
}
</script>
 
<style scoped>
.editable-cell {
  position: relative;
}
 
.editable-cell-input-wrapper,
.editable-cell-text-wrapper {
  padding-right: 24px;
}
 
.editable-cell-text-wrapper {
  padding: 5px 24px 5px 5px;
}
 
.editable-cell-icon,
.editable-cell-icon-check {
  position: absolute;
  right: 0;
  width: 20px;
  cursor: pointer;
}
 
.editable-cell-icon {
  line-height: 18px;
  display: none;
}
 
.editable-cell-icon-check {
  line-height: 28px;
}
 
.editable-cell:hover .editable-cell-icon {
  display: inline-block;
}
 
.editable-cell-icon:hover,
.editable-cell-icon-check:hover {
  color: #108ee9;
}
 
.editable-add-btn {
  margin-bottom: 8px;
}
</style>