index.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. ;
  2. layui.config({
  3. base: "../../js/layuiPlugins/"
  4. }).use(['form', 'layer', 'jquery', 'table', 'laytpl'], function () {
  5. var form = layui.form,
  6. layer = layui.layer,
  7. laytpl = layui.laytpl,
  8. $ = layui.jquery,
  9. table = layui.table;
  10. var funcName = "qrcode";
  11. form.verify({
  12. namelength: [
  13. /^.{0,12}$/,
  14. "长度限制在0-12个字符噢"
  15. ]
  16. });
  17. //工具条处理
  18. function toolOperating(obj) {
  19. var data = obj.data;
  20. if (obj.event === 'del') {
  21. layer.confirm('真的删除吗?', function (index) {
  22. layer.close(index);
  23. var index1 = layer.msg('删除中,请稍候', {
  24. icon: 16,
  25. time: false,
  26. shade: 0.8
  27. });
  28. $.ajax({
  29. type: "get",
  30. url: 'delete_' + funcName + '?guid=' + obj.data.guid,
  31. success: function (res) {
  32. layer.close(index1);
  33. if (!(res.code - 0)) {
  34. table.reload(funcName);
  35. }
  36. }
  37. });
  38. });
  39. } else if (obj.event === 'viewdetail') { //查看
  40. layer.open({
  41. type: 2,
  42. anim: 0,
  43. title: "溯源码预览",
  44. area: ['900px', '560px'],
  45. fixed: true,
  46. scrollbar: true,
  47. maxmin: true,
  48. content: 'add_change.html?event=view&guid=' + data.guid,
  49. end: function () {
  50. }
  51. });
  52. } else if (obj.event === 'drop') { //废弃
  53. layer.confirm('确定废弃吗?', function (index) {
  54. layer.close(index);
  55. var index1 = layer.msg('处理中,请稍候', {
  56. icon: 16,
  57. time: false,
  58. shade: 0.8
  59. });
  60. $.ajax({
  61. type: "get",
  62. url: 'drop_' + funcName + '?guid=' + data.guid,
  63. success: function (res) {
  64. layer.close(index1);
  65. if (!(res.code - 0)) {
  66. table.reload(funcName);
  67. }
  68. }
  69. });
  70. });
  71. } else if (obj.event === 'export') { //导出
  72. var userInfo = layui.sessionData(window.hywa.sessionTable.tableName)
  73. window.open(window.hywa.config.href + window.hywa.config.port.export_qrcode + "?guid=" + data.guid + "&accessToken=" + userInfo.token)
  74. } else if (obj.event === 'view') { //预览
  75. top.layer.open({
  76. type: 2,
  77. anim: 0,
  78. title: "溯源码预览",
  79. area: ['900px', '812px'],
  80. fixed: true,
  81. scrollbar: false,
  82. maxmin: false,
  83. content: '../pages/qrcode/preview-code.html?guid=' + data.guid,
  84. end: function () {
  85. }
  86. });
  87. } else if (obj.event === 'print') {//打印
  88. layer.prompt({
  89. formType: 2,
  90. value: '',
  91. title: '请输入打印份数',
  92. area: ['180px', '25px']
  93. }, function (value, index, elem) {
  94. if (/^[0-9]*[1-9][0-9]*$/.test(value)) {
  95. let params = {
  96. "fkBatchRecordGuid": data.guid,
  97. "pageSize": value
  98. }
  99. $.ajax({
  100. url: 'print_qrcode',
  101. type: 'POST',
  102. data: JSON.stringify(params),
  103. contentType: 'application/json',
  104. success: function (res) {
  105. for (let i = 0; i < res.data.length; i++) {
  106. console.log(res.data[i])
  107. print(res.data[i])
  108. }
  109. }
  110. });
  111. layer.close(index);
  112. } else {
  113. layer.msg('请输入纯数字!');
  114. return false;
  115. }
  116. });
  117. }
  118. }
  119. //打印组件
  120. function print(data) {
  121. console.log(data)
  122. let LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM')),
  123. hPos = 10, // 小票上边距
  124. pageWidth = 620, // 小票宽度
  125. rowHeight = 18 // 小票行距
  126. // 初始化
  127. LODOP.PRINT_INIT('打印初始化中')
  128. LODOP.SET_PRINT_STYLEA(0, 'FontName', '黑体')
  129. LODOP.SET_PRINT_STYLEA(0, 'FontSize', 10)
  130. LODOP.SET_PRINT_STYLEA(0, 'Bold', 1)
  131. LODOP.ADD_PRINT_TEXT(hPos, 80, pageWidth, rowHeight, '企业名称:')
  132. LODOP.ADD_PRINT_TEXT(hPos, 140, pageWidth, rowHeight, data.orgName)
  133. hPos += rowHeight
  134. LODOP.ADD_PRINT_TEXT(hPos, 80, pageWidth, rowHeight, '企业电话:')
  135. LODOP.ADD_PRINT_TEXT(hPos, 140, pageWidth, rowHeight, data.companyTel)
  136. hPos += rowHeight
  137. LODOP.ADD_PRINT_TEXT(hPos, 80, pageWidth, rowHeight, '地址:')
  138. LODOP.ADD_PRINT_TEXT(hPos, 110, pageWidth, rowHeight, data.orgAddress)
  139. hPos += rowHeight
  140. LODOP.ADD_PRINT_IMAGE(hPos, 110, 150, 150, '<img width="150" height="150" src="' + window.hywa.config.href + "/" + data.qrImgUrl + '">'); hPos += rowHeight
  141. hPos += 135
  142. LODOP.ADD_PRINT_TEXT(hPos, 80, pageWidth, rowHeight, '防伪码:')
  143. LODOP.ADD_PRINT_TEXT(hPos, 130, pageWidth, rowHeight, data.qrcodeToken)
  144. // LODOP.PREVIEW()
  145. LODOP.PRINT()
  146. var printArred = [];
  147. printArred.push(data.guid)
  148. setPrintDone(printArred)
  149. }
  150. //像服务器发送已启用打印的二维码
  151. function setPrintDone(data) {
  152. $.ajax({
  153. url: 'setPrint_done',
  154. type: 'POST',
  155. data: JSON.stringify(data),
  156. contentType: 'application/json',
  157. success: function (res) {
  158. console.log(res)
  159. }
  160. });
  161. }
  162. //列表
  163. var DataList = {
  164. id: funcName,
  165. elem: '#DataTable',
  166. url: funcName + 'List',
  167. page: true,
  168. method: "post",
  169. contentType: 'application/json',
  170. loading: true,
  171. cellMinWidth: 80,
  172. cols: [
  173. [ //标题栏
  174. {
  175. field: 'goodsBatchNo',
  176. title: '批次编码',
  177. align: 'left',
  178. width: 130
  179. }, {
  180. field: 'goodsName',
  181. title: '产品名称',
  182. align: 'left',
  183. width: 180
  184. }, {
  185. field: 'goodsParentQrcode',
  186. title: '溯源码父码',
  187. align: 'left',
  188. width: 120
  189. }, {
  190. field: 'qrcodeRecordTime',
  191. title: '生成时间',
  192. align: 'center',
  193. width: 140
  194. }, {
  195. field: 'originNum',
  196. title: '溯源码数量',
  197. align: 'left',
  198. width: 100
  199. }, {
  200. field: 'cancelNum',
  201. title: '废弃数',
  202. align: 'left',
  203. width: 100
  204. }, {
  205. field: 'usedNum',
  206. title: '已使用数',
  207. align: 'left',
  208. width: 100
  209. }, {
  210. field: 'scanNum',
  211. title: '累计扫码数',
  212. align: 'left',
  213. width: 100
  214. }, {
  215. field: 'scanNum',
  216. title: '累计评论数',
  217. align: 'left',
  218. width: 100
  219. }, {
  220. field: 'notPrintNum',
  221. title: '未打印数量',
  222. align: 'left',
  223. width: 100
  224. }, {
  225. field: 'printNum',
  226. title: '打印数量',
  227. align: 'left',
  228. width: 100
  229. }, {
  230. field: 'operating',
  231. title: '操作',
  232. toolbar: '#operatingTool',
  233. align: 'center',
  234. fixed: 'right',
  235. width: 330
  236. }
  237. ]
  238. ] //设置表头
  239. , done: function (res) {
  240. resetButton(layui.sessionData(window.hywa.sessionTable.tableName).userData.menus.subMenuList, $);
  241. //res.button.add ? $('.add-btn-0').show() : $('.add-btn-0').hide();
  242. }
  243. };
  244. //执行默认渲染表格
  245. table.render(DataList);
  246. //监听产品工具事件条
  247. table.on('tool(DataTable)', function (obj) {
  248. toolOperating(obj);
  249. });
  250. //搜索响应函数
  251. var infoSearch = function (obj) {
  252. table.reload(funcName, { //执行重载
  253. where: obj.field
  254. });
  255. return false;
  256. };
  257. //监听搜索表单事件
  258. form.on("submit(DataSearch)", infoSearch);
  259. $("#addBtn").on("click", function () {
  260. layer.open({
  261. type: 2,
  262. anim: 0,
  263. title: "新增",
  264. area: ['800px', '560px'],
  265. fixed: true,
  266. scrollbar: true,
  267. maxmin: true,
  268. content: 'add_change.html',
  269. end: function () {
  270. table.reload(funcName);
  271. }
  272. });
  273. });
  274. });