page_setting.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. {include file='default/base/seller_top'/}
  2. <link rel="stylesheet" href="{$Think.ADMIN_SITE_ROOT}/css/admin.css">
  3. <script src="{$Think.ADMIN_SITE_ROOT}/js/admin.js"></script>
  4. <script src="{$Think.PLUGINS_SITE_ROOT}/jquery.SuperSlide.2.1.1.js"></script>
  5. <link rel="stylesheet" href="{$Think.HOME_SITE_ROOT}/css/editable_page.css">
  6. <link href="{$Think.PLUGINS_SITE_ROOT}/colorpicker/evol.colorpicker.css" rel="stylesheet" type="text/css">
  7. <script src="{$Think.PLUGINS_SITE_ROOT}/colorpicker/evol.colorpicker.min.js"></script>
  8. <script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/jquery.lazyload.min.js"></script>
  9. <script type="text/javascript" charset="utf-8" src="{$Think.PLUGINS_SITE_ROOT}/ueditor/ueditor.config.js"></script>
  10. <script type="text/javascript" charset="utf-8" src="{$Think.PLUGINS_SITE_ROOT}/ueditor/ueditor.all.min.js"> </script>
  11. <script type="text/javascript" charset="utf-8" src="{$Think.PLUGINS_SITE_ROOT}/ueditor/lang/zh-cn/zh-cn.js"></script>
  12. <div class="model-wrapper active">
  13. <div class="model-title"><span class="title">{$Think.lang.model_list}</span><span class="desc">{$Think.lang.model_list_tips}</span></div>
  14. <div class="model-list">
  15. <div id="model_list">
  16. <div class="editable-page-model">
  17. <form>
  18. <div class="model-item-list">
  19. <label class="model-item-wrapper" data-show="1">
  20. <div class="model-item">
  21. <div class="model-image ui-draggable ui-draggable-handle" data-id="7"><img src="{$Think.HOME_SITE_ROOT}/images/editable_page/editable-page-model-7.jpg"></div>
  22. <div class="model-name">一个商品</div>
  23. </div>
  24. </label>
  25. <label class="model-item-wrapper" data-show="1">
  26. <div class="model-item">
  27. <div class="model-image ui-draggable ui-draggable-handle" data-id="5"><img src="{$Think.HOME_SITE_ROOT}/images/editable_page/editable-page-model-5.jpg"></div>
  28. <div class="model-name">两列商品</div>
  29. </div>
  30. </label>
  31. <label class="model-item-wrapper" data-show="1">
  32. <div class="model-item">
  33. <div class="model-image ui-draggable ui-draggable-handle" data-id="4"><img src="{$Think.HOME_SITE_ROOT}/images/editable_page/editable-page-model-4.jpg"></div>
  34. <div class="model-name">一个商品</div>
  35. </div>
  36. </label>
  37. <label class="model-item-wrapper" data-show="1">
  38. <div class="model-item">
  39. <div class="model-image ui-draggable ui-draggable-handle" data-id="3"><img src="{$Think.HOME_SITE_ROOT}/images/editable_page/editable-page-model-3.jpg"></div>
  40. <div class="model-name">三列商品</div>
  41. </div>
  42. </label>
  43. <label class="model-item-wrapper" data-show="0">
  44. <div class="model-item">
  45. <div class="model-image ui-draggable ui-draggable-handle" data-id="2"><img src="{$Think.HOME_SITE_ROOT}/images/editable_page/editable-page-model-2.jpg"></div>
  46. <div class="model-name">富文本</div>
  47. </div>
  48. </label>
  49. <label class="model-item-wrapper" data-show="0">
  50. <div class="model-item">
  51. <div class="model-image ui-draggable ui-draggable-handle" data-id="1"><img src="{$Think.HOME_SITE_ROOT}/images/editable_page/editable-page-model-1.jpg"></div>
  52. <div class="model-name">轮播图</div>
  53. </div>
  54. </label>
  55. </div>
  56. <div class="clear"></div>
  57. </form>
  58. </div>
  59. </div>
  60. </div>
  61. </div>
  62. <div class="pc-page">
  63. <div class="pc-page-content" id="page_content">
  64. {if isset($config_list)}
  65. {foreach name='config_list' item='item' key='key'}
  66. <div onclick="setConfig({$key+1})" data-type="html" data-id="{$key+1}"><div class="model-del iconfont" onclick="delConfig({$key+1})">&#xe6e6;</div>{$item.html|raw}</div>
  67. {/foreach}
  68. {/if}
  69. <div class="pc-page-empty" {if !empty($config_list)}style="display:none"{/if}>请点击组件添加到此区域</div>
  70. </div>
  71. </div>
  72. <div class="page-wrapper" style="display: block;position: relative;">
  73. <div>
  74. <div data-type="load">
  75. {if isset($config_list)}
  76. {foreach name='config_list' item='item' key="key"}
  77. <div data-type="config" data-id="{$key+1}" style="display:none">{$item.config|raw}</div>
  78. {/foreach}
  79. {/if}
  80. </div>
  81. </div>
  82. <div class="footer-btn">
  83. <input class="btn" type="button" value="{$Think.lang.ds_save}" onclick="saveForm()" />
  84. <a href="{:url('home/StoreSpecial/index',['store_id'=>input('param.store_id'),'special_id'=>input('param.editable_page_id')])}" target="_blank"><input class="btn btn-red" type="button" value="预览"/></a>
  85. </div>
  86. </div>
  87. <script>
  88. var ue={}
  89. EDITABLE_PAGE_URL='{$Think.HOME_SITE_URL}/seller_editable_page'
  90. window.UEDITOR_HOME_URL='{$Think.PLUGINS_SITE_ROOT}/ueditor/'
  91. var goods_class={}
  92. function loadGoodsClass(level,id,obj){
  93. id=parseInt(id)
  94. if(goods_class['i_'+id]){
  95. addGoodsClass(level,id,obj)
  96. }else if(level==4){
  97. $('#'+obj).find('*[data-input]').val(id)
  98. }else if(level==1 || id>0){
  99. $.getJSON(EDITABLE_PAGE_URL+'/goods_class?parent_id='+id,function(data){
  100. if(data.code!=10000){
  101. layer.msg(data.message)
  102. }else if(data.result.length){
  103. goods_class['i_'+id]=data.result
  104. addGoodsClass(level,id,obj)
  105. }
  106. })
  107. }
  108. }
  109. function getGoodsClass(id,obj){
  110. $.getJSON(EDITABLE_PAGE_URL+'/goods_class?id='+id,function(data){
  111. if(data.code!=10000){
  112. layer.msg(data.message)
  113. }else{
  114. if(data.result.id.length){
  115. var temp=''
  116. for(var i in data.result.id){
  117. if(i==0){
  118. goods_class['i_0']=data.result.list[i]
  119. }else{
  120. goods_class['i_'+data.result.id[i-1]]=data.result.list[i]
  121. }
  122. i=parseInt(i)
  123. temp+='<select data-level="'+(i+1)+'" onchange="loadGoodsClass('+(i+2)+',$(this).val(),\''+obj+'\')">'
  124. temp+='<option value="0">{$Think.lang.ds_please_choose}</option>'
  125. for(var j in data.result.list[i]){
  126. temp+='<option value="'+data.result.list[i][j]['gc_id']+'" '+(data.result.list[i][j]['gc_id']==data.result.id[i]?'selected=""':'')+'>'+data.result.list[i][j]['gc_name']+'</option>'
  127. }
  128. temp+='</select>'
  129. }
  130. $('#'+obj+' [data-select]').append(temp)
  131. if($('#'+obj+' tbody').length){
  132. var temp=''
  133. var json
  134. var v=$('#'+obj+' *[data-type="template"]').attr('data-value')
  135. if(v){
  136. json=JSON.parse(v)
  137. }
  138. for(var i in data.result.list[data.result.list.length-1]){
  139. temp+='<tr><td class="tl"><label class="checkbox-label"><i class="checkbox-common"><input type="checkbox" onchange="checkboxChange($(this))" /></i><span>'+data.result.list[data.result.list.length-1][i].gc_name+'</span></label></td><td><input type="text" size="1" name="'+$('#'+obj+' *[data-type="template"]').attr('data-name')+'['+data.result.list[data.result.list.length-1][i].gc_id+'][sort]" value="'+((json && json[data.result.list[data.result.list.length-1][i].gc_id])?json[data.result.list[data.result.list.length-1][i].gc_id].sort:"255")+'" '+((json && json[data.result.list[data.result.list.length-1][i].gc_id])?"disabled=''":"")+' /></td></tr>'
  140. }
  141. $('#'+obj+' tbody').html(temp)
  142. }
  143. }
  144. }
  145. })
  146. }
  147. function checkboxChange(obj){
  148. if(obj.is(':checked')){
  149. obj.parents('tr').find('input[type="text"]').removeAttr('disabled');
  150. obj.parent().addClass('selected');
  151. }else{
  152. obj.parents('tr').find('input[type="text"]').attr('disabled','');
  153. obj.parent().removeClass('selected');
  154. }
  155. }
  156. function addGoodsClass(level,id,obj){
  157. if(level==1 || id>0){
  158. $('#'+obj).find('*[data-input]').val(id)
  159. if(goods_class['i_'+id]){
  160. var temp='<option value="0">{$Think.lang.ds_please_choose}</option>'
  161. for(var i in goods_class['i_'+id]){
  162. temp+='<option value="'+goods_class['i_'+id][i]['gc_id']+'">'+goods_class['i_'+id][i]['gc_name']+'</option>'
  163. }
  164. if($('#'+obj).find('select[data-level='+level+']').length){
  165. $('#'+obj).find('select[data-level='+level+']').html(temp)
  166. $('#'+obj).find('select[data-level]:gt('+($('#'+obj).find('select[data-level='+level+']').index()-1)+')').remove()
  167. }else{
  168. $('#'+obj+' [data-select]').append('<select data-level="'+level+'" onchange="loadGoodsClass('+(level+1)+',$(this).val(),\''+obj+'\')">'+temp+'</select>')
  169. }
  170. }
  171. }else{
  172. if(level>2){
  173. $('#'+obj).find('*[data-input]').val($('#'+obj).find('select[data-level='+(level-2)+']').val())
  174. }else{
  175. $('#'+obj).find('*[data-input]').val(0)
  176. }
  177. $('#'+obj).find('select[data-level]:gt('+($('#'+obj).find('select[data-level='+(level-1)+']').index()-1)+')').remove()
  178. }
  179. if($('#'+obj+' tbody').length){
  180. var temp=''
  181. $('#'+obj+' select:last-child').find('option').each(function(){
  182. if($(this).val()>0){
  183. temp+='<tr><td class="tl"><label class="checkbox-label"><i class="checkbox-common"><input type="checkbox" onchange="checkboxChange($(this))" /></i><span>'+$(this).text()+'</span></label></td><td><input type="text" size="1" name="'+$('#'+obj+' *[data-type="template"]').attr('data-name')+'['+$(this).val()+'][sort]" value="255" disabled="" /></td></tr>'
  184. }
  185. })
  186. $('#'+obj+' tbody').html(temp)
  187. }
  188. }
  189. var id={if isset($config_list)}{:count($config_list)}{else}0{/if};
  190. $(function(){
  191. $('#page_content a').removeAttr('href')
  192. //懒加载
  193. $("img.lazyload").lazyload({
  194. effect: "fadeIn",
  195. skip_invisible : false,
  196. threshold : 200,
  197. });
  198. {if isset($config_list)}
  199. {foreach name='config_list' item='item' key='key'}
  200. if(typeof(window['loadHtml{$item.val.editable_page_model_id}'])!='undefined'){
  201. window['loadHtml{$item.val.editable_page_model_id}']($('*[data-type="html"][data-id={$key+1}]'))
  202. }
  203. if(typeof(window['loadConfig{$item.val.editable_page_model_id}'])!='undefined'){
  204. window['loadConfig{$item.val.editable_page_model_id}']($('*[data-type="config"][data-id={$key+1}]'))
  205. }
  206. {/foreach}
  207. {/if}
  208. $('#page_content').sortable();
  209. $('#page_content').disableSelection();
  210. $('.model-wrapper').draggable({ handle: ".model-title" })
  211. $('.model-item-wrapper').click(function(){
  212. var config=$(this).find('.model-image').attr('data-id')
  213. $.getJSON(EDITABLE_PAGE_URL+'/config_load?model_id='+config,function(data){
  214. if(data.code!=10000) {
  215. layer.msg(data.message);
  216. }else{
  217. id++
  218. $('.pc-page-empty').hide()
  219. var obj=$('.active[data-type="html"]')
  220. $('*[data-type="html"]').removeClass('active');
  221. var temp='<div onclick="setConfig('+id+')" class="active" data-type="html" data-id="'+id+'"><div class="model-del iconfont" onclick="delConfig('+id+')">&#xe6e6;</div>'+data.result.html+'</div>'
  222. if(obj.length){
  223. obj.after(temp)
  224. }else{
  225. $('#page_content').append(temp)
  226. }
  227. $('html,body').animate({scrollTop:$('*[data-type="html"][data-id='+id+']').offset().top}, 500);
  228. $('*[data-type="load"]').prepend('<div data-type="config" data-id="'+id+'">'+data.result.config+'</div>')
  229. if(typeof(window['loadHtml'+config])!='undefined'){
  230. window['loadHtml'+config]($('*[data-type="html"][data-id='+id+']'))
  231. }
  232. if(typeof(window['loadConfig'+config])!='undefined'){
  233. window['loadConfig'+config]($('*[data-type="config"][data-id='+id+']'))
  234. }
  235. $('#page_content a').removeAttr('href')
  236. //懒加载
  237. $("img.lazyload").lazyload({
  238. effect: "fadeIn",
  239. skip_invisible : false,
  240. threshold : 200,
  241. });
  242. setConfig(id)
  243. }
  244. })
  245. })
  246. })
  247. // 图片上传ajax
  248. function uploadFile(obj,callback) {
  249. if(!event.target.files[0]){
  250. return false;
  251. }
  252. var formData = new FormData();
  253. formData.append('config_id',0);
  254. formData.append('name','file');
  255. formData.append('file', event.target.files[0]);
  256. $.ajax({
  257. type: "POST",
  258. url : EDITABLE_PAGE_URL+'/image_upload',
  259. dataType : 'json',
  260. data : formData,
  261. contentType: false,
  262. processData: false,
  263. success : function (data, status) {
  264. if (data.code!=10000) {
  265. layer.msg(data.message);
  266. } else {
  267. obj.parents('.uploader-wrapper').find('input[type="hidden"]').val(data.result.file_path);
  268. obj.parents('.uploader-wrapper').find('.uploader-content').hide();
  269. obj.parents('.uploader-wrapper').find('.uploader-image').attr('src', data.result.file_path);
  270. obj.parents('.uploader-wrapper').find('.uploader-image-wrapper').show();
  271. if(callback){
  272. callback(data.result.file_path,obj)
  273. }
  274. }
  275. }
  276. });
  277. return false;
  278. }
  279. function delFile(obj){
  280. obj.parents('.uploader-wrapper').find('input[type="hidden"]').val('');
  281. obj.parents('.uploader-wrapper').find('.uploader-content').show();
  282. obj.parents('.uploader-wrapper').find('.uploader-image').attr('src', '');
  283. obj.parents('.uploader-wrapper').find('.uploader-image-wrapper').hide();
  284. }
  285. function setRadio(obj,callback){
  286. obj.parents('.ds-icon-radio').find('li').removeClass('ds-icon-active')
  287. obj.addClass('ds-icon-active')
  288. obj.parents('.ds-icon-radio').find('input[type="hidden"]').val(obj.attr('data-val'))
  289. if(callback){
  290. callback()
  291. }
  292. }
  293. function setConfig(id){
  294. $('*[data-type="html"].active').removeClass('active')
  295. $('*[data-type="html"][data-id='+id+']').addClass('active')
  296. $('*[data-type="load"]').parent().show()
  297. $('*[data-type="config"]').hide()
  298. $('*[data-type="config"][data-id='+id+']').show()
  299. layer.open({
  300. type: 1,
  301. area: '500px',
  302. maxHeight:600,
  303. title:$('*[data-type="config"][data-id='+id+'] .attr-title').text(),
  304. content: $('*[data-type="config"][data-id='+id+']'),
  305. btn:['保存'],
  306. btn1:function(index){
  307. changeForm($('*[data-type="config"][data-id='+id+']').find('form'),function(){
  308. layer.close(index)
  309. $('*[data-type="load"]').parent().hide()
  310. })
  311. },
  312. btnAlign: 'c',
  313. cancel:function(){
  314. $('*[data-type="load"]').parent().hide()
  315. }
  316. });
  317. }
  318. function delConfig(id){
  319. $('*[data-type="html"][data-id='+id+']').remove()
  320. $('*[data-type="config"][data-id='+id+']').remove()
  321. if(!$('*[data-type="html"]').length){
  322. $('.pc-page-empty').show()
  323. }
  324. event.stopPropagation()
  325. }
  326. var index={}
  327. var html={}
  328. function addModel(obj,id){
  329. index['i_'+id]++
  330. obj.before('<div class="model-item">'+html['i_'+id].replace(/\[i_\d+\]/g,'[i_'+index['i_'+id]+']')+'<div class="model-del iconfont" onclick="delModel($(this))">&#xe696;</div>'+'</div>')
  331. if(typeof(window['loadConfig'+id])!='undefined'){
  332. window['loadConfig'+id](obj.parents('*[data-type="config"]'))
  333. }
  334. }
  335. function delModel(obj){
  336. obj.parents('.model-item').remove()
  337. }
  338. function saveForm(){
  339. var data=[]
  340. $('*[data-type="html"]').each(function(){
  341. data.push(formartForm($('*[data-type="config"][data-id='+$(this).attr('data-id')+']').find('form').serializeArray()))
  342. })
  343. $.ajax({
  344. type: "POST",
  345. url : EDITABLE_PAGE_URL+'/config_edit?page_id={$Request.param.editable_page_id}',
  346. dataType : 'json',
  347. data : {config_list:data},
  348. success : function (data, status) {
  349. layer.msg(data.message)
  350. }
  351. })
  352. }
  353. function formartForm(temp){
  354. var formData={}
  355. var m_s=[]
  356. var m_i=[]
  357. var r={}
  358. for(var i in temp){
  359. var m=temp[i]['name'].match(/(\[([^\[\]]+)\])+?/g)
  360. if(m){
  361. var w={}
  362. for(var j=m.length-1;j>=0;j--){
  363. var o=m[j].match(/\[(.+)\]/)
  364. var t=(j==m.length-1)?temp[i]['value']:w
  365. w={}
  366. if(o[1].match(/^i_\d+$/)){
  367. if(m_s[j]!=o[1]){
  368. if(!m_s[j] || parseInt(o[1].substr(2))<parseInt(m_s[j].substr(2))){
  369. m_i[j]=0
  370. }else{
  371. m_i[j]++
  372. }
  373. m_s[j]=o[1]
  374. }
  375. w[m_i[j]]=t
  376. }else if(o[1].match(/^\d+$/)){
  377. w[o[1].toString()]=t
  378. }else{
  379. w[o[1]]=t
  380. }
  381. }
  382. var n=temp[i]['name'].match(/^([^\[\]]+)/)
  383. r={}
  384. r[n[1]]=w
  385. formData=setAttr(formData,r)
  386. }else{
  387. formData[temp[i]['name']]=temp[i]['value']
  388. }
  389. }
  390. function setAttr(obj,val){
  391. for(var j in val){
  392. if(obj[j]){
  393. obj[j]=setAttr(obj[j],val[j])
  394. return obj
  395. }else{
  396. return Object.assign(obj,val)
  397. }
  398. }
  399. }
  400. return formData
  401. }
  402. function changeForm(obj,callback){
  403. var id=obj.find('input[name="model_id"]').val()
  404. var temp=obj.serializeArray()
  405. var formData=formartForm(temp)
  406. $.ajax({
  407. type: "POST",
  408. url : EDITABLE_PAGE_URL+'/config_load?model_id='+id,
  409. dataType : 'json',
  410. data : {config_info:formData},
  411. success : function (data, status) {
  412. if (data.code!=10000) {
  413. layer.msg(data.message);
  414. } else {
  415. $('*[data-type="html"][data-id='+obj.parents('*[data-type="config"]').attr('data-id')+']').html('<div class="model-del iconfont" onclick="delConfig('+obj.parents('*[data-type="config"]').attr('data-id')+')">&#xe6e6;</div>'+data.result.html)
  416. if(typeof(window['loadHtml'+id])!='undefined'){
  417. window['loadHtml'+id]($('*[data-type="html"][data-id='+obj.parents('*[data-type="config"]').attr('data-id')+']'))
  418. }
  419. $('#page_content a').removeAttr('href')
  420. //懒加载
  421. $("img.lazyload").lazyload({
  422. effect: "fadeIn",
  423. skip_invisible : false,
  424. threshold : 200,
  425. });
  426. if(callback){
  427. callback()
  428. }
  429. }
  430. }
  431. })
  432. }
  433. </script>
  434. <style>
  435. .btn{width:auto}
  436. .page-wrapper .footer-btn{position:fixed;z-index: 10;}
  437. *[data-type="config"]{padding:20px}
  438. *[data-type="config"] .attr-title{display: none;}
  439. *[data-type="html"].active{border:0}
  440. *[data-type="html"].active::after{content:'';position: absolute;width:1200px;top:0;bottom:0;border:1px dashed #FF6A00;left:50%;margin-left:-600px}
  441. *[data-type="html"] .model-del{right:50%;top:0;margin-right:-600px;width:30px;height: 30px;line-height: 30px;z-index: 10;}
  442. .model-wrapper{position: fixed;top:80px;left:-180px;z-index: 100000;width:227px;background: #fff}
  443. .model-wrapper.active{left:0;}
  444. .model-wrapper .model-title{cursor: move}
  445. .pc-page .pc-page-header,.pc-page .pc-page-footer{text-align: center;background-color: #fff;opacity: .5;}
  446. .pc-page .pc-page-header img,.pc-page .pc-page-footer img{width: 1200px;}
  447. .pc-page .pc-page-content .pc-page-empty{font-size: 24px;font-weight:bold;text-align: center;margin: 0 auto;top:300px;position: relative;color:#999}
  448. </style>