You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

203 lines
4.2 KiB

4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
4 years ago
  1. <template>
  2. <div class="field-box" @click="showSelect">
  3. <el-avatar class="avater" :icon="getMyIcon(currentItem)" :style="{backgroundColor:getMyColor(currentItem)}">{{getMyAvaterInfo(currentItem)}}</el-avatar>
  4. <div class="field-info" >
  5. <span class="field-value" v-if="showVal">{{showVal}} </span>
  6. <span class="field-value" v-else></span>
  7. <span class="field-label" >{{label}}</span>
  8. <dict-select :dict="dict" ref="selectRef" v-model="myVal" @change="onChange" :get-icon="getIcon" :get-color="getColor"></dict-select>
  9. </div>
  10. </div>
  11. </template>
  12. <script>
  13. export default {
  14. name: 'dict-field',
  15. components: { },
  16. computed: {
  17. currentItem(){
  18. if(this.dict){
  19. return this.dict.find(k=>k.id==this.myVal)
  20. }else{
  21. return null;
  22. }
  23. },
  24. showVal(){
  25. if(this.dict){
  26. var item= this.dict.find(k=>k.id==this.myVal)
  27. if(item){
  28. return item.name
  29. }else{
  30. return this.myVal
  31. }
  32. }else{
  33. return this.myVal
  34. }
  35. }
  36. },
  37. data(){
  38. return {
  39. myVal:'',
  40. }
  41. },
  42. watch:{
  43. value:{
  44. deep:true,
  45. handler(){
  46. this.initData();
  47. }
  48. },
  49. myVal(){
  50. this.$emit('input',this.myVal)
  51. }
  52. },
  53. props: {
  54. disabled:{
  55. type:Boolean,
  56. default:false,
  57. },
  58. label:{
  59. type:String,
  60. default:''
  61. },
  62. clearable:{
  63. type:Boolean,
  64. default:false,
  65. },
  66. dict:{
  67. type:Array,
  68. default:function(){return []}
  69. },
  70. value: {
  71. },
  72. getIcon:{
  73. type:Function
  74. },
  75. getColor:{
  76. type:Function
  77. } ,
  78. },
  79. methods: {
  80. showSelect(){
  81. this.$refs["selectRef"].$refs["selectRef"].toggleMenu();
  82. },
  83. getMyAvaterInfo(item){
  84. if(!item){
  85. return ""
  86. }else{
  87. return item.icon?"":item.name
  88. }
  89. },
  90. getMyColor(item){
  91. if(item){
  92. if(this.getColor){
  93. return this.getColor(item.id)
  94. }
  95. if(item.color){
  96. return item.color
  97. }
  98. return ""
  99. }else{
  100. if(this.getColor){
  101. return this.getColor(this.myVal)
  102. }else{
  103. return ""
  104. }
  105. }
  106. },
  107. getMyIcon(item){
  108. if(item){
  109. if(this.getIcon){
  110. return this.getIcon(item.id)
  111. }
  112. if(item.icon){
  113. return item.icon
  114. }
  115. return "";
  116. }else{
  117. if(this.getIcon){
  118. return this.getIcon(this.myVal)
  119. }else{
  120. return ""
  121. }
  122. }
  123. },
  124. initData(){
  125. this.myVal=this.value
  126. },
  127. onChange(data){
  128. this.$emit('change',data)
  129. }
  130. },
  131. mounted(){
  132. this.initData();
  133. }
  134. }
  135. </script>
  136. <style lang="scss" scoped>
  137. .field-box {
  138. display: flex;
  139. margin-right:5px;
  140. align-items: center;
  141. cursor: pointer;
  142. height: 40px;
  143. line-height: 40px;
  144. .avater {
  145. background-color:#FF9F73;
  146. }
  147. .field-info {
  148. height: 40px;
  149. line-height: 40px;
  150. margin-left: 10px;
  151. display: flex;
  152. flex-direction: column;
  153. .field-value {
  154. height: 20px;
  155. line-height: 20px;
  156. font-size: 0.75rem;
  157. }
  158. .field-label{
  159. height: 20px;
  160. line-height: 20px;
  161. font-size: 0.75rem;
  162. color: #C0C4CC;
  163. }
  164. }
  165. .my-select{
  166. height: 20px;
  167. line-height: 20px;
  168. margin-left: 5px;
  169. margin-right:5px;
  170. max-width: 120px;
  171. display: none;
  172. }
  173. }
  174. .field-box:hover .field-label{
  175. display: none;
  176. }
  177. .field-box:hover .my-select{
  178. height: 20px;
  179. margin-left: 5px;
  180. display: inline;
  181. }
  182. </style>