<template>
    <div class="need-know" :id="'need-know_' + keyname" v-if="detail">
        <!-- <h2>{{detail.titleZh}}</h2> -->
        <div class="body" ref="body" v-html="$l(detail, 'content')"></div>
    </div>
</template>
<script>
import {getNeedKnowByKey, download} from '@/api/system/needKnow'
import html2canvas from 'html2canvas'
import FileSaver from 'file-saver'
import saveFie from '@/plugins/download'
export default {
    props:{
        keyname: String
    },
    data(){
        return {
            detail: null
        }
    },
    created(){
        getNeedKnowByKey(this.keyname).then(res => {
            this.detail = res.data
        })
    },
    methods:{
        downloadPdf(){
            download({id: this.detail.id}).then(res => {
                this.$download.pdf(res, '入仓须知.pdf')
            })
        },
        download(){
            // 直接保存图片
            let l = this.$loading()
            /* document.querySelectorAll(`#need-know_${this.keyname} img`).forEach(img => {
                img.setAttribute('crossOrigin', '*')
            }) */
            html2canvas(document.querySelector("#need-know_" + this.keyname)).then(canvas => {
                canvas.toBlob((blob) => {
                    FileSaver.saveAs(blob, this.keyname + '.png')
                })
            }).finally(res => {
                l.close()
            });
        },
    }
}
</script>
<style scoped>
.body img{
    max-width: 100%;
}
.need-know{
    padding: 20px;
}
</style>