boutiquevillagl.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. layui.use(['layer', 'table', 'element', 'form','upload'], function () {
  2. var $ = layui.jquery
  3. , layer = layui.layer //弹层
  4. , table = layui.table //表格
  5. , form = layui.form
  6. ,upload = layui.upload
  7. var previd = $('#previd').data('id');
  8. var tableIns = table.render({
  9. elem: '#gulfcitygllist',
  10. url: '/zt/boutiquevillaglform?previd='+previd,
  11. method: 'get',
  12. page: false,
  13. id: 'tablerReload',
  14. cols: [[
  15. {type: 'numbers', title: '序号'},
  16. {field: 'title', title: '标题', width: 400, align: "center"},
  17. {field: 'url', title: '链接地址', width: 400, align: "center"},
  18. {field: 'show_img', title: '图片', width: 400, align: "center",templet: function (d) {
  19. return '<img class="layui_magnify" src="' + d.show_img + '"/>'
  20. }},
  21. {
  22. field: 'sort',
  23. title: '排序',
  24. width: 100,
  25. event: 'sortData',
  26. edit: 'text',
  27. align: 'center',
  28. sort: true,
  29. templet: "#sortBox"
  30. },
  31. {
  32. field: 'state', title: '状态', align: 'center', templet: function (d) {
  33. if (d.state == 1) {
  34. return '<input type="checkbox" checked value="' + d.id + '" data-state="2" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  35. } else {
  36. return '<input type="checkbox" value="' + d.id + '" data-state="1" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  37. }
  38. }
  39. },
  40. {title: '操作', templet: '#gulfcityglfunc', fixed: "right", align: "center"}
  41. ]]
  42. });
  43. table.reload('tablerReload'); //重新加载
  44. //表格头部操作菜单
  45. var $ = layui.$, active = {
  46. addData: function () {
  47. var id = $(this).data('id');
  48. var index = layui.layer.open({
  49. title: "添加湾区导航",
  50. type: 2,
  51. area: ['70%', '50%'],
  52. content: '/zt/boutiquevillagladd?id='+id,
  53. })
  54. },
  55. };
  56. $('.demoTable .layui-btn').on('click', function () {
  57. var type = $(this).data('type');
  58. active[type] ? active[type].call(this) : '';
  59. });
  60. //监听指定开关
  61. form.on('switch(switchTest)', function (data) {
  62. var id = $(this).val();
  63. var state = $(this).data('state');
  64. layer.confirm('确定要修改此操作吗?', {btn: ['确定', '取消']}, function () {
  65. $.post('/zt/gulfcityglstate', {id: id, state: state}, function (data) {
  66. if (data.code == 200) {
  67. layer.msg(data.msg);
  68. table.reload('tablerReload');
  69. } else if (data.code == 300) {
  70. layer.msg(data.msg);
  71. }
  72. })
  73. }, function (aa) {
  74. table.reload('tablerReload'); //重新加载
  75. })
  76. });
  77. //排序
  78. table.on('edit(gulfcitygllist)', function (obj) {
  79. var data = obj.data;
  80. $.post('/zt/gulfcityglsort', {id: data.id, sort: data.sort}, function (data) {
  81. if (data.code == 200) {
  82. layer.msg(data.msg);
  83. } else if (data.code == 300) {
  84. layer.msg(data.msg);
  85. }
  86. })
  87. })
  88. //表格右边操作栏目
  89. table.on('tool(gulfcitygllist)', function (obj) {
  90. var data = obj.data;
  91. var id = data.id;
  92. if (obj.event === 'del') { //删除操作
  93. layer.confirm('确定要删除吗?', {btn: ['确定', '取消']}, function () {
  94. $.post('/zt/gulfcitygldel', {id: id}, function (data) {
  95. if (data.code == 200) {
  96. layer.msg(data.msg);
  97. table.reload('tablerReload');
  98. } else if (data.code == 300) {
  99. layer.msg(data.msg);
  100. }
  101. })
  102. })
  103. } else if (obj.event === 'edit') {//修改排序
  104. var index = layui.layer.open({
  105. title: "广告位编辑",
  106. type: 2,
  107. area: ['70%', '50%'],
  108. content: '/zt/boutiquevillagledit?id='+id,
  109. })
  110. }
  111. })
  112. //图片上传预览
  113. //图片预览
  114. upload.render({
  115. elem: '#test1'
  116. , field: 'img'
  117. , size: 1000 //限制上传图片的大小,单位为KB
  118. , exts: 'png|jpg|jpeg' //只允许上传压缩文件
  119. , auto: false
  120. , choose: function (obj) {
  121. obj.preview(function (index, file, result) {
  122. $('#addfile').attr('src', result); //图片链接(base64)
  123. });
  124. }
  125. });
  126. form.on('submit(add_hainanville)', function (data) {
  127. var formData = new FormData($('form')[0])
  128. if (formData.getAll('img')[0].size == 0) {
  129. layer.msg('请选择图片');
  130. return false;
  131. }
  132. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  133. $.ajax({
  134. cache: false,
  135. type: "post",
  136. url: "/zt/boutiquevillagladdto",
  137. data: formData, // 你的formid
  138. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  139. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  140. error: function (request) {
  141. layer.close(index);
  142. layer.msg("请联系管理员");
  143. },
  144. success: function (data) {
  145. layer.msg(data.msg);
  146. layer.close(layer.index); //关闭当前,
  147. window.parent.location.reload(); //刷新父级页面
  148. }
  149. });
  150. return false;
  151. });
  152. form.on('submit(edit_hainanville)', function (data) {
  153. var formData = new FormData($('form')[0])
  154. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  155. $.ajax({
  156. cache: false,
  157. type: "post",
  158. url: "/zt/boutiquevillagleditto",
  159. data: formData, // 你的formid
  160. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  161. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  162. error: function (request) {
  163. layer.close(index);
  164. layer.msg("请联系管理员");
  165. },
  166. success: function (data) {
  167. layer.msg(data.msg);
  168. layer.close(layer.index); //关闭当前,
  169. window.parent.location.reload(); //刷新父级页面
  170. }
  171. });
  172. return false;
  173. });
  174. })