ACron.vue 1.85 KB
Newer Older
陈浩玮's avatar
陈浩玮 committed
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 80 81 82 83 84 85 86
<template>
  <div class="components-input-demo-presuffix">
    <a-input :placeholder="placeholder" :value="cron" @input="handleinput">
      <a-icon slot="prefix" type="schedule" title="corn控件" @click="openModal" />
      <a-icon v-if="cron" slot="suffix" type="close-circle" @click="handleEmpty" title="清空" />
    </a-input>
    <AntCron ref="innerVueCron" :data="afterCron" @ok="handleOK"></AntCron>
  </div>
</template>
<script>
import AntCron from "./AntCron";
import { replaceWeekName } from "./validator";
export default {
  name: "ACron",
  components: {
    AntCron
  },
  props: {
    value: {
      required: false,
      type: String,
      default: ""
    },
    placeholder: {
      required: false,
      type: String,
      default: ""
    }
  },
  data() {
    return {
      cron: this.value,
      afterCron: ""
    };
  },
  watch: {
    value(val) {
      this.cron = val;
    },
    cron(val) {
      console.log(replaceWeekName(val));
      this.afterCron = replaceWeekName(val);
      console.log(val);
      this.$emit("input", val);
    }
  },
  methods: {
    openModal() {
      this.$refs.innerVueCron.show();
    },
    handleOK(val) {
      this.cron = val;
      this.$emit("change", this.cron);
    },
    handleinput(evt) {
      this.cron = evt.target.value;
      if (this.cron !== "") {
        this.$emit("change", this.cron);
      } else {
        this.$emit("change", undefined);
      }
    },
    handleEmpty() {
      this.handleOK("");
    }
  },
  model: {
    prop: "value",
    event: "change"
  }
};
</script>
<style scoped>
.components-input-demo-presuffix .anticon-close-circle {
  cursor: pointer;
  color: #ccc;
  transition: color 0.3s;
  font-size: 12px;
}
.components-input-demo-presuffix .anticon-close-circle:hover {
  color: #f5222d;
}
.components-input-demo-presuffix .anticon-close-circle:active {
  color: #666;
}
</style>