2<template>
  <el-dialog title="查看签到二维码" width="1200px" top='5%' :model-value="modelValue" :before-close="closed">

    <div class='txbox'>
      <div class='ingbox'>
        <!-- 签到二维码 -->
        <div class='bgbox' id='qderweima'>
          <div style="width: 100%;height: 130px;"></div>
          <div class='titlbox'>
            <div class='title'>
              <span class='lines'></span>
              <span>邀请你参与培训</span>
              <span class='lines'></span>
            </div>
            <!-- <div class='textbox' v-if="ruleForm.examinationType == '4'">{{ ruleForm.planName }}</div> -->
            <div class='textbox'>{{ ruleForm.planName }}</div>
            <!-- 培训实施,展示培训时间,且不展示考试时间 -->
            <div v-if="props.from=='pxssxqdia'" class='timbox'>
              <div>开始时间：{{  ruleForm.startDate }}</div>
              <div>结束时间：{{ ruleForm.finshDate }}</div>
            </div>
            <div v-else class='timbox'>
              <div>开始时间：{{ ruleForm.examinationType == '4' ? ruleForm.examStartTime : ruleForm.startDate }}</div>
              <div>结束时间：{{ ruleForm.examinationType == '4' ? ruleForm.examEndTime : finshDate }}</div>
              <div v-if="ruleForm.examinationType == '4'">考试时长：{{ ruleForm.examTime }}分钟</div>
            </div>
            <div class='ertimg'>
              <img :src="qrcodepxImg(ruleForm.id, 'train_in', '', currDate)" alt="">
            </div>
            <div class='labl'> 识别【签到】二维码</div>
          </div>
        </div>
        <!-- 签离二维码 -->
        <!-- <div class='bgbox' id='qlerweima'>
          <div style="width: 100%;height: 130px;"></div>
          <div class='titlbox'>
            <div class='title'>
              <span class='lines'></span>
              <span>邀请你参与培训</span>
              <span class='lines'></span>
            </div>
            <div class='textbox' v-if="ruleForm.examinationType == '4'">{{ year }}年{{ ruleForm.planName }}考试</div>
            <div class='textbox' v-else>{{ year }}年{{ ruleForm.planName }}</div>
            <div class='timbox'>
              <div>开始时间：{{ ruleForm.examinationType == '4' ? ruleForm.examStartTime : ruleForm.startDate }}</div>
              <div>结束时间：{{ ruleForm.examinationType == '4' ? ruleForm.examEndTime : finshDate }}</div>
              <div v-if="ruleForm.examinationType == '4'">考试时长：{{ ruleForm.examTime }}分钟</div>
            </div>
            <div class='ertimg'>
              <img :src="qrcodepxImg(ruleForm.id, 'train_out', '')" alt="">
            </div>
            <div class='labl'> 识别【签离】二维码</div>
          </div>
        </div> -->
        <div class='fotbtn'>
          <el-button type="primary" @click.stop="onloadqdImg" :loading="btnLoading">
            <span>下载签到二维码</span>
          </el-button>
          <!-- <el-button type="primary" @click="onloadqlImg">
            <span>下载签离二维码</span>
          </el-button> -->
        </div>
        <div class='backbox'>
          <el-button type="primary" @click="closed">
            <el-icon>
              <Close />
            </el-icon>
            <span>关闭</span>
          </el-button>
        </div>
      </div>

    </div>
  </el-dialog>
</template>

<script setup>
import { qrcodepxImg } from "@/utils/tools.js";
import { defineProps, watch, ref, onMounted } from "vue";
import { Html2canvasImg } from '@/utils/html2pdf.js';
const ruleForm = ref({})
const year = ref(new Date().getFullYear())
const currDate = ref(null)
const props = defineProps({
  modelValue: {
    type: Boolean,
    required: true
  },
  pxinfo: {
    type: Object,
    default: {}
  },
  /** 来自哪里 */
  from: {
    type: String,
    default: ''
  }
});

const emits = defineEmits(["update:modelValue", "choosedUsers"]);
const closed = () => {
  emits("update:modelValue", false);
};
/** 下载loading */
const btnLoading = ref(false)
onMounted(() => {
  const now = new Date();
  currDate.value = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate();
})

watch(
  () => props.modelValue,
  (val) => {
    if (val == true) {
      ruleForm.value = props.pxinfo

    } else {

    }
  }
);
//下载签到二维码
function onloadqdImg() {
  btnLoading.value = true
  Html2canvasImg("qderweima", "签到二维码",()=>{
    btnLoading.value = false
  })
}
//下载签离二维码
function onloadqlImg() {
  Html2canvasImg("qlerweima", "签离二维码")
}





</script>

<style lang="scss" scoped>
@import "@/assets/css/layout.scss";
@import "@/assets/css/element-plus.scss";

.txbox {
  width: 100%;
  height: 700px;
  background-color: #dcdfe6;

  .ingbox {
    width: 800px;
    display: flex;
    justify-content: center;
    margin: auto;
  }
}

.bgbox {
  width: 355px;
  height: 660px;
  background: url("~@/assets/images/qdewm.png") no-repeat center;
  background-size: 100% 100%;
}

.titlbox {
  width: 100%;
  text-align: center;
  color: #fff;
}

.title {
  margin-top: 20px;
  font-size: 20px;
  font-family: monospace;
  display: flex;
  justify-content: center;

  .lines {
    display: block;
    width: 54px;
    margin: 11px;
    height: 1px;
    background-color: #efefef7d;
  }
}

.textbox {
  height: 51px;
  margin: 22px auto;
  width: 73%;
  text-align: center;
  font-size: 19px;
  font-weight: 600;
}

.timbox {
  height: 80px;
  margin: 0 auto;
  padding: 0 10px;
  width: 231px;
  margin-top: 52px;
  text-align: left;
  color: #000;

  >div {
    margin: 6px 0;
  }
}

.ertimg {
  height: 167px;
  overflow: hidden;

  >img {
    display: block;
    width: 179px;
    height: 168px;
    margin: 0 auto;
  }
}

.labl {
  text-align: center;
  font-size: 14px;
  color: #958f8f;
}

.fotbtn {
  position: absolute;
  display: flex;
  justify-content: center;
  bottom: 60px;
  left: 27%;
  width: 568px;
}

.backbox {
  position: absolute;
  top: 64px;
  right: 22px;
}
</style>
