index.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. <extend name="Public:base" />
  2. <block name="javascript">
  3. <script src="__PUBLIC__/ztree/jquery.ztree.all-3.5.min.js"></script>
  4. <link rel="stylesheet" type="text/css" href="__PUBLIC__/ztree/zTreeStyle.css" />
  5. <link rel="stylesheet" type="text/css" href="__PUBLIC__/ztree/demo.css" />
  6. <script src="__PUBLIC__/fileupload/jquery.ui.widget.js"></script>
  7. <script src="__PUBLIC__/fileupload/jquery.fileupload.js"></script>
  8. <script>
  9. $(function(){
  10. $('.J_SubmitPL').click(function(e){
  11. $("#dialog").css('display','none');
  12. $('.ks-ext-mask').css('display','none');
  13. var zTree = $.fn.zTree.getZTreeObj("category_tree"),
  14. nodes = zTree.getSelectedNodes(),
  15. treeNode = nodes[0];
  16. if(treeNode!=undefined){
  17. var isp= nodes[0].isParent;
  18. }else{
  19. var isp= true;
  20. }
  21. var id=(treeNode==undefined?0:treeNode.id);
  22. var url;
  23. if($("input[name='action']").val()=='add'){
  24. url='{:U("GoodsCategory/add")}';
  25. }else if($("input[name='action']").val()=='edit'){
  26. url='{:U("GoodsCategory/edit")}';
  27. }
  28. $.post(
  29. url,
  30. {
  31. 'id':id,
  32. 'name':$("input[name='name']").val(),
  33. 'image':$("input[name='image']").val(),
  34. 'is_search':$("input[name='is_search']:checked").val(),
  35. 'is_hot':$("input[name='is_hot']:checked").val(),
  36. 'is_haitao':$("input[name='is_haitao']:checked").val(),
  37. 'sort_order':$("input[name='sort_order']").val(),
  38. 'c_sort_order':$("input[name='c_sort_order']").val()
  39. },
  40. function(d){
  41. if($("input[name='action']").val()=='add'){
  42. //有父节点
  43. if(treeNode){
  44. treeNode = zTree.addNodes(treeNode, {id:d.id, pId:id, isParent:isp, name:d.name});
  45. }else{
  46. treeNode = zTree.addNodes(treeNode, {id:d.id, pId:0, isParent:isp, name:d.name});
  47. }
  48. }else{
  49. if(d.success){
  50. nodes[0].name = d.name;
  51. zTree.updateNode(nodes[0]);
  52. alert('操作成功');
  53. }
  54. if(d.err){
  55. alert(d.err);
  56. }
  57. }
  58. }
  59. );
  60. });
  61. });
  62. </script>
  63. <script>
  64. var setting = {
  65. view: {
  66. addHoverDom: false,
  67. removeHoverDom: false,
  68. selectedMulti: false
  69. },
  70. edit: {
  71. enable: true,
  72. editNameSelectAll: true,
  73. showRemoveBtn: false,
  74. showRenameBtn: false
  75. },
  76. data: {
  77. simpleData: {
  78. enable: true
  79. }
  80. }
  81. };
  82. var zNodes ={$list};
  83. function add(e) {
  84. $("input[name='action']").val('add');
  85. $('.title').find('span').text('新增分类');
  86. $("input[name='name']").val('');
  87. $("input[name='image']").val('');
  88. $("input[name='sort_order']").val('');
  89. $("input[name='c_sort_order']").val('');
  90. $('#thumb').find('img').attr('src', $('#thumb').find('img').attr('data-placeholder'));
  91. $("#dialog").css({'position' : 'fixed','display' : 'block', 'z-index' : '9999'});
  92. }
  93. function edit() {
  94. $("input[name='action']").val('edit');
  95. var zTree = $.fn.zTree.getZTreeObj("category_tree"),
  96. nodes = zTree.getSelectedNodes(),
  97. treeNode = nodes[0];
  98. if (nodes.length == 0) {
  99. alert("请先选择一个节点");
  100. return;
  101. }else{
  102. var id=treeNode.id;
  103. $.post(
  104. '{:U("GoodsCategory/get_info")}',
  105. {
  106. 'id':id,
  107. },
  108. function(d){
  109. $("input[name='name']").val(d.name);
  110. $("input[name='image']").val(d.logo);
  111. $("input[name='sort_order']").val(d.sort_order);
  112. $("input[name='c_sort_order']").val(d.c_sort_order);
  113. if(d.is_hot == 1)
  114. {
  115. $(".is_hot1").attr("checked",true);
  116. } else if(d.is_hot ==0)
  117. {
  118. $(".is_hot0").attr("checked",true);
  119. }
  120. if(d.is_search == 1)
  121. {
  122. $(".is_search1").attr("checked",true);
  123. } else if(d.is_hot ==0)
  124. {
  125. $(".is_search0").attr("checked",true);
  126. }
  127. if(d.is_haitao == 1)
  128. {
  129. $(".is_haitao1").attr("checked",true);
  130. } else if(d.is_hot ==0)
  131. {
  132. $(".is_haitao0").attr("checked",true);
  133. }
  134. if(d.thumb_image != '')
  135. $('#thumb').find('img').attr('src', d.thumb_image);
  136. else
  137. $('#thumb').find('img').attr('src', $('#thumb').find('img').attr('data-placeholder'));
  138. }
  139. );
  140. $('.title').find('span').text('编辑分类');
  141. $("#dialog").css({'position' : 'fixed','display' : 'block', 'z-index' : '9999'});
  142. }
  143. }
  144. function remove(e) {
  145. if(!confirm('确认要删除吗!!')){
  146. return false;
  147. }
  148. var zTree = $.fn.zTree.getZTreeObj("category_tree"),
  149. nodes = zTree.getSelectedNodes(),
  150. treeNode = nodes[0];
  151. if (nodes.length == 0) {
  152. alert("请先选择一个节点");
  153. return;
  154. }
  155. $.post(
  156. '{:U("GoodsCategory/del")}',
  157. {
  158. 'id':treeNode.id,
  159. },
  160. function(d){
  161. if(d.err){
  162. alert(d.err);
  163. }else{
  164. zTree.removeNode(treeNode);
  165. }
  166. }
  167. );
  168. }
  169. $(document).ready(function(){
  170. $.fn.zTree.init($("#category_tree"), setting, zNodes);
  171. $("#addParent").bind("click", {isParent:true}, add);
  172. $("#edit").bind("click", edit);
  173. $("#remove").bind("click", remove);
  174. //关闭弹出层
  175. $('#dialog').on('click','.ks-ext-close',function(){
  176. $("#dialog").css('display','none');
  177. $('.ks-ext-mask').css('display','none');
  178. return false;
  179. });
  180. //关闭弹出层
  181. $('#dialog').on('click','.J_Cancel',function(){
  182. $("#dialog").css('display','none');
  183. $('.ks-ext-mask').css('display','none');
  184. return false;
  185. });
  186. });
  187. </script>
  188. <script>
  189. $(function(){
  190. <present name="Think.get.id">
  191. Oscshop.setValue("status", {$blog.status|default=1});
  192. Oscshop.setValue("allow_reply", {$blog.allow_reply|default=1});
  193. </present>
  194. // tooltips on hover button-upload
  195. $('[data-toggle=\'tooltip\']').tooltip({container: 'body', html: true});
  196. // Makes tooltips work on ajax generated content
  197. $(document).ajaxStop(function() {
  198. $('[data-toggle=\'tooltip\']').tooltip({container: 'body'});
  199. });
  200. $(document).delegate('a[data-toggle=\'image\']', 'click', function(e) {
  201. e.preventDefault();
  202. var index=$(this).attr('num');
  203. var element = this;
  204. if(index==undefined){
  205. $(element).popover({
  206. html: true,
  207. placement: 'right',
  208. trigger: 'manual',
  209. content: function() {
  210. return '<button type="button" id="thumb-image" class="btn btn-primary"><i class="icon-edit"></i></button> <button type="button" id="button-clear" class="btn btn-danger"><i class="icon-trash"></i></button>';
  211. }
  212. });
  213. }else{
  214. $(element).popover({
  215. html: true,
  216. placement: 'right',
  217. trigger: 'manual',
  218. content: function() {
  219. return '<button type="button" n="'+index+'" class="btn btn-primary button-image"><i class="icon-edit"></i></button> <button type="button" id="button-clear" class="btn btn-danger"><i class="icon-trash"></i></button>';
  220. }
  221. });
  222. }
  223. $(element).popover('toggle');
  224. //博客图片
  225. $('#thumb-image').on('click', function() {
  226. $('#modal-image').remove();
  227. $('#form-upload').remove();
  228. $('body').prepend('<form enctype="multipart/form-data" id="form-upload" style="display: none;"><input osctype="btn_upload_image" type="file" name="file" /></form>');
  229. $('#form-upload input[name=\'file\']').trigger('click');
  230. $(element).popover('hide');
  231. $('[osctype="btn_upload_image"]').fileupload({
  232. dataType: 'json',
  233. url: "{:U('Image/upload_image',array('dir'=>'category'))}",
  234. add: function(e, data) {
  235. $parent = $('#thumb');
  236. $input = $parent.find('[osctype="image_input"]');
  237. $img = $parent.find('[osctype="image"]');
  238. data.formData = {old_blog_images:$input.val()};
  239. $img.attr('src', "__IMG__/loading.gif");
  240. data.submit();
  241. },
  242. done: function (e,data) {
  243. var image=data.result;
  244. $parent = $('#thumb');
  245. $input = $parent.find('[osctype="image_input"]');
  246. $img = $parent.find('[osctype="image"]');
  247. if(image) {
  248. // $img.prev('i').hide();
  249. $img.attr('src', '__ROOT__'+image.image_thumb);
  250. $img.show();
  251. $input.val(image.image);
  252. } else {
  253. alert('上传失败');
  254. }
  255. }
  256. });
  257. });
  258. $('#button-clear').on('click', function() {
  259. $(element).find('img').attr('src', $(element).find('img').attr('data-placeholder'));
  260. $(element).parent().find('input').attr('value', '');
  261. $(element).popover('hide');
  262. });
  263. });
  264. });
  265. </script>
  266. </block>
  267. <block name="content">
  268. <link rel="stylesheet" href="__CSS__/dialog.css" />
  269. <div class="ks-ext-mask" style="position: fixed; left: 0px; top: 0px; width: 100%; height: 100%; z-index: 999; display:none"></div>
  270. <div id="dialog" class="dialog" style="z-index: 9999; display:none;top:110px;">
  271. <div class="ks-contentbox">
  272. <div class="title"><span>新增分类</span><a class="ks-ext-close" href="javascript:void(0)">X</a></div>
  273. <input type="hidden" name="action" value="" />
  274. <dl>
  275. <dt>分类名称</dt>
  276. <dd><input type="text" name="name" class="text" /></dd>
  277. <dt>
  278. <span title="" data-toggle="tooltip" data-original-title="">分类logo</span>
  279. </dt>
  280. <dd id="thumb">
  281. <a href="#" data-toggle="image" class="img-thumbnail">
  282. <img osctype="image" data-placeholder="__ROOT__/Common/image/no_image_100x100.jpg" src="__ROOT__/Common/image/no_image_100x100.jpg" />
  283. </a>
  284. <input osctype="image_input" type="hidden" name="image" value="" id="input-image" />
  285. </dd>
  286. <dd>是否推荐首页显示:
  287. <input type="radio" name="is_hot" value="0" class="is_hot0" /> 否&nbsp;&nbsp;
  288. <input type="radio" name="is_hot" value="1" class="is_hot1" />是
  289. </dd>
  290. <dd>
  291. 是否搜索页显示:
  292. <input type="radio" name="is_search" value="0" class="is_search0" /> 否&nbsp;&nbsp;
  293. <input type="radio" name="is_search" value="1" class="is_search1" />是
  294. </dd>
  295. <dd>
  296. 是否海淘分类:
  297. <input type="radio" name="is_haitao" value="0" class="is_haitao0" /> 否&nbsp;&nbsp;
  298. <input type="radio" name="is_haitao" value="1" class="is_haitao1" />是
  299. </dd>
  300. <dt>排序</dt>
  301. <dd><input type="text" name="sort_order" class="text" /></dd>
  302. <dt>搜索排序</dt>
  303. <dd><input type="text" name="c_sort_order" class="text" /></dd>
  304. </dl>
  305. <div class="J_DefaultMessage"></div>
  306. <div class="bottom">
  307. <a href="javascript:void(0);" class="J_SubmitPL ncsc-btn ncsc-btn-green">确认</a>
  308. <a href="javascript:void(0);" class="J_Cancel ncsc-btn">取消</a> </div>
  309. </div>
  310. </div>
  311. <div class="page-header">
  312. <a id="addParent" class="btn btn-primary">新增</a>
  313. <a id="edit" class="btn btn-primary">编辑</a>
  314. <a id="remove" class="btn btn-primary">删除</a>
  315. </div>
  316. <div class="row">
  317. <div id="category_tree" class="ztree"></div>
  318. </div>
  319. </block>