<template>
  <view class="component text-center">
    <view v-if="name" class="component-title">{{name}}</view>
    <view class="component-code">
      <!-- <tki-barcode ref="barcode" onval :val="codes" :load-make="true" :opations="barOpations" /> -->
      <tki-qrcode
          ref="qrcode"
          onval
          :val="codes"
          :size="250"
          :load-make="true"
          :show-loading="false"/>
    </view>
    <view v-if="name" class="example">{{code}}</view>
    <!-- <view class="component-qr">
            <tki-qrcode
                ref="qrcode"
                onval
                :val="code"
                :size="250"
                :load-make="true"
                :show-loading="false"/>
        </view> -->
    <!-- <view class="coupon-no-view">
            <text>编号：</text>
            <text class="coupon-no">{{ code }}</text>
        </view> -->
  </view>
</template>

<script>
  import tkiBarcode from '@/components/tki-barcode/tki-barcode'
  import tkiQrcode from '@/components/tki-qrcode/tki-qrcode'

  export default {
    components: {
      tkiBarcode,
      tkiQrcode
    },
    props: {
      code: {
        type: String,
        default: ''
      }
    },
    data() {
      return {
        name: '',
        codes: '',
        barOpations: {
          height: 150,
          displayValue: false
        }
      }
    },
    mounted() {
      this.codes = this.code;
    },
    methods: {
      init(val) {
        this.name = val.name;
        this.codes = val.code // 生成一维码和二维码
        // setTimeout(() => {
        //   this.code = '0987654321' // 5 秒后刷新一维码和二维码
        // }, 5000)
      }
    }
  }
</script>

<style lang="scss" scoped>
  .component {
    // border-radius: 16rpx;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: #FFFFFF;
    flex: 1;
    height: 250rpx;
    // margin: 32rpx;
    // padding: 64rpx 32rpx;

    &-title {
      max-height: 112rpx;
      font-size: 40rpx;
      font-weight: 600;
      line-height: 56rpx;
      overflow: hidden;
    }

    &-code {
      height: 250rpx;
      // margin: 32rpx 32rpx 0;
    }

    &-qr {
      height: 250rpx;
      // margin-top: 36rpx;
    }

    .coupon-no-view {
      margin: 0 18rpx;
      height: 76rpx;
      border-radius: 8rpx;
      border: 2px solid #F5F5F5;
      display: flex;
      align-items: center;
      padding: 0 24rpx;
      margin-top: 36rpx;

      text {
        font-size: 24rpx;
        font-weight: 400;

        &:first-child {
          color: #999999;
        }
      }

      .coupon-no {
        flex: 1;
        text-align: left;
      }
    }
  }

  .component-title {
    text-align: center;
    font-size: 34rpx;
  }

  .example {
    text-align: center;
    letter-spacing: 12rpx;
    /* 设置字符间距 */
    font-weight: bold;
    font-size: 32rpx;
  }
</style>