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.

233 lines
5.2 KiB

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