$(function() {
			let data = [{
					"personName": "zhang123",
					"title": "manager",
					"region": "China",
					"contactNumber": "199 0989 6789",
					"contactEmail": "zhang@gmail.com",
					"contactNumberSelect": "+88"
				},
				{
					"personName": "zhang456",
					"title": "manager",
					"region": "China",
					"contactNumber": "199 0989 6789",
					"contactEmail": "zhang@gmail.com",
					"contactNumberSelect": "+88"
				},
				{
					"personName": "zhang789",
					"title": "manager",
					"region": "China",
					"contactNumber": "199 0989 6789",
					"contactEmail": "zhang@gmail.com",
					"contactNumberSelect": "+88"
				}
			];
			var loginCompany = window.localStorage.getItem("loginCompany");
			if (loginCompany) {
				loginCompany = JSON.parse(loginCompany)
				data = loginCompany.contacters;
				$("#Disciplines").text(loginCompany.Disciplines)
				$("#introduction").text(loginCompany.introduction)
				$("#companyName").text(loginCompany.companyName)
				$("#logo").attr('src', loginCompany.logo)
			}
			const tmphtml = template("list-contacts", {
				contacts: data
			});

			$(".contact-dtl").append(tmphtml);
			const {
				jsPDF
			} = window.jspdf
			$("#down").click(function() {
				// var doc = new jsPDF();
				// doc.text(20, 20, 'Hello world.');
				// doc.save('Test.pdf');
				setTimeout(function(){
					downloadPdf()
				}, 500);
			})

 

			function downloadPdf() {
				var filename = "company_contact.pdf";
				// 将 id 为 content_kong 的 div 渲染成 canvas
				html2canvas(document.getElementById("print"), {
					// 渲染完成时调用，获得 canvas
					onrendered: function(canvas) {

						// 从 canvas 提取图片数据

						var imgData = canvas.toDataURL('image/jpeg', 1);

						var canWidth = canvas.width;
						var canHeight = canvas.height;

						//一页pdf显示html页面生成的canvas高度;
						var pageHeight = canWidth / 592.28 * 841.89;
						//未生成pdf的html页面高度
						var leftHeight = canHeight;
						//pdf页面偏移
						var position = 0;
						//a4纸的尺寸[595.28,841.89]，html页面生成的canvas在pdf中图片的宽高
						var imgWidth = 595.28;
						var imgHeight = 592.28 / canWidth * canHeight;
						//l:横向， p：纵向
						// var doc = new jsPDF("p", "mm", "a4");
						var doc = new jsPDF("p", "pt", "a4");
						//var doc = new jsPDF('', 'in', [(canWidth+10)/dpiX,(canHeight+10)/dpiY]);//设置PDF宽高为要显示的元素的宽高，将像素转化为英寸

						//doc.addImage(imgData, 'JPEG', 0, 0,0,0);
						//doc.addImage(imgData, 'JPEG', 0, 0,dpiX,dpiY);
						if (leftHeight < pageHeight) {
							doc.addImage(imgData, 'JPEG', 0, 0, imgWidth, imgHeight);
						} else {
							while (leftHeight > 0) {
								doc.addImage(pageData, 'JPEG', 0, position + 0, imgWidth, imgHeight);
								leftHeight -= pageHeight;
								position -= 841.89;
								//避免添加空白页
								if (leftHeight > 0) {
									doc.addPage();
								};
							};
						}
						doc.save(filename);
					},
					background: "#ffffff" //设置PDF背景色（默认透明，实际显示为黑色）
				});
			}
})