<template>
  <div>
    <el-dialog
      v-loading="loading"
      :show-close="false"
      :close-on-click-modal="false"
      :visible.sync="isShow"
      :title="'活动二维码'"
      :fullscreen="false"
      width="400px"
      custom-class="xl-dialog"
      center
    >
      <img :src="curImgUrl" class="scoped-img">
      <base-form ref="ruleForm" :data="formData" :is-inline="false" label-width="100px">
        <div slot="footer" style="padding-top: 20px;">
          <el-button class="xl-form-btn t2" @click="close">关 闭</el-button>
          <el-button class="xl-form-btn t1" @click="close('confirm')">下载</el-button>
        </div>
      </base-form>
    </el-dialog>
  </div>
</template>
<script>
var QRCode = require('qrcode')
export default {
  components: { },
  mixins,
  props: {
    isShow: Boolean,
    curObj: Object
  },
  inject: ['parentData'],
  data() {
    return {
      formData: [],
      loading: true,
      curImgUrl: '',
    }
  },
  watch: {
    isShow: function(val) {
      if (val) {
        const that = this
        QRCode.toDataURL(that.curObj.code, function (err, url) {
          that.curImgUrl = url
        })
      }
    },
  },
  methods: {
    getDef() {
      let params = { ...this.curObj }
      this.formData = [
      ]
      this.setDefaultValue(params)
    },
    close(str) {
      if (str === 'confirm') {
        const cObj = this.curObj
        let Link = document.createElement("a")
        Link.download = `${cObj.estate_name}${cObj.remark}-活动签到二维码`
        Link.href = this.curImgUrl
        Link.click()
        Link.remove()
      } else {
        this.$emit('close')
        this.setDefaultValue()
      }
    },
  }
}
</script>
<style lang="scss" scoped>
@import '../../../../styles/libEdit.scss';
.lib-edit {
  padding-top: 0;
  ::v-deep .el-form-item {
    margin-bottom: 10px;
  }
  ::v-deep .el-date-editor.el-input {
    width: 100%;
  }
}
::v-deep .img-upload {
  height: 40px;
  overflow: hidden;
  .el-upload {
    height: 35px;
  }
  .icon {
    width: 110px;
    height: 35px;
    line-height: 35px;
    font-size: 20px;
  }
  .img {
    width: 110px;
    height: 35px;
  }
}



.scoped-img {
  width: 360px;
  height: 360px;
}

</style>
