index.html 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <!DOCTYPE html>
  2. <html lang="zh-cn">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>浏览页面</title>
  6. <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
  7. <link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
  8. </head>
  9. <body class="pear-container">
  10. <!-- 顶部查询表单 -->
  11. <!-- 数据表格 -->
  12. <div class="layui-card">
  13. <div class="layui-card-body">
  14. <table id="data-table" lay-filter="data-table"></table>
  15. </div>
  16. </div>
  17. <!-- 表格顶部工具栏 -->
  18. <script type="text/html" id="table-toolbar">
  19. <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add" permission="app.admin.bankcard.insert">
  20. <i class="layui-icon layui-icon-add-1"></i>新增
  21. </button>
  22. <button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove" permission="app.admin.bankcard.delete">
  23. <i class="layui-icon layui-icon-delete"></i>删除
  24. </button>
  25. </script>
  26. <!-- 表格行工具栏 -->
  27. <script type="text/html" id="table-bar">
  28. <button class="pear-btn pear-btn-xs tool-btn" lay-event="edit" permission="app.admin.bankcard.update">编辑</button>
  29. <button class="pear-btn pear-btn-xs tool-btn" lay-event="remove" permission="app.admin.bankcard.delete">删除</button>
  30. </script>
  31. <script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
  32. <script src="/app/admin/component/pear/pear.js"></script>
  33. <script src="/app/admin/admin/js/permission.js"></script>
  34. <script src="/app/admin/admin/js/common.js"></script>
  35. <script>
  36. // 相关常量
  37. const PRIMARY_KEY = "id";
  38. const SELECT_API = "/app/admin/bank-card/select";
  39. const UPDATE_API = "/app/admin/bank-card/update";
  40. const DELETE_API = "/app/admin/bank-card/delete";
  41. const INSERT_URL = "/app/admin/bank-card/insert";
  42. const UPDATE_URL = "/app/admin/bank-card/update";
  43. // 表格渲染
  44. layui.use(["table", "form", "common", "popup", "util"], function() {
  45. let table = layui.table;
  46. let form = layui.form;
  47. let $ = layui.$;
  48. let common = layui.common;
  49. let util = layui.util;
  50. // 表头参数
  51. let cols = [
  52. {
  53. type: "checkbox",
  54. align: "center"
  55. },{
  56. title: "id",align: "center",
  57. field: "id",
  58. },{
  59. title: "归属银行",align: "center",
  60. field: "affiliated_bank",
  61. },{
  62. title: "开户人",align: "center",
  63. field: "account_holder",
  64. },{
  65. title: "卡号",align: "center",
  66. field: "card_number",
  67. },{
  68. title: "会员id",align: "center",
  69. field: "uid",
  70. },{
  71. title: "旧归属银行",align: "center",
  72. field: "o_affiliated_bank",
  73. },{
  74. title: "旧开户人",align: "center",
  75. field: "o_account_holder",
  76. },{
  77. title: "旧卡号",align: "center",
  78. field: "o_card_number",
  79. },{
  80. title: "创建时间",align: "center",
  81. field: "created_at",
  82. },{
  83. title: "更新时间",align: "center",
  84. field: "updated_at",
  85. },{
  86. title: "操作",
  87. toolbar: "#table-bar",
  88. align: "center",
  89. fixed: "right",
  90. width: 120,
  91. }
  92. ];
  93. // 渲染表格
  94. table.render({
  95. elem: "#data-table",
  96. url: SELECT_API,
  97. page: true,
  98. cols: [cols],
  99. skin: "line",
  100. size: "lg",
  101. toolbar: "#table-toolbar",
  102. autoSort: false,
  103. defaultToolbar: [{
  104. title: "刷新",
  105. layEvent: "refresh",
  106. icon: "layui-icon-refresh",
  107. }, "filter", "print", "exports"],
  108. done: function () {
  109. layer.photos({photos: 'div[lay-id="data-table"]', anim: 5});
  110. }
  111. });
  112. // 编辑或删除行事件
  113. table.on("tool(data-table)", function(obj) {
  114. if (obj.event === "remove") {
  115. remove(obj);
  116. } else if (obj.event === "edit") {
  117. edit(obj);
  118. }
  119. });
  120. // 表格顶部工具栏事件
  121. table.on("toolbar(data-table)", function(obj) {
  122. if (obj.event === "add") {
  123. add();
  124. } else if (obj.event === "refresh") {
  125. refreshTable();
  126. } else if (obj.event === "batchRemove") {
  127. batchRemove(obj);
  128. }
  129. });
  130. // 表格顶部搜索事件
  131. form.on("submit(table-query)", function(data) {
  132. table.reload("data-table", {
  133. page: {
  134. curr: 1
  135. },
  136. where: data.field
  137. })
  138. return false;
  139. });
  140. // 表格顶部搜索重置事件
  141. form.on("submit(table-reset)", function(data) {
  142. table.reload("data-table", {
  143. where: []
  144. })
  145. });
  146. // 字段允许为空
  147. form.verify({
  148. phone: [/(^$)|^1\d{10}$/, "请输入正确的手机号"],
  149. email: [/(^$)|^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/, "邮箱格式不正确"],
  150. url: [/(^$)|(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/, "链接格式不正确"],
  151. number: [/(^$)|^\d+$/,'只能填写数字'],
  152. date: [/(^$)|^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/, "日期格式不正确"],
  153. identity: [/(^$)|(^\d{15}$)|(^\d{17}(x|X|\d)$)/, "请输入正确的身份证号"]
  154. });
  155. // 表格排序事件
  156. table.on("sort(data-table)", function(obj){
  157. table.reload("data-table", {
  158. initSort: obj,
  159. scrollPos: "fixed",
  160. where: {
  161. field: obj.field,
  162. order: obj.type
  163. }
  164. });
  165. });
  166. // 表格新增数据
  167. let add = function() {
  168. layer.open({
  169. type: 2,
  170. title: "新增",
  171. shade: 0.1,
  172. maxmin: true,
  173. area: [common.isModile()?"100%":"500px", common.isModile()?"100%":"450px"],
  174. content: INSERT_URL
  175. });
  176. }
  177. // 表格编辑数据
  178. let edit = function(obj) {
  179. let value = obj.data[PRIMARY_KEY];
  180. layer.open({
  181. type: 2,
  182. title: "修改",
  183. shade: 0.1,
  184. maxmin: true,
  185. area: [common.isModile()?"100%":"500px", common.isModile()?"100%":"450px"],
  186. content: UPDATE_URL + "?" + PRIMARY_KEY + "=" + value
  187. });
  188. }
  189. // 删除一行
  190. let remove = function(obj) {
  191. return doRemove(obj.data[PRIMARY_KEY]);
  192. }
  193. // 删除多行
  194. let batchRemove = function(obj) {
  195. let checkIds = common.checkField(obj, PRIMARY_KEY);
  196. if (checkIds === "") {
  197. layui.popup.warning("未选中数据");
  198. return false;
  199. }
  200. doRemove(checkIds.split(","));
  201. }
  202. // 执行删除
  203. let doRemove = function (ids) {
  204. let data = {};
  205. data[PRIMARY_KEY] = ids;
  206. layer.confirm("确定删除?", {
  207. icon: 3,
  208. title: "提示"
  209. }, function(index) {
  210. layer.close(index);
  211. let loading = layer.load();
  212. $.ajax({
  213. url: DELETE_API,
  214. data: data,
  215. dataType: "json",
  216. type: "post",
  217. success: function(res) {
  218. layer.close(loading);
  219. if (res.code) {
  220. return layui.popup.failure(res.msg);
  221. }
  222. return layui.popup.success("操作成功", refreshTable);
  223. }
  224. })
  225. });
  226. }
  227. // 刷新表格数据
  228. window.refreshTable = function() {
  229. table.reloadData("data-table", {
  230. scrollPos: "fixed",
  231. done: function (res, curr) {
  232. if (curr > 1 && res.data && !res.data.length) {
  233. curr = curr - 1;
  234. table.reloadData("data-table", {
  235. page: {
  236. curr: curr
  237. },
  238. })
  239. }
  240. }
  241. });
  242. }
  243. })
  244. </script>
  245. </body>
  246. </html>