<apex:page standardController="ReceivingNote__c">
|
<apex:includeScript value="{!URLFOR($Resource.qrcode)}"/>
|
<apex:includeScript value="{!URLFOR($Resource.connection20)}"/>
|
<apex:includeScript value="{!URLFOR($Resource.apex20)}"/>
|
|
<div id="qrcode"></div>
|
<script type="text/javascript">
|
function createAttachment() {
|
var div = document.getElementById("qrcode");
|
var img = div.getElementsByTagName("img");
|
var src = img[0].src;
|
src = src.substring(22, src.length);
|
|
sforce.connection.sessionId = '{!GETSESSIONID()}';
|
//20210312 you WLIG-BV8CHF start
|
// var record = sforce.connection.query("select id from Attachment where ParentId = \'{!ReceivingNote__c.Id}\' and name = \'QRCode-{!ReceivingNote__c.ReceivingNoteNo_New__c}\'");
|
// //20231027 ymh添加注释 lighting修改附件上传 start
|
var record = sforce.connection.query("select Id,ContentDocumentId from ContentDocumentLink where LinkedEntityId = \'{!ReceivingNote__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 = \'QRCode-{!ReceivingNote__c.ReceivingNoteNo_New__c}\'");
|
}
|
//20210312 you WLIG-BV8CHF end
|
// 不存在qr文件时,新生成一个,并连到清单上
|
if (record.size == 0) {
|
var version = new sforce.SObject("ContentVersion");
|
version.VersionData = src;
|
version.Title = "QRCode-{!ReceivingNote__c.ReceivingNoteNo_New__c}";
|
version.ContentLocation = 's';
|
version.PathOnClient= "QRCode-{!ReceivingNote__c.ReceivingNoteNo_New__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 = "{!ReceivingNote__c.Id}";
|
link.ShareType = 'I';
|
link.Visibility = 'AllUsers';
|
var result = sforce.connection.create([link]);
|
|
|
|
// var atta = new sforce.SObject("Attachment");
|
// //20210312 you WLIG-BV8CHF start
|
// atta.Name = "QRCode-{!ReceivingNote__c.ReceivingNoteNo_New__c}";
|
// //20210312 you WLIG-BV8CHF end
|
// atta.ParentId = "{!ReceivingNote__c.Id}";
|
// atta.Body = src;
|
// var result = sforce.connection.create([atta]);
|
|
var es = new sforce.SObject("ReceivingNote__c");
|
es.Id = "{!ReceivingNote__c.Id}";
|
es.QRId__c = versionResult[0].id;
|
result = sforce.connection.update([es]);
|
// window.location = '/' + '{!ReceivingNote__c.Id}';
|
} else {
|
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");
|
// 存在qr时,绑到清单上
|
if(version[0].Id != "{!ReceivingNote__c.QRId__c}"){
|
var es = new sforce.SObject("ReceivingNote__c");
|
es.Id = "{!ReceivingNote__c.Id}";
|
es.QRId__c = version[0].id;
|
result = sforce.connection.update([es]);
|
}
|
// window.location = '/' + '{!ReceivingNote__c.Id}';
|
// //20231027 ymh添加注释 lighting修改附件上传 end
|
}
|
}
|
|
var qrcode = new QRCode(document.getElementById("qrcode"), {
|
//20210312 you WLIG-BV8CHF start
|
text: "{!ReceivingNote__c.ReceivingNoteNo_New__c}",
|
//20210312 you WLIG-BV8CHF end
|
width: 128,
|
height: 128,
|
colorDark : "#000000",
|
colorLight : "#ffffff",
|
correctLevel : QRCode.CorrectLevel.H
|
});
|
|
// qrcode生成後、Attachmentを作成
|
setTimeout("createAttachment()", 1000);
|
</script>
|
</apex:page>
|