index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 = "region";
  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. obj.del();
  35. table.reload(funcName);
  36. }
  37. }
  38. });
  39. });
  40. } else if (obj.event === 'edit') { //修改
  41. layer.open({
  42. type: 2,
  43. anim: 0,
  44. title: "修改",
  45. area: ['800px', '560px'],
  46. fixed: true,
  47. scrollbar: true,
  48. maxmin: true,
  49. content: 'add_change.html?event=edit&guid=' + data.guid,
  50. end: function () {
  51. table.reload(funcName); //重新载入表格
  52. }
  53. });
  54. } else if (obj.event === 'view') { //查看
  55. debugger;
  56. layer.open({
  57. type: 2,
  58. anim: 0,
  59. title: "查看",
  60. area: ['800px', '560px'],
  61. fixed: true,
  62. scrollbar: true,
  63. maxmin: true,
  64. content: 'add_change.html?event=view&guid=' + data.guid,
  65. end: function () {
  66. }
  67. });
  68. }
  69. }
  70. //列表
  71. var DataList = {
  72. id: funcName,
  73. elem: '#DataTable',
  74. url: funcName + 'List',
  75. page: true,
  76. method: "post",
  77. contentType: 'application/json',
  78. loading: true,
  79. cellMinWidth: 80,
  80. cols: [
  81. [ //标题栏
  82. {
  83. field: 'fieldName',
  84. title: '产地名称',
  85. align: 'left',
  86. width: 300
  87. }, {
  88. field: 'saleGoodsRange',
  89. title: '经营产品',
  90. align: 'left',
  91. }, {
  92. field: 'fieldArea',
  93. title: '产地面积',
  94. align: 'left',
  95. width: 140
  96. }, {
  97. field: 'fieldAddress',
  98. title: '产地地址',
  99. align: 'center'
  100. }, {
  101. field: 'remark',
  102. title: '产地简介',
  103. align: 'left',
  104. templet: '<div>{{d.remark.substring(0,30)}}</div>'
  105. }, {
  106. field: 'operating',
  107. title: '操作',
  108. toolbar: '#operatingTool',
  109. align: 'center',
  110. fixed: 'right',
  111. width: 180
  112. }
  113. ]
  114. ] //设置表头
  115. , done: function (res) {
  116. resetButton(layui.sessionData(window.hywa.sessionTable.tableName).userData.menus.subMenuList, $);
  117. //res.button.add ? $('.add-btn-0').show() : $('.add-btn-0').hide();
  118. }
  119. };
  120. //执行默认渲染表格
  121. table.render(DataList);
  122. //监听产品工具事件条
  123. table.on('tool(DataTable)', function (obj) {
  124. toolOperating(obj);
  125. });
  126. //搜索响应函数
  127. var infoSearch = function (obj) {
  128. table.reload(funcName, { //执行重载
  129. where: obj.field
  130. });
  131. return false;
  132. };
  133. //监听搜索表单事件
  134. form.on("submit(DataSearch)", infoSearch);
  135. $("#addBtn").on("click", function () {
  136. layer.open({
  137. type: 2,
  138. anim: 0,
  139. title: "新增",
  140. area: ['800px', '600px'],
  141. fixed: true,
  142. scrollbar: true,
  143. maxmin: true,
  144. content: 'add_change.html',
  145. end: function () {
  146. table.reload(funcName);
  147. }
  148. });
  149. });
  150. });