insert.html 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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/component/jsoneditor/css/jsoneditor.css" />
  8. <link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
  9. </head>
  10. <body>
  11. <form class="layui-form" action="">
  12. <div class="mainBox">
  13. <div class="main-container mr-5">
  14. <div class="layui-form-item">
  15. <label class="layui-form-label">会员账号</label>
  16. <div class="layui-input-block">
  17. <input type="number" name="mobile" value="" class="layui-input">
  18. </div>
  19. </div>
  20. </div>
  21. <div class="main-container mr-5">
  22. <div class="layui-form-item">
  23. <label class="layui-form-label">商品</label>
  24. <div class="layui-input-block">
  25. <div name="goods_id" id="goods_id" value="" ></div>
  26. </div>
  27. </div>
  28. </div>
  29. </div>
  30. <div class="bottom">
  31. <div class="button-container">
  32. <button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit=""
  33. lay-filter="save">
  34. 提交
  35. </button>
  36. <button type="reset" class="pear-btn pear-btn-md">
  37. 重置
  38. </button>
  39. </div>
  40. </div>
  41. </form>
  42. <script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
  43. <script src="/app/admin/component/pear/pear.js"></script>
  44. <script src="/app/admin/component/jsoneditor/jsoneditor.js"></script>
  45. <script src="/app/admin/admin/js/permission.js"></script>
  46. <script>
  47. // 相关接口
  48. const INSERT_API = "/app/admin/my-good/insert";
  49. // 字段 商品ID goods_id
  50. layui.use(["jquery", "xmSelect", "popup"], function() {
  51. layui.$.ajax({
  52. url: "/app/admin/good/addselect",
  53. dataType: "json",
  54. success: function (res) {
  55. let value = layui.$("#goods_id").attr("value");
  56. let initValue = value ? value.split(",") : [];
  57. layui.xmSelect.render({
  58. el: "#goods_id",
  59. name: "goods_id",
  60. initValue: initValue,
  61. filterable: true,
  62. data: res.data,
  63. model: {"icon":"hidden","label":{"type":"text"}},
  64. clickClose: true,
  65. radio: true,
  66. });
  67. if (res.code) {
  68. layui.popup.failure(res.msg);
  69. }
  70. }
  71. });
  72. });
  73. // 字段 商品ID goods_id
  74. layui.use(["jquery", "xmSelect", "popup"], function() {
  75. layui.$.ajax({
  76. url: "/app/admin/goods/addselect",
  77. dataType: "json",
  78. success: function (res) {
  79. let value = layui.$("#goods_id").attr("value");
  80. let initValue = value ? value.split(",") : [];
  81. layui.xmSelect.render({
  82. el: "#goods_id",
  83. name: "goods_id",
  84. initValue: initValue,
  85. filterable: true,
  86. data: res.data,
  87. model: {"icon":"hidden","label":{"type":"text"}},
  88. clickClose: true,
  89. radio: true,
  90. });
  91. if (res.code) {
  92. layui.popup.failure(res.msg);
  93. }
  94. }
  95. });
  96. });
  97. // 字段 状态 1有效 2失效 state
  98. layui.use(["form"], function() {
  99. layui.$("#state").attr("checked", layui.$('input[name="state"]').val() != 0);
  100. layui.form.render();
  101. layui.form.on("switch(state)", function(data) {
  102. layui.$('input[name="state"]').val(this.checked ? 1 : 0);
  103. });
  104. })
  105. // 字段 购买时间 created_at
  106. layui.use(["laydate"], function() {
  107. layui.laydate.render({
  108. elem: "#created_at",
  109. type: "datetime",
  110. });
  111. })
  112. // 字段 更新时间 updated_at
  113. layui.use(["laydate"], function() {
  114. layui.laydate.render({
  115. elem: "#updated_at",
  116. type: "datetime",
  117. });
  118. })
  119. //提交事件
  120. layui.use(["form", "popup"], function () {
  121. // 字段验证允许为空
  122. layui.form.verify({
  123. phone: [/(^$)|^1\d{10}$/, "请输入正确的手机号"],
  124. email: [/(^$)|^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/, "邮箱格式不正确"],
  125. url: [/(^$)|(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/, "链接格式不正确"],
  126. number: [/(^$)|^\d+$/,'只能填写数字'],
  127. date: [/(^$)|^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/, "日期格式不正确"],
  128. identity: [/(^$)|(^\d{15}$)|(^\d{17}(x|X|\d)$)/, "请输入正确的身份证号"]
  129. });
  130. layui.form.on("submit(save)", function (data) {
  131. layui.$.ajax({
  132. url: INSERT_API,
  133. type: "POST",
  134. dateType: "json",
  135. data: data.field,
  136. success: function (res) {
  137. if (res.code) {
  138. return layui.popup.failure(res.msg);
  139. }
  140. return layui.popup.success("操作成功", function () {
  141. parent.refreshTable();
  142. parent.layer.close(parent.layer.getFrameIndex(window.name));
  143. });
  144. }
  145. });
  146. return false;
  147. });
  148. });
  149. </script>
  150. </body>
  151. </html>