<template>
  <el-input
    v-model="value"
    class="normal_input"
    @blur="inputMoney"
    @focus="delPoint"
    :disabled="disabled"
    maxlength="16"
    @input="oninput"
    @clear="handleClear"
    ref="input"
    :placeholder="placeholder"
     clearable
  >
  </el-input>
</template>

<script>
//import { log } from 'console';
import {getInputValue, delInput, delcommafy, comdify} from "../../../../utils/money";

export default {
  // model: {
  //   prop: "inputValue",
  // },
  props: ["inputValue", "zeroLength", "disabled","placeholder"],
  data() {
    return {
      value: this.inputValue,
    };
  },
  computed: {

  },
  watch: {
    inputValue(newValue) {
      this.value = newValue;
      if(this.value > 9999999999999.99){
        this.value = 9999999999999.99
      }
      this.value = comdify(delcommafy(this.value), 2);
    }
  },
  created() {
  },
  methods: {
    inputMoney(el) {
      this.value = getInputValue(el, this.zeroLength);
     this.$emit("change", delcommafy(this.value));
    },
    delPoint() {
      this.value = delInput(this.value, this.zeroLength);
      // this.$emit("change", this.value);
    },

    oninput(num) {
      var str = num;
      if (!/^([0-9]|\.)*$/.test(str)) {
        str = str.substring(0, str.length - 1);
        this.value = str;
        return str;
      }
      if (str.indexOf(".") != -1) {
        str = str.split(".")[0] + "." + str.split(".")[1].substring(0, this.zeroLength); //保留小数
        this.value = str;
      }
    },
    clickFormat(el){
      this.value = getInputValue(this.$refs.input, this.zeroLength);
    },
    handleClear(){
      this.value = null;
      this.$emit("change", null);
    }

  },
};
</script>

<style lang="scss" scoped>
  ::v-deep  input{
    text-align: right !important;
  }
</style>
