index.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. shadeClose: true,
  84. content: '../pages/qrcode/preview-code.html?guid=' + data.guid,
  85. end: function () {
  86. }
  87. });
  88. } else if (obj.event === 'print') {//打印
  89. layer.prompt({
  90. formType: 2,
  91. value: '',
  92. title: '请输入打印份数',
  93. area: ['180px', '25px']
  94. }, function (value, index, elem) {
  95. if (/^[0-9]*[1-9][0-9]*$/.test(value)) {
  96. let params = {
  97. "fkBatchRecordGuid": data.guid,
  98. "pageSize": value
  99. }
  100. $.ajax({
  101. url: 'print_qrcode',
  102. type: 'POST',
  103. data: JSON.stringify(params),
  104. contentType: 'application/json',
  105. success: function (res) {
  106. for (let i = 0; i < res.data.length; i++) {
  107. console.log(res.data[i])
  108. print(res.data[i])
  109. }
  110. }
  111. });
  112. layer.close(index);
  113. } else {
  114. layer.msg('请输入纯数字!');
  115. return false;
  116. }
  117. });
  118. }
  119. }
  120. //打印组件
  121. function print(data) {
  122. console.log(data)
  123. let LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM')),
  124. hPos = 10, // 小票上边距
  125. pageWidth = 620, // 小票宽度
  126. rowHeight = 18 // 小票行距
  127. // 初始化
  128. LODOP.PRINT_INIT('打印初始化中')
  129. LODOP.SET_PRINT_STYLEA(0, 'FontName', '黑体')
  130. LODOP.SET_PRINT_STYLEA(0, 'FontSize', 10)
  131. LODOP.SET_PRINT_STYLEA(0, 'Bold', 1)
  132. LODOP.ADD_PRINT_TEXT(hPos, 80, pageWidth, rowHeight, '企业名称:')
  133. LODOP.ADD_PRINT_TEXT(hPos, 140, pageWidth, rowHeight, data.orgName)
  134. hPos += rowHeight
  135. LODOP.ADD_PRINT_TEXT(hPos, 80, pageWidth, rowHeight, '企业电话:')
  136. LODOP.ADD_PRINT_TEXT(hPos, 140, pageWidth, rowHeight, data.companyTel)
  137. hPos += rowHeight
  138. LODOP.ADD_PRINT_TEXT(hPos, 80, pageWidth, rowHeight, '地址:')
  139. LODOP.ADD_PRINT_TEXT(hPos, 110, pageWidth, rowHeight, data.orgAddress)
  140. hPos += rowHeight
  141. LODOP.ADD_PRINT_IMAGE(hPos, 110, 150, 150, '<img width="150" height="150" src="' + window.hywa.config.href + "/" + data.qrImgUrl + '">'); hPos += rowHeight
  142. hPos += 135
  143. LODOP.ADD_PRINT_TEXT(hPos, 80, pageWidth, rowHeight, '防伪码:')
  144. LODOP.ADD_PRINT_TEXT(hPos, 130, pageWidth, rowHeight, data.qrcodeToken)
  145. // LODOP.PREVIEW()
  146. LODOP.PRINT()
  147. var printArred = [];
  148. printArred.push(data.guid)
  149. setPrintDone(printArred)
  150. }
  151. //像服务器发送已启用打印的二维码
  152. function setPrintDone(data) {
  153. $.ajax({
  154. url: 'setPrint_done',
  155. type: 'POST',
  156. data: JSON.stringify(data),
  157. contentType: 'application/json',
  158. success: function (res) {
  159. console.log(res)
  160. }
  161. });
  162. }
  163. //列表
  164. var DataList = {
  165. id: funcName,
  166. elem: '#DataTable',
  167. url: funcName + 'List',
  168. page: true,
  169. method: "post",
  170. contentType: 'application/json',
  171. loading: true,
  172. cellMinWidth: 80,
  173. cols: [
  174. [ //标题栏
  175. {
  176. field: 'goodsBatchNo',
  177. title: '批次编码',
  178. align: 'left',
  179. width: 130
  180. }, {
  181. field: 'goodsName',
  182. title: '产品名称',
  183. align: 'left',
  184. width: 180
  185. }, {
  186. field: 'goodsParentQrcode',
  187. title: '溯源码父码',
  188. align: 'left',
  189. width: 120
  190. }, {
  191. field: 'qrcodeRecordTime',
  192. title: '生成时间',
  193. align: 'center',
  194. width: 140
  195. }, {
  196. field: 'originNum',
  197. title: '溯源码数量',
  198. align: 'left',
  199. width: 100
  200. }, {
  201. field: 'cancelNum',
  202. title: '废弃数',
  203. align: 'left',
  204. width: 100
  205. }, {
  206. field: 'usedNum',
  207. title: '已使用数',
  208. align: 'left',
  209. width: 100
  210. }, {
  211. field: 'scanNum',
  212. title: '累计扫码数',
  213. align: 'left',
  214. width: 100
  215. }, {
  216. field: 'scanNum',
  217. title: '累计评论数',
  218. align: 'left',
  219. width: 100
  220. }, {
  221. field: 'notPrintNum',
  222. title: '未打印数量',
  223. align: 'left',
  224. width: 100
  225. }, {
  226. field: 'printNum',
  227. title: '打印数量',
  228. align: 'left',
  229. width: 100
  230. }, {
  231. field: 'operating',
  232. title: '操作',
  233. toolbar: '#operatingTool',
  234. align: 'center',
  235. fixed: 'right',
  236. width: 330
  237. }
  238. ]
  239. ] //设置表头
  240. , done: function (res) {
  241. resetButton(layui.sessionData(window.hywa.sessionTable.tableName).userData.menus.subMenuList, $);
  242. //res.button.add ? $('.add-btn-0').show() : $('.add-btn-0').hide();
  243. }
  244. };
  245. //执行默认渲染表格
  246. table.render(DataList);
  247. //监听产品工具事件条
  248. table.on('tool(DataTable)', function (obj) {
  249. toolOperating(obj);
  250. });
  251. //搜索响应函数
  252. var infoSearch = function (obj) {
  253. table.reload(funcName, { //执行重载
  254. where: obj.field
  255. });
  256. return false;
  257. };
  258. //监听搜索表单事件
  259. form.on("submit(DataSearch)", infoSearch);
  260. $("#addBtn").on("click", function () {
  261. layer.open({
  262. type: 2,
  263. anim: 0,
  264. title: "新增",
  265. area: ['800px', '560px'],
  266. fixed: true,
  267. scrollbar: true,
  268. maxmin: true,
  269. content: 'add_change.html',
  270. end: function () {
  271. table.reload(funcName);
  272. }
  273. });
  274. });
  275. });