index.js 3.2 KB

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