<template>
  <div id="GiveChange" v-if="control">
    <input id="give_change_input" type="checkbox" @click="check($event)">
    <label for="give_change_input">找零</label>
<!--    <input id="give_change_input" type="checkbox" @click="check($event)">-->
<!--    <label for="give_change_input">找零</label>-->
  </div>
</template>

<script>
export default {
  name: 'GiveChange',
  data () {
    return {
      // 中转收款金额
      transitCollection: 0,
      // 提示文字
      promptText: ''
    }
  },
  props: {
    // 本期结余
    curbalance: {
      default: 0
    },
    // 收款金额, 双向绑定
    collection: {
      default: 0
    }
  },
  created () {
  },
  mounted () {
  },
  methods: {
    async check (event) {
      if (event.target.checked) {
        this.promptText = `找零金额: ${this.curbalance}`
        this.transitCollection = this.collection - 0
        this.collection = (this.collection - this.curbalance).toFixed(2) - 0
      } else {
        this.promptText = ''
        this.collection = this.transitCollection
      }
    }
  },
  computed: {
    control () {
      return this.$login.r.find(value => value == '找零功能')
    }
  }
}
</script>

<style lang="less">
#GiveChange {
  //display: contents;
}
</style>
