<apex:page standardController="ReceivingNote__c">
|
<apex:includeScript value="{!URLFOR($Resource.qrcode)}"/>
|
<!-- <apex:includeScript value="{!URLFOR($Resource.connection20)}"/>
|
<apex:includeScript value="{!URLFOR($Resource.apex20)}"/> -->
|
<apex:includeScript value="/soap/ajax/40.0/connection.js"/>
|
<apex:includeScript value="/soap/ajax/40.0/apex.js"/>
|
|
<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}\'");
|
//20210312 you WLIG-BV8CHF end
|
// 不存在qr文件时,新生成一个,并连到清单上
|
if (record.size == 0) {
|
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 = result[0].id;
|
result = sforce.connection.update([es]);
|
// 存在qr时,绑到清单上
|
} else {
|
var records = record.getArray("records");
|
var es = new sforce.SObject("ReceivingNote__c");
|
es.Id = "{!ReceivingNote__c.Id}";
|
es.QRId__c = records[0].Id;
|
result = sforce.connection.update([es]);
|
}
|
}
|
|
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>
|