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.

225 lines
5.0 KiB

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