seat_form.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <div class="layui-fluid">
  2. <div class="layui-row layui-col-space15">
  3. <div class="layui-col-md12">
  4. <div class="layui-form layui-form-pane" lay-filter="{$lay_table}">
  5. <div class="layui-card">
  6. <div class="layui-card-header">活动信息</div>
  7. <div class="layui-card-body" pad15>
  8. <input type="hidden" name="id" value="{:array_get($info,'id')}">
  9. <div class="layui-form-item">
  10. <label class="layui-form-label"><span style="color:#f90c05;">*</span>标题</label>
  11. <div class="layui-input-block">
  12. <input type="text" name="title" value="{:array_get($info,'title')}"
  13. lay-verify="required"
  14. placeholder="请输入标题" autocomplete="off"
  15. class="layui-input">
  16. </div>
  17. </div>
  18. <div class="layui-form-item">
  19. <label class="layui-form-label"><span style="color:#f90c05;">*</span>状态</label>
  20. <div class="layui-input-block">
  21. {volist name="status_list" id="v"}
  22. <input type="radio" name="status" value="{$key}" title="{$v}"
  23. {eq name=":array_get($info,'status',1)" value="$key" }checked{/eq}>
  24. {/volist}
  25. </div>
  26. </div>
  27. <div class="layui-form-item">
  28. <label class="layui-form-label"><span style="color:#f90c05;">*</span>时间</label>
  29. <div class="layui-input-block">
  30. <input type="text" name="start_time" id="start_time"
  31. value="{:array_get($info,'start_time')}" lay-verify="required"
  32. placeholder="请选择..." autocomplete="off" class="layui-input">
  33. </div>
  34. </div>
  35. </div>
  36. <div class="layui-card-header">座位设置</div>
  37. <div class="layui-card-body" pad15>
  38. <div>
  39. <button class="layui-btn layuiadmin-btn" id="add-table" type="button">添加</button>
  40. </div>
  41. <form id="form">
  42. <table class="layui-table">
  43. <colgroup>
  44. <col width="400">
  45. <col width="100">
  46. <col width="100">
  47. </colgroup>
  48. <thead>
  49. <tr>
  50. <th>排数</th>
  51. <th>人数</th>
  52. <th>操作</th>
  53. </tr>
  54. </thead>
  55. <tbody id="tb">
  56. </tbody>
  57. </table>
  58. </form>
  59. </div>
  60. </div>
  61. <div class="layui-form-item">
  62. <div class="layui-input-block">
  63. <input type="button" lay-submit lay-filter="{$lay_btn}" value="确认提交" class="layui-btn">
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. <script>
  71. layui.use(['index', 'form', 'layedit', 'upload', 'laydate'], function () {
  72. const $ = layui.$;
  73. const admin = layui.admin;
  74. const laydate = layui.laydate;
  75. const form = layui.form;
  76. form.render();
  77. laydate.render({
  78. elem: '#start_time',
  79. type: 'datetime'
  80. });
  81. form.on('submit({$lay_btn})', function (obj) {
  82. const index = parent.layer.getFrameIndex(window.name);
  83. admin.req({
  84. url: "{:url('seat/editSeat')}",
  85. type: 'post',
  86. data: obj.field,
  87. done: function (res) {
  88. layer.msg("提交成功", {
  89. icon: 1
  90. });
  91. parent.layui.table.reload('lay-vote-index-table'); //重载表格
  92. parent.layer.close(index);
  93. }
  94. });
  95. });
  96. let data = {$seat_list};
  97. function createTable() {
  98. let html = "";
  99. data.forEach((v, k) => {
  100. html += `<tr>
  101. <td>第${k + 1}排</td>
  102. <td>
  103. <input placeholder="人数"
  104. name="seat_list[]"
  105. lay-verify="required"
  106. value="${v}"
  107. type="number"
  108. class="layui-input"/>
  109. </td>
  110. <td>
  111. <button class="layui-btn layui-btn-danger layuiadmin-btn delete-table" type="button" data-index="${k}">删除</button>
  112. </td>
  113. </tr>`;
  114. });
  115. $('#tb').html(html);
  116. }
  117. createTable();
  118. $('#add-table').click(function () {
  119. data = getFormData();
  120. data.push("");
  121. createTable();
  122. });
  123. $("#tb").on('click', '.delete-table', function () {
  124. let index = $(this).data('index');
  125. if (data.length <= 1) {
  126. return false;
  127. }
  128. data = getFormData();
  129. data.splice(index, 1);
  130. createTable();
  131. });
  132. function getFormData() {
  133. let arr = $('#form').serializeArray();
  134. if (arr.length === 0) {
  135. return arr;
  136. }
  137. let res = [];
  138. arr.map((v, k) => {
  139. res.push(v.value);
  140. })
  141. return res;
  142. }
  143. });
  144. </script>