trace_basic.html 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. {% load staticfiles %}
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <meta charset="utf-8">
  6. <title>溯源批次</title>
  7. <meta name="renderer" content="webkit">
  8. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  9. <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  10. <link href="{% static '/lib/bootstrap-3.3.7/css/bootstrap.css' %}" rel="stylesheet">
  11. <link rel="stylesheet" href="{% static '/lib/css/ace.min.css' %}" />
  12. <link rel="stylesheet" href="{% static '/lib/layui/css/layui.css' %}">
  13. <style>
  14. html,body{
  15. background: #fff;
  16. }
  17. .searchTable {
  18. position: absolute;
  19. right: 15px;
  20. top: 0;
  21. }
  22. .searchTable input {
  23. height: 30px;
  24. line-height: 33px;
  25. }
  26. .addData {
  27. /* text-align: right; */
  28. }
  29. /* 表格样式 */
  30. .layui-table thead tr {
  31. /* background-color: #e0f6ea; */
  32. }
  33. .layui-table th,
  34. .layui-table tr {
  35. text-align: center;
  36. }
  37. .editBtn,
  38. .delBtn ,
  39. .blue{
  40. cursor: pointer;
  41. margin: 0 5px;
  42. }
  43. .blue{
  44. color: #2571b4;
  45. }
  46. .green {
  47. color: #5FB878;
  48. }
  49. .red {
  50. color: #e01515;
  51. }
  52. .delBtn:hover {
  53. color: #e01515;
  54. text-decoration: underline;
  55. }
  56. .editBtn:hover {
  57. color: #5FB878;
  58. text-decoration: underline;
  59. }
  60. </style>
  61. </head>
  62. <body>
  63. <div class="layui-fluid">
  64. <div class="layui-row layui-col-space15">
  65. <div class="layui-col-md12">
  66. <div class="layui-card">
  67. <div class="layui-card-header">
  68. <div class="searchTable">
  69. <div class="layui-inline">
  70. <input class="layui-input" name="id" id="companyInp" placeholder="请输入设备ID" autocomplete="off">
  71. </div>
  72. <button class="btn btn-sm btn-primary" data-type="reload">搜索</button>
  73. </div>
  74. <div class="addData">
  75. <button class="btn btn-sm btn-primary" data-type="reload" onclick="addData()"> 新建 </button>
  76. </div>
  77. </div>
  78. <div class="layui-card-body">
  79. <table class="layui-hide baseTable" id="conpanyList" lay-filter="conpanyList"></table>
  80. </div>
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. <!-- 溯源码 -->
  86. <div class="modal fade" id="TagIconmodal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
  87. aria-hidden="true">
  88. <div class="modal-dialog" style="width: 350px;">
  89. <div class="modal-content">
  90. <div class="modal-header">
  91. <button type="button" class="close" data-dismiss="modal">
  92. <span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
  93. <h4 class="modal-title" id="H1">溯源码(此码仅供手机追溯预览)
  94. </h4>
  95. </div>
  96. <div class="modal-body">
  97. <div class="row" style="text-align: center;">
  98. <img src="{% static '/img/wechatCode.png'%}" id="tagIcon" style="width: 250px" />
  99. <input type="hidden" value="" id="hid_Number" name="hid_Number" />
  100. </div>
  101. </div>
  102. <div class="modal-footer" style="text-align: center;">
  103. <button type="button" class="layui-btn layui-btn-primary" data-dismiss="modal" style="width: 100%">
  104. 关闭
  105. </button>
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. <script type="text/html" id="barDemo">
  111. <a class="QRcode blue" lay-event="lookQRcode">二维码</a>
  112. |
  113. <a class="editBtn green" lay-event="edit">编辑</a>
  114. |
  115. <a class="delBtn red" lay-event="del">删除</a>
  116. <!-- <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"></a> -->
  117. </script>
  118. <script src="{% static '/lib/js/jquery-2.1.4.min.js' %}"></script>
  119. <script src="{% static '/lib/bootstrap-3.3.7/js/bootstrap.js' %}"></script>
  120. <script src="{% static '/lib/layui/layui.all.js' %}"></script>
  121. <script>
  122. var table, layer;
  123. layui.use(['table', 'layer'], function () {
  124. table = layui.table;
  125. layer = layui.layer;
  126. var data = [
  127. {
  128. "id": '10000',
  129. "basename": "黄瓜",
  130. "time": "202001021041",
  131. "nums": "100",
  132. "remark": "kg/框",
  133. "productionTime": "2020-01-02",
  134. "log": "0",
  135. },
  136. {
  137. "id": '10000',
  138. "basename": "四季豆(菜豆)",
  139. "time": "202002111041",
  140. "nums": "30",
  141. "remark": "kg/框",
  142. "productionTime": "2020-01-22",
  143. "log": "1",
  144. },
  145. {
  146. "id": '10000',
  147. "basename": "冬瓜",
  148. "time": " 201910311445",
  149. "nums": "100",
  150. "remark": "正常",
  151. "productionTime": " 2019-10-31",
  152. "log": "0",
  153. },
  154. {
  155. "id": '10000',
  156. "basename": "黄瓜",
  157. "time": "202001021041",
  158. "nums": "100",
  159. "remark": "kg/框",
  160. "productionTime": "2020-01-02",
  161. "log": "0",
  162. },
  163. {
  164. "id": '10000',
  165. "basename": "黄心菜",
  166. "time": "202001021041",
  167. "nums": "100",
  168. "remark": "kg/框",
  169. "productionTime": "2020-01-02",
  170. "log": "0",
  171. },
  172. {
  173. "id": '10000',
  174. "basename": "甜瓜",
  175. "time": "202001021041",
  176. "nums": "100",
  177. "remark": "kg/框",
  178. "productionTime": "2020-01-02",
  179. "log": "0",
  180. },
  181. ];
  182. // 方法渲染表格
  183. table.render({
  184. elem: '#conpanyList'
  185. // , url: 'list'
  186. , data: data
  187. ,skin: 'line' //行边框风格
  188. ,even: true //开启隔行背景
  189. , method: 'post' //如果无需自定义HTTP类型,可不加该参数
  190. , title: '用户数据表'
  191. , cols: [[
  192. { type: 'checkbox' }
  193. , { field: 'basename', title: '产品名称', }
  194. , { field: 'time', title: '批次', }
  195. , { field: 'nums', title: '数量', }
  196. , { field: 'remark', title: '规格', }
  197. , { field: 'productionTime', title: '生产日期', }
  198. , { field: 'log', title: '日志记录/条', }
  199. , { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 200 }
  200. ]]
  201. , id: 'tableReload'
  202. , page: {
  203. layout: ['prev', 'page', 'next', 'count']
  204. , groups: 3 //只显示 1 个连续页码
  205. , first: true //不显示首页
  206. , last: true //不显示尾页
  207. , theme: '#428bca'
  208. }
  209. });
  210. // table.on('checkbox(conpanyList)', function (obj) {
  211. // console.log(obj.checked); //当前是否选中状态
  212. // console.log(obj.data); //选中行的相关数据
  213. // console.log(obj.type); //如果触发的是全选,则为:all,如果触发的是单选,则为:one
  214. // });
  215. //监听行工具事件
  216. table.on('tool(conpanyList)', function (obj) {
  217. var data = obj.data;
  218. console.log(obj)
  219. id = obj.data.id
  220. if (obj.event === 'edit') {
  221. var index = layer.open({
  222. type: 2,
  223. title: '添加单位信息',
  224. shadeClose: false,
  225. shade: [0.5, '#000'],
  226. area: ['50%', '60%'],
  227. content: '/detection_add?id=' + id //iframe的url
  228. });
  229. } else if (obj.event === 'del') {
  230. var userid = [];
  231. userid.push(id)
  232. layer.confirm('是否删除“ ' + obj.data.name + ' ”!', {
  233. title: '删除'
  234. , icon: 3
  235. , btn: ['确定', '取消']
  236. }, function (index, layero) {
  237. $.ajax({
  238. url: 'dele',
  239. type: 'get',
  240. async: true,
  241. data: {
  242. id: JSON.stringify(userid)
  243. },
  244. // dataType: 'json',
  245. success: function (data) {
  246. if (data == 0) {
  247. //执行重载
  248. var companyInp = $('#companyInp');
  249. table.reload('tableReload', {
  250. where: {
  251. id: companyInp.val()
  252. }
  253. }, 'data');
  254. //无法关闭这个消息框
  255. layer.closeAll('dialog'); //加入这个信息点击确定 会关闭这个消息框
  256. layer.msg("删除成功!", { icon: 1, time: 1000 });
  257. }
  258. },
  259. error: function (type) {
  260. }
  261. })
  262. }
  263. );
  264. } else if (obj.event === 'lookQRcode') {
  265. $('#TagIconmodal').modal('show');
  266. }
  267. });
  268. var $ = layui.$, active = {
  269. reload: function () {
  270. var companyInp = $('#companyInp');
  271. //执行重载
  272. table.reload('tableReload', {
  273. page: {
  274. curr: 1 //重新从第 1 页开始
  275. }
  276. , where: {
  277. id: companyInp.val()
  278. }
  279. }, 'data');
  280. }
  281. };
  282. // 搜索
  283. $('.searchTable .layui-btn').on('click', function () {
  284. var type = $(this).data('type');
  285. active[type] ? active[type].call(this) : '';
  286. });
  287. $('.searchTable #companyInp').on('keyup', function (event) {
  288. if (event.keyCode == 13) {
  289. active.reload()
  290. }
  291. });
  292. });
  293. function addData() {
  294. var index = layer.open({
  295. type: 2,
  296. title: '添加单位信息',
  297. shadeClose: false,
  298. shade: [0.5, '#000'],
  299. area: ['800px', '50%'],
  300. content: 'detection_add' //iframe的url
  301. });
  302. }
  303. </script>
  304. </body>
  305. </html>