deliverynote.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  6. <title>送货单</title>
  7. <style>
  8. * { box-sizing: border-box; }
  9. html, body {
  10. margin: 0; min-height: 100%;
  11. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  12. background: #eef3f7; color: #222; font-size: 14px;
  13. }
  14. .bar {
  15. position: sticky; top: 0; z-index: 20;
  16. height: 48px; padding: 0 12px;
  17. background: #3c8dbc; color: #fff;
  18. display: flex; align-items: center; justify-content: space-between;
  19. }
  20. .bar a, .bar button {
  21. color: #fff; text-decoration: none; font-size: 14px; padding: 6px 4px;
  22. background: none; border: 0; font-family: inherit; cursor: pointer;
  23. }
  24. .bar h1 { margin: 0; font-size: 16px; font-weight: 600; }
  25. .bar button:disabled { opacity: .7; }
  26. #note-toast {
  27. position: fixed; left: 50%; bottom: 72px; z-index: 40;
  28. transform: translateX(-50%);
  29. padding: 8px 16px; border-radius: 6px;
  30. background: rgba(0,0,0,.78); color: #fff; font-size: 13px;
  31. pointer-events: none;
  32. }
  33. #save-mask {
  34. display: none; position: fixed; inset: 0; z-index: 30;
  35. background: rgba(0,0,0,.78); flex-direction: column;
  36. align-items: center; justify-content: center; padding: 16px 12px 24px;
  37. }
  38. #save-mask.show { display: flex; }
  39. #save-mask .save-tip { color: #fff; font-size: 14px; margin-bottom: 12px; }
  40. #save-mask img {
  41. max-width: 88%; max-height: 68vh; background: #fff;
  42. -webkit-touch-callout: default;
  43. }
  44. #save-mask .save-actions { margin-top: 14px; }
  45. #save-mask .save-actions button {
  46. min-width: 108px; height: 36px; border: 0; border-radius: 6px;
  47. font-size: 14px; color: #fff; background: #666;
  48. -webkit-tap-highlight-color: transparent;
  49. }
  50. .sheet {
  51. position: relative;
  52. max-width: 420px; margin: 12px auto 24px;
  53. background: #fff; padding: 16px 16px 22px;
  54. box-shadow: 0 1px 6px rgba(0,0,0,.06);
  55. }
  56. .meta-top { font-size: 12px; color: #666; }
  57. .brand { text-align: center; margin-top: 6px; }
  58. .brand .co { font-size: 17px; font-weight: 700; color: #111; line-height: 1.35; }
  59. .brand .doc { margin-top: 4px; font-size: 20px; font-weight: 700; letter-spacing: .3em; color: #222; }
  60. .kv { margin-top: 12px; font-size: 13px; line-height: 1.7; color: #333; }
  61. .kv b { font-weight: 600; color: #555; }
  62. .qr-wrap { text-align: center; margin: 14px 0 8px; }
  63. #qrcode {
  64. display: inline-block; width: 132px; height: 132px;
  65. padding: 6px; border: 1px solid #ddd; background: #fff;
  66. }
  67. #qrcode img, #qrcode canvas { display: block; margin: 0 auto; }
  68. #qrcode table {
  69. width: 120px !important; height: 120px !important;
  70. border-collapse: collapse; table-layout: fixed; margin: 0 auto;
  71. }
  72. #qrcode table td { padding: 0 !important; border: 0 !important; }
  73. .ord-no { text-align: center; font-size: 13px; font-weight: 600; margin: 6px 0 0; letter-spacing: .04em; }
  74. .block { margin-top: 16px; padding-top: 12px; border-top: 1px dashed #ddd; }
  75. .block h2 { margin: 0 0 8px; font-size: 13px; color: #888; font-weight: 600; }
  76. .line { font-size: 13px; line-height: 1.75; color: #333; }
  77. .line span { color: #888; }
  78. @media print {
  79. body { background: #fff; }
  80. .bar, #save-mask, #note-toast { display: none !important; }
  81. .sheet { margin: 0; box-shadow: none; max-width: none; }
  82. }
  83. </style>
  84. </head>
  85. <body>
  86. <div class="bar">
  87. <a href="{:url('index/index/index')}?tab=done" id="btn-note-back">返回</a>
  88. <h1>送货码</h1>
  89. <button type="button" id="btn-note-save">保存</button>
  90. </div>
  91. <div id="save-mask" aria-hidden="true">
  92. <div class="save-tip">长按图片保存到相册或转发</div>
  93. <img id="save-preview" alt="送货码">
  94. <div class="save-actions">
  95. <button type="button" id="btn-save-close">关闭</button>
  96. </div>
  97. </div>
  98. <div id="note-toast" hidden></div>
  99. <div class="sheet">
  100. <div class="meta-top">生成时间:{$note.generated_at|default=''|htmlentities}</div>
  101. <div class="brand">
  102. <div class="co">{$note.supplier_name|default=''|htmlentities}</div>
  103. <div class="doc">送货码</div>
  104. </div>
  105. <div class="kv"><b>客户名称:</b>{notempty name="note.customer_name"}{$note.customer_name|htmlentities}{else /}—{/notempty}</div>
  106. <div class="kv"><b>送货地址:</b>{notempty name="note.address"}{$note.address|htmlentities}{else /}—{/notempty}</div>
  107. <div class="qr-wrap">
  108. <div id="qrcode">{notempty name="note.qr_data_uri"}<img src="{$note.qr_data_uri}" width="120" height="120" alt="送货码">{/notempty}</div>
  109. </div>
  110. <div class="block">
  111. <h2>订单信息</h2>
  112. <div class="line"><span>订单号:</span>{$note.ccydh|default=''|htmlentities}</div>
  113. <div class="line"><span>印件名称:</span>{$note.cyjmc|default=''|htmlentities}</div>
  114. <div class="line"><span>工序名称:</span>{$note.cgymc|default=''|htmlentities}</div>
  115. <div class="line"><span>单位:</span>{$note.cdw|default=''|htmlentities}</div>
  116. <div class="line"><span>订法:</span>{$note.cdf|default=''|htmlentities}</div>
  117. <div class="line"><span>备注:</span>{notempty name="note.remark"}{$note.remark|htmlentities}{else /}—{/notempty}</div>
  118. </div>
  119. <div class="block">
  120. <h2>供应商信息</h2>
  121. <div class="line"><span>供应商名称:</span>{$note.supplier_name|default=''|htmlentities}</div>
  122. <div class="line"><span>姓名:</span>{$note.contact_name|default=''|htmlentities}</div>
  123. <div class="line"><span>手机号:</span>{$note.mobile|default=''|htmlentities}</div>
  124. </div>
  125. </div>
  126. <script src="__CDN__/assets/js/jquery.js"></script>
  127. <script src="__CDN__/assets/js/jquery.qrcode.min.js"></script>
  128. <script>
  129. (function () {
  130. var ccydh = {:json_encode((string)($note['ccydh'] ?? ''), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)};
  131. var saveBlob = null;
  132. var saveUrl = '';
  133. var toastTimer = 0;
  134. var back = document.getElementById('btn-note-back');
  135. if (back) {
  136. back.addEventListener('click', function (e) {
  137. if (window.history.length > 1) {
  138. e.preventDefault();
  139. history.back();
  140. }
  141. });
  142. }
  143. function toast(msg) {
  144. var el = document.getElementById('note-toast');
  145. if (!el) {
  146. return;
  147. }
  148. el.textContent = msg;
  149. el.hidden = false;
  150. clearTimeout(toastTimer);
  151. toastTimer = setTimeout(function () {
  152. el.hidden = true;
  153. }, 1800);
  154. }
  155. function isMobile() {
  156. return /Android|iPhone|iPad|iPod|Mobile|MicroMessenger/i.test(navigator.userAgent || '');
  157. }
  158. function filename() {
  159. return '送货单' + (ccydh ? '-' + ccydh : '') + '.png';
  160. }
  161. function revokeSaveUrl() {
  162. if (saveUrl) {
  163. URL.revokeObjectURL(saveUrl);
  164. saveUrl = '';
  165. }
  166. }
  167. function closeMask() {
  168. var mask = document.getElementById('save-mask');
  169. if (mask) {
  170. mask.classList.remove('show');
  171. mask.setAttribute('aria-hidden', 'true');
  172. }
  173. document.body.style.overflow = '';
  174. }
  175. function showMask(blob) {
  176. var mask = document.getElementById('save-mask');
  177. var img = document.getElementById('save-preview');
  178. if (!mask || !img) {
  179. return;
  180. }
  181. revokeSaveUrl();
  182. saveBlob = blob;
  183. saveUrl = URL.createObjectURL(blob);
  184. img.src = saveUrl;
  185. mask.classList.add('show');
  186. mask.setAttribute('aria-hidden', 'false');
  187. document.body.style.overflow = 'hidden';
  188. }
  189. function tryShare(blob) {
  190. if (!blob || typeof navigator.share !== 'function' || typeof File === 'undefined') {
  191. return Promise.resolve(false);
  192. }
  193. var file = new File([blob], filename(), {type: 'image/png'});
  194. var payload = {files: [file], title: '送货单'};
  195. if (typeof navigator.canShare === 'function' && !navigator.canShare(payload)) {
  196. return Promise.resolve(false);
  197. }
  198. return navigator.share(payload).then(function () {
  199. return true;
  200. }).catch(function (err) {
  201. if (err && err.name === 'AbortError') {
  202. return true;
  203. }
  204. return false;
  205. });
  206. }
  207. function tryDownload(blob) {
  208. if (isMobile()) {
  209. return false;
  210. }
  211. var a = document.createElement('a');
  212. a.href = URL.createObjectURL(blob);
  213. a.download = filename();
  214. a.style.display = 'none';
  215. document.body.appendChild(a);
  216. a.click();
  217. setTimeout(function () {
  218. URL.revokeObjectURL(a.href);
  219. a.remove();
  220. }, 800);
  221. return true;
  222. }
  223. function isDarkColor(color) {
  224. var c = String(color || '').replace(/\s+/g, '').toLowerCase();
  225. if (!c || c === 'transparent' || c === 'rgba(0,0,0,0)') {
  226. return false;
  227. }
  228. if (c === '#000' || c === '#000000' || c === 'black' || c === 'rgb(0,0,0)') {
  229. return true;
  230. }
  231. var m = c.match(/^rgba?\((\d+),(\d+),(\d+)/);
  232. if (m) {
  233. return (parseInt(m[1], 10) + parseInt(m[2], 10) + parseInt(m[3], 10)) < 380;
  234. }
  235. return false;
  236. }
  237. function qrTableToDataUrl(table) {
  238. var n = table.rows.length;
  239. if (!n) {
  240. return '';
  241. }
  242. var c = document.createElement('canvas');
  243. c.width = n;
  244. c.height = n;
  245. var ctx = c.getContext('2d');
  246. if (!ctx) {
  247. return '';
  248. }
  249. ctx.fillStyle = '#ffffff';
  250. ctx.fillRect(0, 0, n, n);
  251. ctx.fillStyle = '#000000';
  252. for (var r = 0; r < n; r++) {
  253. var cells = table.rows[r].cells;
  254. for (var i = 0; i < cells.length; i++) {
  255. var bg = cells[i].style.backgroundColor || '';
  256. if (!bg && window.getComputedStyle) {
  257. bg = getComputedStyle(cells[i]).backgroundColor;
  258. }
  259. if (isDarkColor(bg)) {
  260. ctx.fillRect(i, r, 1, 1);
  261. }
  262. }
  263. }
  264. return c.toDataURL('image/png');
  265. }
  266. function getQrDataUrl() {
  267. var box = document.getElementById('qrcode');
  268. if (!box) {
  269. return '';
  270. }
  271. var img = box.querySelector('img');
  272. if (img && img.src) {
  273. return img.src;
  274. }
  275. var canvas = box.querySelector('canvas');
  276. if (canvas) {
  277. try {
  278. return canvas.toDataURL('image/png');
  279. } catch (e) {}
  280. }
  281. var table = box.querySelector('table');
  282. if (table) {
  283. return qrTableToDataUrl(table);
  284. }
  285. return '';
  286. }
  287. function loadQrImage(src) {
  288. return new Promise(function (resolve) {
  289. if (!src) {
  290. resolve(null);
  291. return;
  292. }
  293. var exist = document.querySelector('#qrcode img');
  294. if (exist && exist.src === src && exist.complete && exist.naturalWidth) {
  295. resolve(exist);
  296. return;
  297. }
  298. var im = new Image();
  299. im.onload = function () {
  300. resolve(im);
  301. };
  302. im.onerror = function () {
  303. resolve(null);
  304. };
  305. im.src = src;
  306. });
  307. }
  308. function wrapText(ctx, text, maxWidth) {
  309. var s = String(text || '');
  310. var lines = [];
  311. var line = '';
  312. for (var i = 0; i < s.length; i++) {
  313. var next = line + s.charAt(i);
  314. if (line && ctx.measureText(next).width > maxWidth) {
  315. lines.push(line);
  316. line = s.charAt(i);
  317. } else {
  318. line = next;
  319. }
  320. }
  321. if (line !== '') {
  322. lines.push(line);
  323. }
  324. return lines.length ? lines : [''];
  325. }
  326. function drawSpacedCenter(ctx, text, x, y, tracking) {
  327. var s = String(text || '');
  328. var extra = tracking * Math.max(0, s.length - 1);
  329. var w = ctx.measureText(s).width + extra;
  330. var left = x - w / 2;
  331. for (var i = 0; i < s.length; i++) {
  332. ctx.fillText(s.charAt(i), left, y);
  333. left += ctx.measureText(s.charAt(i)).width + tracking;
  334. }
  335. }
  336. function drawLabeledLine(ctx, text, x, y, maxWidth, fontFamily) {
  337. var sp = String(text || '').indexOf(':');
  338. var label = sp >= 0 ? text.slice(0, sp + 1) : '';
  339. var rest = sp >= 0 ? text.slice(sp + 1) : text;
  340. ctx.font = '13px ' + fontFamily;
  341. if (!label) {
  342. ctx.fillStyle = '#333333';
  343. wrapText(ctx, text, maxWidth).forEach(function (ln) {
  344. ctx.fillText(ln, x, y);
  345. y += 22;
  346. });
  347. return y;
  348. }
  349. ctx.fillStyle = '#888888';
  350. ctx.fillText(label, x, y);
  351. var lw = ctx.measureText(label).width;
  352. ctx.fillStyle = '#333333';
  353. var firstMax = Math.max(40, maxWidth - lw);
  354. var restLines = wrapText(ctx, rest, firstMax);
  355. if (restLines.length) {
  356. ctx.fillText(restLines[0], x + lw, y);
  357. y += 22;
  358. for (var i = 1; i < restLines.length; i++) {
  359. ctx.fillText(restLines[i], x, y);
  360. y += 22;
  361. }
  362. } else {
  363. y += 22;
  364. }
  365. return y;
  366. }
  367. function drawNoteCanvas(qrImage) {
  368. var sheet = document.querySelector('.sheet');
  369. var cssW = sheet && sheet.offsetWidth ? sheet.offsetWidth : 360;
  370. var pad = 16;
  371. var inner = cssW - pad * 2;
  372. var scale = 2;
  373. var fontFamily = '-apple-system,BlinkMacSystemFont,"PingFang SC","Hiragino Sans GB","Microsoft YaHei",sans-serif';
  374. var probe = document.createElement('canvas').getContext('2d');
  375. if (!probe) {
  376. throw new Error('无法生成图片');
  377. }
  378. var meta = ((document.querySelector('.meta-top') || {}).textContent || '').replace(/\s+/g, ' ').trim();
  379. var co = ((document.querySelector('.brand .co') || {}).textContent || '').replace(/\s+/g, ' ').trim();
  380. var docTitle = ((document.querySelector('.brand .doc') || {}).textContent || '送货单').replace(/\s+/g, ' ').trim();
  381. var kvs = [];
  382. document.querySelectorAll('.sheet > .kv').forEach(function (el) {
  383. kvs.push((el.textContent || '').replace(/\s+/g, ' ').trim());
  384. });
  385. var ordNo = ((document.querySelector('.ord-no') || {}).textContent || '').replace(/\s+/g, ' ').trim();
  386. var blocks = [];
  387. document.querySelectorAll('.sheet > .block').forEach(function (block) {
  388. blocks.push({
  389. title: ((block.querySelector('h2') || {}).textContent || '').replace(/\s+/g, ' ').trim(),
  390. lines: Array.prototype.map.call(block.querySelectorAll('.line'), function (line) {
  391. return (line.textContent || '').replace(/\s+/g, ' ').trim();
  392. })
  393. });
  394. });
  395. var canvas = document.createElement('canvas');
  396. canvas.width = Math.round(cssW * scale);
  397. canvas.height = Math.round(1200 * scale);
  398. var ctx = canvas.getContext('2d');
  399. ctx.scale(scale, scale);
  400. ctx.fillStyle = '#ffffff';
  401. ctx.fillRect(0, 0, cssW, 1200);
  402. ctx.textBaseline = 'top';
  403. var cy = pad;
  404. ctx.font = '12px ' + fontFamily;
  405. ctx.fillStyle = '#666666';
  406. ctx.fillText(meta, pad, cy);
  407. cy += 24;
  408. ctx.font = 'bold 17px ' + fontFamily;
  409. ctx.fillStyle = '#111111';
  410. wrapText(ctx, co, inner).forEach(function (ln) {
  411. var tw = ctx.measureText(ln).width;
  412. ctx.fillText(ln, (cssW - tw) / 2, cy);
  413. cy += 24;
  414. });
  415. cy += 4;
  416. ctx.font = 'bold 20px ' + fontFamily;
  417. ctx.fillStyle = '#222222';
  418. drawSpacedCenter(ctx, docTitle, cssW / 2, cy, 6);
  419. cy += 34;
  420. kvs.forEach(function (kv) {
  421. var sp = kv.indexOf(':');
  422. var label = sp >= 0 ? kv.slice(0, sp + 1) : '';
  423. var val = sp >= 0 ? kv.slice(sp + 1) : kv;
  424. ctx.font = '600 13px ' + fontFamily;
  425. ctx.fillStyle = '#555555';
  426. ctx.fillText(label, pad, cy);
  427. var lw = ctx.measureText(label).width;
  428. ctx.font = '13px ' + fontFamily;
  429. ctx.fillStyle = '#333333';
  430. var valLines = wrapText(ctx, val, Math.max(40, inner - lw));
  431. valLines.forEach(function (ln, i) {
  432. ctx.fillText(ln, pad + (i === 0 ? lw : 0), cy);
  433. cy += 22;
  434. });
  435. cy += 4;
  436. });
  437. cy += 8;
  438. var qrBox = 132;
  439. var qx = (cssW - qrBox) / 2;
  440. ctx.strokeStyle = '#dddddd';
  441. ctx.lineWidth = 1;
  442. ctx.fillStyle = '#ffffff';
  443. ctx.fillRect(qx, cy, qrBox, qrBox);
  444. ctx.strokeRect(qx + 0.5, cy + 0.5, qrBox - 1, qrBox - 1);
  445. if (qrImage) {
  446. ctx.imageSmoothingEnabled = false;
  447. ctx.drawImage(qrImage, qx + 6, cy + 6, 120, 120);
  448. }
  449. cy += qrBox + 8;
  450. ctx.font = 'bold 13px ' + fontFamily;
  451. ctx.fillStyle = '#222222';
  452. var onw = ctx.measureText(ordNo).width;
  453. ctx.fillText(ordNo, (cssW - onw) / 2, cy);
  454. cy += 20;
  455. blocks.forEach(function (block) {
  456. cy += 10;
  457. ctx.strokeStyle = '#dddddd';
  458. ctx.setLineDash([4, 3]);
  459. ctx.beginPath();
  460. ctx.moveTo(pad, cy);
  461. ctx.lineTo(cssW - pad, cy);
  462. ctx.stroke();
  463. ctx.setLineDash([]);
  464. cy += 12;
  465. ctx.font = '600 13px ' + fontFamily;
  466. ctx.fillStyle = '#888888';
  467. ctx.fillText(block.title, pad, cy);
  468. cy += 22;
  469. block.lines.forEach(function (line) {
  470. cy = drawLabeledLine(ctx, line, pad, cy, inner, fontFamily);
  471. });
  472. });
  473. cy += pad;
  474. var out = document.createElement('canvas');
  475. out.width = canvas.width;
  476. out.height = Math.max(1, Math.round(cy * scale));
  477. var octx = out.getContext('2d');
  478. octx.fillStyle = '#ffffff';
  479. octx.fillRect(0, 0, out.width, out.height);
  480. octx.drawImage(canvas, 0, 0);
  481. return out;
  482. }
  483. function canvasToBlob(canvas) {
  484. return new Promise(function (resolve, reject) {
  485. if (canvas.toBlob) {
  486. canvas.toBlob(function (blob) {
  487. if (blob) {
  488. resolve(blob);
  489. } else {
  490. reject(new Error('生成图片失败'));
  491. }
  492. }, 'image/png');
  493. return;
  494. }
  495. try {
  496. var data = canvas.toDataURL('image/png');
  497. var arr = data.split(',');
  498. var bin = atob(arr[1] || '');
  499. var u8 = new Uint8Array(bin.length);
  500. for (var i = 0; i < bin.length; i++) {
  501. u8[i] = bin.charCodeAt(i);
  502. }
  503. resolve(new Blob([u8], {type: 'image/png'}));
  504. } catch (e) {
  505. reject(e);
  506. }
  507. });
  508. }
  509. function captureSheet() {
  510. return loadQrImage(getQrDataUrl()).then(function (qrImage) {
  511. return canvasToBlob(drawNoteCanvas(qrImage));
  512. });
  513. }
  514. var saveBtn = document.getElementById('btn-note-save');
  515. if (saveBtn) {
  516. saveBtn.addEventListener('click', function (e) {
  517. e.preventDefault();
  518. if (saveBtn.disabled) {
  519. return;
  520. }
  521. saveBtn.disabled = true;
  522. saveBtn.textContent = '保存中';
  523. captureSheet().then(function (blob) {
  524. if (!isMobile()) {
  525. return tryShare(blob).then(function (ok) {
  526. if (ok) {
  527. toast('已保存');
  528. return;
  529. }
  530. if (tryDownload(blob)) {
  531. toast('图片已下载');
  532. return;
  533. }
  534. showMask(blob);
  535. });
  536. }
  537. showMask(blob);
  538. }).catch(function () {
  539. toast('保存失败,请稍后重试');
  540. }).then(function () {
  541. saveBtn.disabled = false;
  542. saveBtn.textContent = '保存';
  543. });
  544. });
  545. }
  546. var closeBtn = document.getElementById('btn-save-close');
  547. if (closeBtn) {
  548. closeBtn.addEventListener('click', function (e) {
  549. e.preventDefault();
  550. closeMask();
  551. });
  552. }
  553. function renderQr(text) {
  554. var box = document.getElementById('qrcode');
  555. if (!box) {
  556. return;
  557. }
  558. if (box.querySelector('img')) {
  559. return;
  560. }
  561. if (!text || typeof jQuery === 'undefined' || !jQuery.fn.qrcode) {
  562. return;
  563. }
  564. try {
  565. jQuery(box).empty().qrcode({
  566. width: 120,
  567. height: 120,
  568. text: text,
  569. render: 'table',
  570. correctLevel: 2,
  571. background: '#ffffff',
  572. foreground: '#000000'
  573. });
  574. } catch (err) {
  575. return;
  576. }
  577. var table = box.querySelector('table');
  578. var dataUrl = table ? qrTableToDataUrl(table) : '';
  579. if (!dataUrl) {
  580. return;
  581. }
  582. var img = document.createElement('img');
  583. img.src = dataUrl;
  584. img.width = 120;
  585. img.height = 120;
  586. img.alt = '送货码';
  587. box.innerHTML = '';
  588. box.appendChild(img);
  589. }
  590. var url = {:json_encode((string)($note['scan_url'] ?? ''), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)};
  591. renderQr(url);
  592. })();
  593. </script>
  594. </body>
  595. </html>