UiDateTime.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <el-row class="form-group">
  3. <el-col style="min-height:50px;padding-top:10px;" :span="3">
  4. <label style="margin-left:10px;vertical-align: middle;" class="control-label">{{label ? label : 'Date-Time'}}</label>
  5. </el-col>
  6. <el-col :span="14" style="min-height:50px;padding-top:5px;">
  7. <el-date-picker class="date-time-J"
  8. v-model="valueD"
  9. type="datetime"
  10. :readonly="readonly ? true : false"
  11. :disable="disable ? true : false"
  12. :editable="editable ? true : false"
  13. :size="size ? size : 'large'"
  14. :placeholder="placeholder ? placeholder : '选择日期时间'"
  15. align="left"
  16. :format="format ? format : 'yyyy-MM-dd HH:mm'"
  17. :picker-options="pickerOptions1"
  18. @change="dateTimeChange">
  19. </el-date-picker>
  20. <input type="hidden" class="ui-date-time" :name="name ? name : 'date_time'" :value="valueD" style="width:0;height:0.5px;border: 0 solid rgba(255,255,255,0)" />
  21. </el-col>
  22. <el-col :span="7">
  23. <div class="classJs">
  24. <div v-if="tips">
  25. <span class="red">*</span>&ensp;{{tips}}
  26. </div>
  27. </div>
  28. </el-col>
  29. </el-row>
  30. </template>
  31. <script>
  32. export default {
  33. props: ['label','name','value','readonly','disable','editable','size','format','placeholder','tips'],
  34. data() {
  35. return {
  36. valueD: this._props.value ? this._props.value : '',
  37. pickerOptions1: {
  38. shortcuts: [
  39. {
  40. text: '一周后',
  41. onClick(picker) {
  42. const date = new Date();
  43. date.setTime(date.getTime() + 3600 * 1000 * 24 * 7);
  44. picker.$emit('pick', date);
  45. }
  46. },
  47. {
  48. text: '明天',
  49. onClick(picker) {
  50. const date = new Date();
  51. date.setTime(date.getTime() + 3600 * 1000 * 24);
  52. picker.$emit('pick', date);
  53. }
  54. },
  55. {
  56. text: '今天',
  57. onClick(picker) {
  58. picker.$emit('pick', new Date());
  59. }
  60. },
  61. {
  62. text: '昨天',
  63. onClick(picker) {
  64. const date = new Date();
  65. date.setTime(date.getTime() - 3600 * 1000 * 24);
  66. picker.$emit('pick', date);
  67. }
  68. },
  69. {
  70. text: '一周前',
  71. onClick(picker) {
  72. const date = new Date();
  73. date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
  74. picker.$emit('pick', date);
  75. }
  76. }]
  77. }
  78. };
  79. },
  80. mounted() {
  81. },
  82. methods: {
  83. dateTimeChange (value) {
  84. console.log('----------------'+value)
  85. let date = new Date(value)
  86. let y = 1900 + date.getYear();
  87. let d_m = "0" + (date.getMonth() * 1 + 1);
  88. let d = "0" + date.getDate();
  89. let h = "0" + date.getHours();
  90. let m = "0" + date.getMinutes();
  91. let s = "0" + date.getSeconds();
  92. const time = y + "-" + d_m.substring(d_m.length - 2, d_m.length) + "-" + d.substring(d.length - 2, d.length)+' '+h.substring(h.length - 2, h.length)+':'+m.substring(m.length - 2, m.length)+':'+s.substring(s.length - 2, s.length);
  93. console.log('----------------'+time)
  94. this.valueD = time;
  95. this.$emit('set-keys',time);
  96. }
  97. }
  98. }
  99. </script>
  100. <style scoped>
  101. .classJs {
  102. margin-left: 10px;
  103. vertical-align: middle;
  104. height:42px;
  105. line-height:42px;
  106. }
  107. .red{
  108. color: red;
  109. }
  110. </style>