<!-- 20211209 ljh 条形码 -->
|
<apex:page standardController="Rental_Apply__c">
|
<apex:includeScript value="{!URLFOR($Resource.connection20)}"/>
|
<apex:includeScript value="{!URLFOR($Resource.apex20)}"/>
|
|
<apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
|
<apex:includeScript value="{!URLFOR($Resource.jqueryBarcode)}"/>
|
<script type="text/javascript">
|
function generateBarcode(){
|
var value = $("#barcodeValue").val();
|
var btype = 'code128';
|
var renderer = 'svg';
|
|
var settings = {
|
output:'svg',
|
bgColor: '#FFFFFF',
|
color: '#000000',
|
showHRI: false,
|
barWidth: '1',
|
barHeight: '50',
|
moduleSize: '5',
|
posX: '10',
|
posY: '20',
|
addQuietZone: '1'
|
};
|
value = {code:value, rect: true};
|
$("#barcodeTarget").html("").show().barcode(value, btype, settings);
|
}
|
$(function(){
|
generateBarcode();
|
});
|
</script>
|
<input type="hidden" id="barcodeValue" value="{!Rental_Apply__c.Name_No__c}"/>
|
<div id="barcodeTarget" class="barcodeTarget"></div>
|
<script type="text/javascript">
|
function getImgBase64(imageBase64){
|
const imgNew = new Image(); // 创建图片容器
|
imgNew.src = imageBase64; //imageBase64 为svg+xml的Base64 文件流
|
// 图片创建后再执行,转Base64过程
|
const canvas = document.createElement("canvas");
|
canvas.width = 320; //设置好 宽高 不然图片 不完整
|
canvas.height = 60;
|
const context = canvas.getContext("2d");
|
context.drawImage(imgNew, 5, 5);
|
let ImgBase64 = canvas.toDataURL("image/png");
|
return ImgBase64
|
}
|
function createAttachmentBrcode() {
|
var img = $("#barcodeTarget img");
|
var src = img[0].src;
|
var srcNew = getImgBase64(src);
|
src = srcNew.substring(22, srcNew.length);
|
sforce.connection.sessionId = '{!GETSESSIONID()}';
|
|
// var record = sforce.connection.query("select id from Attachment where ParentId = \'{!Rental_Apply__c.Id}\' and name = \'BRCode-{!Rental_Apply__c.Name_No__c}\'");
|
var record = sforce.connection.query("select ContentDocumentId from ContentDocumentLink where LinkedEntityId = \'{!Rental_Apply__c.Id}\'");
|
if(record.size > 0){
|
var records = record.getArray("records");
|
var idList = records.map(obj => "'" + obj.ContentDocumentId + "'").join(",");
|
record = sforce.connection.query("select Id from ContentDocument where Id in (" + idList + ") and Title = \'BRCode-{!Rental_Apply__c.Name_No__c}\'");
|
}
|
// 既にあれば無視
|
if (record.size == 0) {
|
var version = new sforce.SObject("ContentVersion");
|
version.VersionData = src;
|
version.Title = "BRCode-{!Rental_Apply__c.Name_No__c}";
|
version.ContentLocation = 's';
|
version.PathOnClient= "BRCode-{!Rental_Apply__c.Name_No__c}.jpg";
|
var versionResult = sforce.connection.create([version]);
|
record = sforce.connection.query("SELECT ContentDocumentId FROM ContentVersion WHERE Id =\'" + versionResult[0].id + "\'");
|
var records = record.getArray("records");
|
var link = new sforce.SObject("ContentDocumentLink");
|
link.ContentDocumentId = records[0].ContentDocumentId;
|
link.LinkedEntityId = "{!Rental_Apply__c.Id}";
|
link.ShareType = 'I';
|
link.Visibility = 'AllUsers';
|
var result = sforce.connection.create([link]);
|
|
// var atta = new sforce.SObject("Attachment");
|
// atta.Name = "BRCode-{!Rental_Apply__c.Name_No__c}";
|
// atta.ParentId = "{!Rental_Apply__c.Id}";
|
// atta.Body = src;
|
// var result = sforce.connection.create([atta]);
|
|
var es = new sforce.SObject("Rental_Apply__c");
|
es.Id = "{!Rental_Apply__c.Id}";
|
es.BRId__c = versionResult[0].id;
|
result = sforce.connection.update([es]);
|
//申请书更新失败的话再次更新
|
} else if ("{!Rental_Apply__c.BRId__c}" == '' || "{!Rental_Apply__c.BRId__c}" == null) {
|
console.log("record.size------222------------",record.size);
|
// var records = record.getArray("records");
|
// var es = new sforce.SObject("Rental_Apply__c");
|
// es.Id = "{!Rental_Apply__c.Id}";
|
// es.BRId__c = records[0].Id;
|
// result = sforce.connection.update([es]);
|
// TODO Name変わる可能性あり、upsertにします
|
var records = record.getArray("records");
|
var version = new sforce.SObject("ContentVersion");
|
version = sforce.connection.query("select Id,ContentDocumentId from ContentVersion where ContentDocumentId = \'" + records[0].id + "\'");
|
version = version.getArray("records");
|
if(version[0].Id != "{!Rental_Apply__c.QRId__c}"){
|
var es = new sforce.SObject("Rental_Apply__c");
|
es.Id = "{!Rental_Apply__c.Id}";
|
es.QRId__c = version[0].id;
|
result = sforce.connection.update([es]);
|
}
|
} else {
|
console.log("record.size------333------------",record.size);
|
// alert(record[0].id);
|
}
|
}
|
// BRcode生成後、Attachmentを作成
|
setTimeout("createAttachmentBrcode()", 1000);
|
</script>
|
</apex:page>
|