<template>
	<el-dialog
		title="下载离职证明"
		:close-on-click-modal="false"
		draggable
		width="1100px"
		height="500px"
		@close="close"
		append-to-body
		v-model="visible">
		<div style="height: calc(100% - 80px);">
			{{works}}

			<el-button type="primary" @click="toHref()">离职证明下载</el-button>
		</div>
		<template #footer>
			<span class="dialog-footer">
			  <el-button @click="close()" icon="el-icon-circle-close">关闭</el-button>
			</span>
		</template>
	</el-dialog>
</template>

<script>
	import enrollmentRegistrationService from '@/api/human/enrollment/EnrollmentRegistrationService'
	import departRegistrationService from '@/api/human/depart/DepartRegistrationService'
	import OSSSerivce, {
		toHrefByUrlAndName
	} from '@/api/sys/OSSService'

    export default {
		data () {
			return {
				dimissionProveUrl: '',
				fileName: '',
				handoverId: '',
				works: '',
				visible: false,
				loading: false,
				isAdmin: false,
			}
		},
		created () {
			this.ossService = new OSSSerivce()
		},

		methods: {
			init (works,handoverId) {
				this.visible = true
				this.works = works
				this.handoverId = handoverId
				this.visible = true
				this.loading = false
				this.$nextTick(() => {
					this.loading = true
					console.log(this.handoverId)
					departRegistrationService.getByHandoverId(this.handoverId).then((data) => {
						this.dimissionProveUrl = data.dimissionProveUrl
						this.fileName = data.name + "离职证明"
						this.loading = false
					})
				})
			},
			toHref () {
				console.log(this.dimissionProveUrl)
				console.log(this.fileName)
				toHrefByUrlAndName(this.dimissionProveUrl,this.fileName)
			},
			close () {
				this.visible = false
			},
			departFreemarker () {
				this.loading = true
				enrollmentRegistrationService.downloadDepartFile(this.handoverId).then((res) => {
					// 将二进制流文件写入excel表，以下为重要步骤
					this.$utils.downloadWord(res, '离职证明.doc')
					this.loading = false
				}).catch(function (err) {
					this.loading = false
					if (err.response) {
						console.log(err.response)
					}
				})
			},

		}
    }
</script>

<style scoped>
</style>
