<!--
 * @Author: zwq
 * @Date: 2024-07-01 14:53:55
 * @LastEditors: zwq
 * @LastEditTime: 2024-07-10 10:28:05
 * @Description:
-->
<template>
  <el-switch v-model="state" type="text" size="small" :disabled="readonly" @change="changeHandler" />
</template>

<script>
export default {
  props: {
    injectData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      state: false
    }
  },
  computed: {
    readonly() {
      return !!this.injectData.readonly
    }
  },
  mounted() {
    this.mapToState()
  },
  methods: {
    mapToState() {
      if (this.injectData.prop === 'enabled') {
        this.state = this.injectData.enabled === 1 ? true : false
      }
    },
    changeHandler() {
      let params = {}
      let payload = {}
      params.name = 'state'
      payload.id = this.injectData.id
      payload.enabled = this.state ? '1' : '0'
      payload.startTime = this.injectData.startTime
      payload.endTime = this.injectData.endTime
      params.payload = payload
      this.$emit('emitData', params)
    }
  }
}
</script>
