add.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. {include file="public/header" /}
  2. <body class="gray-bg">
  3. <div class="layui-fluid layui-col-md12">
  4. <div class="layui-card">
  5. <div class="layui-card-body layui-form">
  6. <div class="layui-row layui-col-space10 layui-form-item ">
  7. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  8. <label class="layui-form-label">轮播图片</label>
  9. <input type="hidden" name="image" id="image">
  10. <button type="button" class="layui-btn" id="test5">
  11. 选择文件
  12. </button>
  13. <div class="layui-input-block">
  14. <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
  15. 预览图:
  16. <div class="layui-upload-list" >
  17. <img src="" id="images" style="width:100px;height:100px;">
  18. </div>
  19. </blockquote>
  20. </div>
  21. </div>
  22. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  23. <label class="layui-form-label">url(可为空)</label>
  24. <div class="layui-input-block">
  25. <textarea name="url" placeholder="图片地址(为空请填0)" lay-verify="required" class="layui-textarea" maxlength="200"></textarea>
  26. </div>
  27. </div>
  28. <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
  29. <div class="layui-input-block">
  30. <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
  31. </button>
  32. <button class="layui-btn layui-btn-primary" onclick="wk.layer_close('close')">关闭</button>
  33. </div>
  34. </div>
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. {include file="public/footer" /}
  40. <script>
  41. layui.use(['form'], function() {
  42. var form = layui.form;
  43. form.on('submit(component-form-element)', function (data) {
  44. $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
  45. $.ajax({
  46. url:"{:url('Add')}",
  47. type:'post',
  48. dataType:'json',
  49. data:data.field,
  50. success:function(res){
  51. if (res.code == 200) {
  52. wk.success(res.msg,'wk.layer_close()');
  53. } else {
  54. wk.error(res.msg,'$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\')');
  55. }
  56. }
  57. })
  58. });
  59. });
  60. </script>
  61. <script>
  62. layui.use('upload', function(){
  63. var upload = layui.upload;
  64. var uploadInst = upload.render({
  65. elem: '#test5'
  66. ,url: "{:url('admin/upload/uploadLocality')}"
  67. ,accept: 'images'
  68. ,multiple:false
  69. ,done: function(res){
  70. $('#images').attr("src",res.url);
  71. $('#image').val(res.url);
  72. }
  73. ,error: function(){
  74. }
  75. });
  76. });
  77. </script>
  78. </body>
  79. </html>