index.js 6.1 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 = "pdinfo";
  11. var funcName2 = "pdinfo2";
  12. form.verify({
  13. namelength: [
  14. /^.{0,12}$/,
  15. "长度限制在0-12个字符噢"
  16. ]
  17. });
  18. //批次的处理
  19. //工具条处理
  20. function toolOperating(obj) {
  21. var data = obj.data;
  22. if (obj.event === 'del') {
  23. layer.confirm('真的删除吗?', function (index) {
  24. layer.close(index);
  25. var index1 = layer.msg('删除中,请稍候', {
  26. icon: 16,
  27. time: false,
  28. shade: 0.8
  29. });
  30. $.ajax({
  31. type: "get",
  32. url: 'delete_' + funcName + '?guid=' + obj.data.guid,
  33. success: function (res) {
  34. layer.close(index1);
  35. if (!(res.code - 0)) {
  36. obj.del();
  37. table.reload(funcName);
  38. }
  39. }
  40. });
  41. });
  42. } else if (obj.event === 'edit') { //修改
  43. layer.open({
  44. type: 2,
  45. anim: 0,
  46. title: "修改",
  47. area: ['80%', '80%'],
  48. fixed: true,
  49. scrollbar: true,
  50. maxmin: true,
  51. content: 'add_change.html?event=edit&guid=' + data.guid,
  52. end: function () {
  53. table.reload(funcName); //重新载入表格
  54. }
  55. });
  56. } else if (obj.event === 'view') { //查看
  57. layer.open({
  58. type: 2,
  59. anim: 0,
  60. title: "查看",
  61. area: ['80%', '80%'],
  62. fixed: true,
  63. scrollbar: true,
  64. maxmin: true,
  65. content: 'add_change.html?event=view&guid=' + data.guid,
  66. end: function () {
  67. }
  68. });
  69. } else if (obj.event === 'code') { //生成溯源码
  70. layer.open({
  71. type: 2,
  72. anim: 0,
  73. title: "生成溯源码",
  74. area: ['300px', '240px'],
  75. fixed: true,
  76. scrollbar: true,
  77. maxmin: true,
  78. content: 'add_change3.html?event=code&guid=' + data.guid,
  79. end: function () {
  80. }
  81. });
  82. }
  83. }
  84. //列表
  85. var DataList = {
  86. id: funcName,
  87. elem: '#DataTable',
  88. url: funcName + 'List',
  89. page: true,
  90. method: "post",
  91. contentType: 'application/json',
  92. loading: true,
  93. cellMinWidth: 80,
  94. cols: [
  95. [ //标题栏
  96. {
  97. field: 'goodsBatchNo',
  98. title: '批次编码',
  99. align: 'left',
  100. }, {
  101. field: 'goodsName',
  102. title: '产品分类',
  103. align: 'left',
  104. }, {
  105. field: 'goodsUnit',
  106. title: '产品规格',
  107. align: 'left',
  108. }, {
  109. field: 'goodsProductDate',
  110. title: '生产日期',
  111. align: 'center'
  112. }, {
  113. field: 'goodsExpired',
  114. title: '保质期',
  115. align: 'center'
  116. }, {
  117. field: 'operating',
  118. title: '操作',
  119. toolbar: '#operatingTool',
  120. align: 'center',
  121. fixed: 'right',
  122. width: 240
  123. }
  124. ]
  125. ] //设置表头
  126. , done: function (res) {
  127. resetButton(layui.sessionData(window.hywa.sessionTable.tableName).userData.menus.subMenuList, $);
  128. //res.button.add ? $('.add-btn-0').show() : $('.add-btn-0').hide();
  129. }
  130. };
  131. //执行默认渲染表格
  132. table.render(DataList);
  133. //监听产品工具事件条
  134. table.on('tool(DataTable)', function (obj) {
  135. toolOperating(obj);
  136. });
  137. //搜索响应函数
  138. var infoSearch = function (obj) {
  139. table.reload(funcName, { //执行重载
  140. where: obj.field
  141. });
  142. return false;
  143. };
  144. //监听搜索表单事件
  145. form.on("submit(DataSearch)", infoSearch);
  146. var pdName = "", pid = "";
  147. $("#addBtn").on("click", function () {
  148. if (pdName == "") {
  149. layer.msg("请先选择一个产品");
  150. return;
  151. }
  152. layer.open({
  153. type: 2,
  154. anim: 0,
  155. title: "新增",
  156. area: ['90%', '90%'],
  157. fixed: true,
  158. scrollbar: true,
  159. maxmin: true,
  160. content: 'add_change.html?pdName=' + pdName + '&pid=' + pid,
  161. end: function () {
  162. table.reload(funcName);
  163. }
  164. });
  165. });
  166. //产品的处理
  167. //工具条处理
  168. function toolOperating2(obj) {
  169. var data = obj.data;
  170. if (obj.event === 'del') {
  171. layer.confirm('真的删除吗?', function (index) {
  172. layer.close(index);
  173. var index1 = layer.msg('删除中,请稍候', {
  174. icon: 16,
  175. time: false,
  176. shade: 0.8
  177. });
  178. $.ajax({
  179. type: "get",
  180. url: 'delete_' + funcName2 + '?guid=' + obj.data.guid,
  181. success: function (res) {
  182. layer.close(index1);
  183. if (!(res.code - 0)) {
  184. obj.del();
  185. table.reload(funcName2);
  186. }
  187. }
  188. });
  189. });
  190. } else if (obj.event === 'edit') { //修改
  191. layer.open({
  192. type: 2,
  193. anim: 0,
  194. title: "修改",
  195. area: ['300px', '200px'],
  196. fixed: true,
  197. scrollbar: true,
  198. maxmin: true,
  199. content: 'add_change2.html?event=edit&guid=' + data.guid,
  200. end: function () {
  201. table.reload(funcName2); //重新载入表格
  202. }
  203. });
  204. }
  205. }
  206. //列表
  207. var DataList2 = {
  208. id: funcName2,
  209. elem: '#DataTable2',
  210. url: funcName2 + 'List',
  211. page: true,
  212. method: "post",
  213. contentType: 'application/json',
  214. loading: true,
  215. cellMinWidth: 80,
  216. cols: [
  217. [ //标题栏
  218. {
  219. field: 'goodsName',
  220. title: '产品分类',
  221. align: 'left',
  222. }, {
  223. field: 'operating',
  224. title: '操作',
  225. toolbar: '#operatingTool2',
  226. align: 'center',
  227. fixed: 'right',
  228. width: 120
  229. }
  230. ]
  231. ] //设置表头
  232. , done: function (res) {
  233. resetButton(layui.sessionData(window.hywa.sessionTable.tableName).userData.menus.subMenuList, $);
  234. //res.button.add ? $('.add-btn-0').show() : $('.add-btn-0').hide();
  235. }
  236. };
  237. //执行默认渲染表格
  238. table.render(DataList2);
  239. //监听产品工具事件条
  240. table.on('tool(DataTable2)', function (obj) {
  241. toolOperating2(obj);
  242. });
  243. table.on('row(DataTable2)', function (obj) {
  244. $(".my-search")[0].value = obj.data.goodsName;
  245. $(".my-search")[1].value = "";
  246. pdName = obj.data.goodsName;
  247. pid = obj.data.guid;
  248. infoSearch({ field: { goodsName: obj.data.goodsName, goodsBatchNo: obj.data.goodsBatchNo, } })
  249. });
  250. //搜索响应函数
  251. var infoSearch2 = function (obj) {
  252. table.reload(funcName2, { //执行重载
  253. where: obj.field
  254. });
  255. return false;
  256. };
  257. //监听搜索表单事件
  258. form.on("submit(DataSearch2)", infoSearch2);
  259. $("#addBtn2").on("click", function () {
  260. layer.open({
  261. type: 2,
  262. anim: 0,
  263. title: "新增",
  264. area: ['300px', '200px'],
  265. fixed: true,
  266. scrollbar: true,
  267. maxmin: true,
  268. content: 'add_change2.html',
  269. end: function () {
  270. table.reload(funcName2);
  271. }
  272. });
  273. });
  274. });