subdata.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <!DOCTYPE html>
  2. <html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
  3. <head>
  4. <th:block th:include="include :: header('主子表提交')" />
  5. <th:block th:include="include :: datetimepicker-css" />
  6. </head>
  7. <body class="gray-bg">
  8. <div class="main-content">
  9. <form id="form-add" class="form-horizontal">
  10. <h4 class="form-header h4">客户信息</h4>
  11. <div class="row">
  12. <div class="col-sm-6">
  13. <div class="form-group">
  14. <label class="col-sm-4 control-label is-required">客户名称:</label>
  15. <div class="col-sm-8">
  16. <input name="name" placeholder="请输入客户名称" class="form-control" type="text" maxlength="30">
  17. </div>
  18. </div>
  19. </div>
  20. <div class="col-sm-6">
  21. <div class="form-group">
  22. <label class="col-sm-4 control-label is-required">用户性别:</label>
  23. <div class="col-sm-8">
  24. <select name="sex" class="form-control" th:with="type=${@dict.getType('sys_user_sex')}">
  25. <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
  26. </select>
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. <div class="row">
  32. <div class="col-sm-6">
  33. <div class="form-group">
  34. <label class="col-sm-4 control-label is-required">手机号码:</label>
  35. <div class="col-sm-8">
  36. <input id="phonenumber" name="phonenumber" placeholder="请输入手机号码" class="form-control" type="text" maxlength="11">
  37. </div>
  38. </div>
  39. </div>
  40. <div class="col-sm-6">
  41. <div class="form-group">
  42. <label class="col-sm-4 control-label is-required">生日:</label>
  43. <div class="col-sm-8">
  44. <div class="input-group date">
  45. <input name="birthday" class="form-control" placeholder="yyyy-MM-dd" type="text">
  46. <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. <div class="row">
  53. <div class="col-sm-12">
  54. <div class="form-group">
  55. <label class="col-xs-2 control-label">备注:</label>
  56. <div class="col-xs-10">
  57. <textarea name="remark" maxlength="500" class="form-control" rows="3"></textarea>
  58. </div>
  59. </div>
  60. </div>
  61. </div>
  62. <h4 class="form-header h4">商品数据</h4>
  63. <div class="row">
  64. <div class="col-sm-12">
  65. <button type="button" class="btn btn-white btn-sm" onclick="addColumn()"><i class="fa fa-plus"> 增加</i></button>
  66. <button type="button" class="btn btn-white btn-sm" onclick="sub.delColumn()"><i class="fa fa-minus"> 删除</i></button>
  67. <div class="col-sm-12 select-table table-striped">
  68. <table id="bootstrap-table"></table>
  69. </div>
  70. </div>
  71. </div>
  72. </form>
  73. </div>
  74. <div class="row">
  75. <div class="col-sm-offset-5 col-sm-10">
  76. <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
  77. <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
  78. </div>
  79. </div>
  80. <th:block th:include="include :: footer" />
  81. <th:block th:include="include :: datetimepicker-js" />
  82. <script th:src="@{/js/jquery.tmpl.js}"></script>
  83. <script th:inline="javascript">
  84. $(function() {
  85. // 初始化数据, 可以由后台传过来
  86. var data = [
  87. {
  88. id: "100",
  89. name: "商品名称",
  90. weight: "100",
  91. price: "12.5",
  92. date: "2021-02-01",
  93. type: "1",
  94. },
  95. {
  96. id: "101",
  97. name: "商品名称2",
  98. weight: "50",
  99. price: "10.8",
  100. date: "2021-02-01",
  101. type: "0",
  102. }];
  103. var options = {
  104. data: data,
  105. pagination: false,
  106. showSearch: false,
  107. showRefresh: false,
  108. showToggle: false,
  109. showColumns: false,
  110. sidePagination: "client",
  111. columns: [{
  112. checkbox: true
  113. },
  114. {
  115. field: 'index',
  116. align: 'center',
  117. title: "序号",
  118. formatter: function (value, row, index) {
  119. var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
  120. var columnId = $.common.sprintf("<input type='hidden' name='goods[%s].id' value='%s'>", index, row.id);
  121. return columnIndex + $.table.serialNumber(index) + columnId;
  122. }
  123. },
  124. {
  125. field: 'name',
  126. align: 'center',
  127. title: '商品名称',
  128. formatter: function(value, row, index) {
  129. var html = $.common.sprintf("<input class='form-control' type='text' name='goods[%s].name' value='%s'>", index, value);
  130. return html;
  131. }
  132. },
  133. {
  134. field: 'weight',
  135. align: 'center',
  136. title: '商品重量',
  137. formatter: function(value, row, index) {
  138. var html = $.common.sprintf("<input class='form-control' type='text' name='goods[%s].weight' value='%s'>", index, value);
  139. return html;
  140. }
  141. },
  142. {
  143. field: 'date',
  144. align: 'center',
  145. title: '商品日期',
  146. formatter: function(value, row, index) {
  147. var html = $.common.sprintf("<input class='form-control' type='text' name='goods[%s].date' value='%s' placeholder='yyyy-MM-dd'>", index, value);
  148. return html;
  149. }
  150. },
  151. {
  152. field: 'price',
  153. align: 'center',
  154. title: '商品价格',
  155. formatter: function(value, row, index) {
  156. var html = $.common.sprintf("<input class='form-control' type='text' name='goods[%s].price' value='%s'>", index, value);
  157. return html;
  158. }
  159. },
  160. {
  161. field: 'type',
  162. align: 'center',
  163. title: '商品种类',
  164. formatter: function(value, row, index) {
  165. var data = [{ index: index, type: value }];
  166. return $("#goodsTypeTpl").tmpl(data).html();
  167. }
  168. }]
  169. };
  170. $.table.init(options);
  171. });
  172. /* 主子表-提交 */
  173. function submitHandler(index, layero){
  174. var data = $("#form-add").serializeArray();
  175. alert(JSON.stringify(data))
  176. $.operate.saveModal("/demo/operate/customer/add", data);
  177. }
  178. $("input[name='birthday']").datetimepicker({
  179. format: "yyyy-mm-dd",
  180. minView: "month",
  181. autoclose: true
  182. });
  183. function addColumn() {
  184. var row = {
  185. name: "",
  186. weight: "",
  187. price: "",
  188. date: "",
  189. type: "",
  190. }
  191. sub.addColumn(row);
  192. }
  193. $("#bootstrap-table").on("post-body.bs.table", function (e, args) {
  194. $("input[name$='date']").datetimepicker({
  195. format: "yyyy-mm-dd",
  196. minView: "month",
  197. autoclose: true,
  198. pickerPosition:'top-right'
  199. });
  200. });
  201. </script>
  202. </body>
  203. </html>
  204. <!-- 商品类型 -->
  205. <script id="goodsTypeTpl" type="text/x-jquery-tmpl">
  206. <div>
  207. <select class='form-control' name='goods[${index}].type'>
  208. <option value="">所有</option>
  209. <option value="0" {{if type==="0"}}selected{{/if}}>寒性</option>
  210. <option value="1" {{if type==="1"}}selected{{/if}}>热性</option>
  211. </select>
  212. </div>
  213. </script>