add.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <!DOCTYPE html>
  2. <html lang="zh" xmlns:th="http://www.thymeleaf.org" >
  3. <head>
  4. <th:block th:include="include :: header('新增卡种信息')" />
  5. <th:block th:include="include :: datetimepicker-css" />
  6. <th:block th:include="include :: bootstrap-fileinput-css"/>
  7. </head>
  8. <body class="white-bg">
  9. <div class="wrapper wrapper-content animated fadeInRight ibox-content">
  10. <form class="form-horizontal m" id="form-information-add">
  11. <div class="col-xs-12">
  12. <div class="form-group">
  13. <label class="col-sm-2 control-label is-required">名称:</label>
  14. <div class="col-sm-4">
  15. <input name="name" class="form-control" type="text" maxlength="20" required>
  16. </div>
  17. <label class="col-sm-2 control-label is-required">类型:</label>
  18. <div class="col-sm-4">
  19. <select name="type" class="form-control" th:with="type=${@dict.getType('site_type')}" required>
  20. <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
  21. </select>
  22. </div>
  23. </div>
  24. </div>
  25. <div class="col-xs-12">
  26. <div class="form-group">
  27. <label class="col-sm-2 control-label is-required">可用次数:</label>
  28. <div class="col-sm-4">
  29. <input name="totalNumber" class="form-control" type="number" min="0" step="1" maxlength="8" required>
  30. </div>
  31. <label class="col-sm-2 control-label is-required">原价格:</label>
  32. <div class="col-sm-4">
  33. <input name="originalPrice" class="form-control" type="number" min="0" step="0.01" maxlength="8" required>
  34. </div>
  35. </div>
  36. </div>
  37. <div class="col-xs-12">
  38. <div class="form-group">
  39. <label class="col-sm-2 control-label is-required">会员价格:</label>
  40. <div class="col-sm-4">
  41. <input name="memberPrice" class="form-control" type="number" min="0" step="0.01" maxlength="8" required>
  42. </div>
  43. <label class="col-sm-2 control-label is-required">单次积分:</label>
  44. <div class="col-sm-4">
  45. <input name="point" class="form-control" type="number" min="0" step="1" maxlength="8" required>
  46. </div>
  47. </div>
  48. </div>
  49. <div class="col-xs-12">
  50. <div class="form-group">
  51. <label class="col-sm-2 control-label">使用规则:</label>
  52. <div class="col-sm-8">
  53. <input name="notes" class="form-control" type="hidden" maxlength="255">
  54. <div class="summernote" id = "notes"></div>
  55. </div>
  56. </div>
  57. </div>
  58. <div class="col-xs-12">
  59. <div class="form-group">
  60. <label class="col-sm-2 control-label is-required">图片:</label>
  61. <div class="col-sm-8">
  62. <input type="hidden" name="file">
  63. <div class="file-loading">
  64. <input class="form-control file-upload" id="file" name="file" type="file">
  65. </div>
  66. </div>
  67. </div>
  68. </div>
  69. </form>
  70. </div>
  71. <th:block th:include="include :: footer" />
  72. <th:block th:include="include :: datetimepicker-js" />
  73. <th:block th:include="include :: summernote-js"/>
  74. <th:block th:include="include :: bootstrap-fileinput-js"/>
  75. <th:block th:include="include :: summernote-css"/>
  76. <script th:inline="javascript">
  77. var prefix = ctx + "information"
  78. $("#form-information-add").validate({
  79. focusCleanup: true
  80. });
  81. function submitHandler() {
  82. if ($.validate.form()) {
  83. const originalPrice = parseInt(document.getElementsByName("originalPrice")[0].value);
  84. const memberPrice = parseInt(document.getElementsByName("memberPrice")[0].value);
  85. if (memberPrice>originalPrice){
  86. alert("会员价格不能大于原价格")
  87. }else {
  88. $.operate.save(prefix + "/add", $('#form-information-add').serialize());
  89. }
  90. }
  91. }
  92. $("input[name='expirationDate']").datetimepicker({
  93. format: "yyyy-mm-dd",
  94. minView: "month",
  95. autoclose: true
  96. });
  97. $(".file-upload").fileinput({
  98. uploadUrl: ctx + 'common/upload',
  99. maxFileCount: 1,
  100. allowedFileExtensions:['jpg','png'],
  101. maxFileSize: 10240,
  102. multiple: true,
  103. }).on('fileuploaded', function (event, data, previewId, index) {
  104. var inputName = event.currentTarget.id;
  105. var existingValue = $("input[name='" + inputName + "']").val();
  106. var newValue = data.response.url;
  107. // 如果已经存在值,则在后面加上逗号分隔的新值
  108. if (existingValue) {
  109. $("input[name='" + inputName + "']").val(existingValue + ',' + newValue);
  110. } else {
  111. $("input[name='" + inputName + "']").val(newValue);
  112. }
  113. }).on('fileremoved', function (event, id, index) {
  114. var inputName = event.currentTarget.id;
  115. var existingValue = $("input[name='" + inputName + "']").val();
  116. var fileUrls = existingValue.split(',');
  117. // 移除对应的文件路径
  118. fileUrls.splice(index, 1);
  119. // 重新拼接文件路径
  120. $("input[name='" + inputName + "']").val(fileUrls.join(','));
  121. });
  122. $(function () {
  123. $('.summernote').summernote({
  124. lang: 'zh-CN',
  125. dialogsInBody: true,
  126. height: 150,
  127. callbacks: {
  128. onChange: function (contents, $edittable) {
  129. $("input[name='" + this.id + "']").val(contents);
  130. },
  131. onImageUpload: function (files) {
  132. var obj = this;
  133. var data = new FormData();
  134. data.append("file", files[0]);
  135. $.ajax({
  136. type: "post",
  137. url: ctx + "common/upload",
  138. data: data,
  139. cache: false,
  140. contentType: false,
  141. processData: false,
  142. dataType: 'json',
  143. success: function (result) {
  144. if (result.code == web_status.SUCCESS) {
  145. $('#' + obj.id).summernote('insertImage', result.url);
  146. } else {
  147. $.modal.alertError(result.msg);
  148. }
  149. },
  150. error: function (error) {
  151. $.modal.alertWarning("图片上传失败。");
  152. }
  153. });
  154. }
  155. }
  156. });
  157. });
  158. </script>
  159. </body>
  160. </html>