<template>
  <view>
    <u-popup
      :show="show"
      mode="center"
      @close="handleClose"
      @open="handleOpen"
      :round="10"
      :closeOnClickOverlay="false"
    >
      <view class="pop-content">
        <view class="pop-main">
          <view class="flex_box flex-row-center pd-30">
            <view class="qr-code">
              <uqrcode
                ref="uqrcode"
                canvas-id="qrcode"
                :value="info.number"
                sizeUnit="rpx"
                :size="200"
              ></uqrcode>
            </view>
            <view class="flex-box flex-column flex-justify-sa info-box">
              <view class="item-value">{{ info.customerName }}</view>
              <view class="item-value">{{ info.number }}</view>
            </view>
          </view>
          <tki-barcode
            ref="barcode"
            :show="showBarCode"
            :val="barcodeVal"
            :opations="{
              width: 1,
              height: 100,
              displayValue: true,
              margin: 10,
            }"
            @result="getBarCodeImg"
          />
          <view class="tips-value">请确认打印条码数量</view>
          <view class="num-box">
            <u-number-box
              v-model="printNum"
              :inputWidth="56"
              :min="0"
            ></u-number-box>
          </view>
        </view>
        <!-- 操作按钮 -->
        <view class="btn-footer">
          <u-button
            text="取消"
            type="primary"
            :plain="true"
            @click="handleClose"
            :customStyle="{
              marginRight: '16rpx',
              border: '1px solid #bfc8db',
              color: '#86909c',
            }"
            class="footer-btn no-btn"
          ></u-button>
          <u-button
            text="确定"
            type="primary"
            @click="handleConfirm"
            class="footer-btn yes-btn"
          ></u-button>
        </view>
      </view>
    </u-popup>
  </view>
</template>

<script>
import tkiBarcode from "@/components/tki-barcode/tki-barcode.vue";

export default {
  components: { tkiBarcode },
  props: {
    show: {
      type: Boolean,
      default: false,
    },
    info: {
      type: Object,
      default: () => ({
        customerName: "",
        number: "",
        barCode: "",
      }),
    },
  },
  computed: {
    barcodeVal() {
      return this.info.barCode || "";
    },
  },
  data() {
    return {
      showBarCode: false,
      printNum: 1,
    };
  },
  methods: {
    // 关闭弹窗
    handleClose() {
      this.showBarCode = false;
      this.$emit("update:show", false);
      this.$emit("close");
    },
    handleOpen() {
      this.printNum = 1;
      this.showBarCode = true;
    },
    handleConfirm() {
      const params = {
        num: this.printNum,
        data: {
          barCode: this.info.barCode, // 商品条码
          customerName: this.info.customerName, //客户名
          number: this.info.number, // 单据编号
        },
      };
      this.$emit("confirm", params);
      this.handleClose();
    },
    getBarCodeImg(res) {
      console.log("条形码图片", res);
      this.$emit("barCodeImg", res);
    },
  },
};
</script>

<style lang="scss" scoped>
.pop-content {
  width: 590rpx;
  padding: 60rpx 20rpx 48rpx;
  background: #fff;
  border-radius: 10rpx;

  .pop-main {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .flex_box {
    display: flex;
  }
  .pd-30 {
    padding: 30rpx;
  }
  .mt-30 {
    margin-top: 30rpx;
  }
  .flex-column {
    flex-direction: column;
  }
  .flex-align-center {
    align-items: center;
  }
  .flex-row-center {
    flex-direction: row;
    justify-content: center;
  }

  .info-box {
    flex: 1;
  }
  .item-value {
    font-size: 32rpx;
    margin-bottom: 10rpx;
  }
  .qr-code {
    width: 200rpx;
    height: 200rpx;
    background-color: #bfc8db;
    margin-right: 20rpx;
  }

  .bar-code {
    width: 400rpx;
    margin-bottom: 10rpx;
  }
  .tips-value {
    color: #1d212a;
    font-family: "PingFang SC";
    font-size: 32rpx;
    font-style: normal;
    font-weight: bold;
    margin-top: 30rpx;
    text-align: center;
  }

  .num-box {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 30rpx;
  }
  .btn-footer {
    display: flex;
    padding: 30rpx;

    .no-btn {
      border: 1px solid #bfc8db;
      color: #86909c;
    }
    .yes-btn {
      background: #0256ff;
    }

    .footer-btn {
      flex: 1;
      margin: 0 16rpx;
      width: 244rpx;
      border-radius: 16rpx;
      font-size: 32rpx;
    }
  }
}
</style>
