<template>
  <el-input :disabled="disabled" placeholder="请输入金额" v-model="data" @change="handleChange" type="number" :min="0">
    <template slot="append">万</template>
  </el-input>
</template>
<script>
  import Decimal from 'decimal.js';

  export default {
    name: 'Capital',
    props: {
      disabled: {
        type: Boolean,
        default: false,
      },
      value: null,
    },
    data () {
      return {
        data: undefined,
      }
    },
    watch: {
      value: function (val) {
        if (val !== undefined && val !== null) {
          if (val > 0) {
            this.data = Decimal.div(new Decimal(val), new Decimal(10000)).toNumber();
          } else {
            this.data = 0;
          }
        } else {
          this.data = val;
        }
      }
    },
    methods: {
      handleChange(val) {
        const result = Decimal.mul(new Decimal(val), new Decimal(10000)).toNumber();
        this.$emit('change', result);
        this.$emit('input', result);
      },
    }
  };
</script>
