<template>
  <div class="app-deploy-control-key">
    <el-input-number
      v-if="keyType === 'number'"
      v-model="data"
      style="width: 100%"
      :controls="false"
      placeholder="请输入数字"
      @change="dataChange"
    ></el-input-number>
    <el-date-picker
      v-if="keyType === 'time'"
      v-model="data"
      type="datetime"
      style="width: 100%"
      value-format="timestamp"
      placeholder="选择日期时间"
      @change="dataChange"
    >
    </el-date-picker>
  </div>
</template>

<script>
export default {
  name: "app-deploy-control-key",
  props: {
    value: { type: [Number, String] },
    keyType: {
      type: String,
      default: "number",
      validator: (val) => ["number", "time"].includes(val),
    },
  },
  watch: {
    value: {
      immediate: true,
      handler(val) {
        this.data = val;
      },
    },
  },
  data() {
    return {
      data: null,
    };
  },
  methods: {
    dataChange() {
      // console.log(this.data);
      this.$emit("input", this.data);
      this.$emit("change", this.data);
    },
  },
};
</script>
