calendar.vue 2.01 KB
Newer Older
潘永坪's avatar
潘永坪 committed
1 2
<template>
		<u-calendar 
潘永坪's avatar
潘永坪 committed
3
		:show="showPop" 
潘永坪's avatar
潘永坪 committed
4
		@confirm="onConfirm"
潘永坪's avatar
潘永坪 committed
5
		@close="showPop=false"
潘永坪's avatar
潘永坪 committed
6 7
		:defaultDate="defaultDate"
		:formatter='formatter'
潘永坪's avatar
潘永坪 committed
8
		:customList='customList'
潘永坪's avatar
潘永坪 committed
9
		ref="calendar2"
潘永坪's avatar
潘永坪 committed
10 11 12
		rowHeight='112'
		round='20'
		closeOnClickOverlay='true'
潘永坪's avatar
潘永坪 committed
13 14 15 16
		></u-calendar>
</template>

<script>
潘永坪's avatar
潘永坪 committed
17 18 19
export default {
  props: ['dateList'],
  watch: {
潘永坪's avatar
潘永坪 committed
20 21 22
    dateList:{
      handler(newValue, oldValue){
        if(newValue&&newValue.length>0){
潘永坪's avatar
潘永坪 committed
23 24 25
          this.customList=newValue.map(item=>{
            return item.startTime.substr(0,10)
          })
潘永坪's avatar
潘永坪 committed
26
          this.defaultDate=newValue[0].startTime.substr(0,10)
潘永坪's avatar
潘永坪 committed
27 28 29 30
          //由于传入了customList,最大日期和最小日期可以取消
          // this.maxDate=newValue[newValue.length-1].startTime.substr(0,10)
          // //默认和最小日期都为第一天
          // this.minDate=newValue[0].startTime.substr(0,10)
潘永坪's avatar
潘永坪 committed
31 32 33 34 35
        }
      },
      deep:true,
      immediate:true
    }
潘永坪's avatar
潘永坪 committed
36 37 38
  },
  data() {
    return {
潘永坪's avatar
潘永坪 committed
39
      showPop: false, //控制日历显示隐藏
潘永坪's avatar
潘永坪 committed
40 41
      defaultDate:'', //默认日期
      maxDate:'',//最大日期
潘永坪's avatar
潘永坪 committed
42
      minDate:'',//最小日期
潘永坪's avatar
潘永坪 committed
43
      customList:[],//转化之后的日期列表
潘永坪's avatar
潘永坪 committed
44 45
    }
  },
潘永坪's avatar
潘永坪 committed
46
  mounted() {
潘永坪's avatar
潘永坪 committed
47 48 49 50
    this.$refs.calendar2.setFormatter(this.formatter)
  },
  methods: {
    //---日期确认事件
潘永坪's avatar
潘永坪 committed
51
    onConfirm(date){
潘永坪's avatar
潘永坪 committed
52
      this.showPop = false
潘永坪's avatar
潘永坪 committed
53
      this.$emit('dateConfig', date[0])
潘永坪's avatar
潘永坪 committed
54
    },
潘永坪's avatar
潘永坪 committed
55 56 57 58 59 60
    //---时间格式转换
    formatter(day) { 
      let year = day.date.getFullYear()
      let month = day.date.getMonth() + 1
      if (month < 10) {
        month = '0' + month
潘永坪's avatar
潘永坪 committed
61
      }
潘永坪's avatar
潘永坪 committed
62 63 64 65 66 67 68 69
      let days = day.date.getDate()
      if (days < 10) {
        days = '0' + days
      }
      let dates = year + '-' + month + '-' + days
      //真机调试手极端报错,暂时注释
      // this.dateList.forEach((item, index) => {
      // 	if (item.startTime.substr(0, 10) == dates) {
潘永坪's avatar
潘永坪 committed
70
      // 		day.bottomInfo = '¥' + item.sellingPrice
潘永坪's avatar
潘永坪 committed
71 72 73 74
      // 		day.dot = true
      // 	}
      // })
      return day
潘永坪's avatar
潘永坪 committed
75
			
潘永坪's avatar
潘永坪 committed
76
    }
潘永坪's avatar
潘永坪 committed
77
  }
潘永坪's avatar
潘永坪 committed
78
}
潘永坪's avatar
潘永坪 committed
79 80 81 82 83
</script>

<style scoped="scoped">

</style>