<template>
  <div class="check">
    <cr-checkbox
      v-model="checked"
      shape="round"
      class="check-all"
      checked-color="#ec1500"
      :disabled="checkDisabled"
      @change="checkAllOptions"
      >全选</cr-checkbox
    >
    <div class="check-price">
      <div class="check-price-left">
        <span class="check-price-left__content">合计开票:</span>
        <span class="check-price-left__total">￥{{ allPrice }}</span>
        <cr-icon
          class="check-price-left__icon"
          type="info-o"
          size="15px"
          color="#c8c9cc"
          @click="showMessageDialog"
        />
      </div>
      <cr-button
        class="check-button"
        shape="circle"
        type="primary"
        :disabled="btnDisabled"
        @click="onSure"
      >
        {{ buttonText }}
      </cr-button>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    checkAll: {
      type: Boolean,
      default: false
    },
    checkDisabled: {
      type: Boolean,
      default: false
    },
    allPrice: {
      type: [Number, String],
      default: ''
    },
    btnDisabled: {
      type: Boolean,
      default: false
    },
    buttonText: {
      type: String,
      default: '开票'
    }
  },
  data() {
    return {
      checked: false
    };
  },
  watch: {
    checkAll(val) {
      this.checked = val;
    }
  },
  methods: {
    checkAllOptions(val) {
      this.$emit('update:checkAll', val);
      this.$emit('change');
    },
    onSure() {
      this.$emit('submit');
    },
    showMessageDialog() {
      this.$dialog({
        customClass: 'cr-dialog-invoice',
        closeOnClickOverlay: true,
        title: '开票规则说明',
        message: `1.开票金额为消费者实付金额，不包含运费、支付优惠金额<br />2.如果订单发生退货退款，开票金额将变更为最终实付金额`,
        messageAlign: 'left',
        showCancelButton: false,
        confirmButtonText: '知道了'
      });
    }
  }
};
</script>
<style lang="less" scoped>
.check {
  width: 100%;
  // height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  margin-top: 10px;
  position: fixed;
  bottom: 0;
  background-color: @white;
  border-top: solid 1px #ededed;
  padding-bottom: constant(safe-area-inset-bottom) !important;
  padding-bottom: env(safe-area-inset-bottom) !important;
  height: calc(constant(safe-area-inset-bottom) + 60px) !important;
  height: calc(env(safe-area-inset-bottom) + 60px) !important;
  box-sizing: border-box;
  &-all {
    height: 25px;
    padding-left: 12px;
    padding-right: 5px;
    overflow: hidden;
    @{deep} .cr-checkbox__label {
      color: @gray-4;
      font-size: 12px;
    }
  }
  &-price {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 1;
    &-left {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: center;
      &__content {
        .text-size(12);
      }
      &__total {
        color: @red;
        font-size: 16px;
        font-weight: bold;
      }
      &__icon {
        margin-left: 3px;
      }
    }
  }
  &-button {
    width: 130px;
    font-size: 16px;
    margin-right: 10px;
  }
}
</style>
