quanyawei
2024-03-01 dd6cb011fc4fccd925f5ddaa524c5c320725534b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<template>
  <el-radio-group
    v-model="radio"
    :size="size"
    @input="changeRadio"
  >
    <el-radio-button
      v-for="(item,index) in radioData"
      :key="index"
      :label="item.label"
    />
  </el-radio-group>
</template>
 
<script>
import dayjs from 'dayjs'
import _ from 'lodash'
export default {
  components: {},
  props: {
    type: {
      type: String,
      default: 'timeDate'
    },
    radioSelect: {
      type: String,
      default: ''
    },
    radioData: {
      type: Array,
      default: null
    //   { label: '今天', value: 'today', type: 'day', num: '0' },
    //     { label: '昨天', value: 'yesterday', type: 'day', num: '1', },
    //     { label: '近3天', value: 'week', type: 'day', num: '3', },
    //     { label: '近1个月', value: 'month', type: 'month', num: '1', },
    //     { label: '近3个月', value: 'threeMonth', type: 'month', num: '3', },
    },
    size: {
      type: String,
      default: 'medium'
    }
  },
  data () {
    return {
      radio: ''
    }
  },
  computed: {},
  watch: {
    radioSelect (newVal) {
      console.log('newval', newVal)
      this.radio = newVal
    }
  },
  created () {
    this.radio = this.radioSelect
    this.changeRadio(this.radio)
  },
  mounted () {
 
  },
  methods: {
    changeRadio (e) {
      let data = _.find(this.radioData, ['label', e])
      if (this.type === 'timeDate') {
        const endTime = dayjs()
        const startTime = data.num === '0' ? dayjs().startOf('day') : dayjs().subtract(data.num, data.type)
        data.startTime = startTime
        data.endTime = endTime
      }
      console.log('data', data)
      this.$emit('changeRadio', data)
    }
  }
}
</script>
<style scoped>
 
</style>