custom.js 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form','selectpage', 'custommain'], function ($, undefined, Backend, Table, Form,Selectpage, Custommain) {
  2. //去掉特殊字符和转义字符
  3. function excludeSpecial(s) {
  4. s = s.replace(/[\\\/\b\f\n\r\t\'\[\]\@\#\$\%\^\&\*\{\}\:\"\L\<\>\?]/g,'');
  5. return s;
  6. };
  7. $(document).on('keyup','#description, #description-book, #description-activity, #description-recent, #description-url',function () {
  8. var descrp = $(this).val();
  9. $(this).val(excludeSpecial(descrp));
  10. });
  11. //编辑按钮
  12. $(document).on('click','.btn-editone',function(){
  13. var url = $(this).data('tourl');
  14. var sendtime = Number($(this).data('sendtime'));
  15. if((sendtime - Date.parse(new Date())/1000)<300){
  16. $(this).hide();
  17. return false;
  18. }else{
  19. Fast.api.open(url, __('Edit'), $(this).data() || {});
  20. }
  21. });
  22. $(document).on('click', '.btn-editold', function () {
  23. var ids = $(this).data('field-index');
  24. Fast.api.open("/admin/custom/editold/ids/"+ids, __('Edit'), $(this).data() || {});
  25. });
  26. var Controller = {
  27. index: function () {
  28. // 初始化表格参数配置
  29. Table.api.init({
  30. extend: {
  31. index_url: 'custom/index',
  32. add_url: 'custom/add',
  33. edit_url: 'custom/edit',
  34. del_url: 'custom/del',
  35. multi_url: 'custom/multi',
  36. table: 'custom',
  37. },
  38. search:false,
  39. });
  40. var table = $("#table");
  41. // 初始化表格
  42. table.bootstrapTable({
  43. url: $.fn.bootstrapTable.defaults.extend.index_url,
  44. pk: 'id',
  45. sortName: 'id',
  46. columns: [
  47. [
  48. {checkbox: true},
  49. // {field: 'id', title: __('Id')},
  50. {field: 'title', title: __('标题'), operate: 'LIKE %...%'},
  51. {
  52. field: 'sendtime',
  53. title: __('Sendtime'),
  54. operate: 'RANGE',
  55. addclass: 'datetimerange',
  56. formatter: Table.api.formatter.datetime
  57. },
  58. {field: 'statue', title: __('Statue'), visible: false, operate: false},
  59. {field: 'statue_text', title: __('Statue'), operate: false},
  60. {field: 'send_num', title: '发送人数', operate: false},
  61. {
  62. field: 'createtime',
  63. title: __('Createtime'),
  64. operate: 'RANGE',
  65. addclass: 'datetimerange',
  66. formatter: Table.api.formatter.datetime
  67. },
  68. // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  69. {
  70. field: 'operate',
  71. title: __('Operate'),
  72. table: table,
  73. events: Table.api.events.operate,
  74. formatter: Controller.api.formatter.total_benefit_channel
  75. }
  76. //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  77. ]
  78. ]
  79. });
  80. // 为表格绑定事件
  81. Table.api.bindevent(table);
  82. },
  83. add: function () {
  84. Controller.api.bindevent();
  85. $('.s_time_box span:eq(1)').click();
  86. //文字消息字数限制
  87. $('#textarea_txt_box').on('input change',function(){
  88. var $this = $(this);
  89. var sval = $this.val();
  90. if(sval.length > 600){
  91. sval = sval.substring(0,600);
  92. $this.val(sval);
  93. }
  94. $('.textarea_txt_error span').text(sval.length + '/600');
  95. });
  96. //文字消息添加内容
  97. function setTextareaVal(str){
  98. var obj = $('#textarea_txt_box');
  99. }
  100. //修改菜单链接
  101. $(document).on('click', '.t_t_menuurl_but', function () {
  102. var $this = $(this);
  103. Fast.api.open('link/select?one=1', '选择', {
  104. callback: function (data) {
  105. var data = data[0];
  106. var otextareaval = $this.parents('.new-template-wrap').find('textarea');
  107. var stextareaval = otextareaval.val();
  108. otextareaval.val(stextareaval + data.menu_url);
  109. }
  110. });
  111. });
  112. //修改最近阅读链接
  113. $(document).on('click', '.t_t_goonurl_but', function () {
  114. var $this = $(this);
  115. $.ajax({
  116. type: 'get',
  117. url: '/admin/book/book/getrecenturl',
  118. cache: false,
  119. async: false,
  120. success:function(data){
  121. var otextareaval = $this.parents('.new-template-wrap').find('textarea');
  122. var stextareaval = otextareaval.val();
  123. otextareaval.val(stextareaval + data.url);
  124. },
  125. error:function(err){
  126. ofansopen = true;
  127. $('.s_tag_footer').removeClass('s_tag_fans_show');
  128. }
  129. });
  130. });
  131. //修改活动
  132. $(document).on('click', '.t_t_activityurl_but', function () {
  133. var $this = $(this);
  134. Fast.api.open('activity/select?one=1', '选择', {
  135. callback: function (data) {
  136. var data = data[0];
  137. var otextareaval = $this.parents('.new-template-wrap').find('textarea');
  138. var stextareaval = otextareaval.val();
  139. otextareaval.val(stextareaval + data.activity_url);
  140. }
  141. });
  142. });
  143. //修改url
  144. $(document).on('click','.t_t_pushurl_but',function(){
  145. var $this=$(this);
  146. Fast.api.open('referral/referral/select?one=1', '选择', {
  147. callback: function (data) {
  148. var data = data[0];
  149. // console.log('展示title回调', data);
  150. var otextareaval = $this.parents('.new-template-wrap').find('textarea');
  151. var stextareaval = otextareaval.val();
  152. otextareaval.val(stextareaval + data.source_url);
  153. }
  154. });
  155. });
  156. //修改book
  157. $(document).on('click','.t_t_book_but',function(){
  158. var $this=$(this);
  159. Fast.api.open('book.book/select?one=1', '选择', {
  160. callback: function (data) {
  161. var data = data[0];
  162. var otextareaval = $this.parents('.new-template-wrap').find('textarea');
  163. var stextareaval = otextareaval.val();
  164. //otextareaval.val(stextareaval + data.current_book_url);
  165. insertText(data.current_book_url);
  166. }
  167. });
  168. });
  169. function insertText(str) {
  170. var obj = document.getElementById('textarea_txt_box');
  171. obj.focus();
  172. if (document.selection) {
  173. var sel = document.selection.createRange();
  174. sel.text = str;
  175. } else if (typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
  176. var startPos = obj.selectionStart,
  177. endPos = obj.selectionEnd,
  178. cursorPos = startPos,
  179. tmpStr = obj.value;
  180. obj.value = tmpStr.substring(0, startPos) + str + tmpStr.substring(endPos, tmpStr.length);
  181. cursorPos += str.length;
  182. obj.selectionStart = obj.selectionEnd = cursorPos;
  183. } else {
  184. obj.value += str;
  185. }
  186. var sval = obj.value;
  187. if(sval.length > 600){
  188. sval = sval.substring(0,600);
  189. obj.value = sval;
  190. }
  191. $('.textarea_txt_error span').text(sval.length + '/600');
  192. }
  193. function moveEnd(len){
  194. var obj = document.getElementById('textarea_txt_box');
  195. obj.focus();
  196. if (document.selection) {
  197. var sel = obj.createTextRange();
  198. sel.moveStart('character',len);
  199. sel.collapse();
  200. sel.select();
  201. } else if (typeof obj.selectionStart == 'number' && typeof obj.selectionEnd == 'number') {
  202. obj.selectionStart = obj.selectionEnd = len;
  203. }
  204. }
  205. require(['vue', 'component', 'ELEMENT'], function (Vue, component, ELEMENT) {
  206. Vue.use(ELEMENT);
  207. Vue.use(component);
  208. var Main = {
  209. el: '#title-select',
  210. methods: {
  211. select: function (value) {
  212. $('.anticon_edit_input_tit').find('input').val(value);
  213. }
  214. }
  215. };
  216. new Vue(Main)
  217. });
  218. },
  219. edit: function () {
  220. Controller.api.isEidt = true;
  221. Controller.api.bindevent();
  222. require(['vue', 'component', 'ELEMENT'], function (Vue, component, ELEMENT) {
  223. Vue.use(ELEMENT);
  224. Vue.use(component);
  225. var Main = {
  226. el: '#title-select',
  227. methods: {
  228. select: function (value) {
  229. $('.anticon_edit_input_tit').find('input').val(value)
  230. }
  231. }
  232. };
  233. new Vue(Main)
  234. });
  235. },
  236. editold: function () {
  237. Controller.api.oldbindevet();
  238. },
  239. addimagetext: function () {
  240. Controller.api.bindevent();
  241. var selectdata = '';
  242. $('#c-book_book_name').selectPage({
  243. eAjaxSuccess : function(d){
  244. if(d.list.length==0){
  245. $('#c-book_book_name').val('');
  246. $('#select_book_id').val('');
  247. $("#description-book").val('');
  248. }else {
  249. if (selectdata && JSON.stringify(selectdata) != JSON.stringify(d)) {
  250. $('#select_book_id').val('');
  251. }
  252. selectdata = d;
  253. return d ? d : '';
  254. }
  255. },
  256. eSelect : function(d){
  257. selectdata = '';
  258. $('#c-book_book_name').val(d.name);
  259. $('#select_book_id').val(d.id);
  260. $('#select_book_id').attr('data-sex_text', d.sex_text);
  261. $("#description-book").val(d.description);
  262. Custommain.get_channel_book_name();
  263. },
  264. eClear : function(){
  265. $('#select_book_id').val('');
  266. }
  267. });
  268. require(['upload'], function (Upload) {
  269. var data = {};
  270. data.width=1080;
  271. data.height = 864;
  272. Upload.api.plupload(".mini_plupload", function (data, ret) {
  273. $('.mini-card').find('.img_card img').attr('src',data.url);
  274. $('.mini-image').val(data.url);
  275. $('.mini-card').find('.inner').hide();
  276. $('.mini-card').find('.img_card').show();
  277. });
  278. });
  279. $(document).on('click','#c-mini_type',function () {
  280. $(this).change(function(){
  281. var value = $(this).find('input:checked').val();
  282. console.log(value);
  283. switch (value) {
  284. case "3":
  285. $('.mini-type3').show()
  286. break;
  287. case "4":
  288. $('.mini-type3').hide()
  289. break;
  290. }
  291. })
  292. })
  293. Controller.api.eventTitle()
  294. },
  295. editimagetext:function(){
  296. Controller.api.bindevent();
  297. var spage = $('#c-book_book_name').val();
  298. var sbl = true;
  299. var selectdata = '';
  300. $('#c-book_book_name').selectPage({
  301. eAjaxSuccess : function(d){
  302. if(d.list.length==0){
  303. $('#c-book_book_name').val('');
  304. $('#select_book_id').val('');
  305. $("#description-book").val('');
  306. }else{
  307. if(selectdata && JSON.stringify(selectdata) != JSON.stringify(d)){
  308. $('#select_book_id').val('');
  309. }
  310. selectdata = d;
  311. return d ? d : '';
  312. }
  313. },
  314. eSelect : function(d){
  315. selectdata = '';
  316. $('#c-book_book_name').val(d.name);
  317. $('#select_book_id').val(d.id);
  318. $('#select_book_id').attr('data-sex_text', d.sex_text);
  319. $("#description-book").val(d.description);
  320. Custommain.get_channel_book_name('图文客服消息');
  321. },
  322. eClear : function(){
  323. $('#select_book_id').val('');
  324. }
  325. });
  326. if(Config.bnotin.length>0){
  327. $.each(Config.bnotin,function (index,value) {
  328. if($('#select_book_id').val().indexOf(value)!=-1){
  329. $('#select_book_id').val('');
  330. $('#c-book_book_name').val('');
  331. $('#c-book_book_name_text').val('');
  332. return false;
  333. }
  334. });
  335. }
  336. $(document).on('click','#c-mini_type',function () {
  337. $(this).change(function(){
  338. var value = $(this).find('input:checked').val();
  339. console.log(value);
  340. switch (value) {
  341. case "3":
  342. $('.mini-type3').show()
  343. break;
  344. case "4":
  345. $('.mini-type3').hide()
  346. break;
  347. }
  348. })
  349. })
  350. require(['upload'], function (Upload) {
  351. var data = {};
  352. data.width=1080;
  353. data.height = 864;
  354. Upload.api.plupload(".mini_plupload", function (data, ret) {
  355. $('.mini-card').find('.img_card img').attr('src',data.url);
  356. $('.mini-image').val(data.url);
  357. $('.mini-card').find('.inner').hide();
  358. $('.mini-card').find('.img_card').show();
  359. });
  360. });
  361. Controller.api.eventTitle()
  362. },
  363. addlinktext:function(){
  364. Controller.api.bindevent();
  365. var selectdata = '';
  366. $('#c-book_book_name').selectPage({
  367. eAjaxSuccess : function(d){
  368. if(selectdata && JSON.stringify(selectdata) != JSON.stringify(d)){
  369. $('#select_book_id').val('');
  370. }
  371. selectdata = d;
  372. return d ? d : '';
  373. },
  374. eSelect : function(d){
  375. selectdata = '';
  376. $('#c-book_book_name').val(d.name);
  377. $('#select_book_id').val(d.id);
  378. $('#select_book_id').attr('data-sex_text', d.sex_text);
  379. $("#description-book").val(d.description);
  380. Custommain.get_channel_book_name('文字客服消息');
  381. },
  382. eClear : function(){
  383. $('#select_book_id').val('');
  384. }
  385. });
  386. Controller.api.eventTitle()
  387. },
  388. editlinktext:function(){
  389. Controller.api.bindevent();
  390. var spage = $('#c-book_book_name').val();
  391. var sbl = true;
  392. var selectdata = '';
  393. $('#c-book_book_name').selectPage({
  394. eAjaxSuccess : function(d){
  395. if(selectdata && JSON.stringify(selectdata) != JSON.stringify(d)){
  396. $('#select_book_id').val('');
  397. }
  398. selectdata = d;
  399. return d ? d : '';
  400. },
  401. eSelect : function(d){
  402. selectdata = '';
  403. $('#c-book_book_name').val(d.name);
  404. $('#select_book_id').val(d.id);
  405. $('#select_book_id').attr('data-sex_text', d.sex_text);
  406. $("#description-book").val(d.description);
  407. Custommain.get_channel_book_name('文字客服消息');
  408. },
  409. eClear : function(){
  410. $('#select_book_id').val('');
  411. }
  412. });
  413. if(Config.bnotin.length>0){
  414. $.each(Config.bnotin,function (index,value) {
  415. if($('#select_book_id').val().indexOf(value)!=-1){
  416. $('#select_book_id').val('');
  417. $('#c-book_book_name').val('');
  418. $('#c-book_book_name_text').val('');
  419. return false;
  420. }
  421. });
  422. }
  423. Controller.api.eventTitle()
  424. },
  425. api: {
  426. eventTitle: function () {
  427. require(['vue', 'component', 'ELEMENT'], function (Vue, component, ELEMENT) {
  428. Vue.use(ELEMENT);
  429. Vue.use(component);
  430. var Main = {
  431. el: '#title-select',
  432. methods: {
  433. select: function (value) {
  434. $('.group-type:visible').find('input').first().val(value)
  435. }
  436. }
  437. };
  438. new Vue(Main)
  439. });
  440. },
  441. isEidt:false,
  442. getStatue: function (value, row, index) {
  443. if (value == 'normal') {
  444. if (row.sendtime < Date.parse(new Date()) / 1000) {
  445. return '<span style="color:red">发送失败</span>';
  446. } else {
  447. return '未发送';
  448. }
  449. } else {
  450. return '<span style="color:green">已发送</span>';
  451. }
  452. }, formatter: {
  453. total_benefit_channel: function (value, row, index) {
  454. if (row.createtime < 1556539200) {
  455. if (row.sendtime - Config.nowtime < 600) {
  456. return '<a href="javascript:;" class="btn btn-xs btn-success btn-editold" title="预览" data-table-id="table" data-field-index="'+row.id+'" data-row-index="0" data-button-index="1"><i class="fa fa-eye"></i></a> ' +
  457. '<a href="javascript:;" class="btn btn-xs btn-danger btn-delone" title="" data-table-id="table" data-field-index="9" data-row-index="0" data-button-index="2"><i class="fa fa-trash"></i></a>';
  458. } else {
  459. return '<a href="javascript:;" class="btn btn-xs btn-success btn-editold" title="编辑" data-table-id="table" data-field-index="'+row.id+'" data-row-index="0" data-button-index="1"><i class="fa fa-pencil"></i></a> ' +
  460. '<a href="javascript:;" class="btn btn-xs btn-danger btn-delone" title="" data-table-id="table" data-field-index="9" data-row-index="0" data-button-index="2"><i class="fa fa-trash"></i></a>';
  461. }
  462. } else {
  463. if (row.sendtime - Config.nowtime < 600) {
  464. return '<a href="/admin/custom/edit/ids/' + row.id + '" class="btn btn-xs btn-success btn-editone" title="预览" data-table-id="table" data-field-index="9" data-row-index="0" data-button-index="1"><i class="fa fa-eye"></i></a> ' +
  465. '<a href="javascript:;" class="btn btn-xs btn-danger btn-delone" title="" data-table-id="table" data-field-index="9" data-row-index="0" data-button-index="2"><i class="fa fa-trash"></i></a>';
  466. } else {
  467. return '<a href="/admin/custom/edit/ids/' + row.id + '" class="btn btn-xs btn-success btn-editone" title="编辑" data-table-id="table" data-field-index="9" data-row-index="0" data-button-index="1"><i class="fa fa-pencil"></i></a> ' +
  468. '<a href="javascript:;" class="btn btn-xs btn-danger btn-delone" title="" data-table-id="table" data-field-index="9" data-row-index="0" data-button-index="2"><i class="fa fa-trash"></i></a>';
  469. }
  470. }
  471. }
  472. },
  473. editCustom: function (value, row, index) {
  474. if (row.statue == 'normal' && (Number(row.sendtime) - Date.parse(new Date()) / 1000) > 300) {
  475. //5分钟外的
  476. return '<a href="javascript:;" class="btn btn-xs btn-success btn-editone" data-sendtime="' + row.sendtime + '" data-tourl="/admin/custom/edit/ids/' + row.id + '" data-table-id="table" data-field-index="8" data-row-index="2" data-button-index="1"><i class="fa fa-pencil"></i></a>';
  477. }
  478. },
  479. /*bindevent: function () {
  480. Form.api.bindevent($("form[role=form]"));
  481. if (canedit) {
  482. //资源管理
  483. var ore = {
  484. arrma: [
  485. {
  486. 'title': '',
  487. 'image': '',
  488. 'url': 'http://'
  489. }
  490. ],
  491. imglis: [],
  492. titlist: [],
  493. sli: '<div class="img_txt_li img_txt_main">\
  494. <div class="img_txt_li_img img_txt_edit_img"><img src="sli_img" /></div>\
  495. <div class="img_txt_li_txt">\
  496. <div class="img_txt_li_h3"><input type="text" value="sli_value" /></div>\
  497. <div class="img_txt_li_url"><input type="text" value="click_url" /></div>\
  498. </div>\
  499. <div class="fa img_txt_remvoe"></div>\
  500. </div>'
  501. };
  502. } else {
  503. //资源管理
  504. var ore = {
  505. arrma: [
  506. {
  507. 'title': '',
  508. 'image': '',
  509. 'url': 'http://'
  510. }
  511. ],
  512. imglis: [],
  513. titlist: [],
  514. sli: '<div class="img_txt_li img_txt_main">\
  515. <div class="img_txt_li_img img_txt_edit_img"><img src="sli_img" /></div>\
  516. <div class="img_txt_li_txt">\
  517. <i class="fa fa-pencil img_txt_edit_tit"></i>\
  518. <div class="img_txt_li_h3"><input type="text" value="sli_value" /></div>\
  519. <i class="fa fa-chain img_txt_edit_url"></i>\
  520. <i class="fa fa-book img_txt_edit_book"></i>\
  521. <div class="img_txt_li_url"><input type="text" value="click_url" /></div>\
  522. </div>\
  523. <div class="fa img_txt_remvoe"></div>\
  524. </div>'
  525. };*/
  526. bindevent: function () {
  527. $('#c-menu_menu_id,#c-activity_activity_id').change(function(){
  528. Custommain.get_channel_other_name();
  529. });
  530. //推广链接类型id
  531. var simgtexttype = $('input[name="row[imgtxt_type]"]:checked').val();
  532. //资源管理
  533. var ore={
  534. arrma:[
  535. {
  536. 'title':'',
  537. 'image':'',
  538. 'url':'http://'
  539. }
  540. ],
  541. imglis:[],
  542. titlist:[],
  543. sli:'<div class="img_txt_li img_txt_main">\
  544. <div class="img_txt_li_img img_txt_edit_img"><img src="sli_img" /></div>\
  545. <div class="img_txt_li_txt">\
  546. <i class="fa fa-pencil img_txt_edit_tit"></i>\
  547. <div class="img_txt_li_h3"><input type="text" value="sli_value" /></div>\
  548. <i class="fa fa-chain img_txt_edit_url" title="推广链接"></i>\
  549. <i class="fa fa-book img_txt_edit_book" title="小说链接"></i>\
  550. <i class="fa fa-address-card-o img_txt_edit_card_o" title="活动链接"></i>\
  551. <i class="fa fa-bookmark-o img_txt_edit_bookmark_o" title="继续阅读链接"></i>\
  552. <i class="fa fa-bars img_txt_edit_bars" title="菜单链接"></i>\
  553. <div class="img_txt_li_url"><input type="text" value="click_url" /></div>\
  554. </div>\
  555. <div class="fa img_txt_remvoe"></div>\
  556. </div>',
  557. pli:'<li>\
  558. <a class="article-item">\
  559. <div class="novel-img article-item-cover" style="background-image: url(sli_img);"></div>\
  560. <p class="article-item-title">sli_value</p>\
  561. </a>\
  562. <div class="article-actions">\
  563. <div>\
  564. <span class="action-item">\
  565. <i class="anticon anticon-title-edit" style="font-size: 17px;" data-toggle="tooltip" data-original-title="修改标题"></i>\
  566. </span>\
  567. <span class="action-item">\
  568. <i class="anticon anticon-cover-edit" data-toggle="tooltip" data-original-title="修改封面"></i>\
  569. </span>\
  570. <span class="action-item">\
  571. <i class="anticon anticon-novel-edit" style="font-size: 13px;" data-toggle="tooltip" data-original-title="编辑链接"></i>\
  572. </span>\
  573. <span class="action-item action-item-up">\
  574. <i class="anticon anticon-arrow-up" data-toggle="tooltip" data-original-title="上移"></i>\
  575. </span>\
  576. <span class="action-item action-item-down">\
  577. <i class="anticon anticon-arrow-down" data-toggle="tooltip" data-original-title="下移"></i>\
  578. </span>\
  579. <span class="action-item">\
  580. <i class="anticon anticon-delete" data-toggle="tooltip" data-original-title="删除"></i>\
  581. </span>\
  582. </div>\
  583. </div>\
  584. </li>',
  585. ptxtli:'<li>\
  586. <p scolor>sli_value</p>\
  587. <div class="img_txt_tip_box">\
  588. <i class="anticon anticon-novel-edit" style="font-size: 13px;" data-toggle="tooltip" data-original-title="编辑链接"></i>\
  589. <i class="anticon anticon-delete" data-toggle="tooltip" data-original-title="删除"></i>\
  590. </div>\
  591. </li>'
  592. };
  593. //图文切换为文字链
  594. $(document).on('click', '.switch_txt_but', function () {
  595. layer.open({
  596. type: 1,
  597. title: '温馨提示',
  598. maxmin: false,
  599. area: ['300px', '200px'],
  600. btn: ['确认', '取消'],
  601. shadeClose: true,
  602. resize: false,
  603. // skin: 'layui-layer-rim',
  604. content: '<div class="layui_txt">切换为文字链模式后将无法恢复为图文模式,确定切换吗?</div>',
  605. yes: function (index, layero) {
  606. var imgsval = $('.img_txt_hidden_input').val();
  607. $('.msg_type').val('1');
  608. $('#group-type-news').remove();
  609. $('#group-type-news_txt').show();
  610. $('.textarea_txt_hidden_input').val(imgsval);
  611. try {
  612. imgsval = JSON.parse(imgsval);
  613. txttext(imgsval);
  614. } catch (e) {
  615. }
  616. Toastr.success('切换成功');
  617. layer.close(index);
  618. },
  619. btn2: function (index, node) {
  620. layer.close(index)
  621. }
  622. });
  623. })
  624. //添加图文
  625. $(document).on('click', '.img_txt_add_but', function () {
  626. var $this = $(this);
  627. Fast.api.open('custom/addimagetext', '添加图文', {
  628. callback: function (data) {
  629. console.log(data);
  630. strImgtext = $('.img_txt_hidden_input').val();
  631. var imgtext_data = [];
  632. if (strImgtext.length > 0) {
  633. imgtext_data = JSON.parse(strImgtext);
  634. }
  635. imgtext_data.push(data);
  636. $('.img_txt_hidden_input').val(JSON.stringify(imgtext_data));
  637. $('.textarea_txt_hidden_input').val(JSON.stringify(imgtext_data));
  638. console.log(data);
  639. imagetext(imgtext_data);
  640. txttext(imgtext_data);
  641. $this.hide();
  642. }
  643. })
  644. });
  645. //编辑图文文字链单条列表
  646. if (Controller.api.isEidt) {
  647. try {
  648. var inpimgjson = $('.img_txt_hidden_input').val();
  649. inpimgjson ? inpimgjson = JSON.parse(inpimgjson) : '';
  650. if (inpimgjson && inpimgjson.length) {
  651. imagetext(inpimgjson);
  652. $('.img_txt_add_but').hide();
  653. }
  654. var inptestjson = $('.textarea_txt_hidden_input').val();
  655. inptestjson ? inptestjson = JSON.parse(inptestjson) : '';
  656. if (inptestjson && inptestjson.length) {
  657. txttext(inptestjson);
  658. }
  659. } catch (e) {
  660. console.log(e);
  661. }
  662. }
  663. //渲染图文列表
  664. function imagetext(data) {
  665. var lihtmls = '';
  666. var sli = '';
  667. for (var i = 0; i < data.length; i++) {
  668. sli = ore.pli.replace('sli_img', data[i]['image']);
  669. sli = sli.replace('sli_value', data[i]['title']);
  670. lihtmls += sli;
  671. }
  672. lihtmls = '<div class="wxb-card-item"><div class="wxb-card-item-inner"><ul class="article-list">' + lihtmls + '</ul></div></div>';
  673. $('.wxb-card-list-scroll').html(lihtmls);
  674. //图文列表tip
  675. $('.wxb-card-list-scroll .action-item i').tooltip();
  676. }
  677. //渲染文字列表
  678. function txttext(data) {
  679. var lihtmls = '';
  680. var sli = '';
  681. for (var i = 0; i < data.length; i++) {
  682. var scol = '';
  683. sli = ore.ptxtli.replace('sli_value', data[i]['title']);
  684. if (data[i]['type'] == 4) scol = 'style="color:#333"'
  685. sli = sli.replace('scolor', scol);
  686. lihtmls += sli;
  687. }
  688. lihtmls = '<div class="img_txt_url"><ul>' + lihtmls + '</ul></div>';
  689. $('#group-type-news_txt .img_txt_list').html(lihtmls);
  690. //图文列表tip
  691. $('.img_txt_url i').tooltip();
  692. }
  693. //获取数组
  694. function getimagetxtarr(val) {
  695. strImgtext = val;
  696. var imgtext_data = [];
  697. if (strImgtext.length > 0) {
  698. try {
  699. return JSON.parse(strImgtext);
  700. } catch (err) {
  701. return '';
  702. }
  703. }
  704. return '';
  705. }
  706. //数组上移下移
  707. Array.prototype.swapItems = function (startindex, endindex) {
  708. this[startindex] = this.splice(endindex, 1, this[startindex])[0];
  709. return this;
  710. }
  711. //数组删除指定项
  712. Array.prototype.removeItems = function (index) {
  713. this.splice(index, 1);
  714. return this;
  715. }
  716. //图文上移 下移
  717. $('.wxb-card-list-scroll').on('click', '.anticon-arrow-up,.anticon-arrow-down', function () {
  718. var $this = $(this);
  719. var nindex = $this.parents('li').index();
  720. var arrimgtxt = getimagetxtarr($('.img_txt_hidden_input').val());
  721. if (!arrimgtxt) return false;
  722. if ($this.hasClass('anticon-arrow-up')) {
  723. if (nindex == 0) return false;
  724. arrimgtxt.swapItems(nindex, nindex - 1);
  725. } else {
  726. if (nindex == arrimgtxt.length - 1) return false;
  727. arrimgtxt.swapItems(nindex, nindex + 1);
  728. }
  729. $('.img_txt_hidden_input').val(JSON.stringify(arrimgtxt));
  730. $('.textarea_txt_hidden_input').val(JSON.stringify(arrimgtxt));
  731. imagetext(arrimgtxt);
  732. });
  733. //删除图文
  734. $('.wxb-card-list-scroll').on('click', '.anticon-delete', function () {
  735. var $this = $(this);
  736. layer.open({
  737. type: 1,
  738. title: '温馨提示',
  739. maxmin: false,
  740. area: ['260px', '160px'],
  741. btn: ['确认', '取消'],
  742. shadeClose: true,
  743. resize: false,
  744. // skin: 'layui-layer-rim',
  745. content: '<div style="height:100%; width:100%; text-align: center; line-height: 65px;">您确定删除此条信息?</div>',
  746. yes: function (index, layero) {
  747. var nindex = $this.parents('li').index();
  748. var arrimgtxt = getimagetxtarr($('.img_txt_hidden_input').val());
  749. if (!arrimgtxt) return false;
  750. arrimgtxt.removeItems(nindex);
  751. $('.img_txt_hidden_input').val(JSON.stringify(arrimgtxt));
  752. $('.textarea_txt_hidden_input').val(JSON.stringify(arrimgtxt));
  753. if (arrimgtxt.length == 0) {
  754. $('.wxb-card-list-scroll').html('');
  755. $('.img_txt_add_but').show();
  756. } else {
  757. imagetext(arrimgtxt);
  758. }
  759. Toastr.success('删除成功');
  760. layer.close(index);
  761. },
  762. btn2: function (index, node) {
  763. layer.close(index)
  764. }
  765. });
  766. });
  767. //修改title
  768. $(document).on('click', '.anticon-title-edit', function () {
  769. var $this = $(this);
  770. var nIndex = $this.parents('li').index();
  771. var stitle = $this.parents('li').find('p').text();
  772. layer.open({
  773. type: 1,
  774. title: false,
  775. maxmin: false,
  776. zIndex:1800,
  777. area: ['auto', 'auto'],
  778. btn: ['确认', '取消'],
  779. shadeClose: true,
  780. resize: false,
  781. skin: 'layui-layer-rim',
  782. content: '<div class="anticon_edit_box">\
  783. <div class="anticon_edit_select_tit_box">\
  784. <strong>当前标题:</strong>\
  785. <p>' + stitle + '</p>\
  786. <a href="javascript:;" class="anticon_edit_select_tit_box_in"><i class="fa fa-pencil"></i></a>\
  787. </div>\
  788. <div class="anticon_edit_input_tit_box">\
  789. <strong>修改为:</strong>\
  790. <div class="anticon_edit_input_tit"><input type="text" value="' + stitle + '" /></div>\
  791. </div>\
  792. </div>',
  793. yes: function (index, layero) {
  794. var stit = $(layero.selector + ' p').text();
  795. var sinputtit = $(layero.selector + ' input').val();
  796. if (sinputtit) {
  797. stit = sinputtit;
  798. }
  799. editimglist('title', nIndex, stit);
  800. layer.close(index);
  801. },
  802. btn2: function (index, node) {
  803. layer.close(index)
  804. }
  805. });
  806. });
  807. //修改列表内容
  808. function editimglist(name, item, val) {
  809. var strImgtext = JSON.parse($('.img_txt_hidden_input').val());
  810. strImgtext[item][name] = val;
  811. $('.img_txt_hidden_input').val(JSON.stringify(strImgtext));
  812. $('.textarea_txt_hidden_input').val(JSON.stringify(strImgtext));
  813. imagetext(strImgtext);
  814. }
  815. //修改封面
  816. $(document).on('click', '.anticon-cover-edit', function () {
  817. var $this = $(this);
  818. var nIndex = $this.parents('li').index();
  819. Fast.api.open('manage/cover/select', '选择', {
  820. callback: function (data) {
  821. // console.log('展示image回调', data);
  822. editimglist('image', nIndex, data.image);
  823. }
  824. });
  825. });
  826. //修改图文内容
  827. $(document).on('click', '#group-type-news .anticon-novel-edit', function () {
  828. var $this = $(this);
  829. var nIndex = $this.parents('li').index();
  830. var sjson = JSON.parse($('.img_txt_hidden_input').val());
  831. Fast.api.open('custom/editimagetext?json=' + encodeURIComponent(JSON.stringify(sjson[nIndex])), '修改内容', {
  832. callback: function (data) {
  833. var data = data;
  834. var strImgtext = JSON.parse($('.img_txt_hidden_input').val());
  835. strImgtext[nIndex] = data;
  836. $('.img_txt_hidden_input').val(JSON.stringify(strImgtext));
  837. $('.textarea_txt_hidden_input').val(JSON.stringify(strImgtext));
  838. imagetext(strImgtext);
  839. }
  840. });
  841. });
  842. //修改文字内容
  843. $(document).on('click', '#group-type-news_txt .anticon-novel-edit', function () {
  844. var $this = $(this);
  845. var nIndex = $this.parents('li').index();
  846. var sjson = JSON.parse($('.textarea_txt_hidden_input').val());
  847. Fast.api.open('custom/editlinktext?json=' + encodeURIComponent(JSON.stringify(sjson[nIndex])), '修改文字链接', {
  848. callback: function (data) {
  849. var data = data;
  850. console.log('展示title回调', data);
  851. var strImgtext = JSON.parse($('.textarea_txt_hidden_input').val());
  852. strImgtext[nIndex] = data;
  853. $('.textarea_txt_hidden_input').val(JSON.stringify(strImgtext));
  854. txttext(strImgtext);
  855. }
  856. });
  857. });
  858. //删除文字列表
  859. $('#group-type-news_txt').on('click', '.anticon-delete', function () {
  860. var $this = $(this);
  861. layer.open({
  862. type: 1,
  863. title: '温馨提示',
  864. maxmin: false,
  865. area: ['260px', '160px'],
  866. btn: ['确认', '取消'],
  867. shadeClose: true,
  868. resize: false,
  869. // skin: 'layui-layer-rim',
  870. content: '<div style="height:100%; width:100%; text-align: center; line-height: 65px;">您确定删除此条信息?</div>',
  871. yes: function (index, layero) {
  872. var nindex = $this.parents('li').index();
  873. var arrimgtxt = getimagetxtarr($('.textarea_txt_hidden_input').val());
  874. if (!arrimgtxt) return false;
  875. arrimgtxt.removeItems(nindex);
  876. $('.textarea_txt_hidden_input').val(JSON.stringify(arrimgtxt));
  877. if (arrimgtxt.length == 0) {
  878. $('.img_txt_list').html('');
  879. } else {
  880. txttext(arrimgtxt);
  881. }
  882. Toastr.success('删除成功');
  883. layer.close(index);
  884. },
  885. btn2: function (index, node) {
  886. layer.close(index)
  887. }
  888. });
  889. });
  890. Custommain.bind_form_validation();
  891. /**
  892. * form表单验证
  893. */
  894. //$("form[role=form]").data("validator-options", {
  895. $("#add-form").data("validator-options", {
  896. ignore: ':hidden',
  897. beforeSubmit: function (form) {
  898. var user_json = $.parseJSON($('.img_txt_hidde_input_no').val())
  899. if (user_json.all==0 && !user_json.subscribe_time) {
  900. var sub_from = (new Moment($('input[name="row[sub_from]"]').val())).valueOf() / 1000
  901. var sub_to = (new Moment($('input[name="row[sub_to]"]').val())).valueOf() / 1000
  902. if(!sub_from && !sub_to){
  903. Toastr.error("起止时间不能为空");
  904. return false;
  905. }else{
  906. user_json.subscribe_range = sub_from +'-'+ sub_to;
  907. }
  908. }
  909. $('.img_txt_hidde_input_no').val(JSON.stringify(user_json));
  910. var $imgTxtMain = $('.img_txt_main');
  911. var reg = /^(http[s]?|ftp):\/\/[^\/\.]+?\..+\w/;
  912. var sList = '';
  913. ore.arrma = [];
  914. //标题
  915. if ($.trim($('#title').val()).length == 0) {
  916. Toastr.error("标题不能为空");
  917. return false;
  918. }
  919. if ($('.msg_type').val() == '1') {
  920. var scdata = $(".textarea_txt_hidden_input").val();
  921. } else {
  922. var scdata = $(".img_txt_hidden_input").val();
  923. }
  924. try {
  925. if (!scdata || JSON.parse(scdata).length == 0) {
  926. Toastr.error("请编辑消息内容");
  927. flag = 0;
  928. return false;
  929. }
  930. } catch (e) {
  931. Toastr.error("请编辑消息内容");
  932. flag = 0;
  933. return false;
  934. }
  935. for (var i = 0; i < $imgTxtMain.length; i++) {
  936. ore.arrma.push({});
  937. //标题
  938. if ($('.img_txt_main:eq(' + i + ') input:eq(0)').val().length > 0) {
  939. ore.arrma[i].title = $('.img_txt_main:eq(' + i + ') input:eq(0)').val();
  940. } else {
  941. Toastr.error("图文标题不能为空");
  942. return false;
  943. }
  944. //链接
  945. if (reg.test($('.img_txt_main:eq(' + i + ') input:eq(1)').val())) {
  946. ore.arrma[i].url = $('.img_txt_main:eq(' + i + ') input:eq(1)').val();
  947. } else {
  948. Toastr.error("请填写图文正确的跳转链接");
  949. return false;
  950. }
  951. //图片
  952. if ($('.img_txt_main:eq(' + i + ') img').attr('src').length > 0) {
  953. ore.arrma[i].image = $('.img_txt_main:eq(' + i + ') img').attr('src');
  954. } else {
  955. Toastr.error("请填写图文正确的跳转链接");
  956. return false;
  957. }
  958. ore.arrma[i].description = excludeSpecial($('#description').val());
  959. }
  960. //发送时间必须大于当前时间
  961. var sdatatime = $('#c-sendtime').val() + '';
  962. sdatatime = sdatatime.replace(/-/g, '/');
  963. sdatatime = new Date(sdatatime).getTime();
  964. if (sdatatime <= new Date().getTime()) {
  965. Toastr.error("发送时间必须大于当前时间");
  966. return false;
  967. }
  968. sList = JSON.stringify(ore.arrma);
  969. $('.img_txt_hidde_input').val(sList);
  970. }
  971. });
  972. Form.api.bindevent($("form[role=form]"),
  973. function (data) {
  974. if (data.jump) {
  975. window.parent.location.href = data.jump;
  976. } else {
  977. Fast.api.close(data);
  978. }
  979. },
  980. function (data) {
  981. console.log('error', data);
  982. }
  983. );
  984. /**
  985. * 资源类型管理
  986. */
  987. $(document).on('click', "input[name='row[type]']", function () {
  988. if (canedit) {
  989. return false;
  990. }
  991. var type = $(this).val();
  992. if (type == 'all') {
  993. var tagObj = {
  994. all: "1"
  995. }
  996. } else {
  997. var tagObj = {
  998. sex: -1,
  999. mobile_system: 0,
  1000. tag: -1,
  1001. consume: -1,
  1002. kandian: -1,
  1003. subscribe_time: -1,
  1004. all: "0"
  1005. }
  1006. }
  1007. var ucon = JSON.stringify(tagObj);
  1008. $('#usercondition').val(ucon);
  1009. $('.group-tag-type').addClass('hide');
  1010. $('.group-tag-type input').attr('disabled');
  1011. $('#group-tag-type-' + type).removeClass('hide');
  1012. $('#group-tag-type-' + type + ' input').removeAttr('disabled');
  1013. });
  1014. //切换推广链接类型
  1015. $(document).on('click', "input[name='row[imgtxt_type]']", function () {
  1016. var type = $(this).val();
  1017. $('.group-type').addClass('hide');
  1018. $('.group-type input').attr('disabled');
  1019. $('#group-type-' + type).removeClass('hide');
  1020. $('#group-type-' + type + ' input').removeAttr('disabled');
  1021. var oshowfrombox = $('#group-type-' + type + ' input[type="hidden"]');
  1022. simgtexttype = type;
  1023. if (type == 0) {
  1024. Custommain.get_channel_book_name();
  1025. } else {
  1026. Custommain.get_channel_other_name();
  1027. }
  1028. });
  1029. $(document).on('click', "input[name='book[push]']", function () {
  1030. var type = $(this).val();
  1031. $('.group-push').addClass('hide');
  1032. $('.group-push input').attr('disabled');
  1033. $('#group-push-' + type).removeClass('hide');
  1034. $('#group-push-' + type + ' input').removeAttr('disabled');
  1035. Custommain.get_channel_book_name();
  1036. });
  1037. /**
  1038. * 插入链接
  1039. */
  1040. $(document).on('click', ".btn-insertlink", function () {
  1041. if (canedit) {
  1042. return false;
  1043. }
  1044. var textarea = $("textarea[name='row[content]']");
  1045. var cursorPos = textarea.prop('selectionStart');
  1046. var v = textarea.val();
  1047. var textBefore = v.substring(0, cursorPos);
  1048. var textAfter = v.substring(cursorPos, v.length);
  1049. Layer.prompt({title: '请输入显示的文字', formType: 3}, function (text, index) {
  1050. Layer.close(index);
  1051. Layer.prompt({title: '请输入跳转的链接URL(包含http/https)', formType: 3}, function (link, index) {
  1052. text = text == '' ? link : text;
  1053. textarea.val(textBefore + '<a href="' + link + '">' + text + '</a>' + textAfter);
  1054. Layer.close(index);
  1055. });
  1056. });
  1057. });
  1058. if ($('#usercondition').val() && $('#usercondition').val().length > 0) {
  1059. $tagval = JSON.parse($('#usercondition').val());
  1060. if ($tagval.all == 1) { //选择所有用户
  1061. $('#type-all').attr('checked', true);
  1062. var type = 'all';
  1063. $('.group-tag-type').addClass('hide');
  1064. $('.group-tag-type input').attr('disabled');
  1065. $('#group-tag-type-' + type).removeClass('hide');
  1066. $('#group-tag-type-' + type + ' input').removeAttr('disabled');
  1067. }
  1068. }
  1069. $.ajax({
  1070. type: 'get',
  1071. url: '/admin/custom/ajaxcategory',
  1072. cache: false,
  1073. async: false,
  1074. success: function (res) {
  1075. data = res.data;
  1076. var htmlstr = '';
  1077. for (var i = 0; i < data.length; i++) {
  1078. htmlstr += '<span data-cid="' + data[i].id + '" >' + data[i].name + '</span>';
  1079. }
  1080. $('#ctag').append(htmlstr);
  1081. $('#mustbe').html('约' + res.ids + '人');
  1082. if ($('#usercondition').val() && $('#usercondition').val().length > 0) {
  1083. $tagval = JSON.parse($('#usercondition').val());
  1084. $("#sex span[data-sex='" + $tagval.sex + "']").addClass('s_s_tag').siblings().removeClass('s_s_tag');
  1085. $("#mobile_system span[data-mobile_system='" + $tagval.mobile_system + "']").addClass('s_s_tag').siblings().removeClass('s_s_tag');
  1086. $("#ctag span[data-cid='" + $tagval.tag + "']").addClass('s_s_tag').siblings().removeClass('s_s_tag');
  1087. $("#consume span[data-fee='" + $tagval.consume + "']").addClass('s_s_tag').siblings().removeClass('s_s_tag');
  1088. $("#kandian span[data-kandian='" + $tagval.kandian + "']").addClass('s_s_tag').siblings().removeClass('s_s_tag');
  1089. if ($tagval.subscribe_time) {
  1090. $("#subscribe_time1 span[data-fee='" + $tagval.subscribe_time + "']").addClass('s_s_tag').siblings().removeClass('s_s_tag');
  1091. $('#subscribe_time2').hide();
  1092. } else {
  1093. $("#subscribe_time1 span").last().addClass('s_s_tag').siblings().removeClass('s_s_tag');
  1094. }
  1095. } else {
  1096. var tagObj1 = {
  1097. sex: -1,
  1098. mobile_system:0,
  1099. tag: -1,
  1100. consume: -1,
  1101. kandian: -1,
  1102. subscribe_time: -1,
  1103. all: "0"
  1104. };
  1105. var ucon1 = JSON.stringify(tagObj1);
  1106. $('#usercondition').val(ucon1);
  1107. }
  1108. },
  1109. error: function (err) {
  1110. }
  1111. });
  1112. var flag = 0;
  1113. //测试发送
  1114. $('.test_fans_but').click(function () {
  1115. Custommain.fans_send_message();
  1116. });
  1117. //发送消息时间
  1118. $(document).on('click', '.s_time_box span', function () {
  1119. if (canedit) {
  1120. return false;
  1121. }
  1122. var $this = $(this);
  1123. var nval = parseInt($this.attr('stime'));
  1124. var ntime = Date.parse(new Date());
  1125. var nt = ntime + nval;
  1126. $('#c-sendtime').val(GetRTime(nt));
  1127. });
  1128. $(document).on('click', '.s_tag_li_list span', function () {
  1129. if (canedit) {
  1130. return false;
  1131. }
  1132. var $this = $(this);
  1133. $this.addClass('s_s_tag').siblings('span').removeClass('s_s_tag');
  1134. var tagObj = {
  1135. sex: $('#sex span.s_s_tag').data('sex'),
  1136. mobile_system: $('#mobile_system span.s_s_tag').data('mobile_system'),
  1137. tag: $('#ctag span.s_s_tag').data('cid'),
  1138. consume: $('#consume span.s_s_tag').data('fee'),
  1139. kandian: $('#kandian span.s_s_tag').data('kandian'),
  1140. subscribe_time: $('#subscribe_time1 span.s_s_tag').data('fee'),
  1141. all: "0"
  1142. }
  1143. if ($(this).parent().attr('id') == 'subscribe_time1') {
  1144. if ($(this).data('fee')) {
  1145. $('#cdstarttime').val('');
  1146. $('#cdendtime').val('');
  1147. $('#subscribe_time2').hide();
  1148. } else {
  1149. $('#subscribe_time2').show();
  1150. }
  1151. }
  1152. var uconditon = JSON.stringify(tagObj);
  1153. $('#usercondition').val(uconditon);
  1154. });
  1155. var ofansopen = true;
  1156. //tag切换
  1157. $(document).on('click', '.s_tag_fans_num', function () {
  1158. var $this = $(this);
  1159. //防止重复点击
  1160. if (!ofansopen) {
  1161. return false;
  1162. }
  1163. ofansopen = false;
  1164. $('.s_tag_footer').addClass('s_tag_fans_show');
  1165. var tagObj = {
  1166. sex: $('#sex span.s_s_tag').data('sex'),
  1167. mobile_system: $('#mobile_system span.s_s_tag').data('mobile_system'),
  1168. tag: $('#ctag span.s_s_tag').data('cid'),
  1169. consume: $('#consume span.s_s_tag').data('fee'),
  1170. kandian: $('#kandian span.s_s_tag').data('kandian'),
  1171. subscribe_time: $('#subscribe_time1 span.s_s_tag').data('fee'),
  1172. all: "0"
  1173. }
  1174. var uconditon = JSON.stringify(tagObj);
  1175. $('#usercondition').val(uconditon);
  1176. //console.log(tagObj);
  1177. $.ajax({
  1178. type: 'post',
  1179. data: tagObj,
  1180. //dataType:'json',
  1181. url: '/admin/custom/ajaxcustom',
  1182. success: function (data) {
  1183. //console.log(data);
  1184. $('#mustbe').html('约' + data.ids + '人');
  1185. ofansopen = true;
  1186. $('.s_tag_footer').removeClass('s_tag_fans_show');
  1187. },
  1188. error: function (err) {
  1189. ofansopen = true;
  1190. $('.s_tag_footer').removeClass('s_tag_fans_show');
  1191. }
  1192. });
  1193. });
  1194. /*$(document).on('click', '.img_txt_add_but', function () {
  1195. if (canedit) {
  1196. return false;
  1197. }
  1198. var $List = $('.img_txt_main');
  1199. var oNowData = {
  1200. image: ore.imglis[parseInt(Math.random() * ore.imglis.length)]['image'],
  1201. title: ore.titlist[parseInt(Math.random() * ore.titlist.length)]['title'],
  1202. url: 'http://'
  1203. };
  1204. var sLiImg = ore.sli.replace(/sli_img/g, oNowData['image']);
  1205. sLiImg = sLiImg.replace(/sli_value/g, oNowData['title']);
  1206. sLiImg = sLiImg.replace(/click_url/g, 'http://');
  1207. if ($List.length < 8) {
  1208. $('.img_txt_list').append(sLiImg);
  1209. ore.arrma.push(oNowData);
  1210. } else {
  1211. Toastr.error("不能超过8篇");
  1212. }
  1213. });*/
  1214. $(document).on('click', '.img_txt_remvoe', function () {
  1215. if (canedit) {
  1216. return false;
  1217. }
  1218. var $this = $(this);
  1219. $this.parent().remove();
  1220. });
  1221. //修改title
  1222. // $(document).on('click', '.img_txt_edit_tit', function () {
  1223. // var $this = $(this);
  1224. // Fast.api.open('manage/title/select', '选择', {
  1225. // callback: function (data) {
  1226. // $this.parent().parent().find('input').eq(0).val(data.title);
  1227. // $this.parent().parent().find('input').eq(0)
  1228. // .next().empty().css('display', 'none').closest('.form-group').removeClass('has-error').addClass('has-success');
  1229. // }
  1230. // });
  1231. // });
  1232. //修改菜单链接
  1233. $(document).on('click', '.img_txt_edit_bars', function () {
  1234. var $this = $(this);
  1235. Fast.api.open('link/select?one=1', '选择', {
  1236. callback: function (data) {
  1237. var data = data[0];
  1238. $this.parent().find('input').eq(1).val(data.menu_url);
  1239. }
  1240. });
  1241. });
  1242. //添加文字链
  1243. $(document).on('click', '.textarea_txt_add_but', function () {
  1244. Fast.api.open('custom/addlinktext', '添加消息', {
  1245. callback: function (data) {
  1246. strLinktext = $('.textarea_txt_hidden_input').val()
  1247. var linktext_data = [];
  1248. if (strLinktext.length > 0) {
  1249. linktext_data = JSON.parse(strLinktext);
  1250. }
  1251. linktext_data.push(data);
  1252. $('.textarea_txt_hidden_input').val(JSON.stringify(linktext_data));
  1253. txttext(linktext_data);
  1254. }
  1255. })
  1256. });
  1257. $(document).on('click', '.btn_save_media_but button', function () {
  1258. var saveval = $(this).data('save-val');
  1259. if (typeof saveval != 'undefined') {
  1260. $('.js_is_save_media').val(saveval);
  1261. } else {
  1262. Fast.api.close();
  1263. }
  1264. });
  1265. $(document).on('click', '.js_save_media', function () {
  1266. $('.js_is_save_media').val(1);
  1267. });
  1268. //修改最近阅读链接
  1269. $(document).on('click', '.img_txt_edit_bookmark_o', function () {
  1270. var $this = $(this);
  1271. $.ajax({
  1272. type: 'get',
  1273. url: '/admin/book/book/getrecenturl',
  1274. cache: false,
  1275. async: false,
  1276. success: function (data) {
  1277. $this.parent().find('input').eq(1).val(data.url);
  1278. },
  1279. error: function (err) {
  1280. ofansopen = true;
  1281. $('.s_tag_footer').removeClass('s_tag_fans_show');
  1282. }
  1283. });
  1284. });
  1285. //修改活动
  1286. $(document).on('click', '.img_txt_edit_card_o', function () {
  1287. var $this = $(this);
  1288. Fast.api.open('activity/select?one=1', '选择', {
  1289. callback: function (data) {
  1290. var data = data[0];
  1291. $this.parent().find('input').eq(1).val(data.activity_url);
  1292. }
  1293. });
  1294. });
  1295. //修改url
  1296. $(document).on('click', '.img_txt_edit_url', function () {
  1297. if (canedit) {
  1298. return false;
  1299. }
  1300. var $this = $(this);
  1301. Fast.api.open('referral/referral/select?one=1', '选择', {
  1302. callback: function (data) {
  1303. var data = data[0];
  1304. $('#description').val(excludeSpecial(data['book']['description']));
  1305. // console.log('展示title回调', data);
  1306. $this.parent().find('input').eq(1).val(data.source_url);
  1307. }
  1308. });
  1309. });
  1310. //修改book
  1311. $(document).on('click', '.img_txt_edit_book', function () {
  1312. if (canedit) {
  1313. return false;
  1314. }
  1315. var $this = $(this);
  1316. Fast.api.open('book.book/select?one=1', '选择', {
  1317. callback: function (data) {
  1318. var data = data[0];
  1319. $this.parent().find('input').eq(1).val(data.current_book_url);
  1320. $('#description').val(excludeSpecial(data.description));
  1321. }
  1322. });
  1323. });
  1324. //修改图片
  1325. $(document).on('click', '.img_txt_edit_img', function () {
  1326. if (canedit) {
  1327. return false;
  1328. }
  1329. var $this = $(this);
  1330. Fast.api.open('manage/cover/select', '选择', {
  1331. callback: function (data) {
  1332. $this.find('img').attr('src', data.image);
  1333. }
  1334. });
  1335. });
  1336. //修改图片
  1337. $(document).on('click', '.add_img_txt_edit_img', function () {
  1338. var $this = $(this);
  1339. Fast.api.open('manage/cover/select', '选择', {
  1340. callback: function (data) {
  1341. $this.parent().find('img').attr('src', data.image);
  1342. $this.parent().find('input').eq(0).val(data.image);
  1343. }
  1344. });
  1345. });
  1346. //修改跳转链接
  1347. $(document).on('click', '.img_txt_main a', function () {
  1348. if (canedit) {
  1349. return false;
  1350. }
  1351. var $this = $(this);
  1352. var nIndex = $this.parents('.img_txt_main').index();
  1353. layer.prompt({
  1354. formType: 2,
  1355. value: ore.arrma[nIndex].url,
  1356. title: '请输入跳转链接地址(http://)',
  1357. area: ['300px', '100px'] //自定义文本域宽高
  1358. }, function (value, index, elem) {
  1359. var reg = /^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\/])+$/;
  1360. if (reg.test(value)) {
  1361. layer.close(index);
  1362. ore.arrma[nIndex].url = value;
  1363. $this.html(value);
  1364. } else {
  1365. Toastr.error("请输入正确的跳转地址。");
  1366. }
  1367. });
  1368. });
  1369. function GetRTime(time) {
  1370. var stime;
  1371. time = new Date(time);
  1372. var year = time.getYear() + 1900;
  1373. var month = time.getMonth() + 1;
  1374. var day = time.getDate();
  1375. var hours = time.getHours();
  1376. var minutes = time.getMinutes();
  1377. var seconds = time.getSeconds();
  1378. stime = year + '-' +
  1379. (month < 10 ? '0' + month : month) + '-' +
  1380. (day < 10 ? '0' + day : day) + ' ' +
  1381. (hours < 10 ? '0' + hours : hours) + ':' +
  1382. (minutes < 10 ? '0' + minutes : minutes) + ':' +
  1383. (seconds < 10 ? '0' + seconds : seconds);
  1384. return stime;
  1385. }
  1386. },
  1387. oldbindevet: function () {
  1388. //资源管理
  1389. var ore = {
  1390. arrma: [
  1391. {
  1392. 'title': '',
  1393. 'image': '',
  1394. 'url': 'http://'
  1395. }
  1396. ],
  1397. imglis: [],
  1398. titlist: [],
  1399. sli: '<div class="img_txt_li img_txt_main">\
  1400. <div class="img_txt_li_img img_txt_edit_img"><img src="sli_img" /></div>\
  1401. <div class="img_txt_li_txt">\
  1402. <i class="fa fa-pencil img_txt_edit_tit"></i>\
  1403. <div class="img_txt_li_h3"><input type="text" value="sli_value" /></div>\
  1404. <i class="fa fa-chain img_txt_edit_url"></i>\
  1405. <i class="fa fa-book img_txt_edit_book"></i>\
  1406. <div class="img_txt_li_url"><input type="text" value="click_url" /></div>\
  1407. </div>\
  1408. <div class="fa img_txt_remvoe"></div>\
  1409. </div>'
  1410. };
  1411. $.ajax({
  1412. type:'get',
  1413. url:'/admin/manage/cover/ajax?sort=id&order=desc&offset=0&limit=10&filter={"status":"normal"}',
  1414. cache:false,
  1415. async:false,
  1416. success:function(data){
  1417. // console.log(data)
  1418. ore.imglis = data.rows;
  1419. },
  1420. error:function(err){
  1421. }
  1422. });
  1423. $.ajax({
  1424. type:'get',
  1425. url:'/admin/manage/title/ajax?sort=id&order=desc&offset=0&limit=10&filter={"status":"normal"}',
  1426. cache:false,
  1427. async:false,
  1428. success:function(data){
  1429. // console.log(data)
  1430. ore.titlist = data.rows;
  1431. ore.arrma[0]['image'] = ore.imglis[parseInt(Math.random()*ore.imglis.length)]['image'];
  1432. ore.arrma[0]['title'] = ore.titlist[parseInt(Math.random()*ore.titlist.length)]['title'];
  1433. if($('.img_txt_hidde_input').val().length > 0){
  1434. ore.arrma = JSON.parse($('.img_txt_hidde_input').val());
  1435. //console.log(ore.arrma);
  1436. for(var i=0; i<1; i++){
  1437. if(i==0){
  1438. if(canedit){
  1439. $('.img_txt_list').html('<div class="img_txt_one img_txt_main">\
  1440. <div class="img_txt_one_tit">\
  1441. <div class="img_txt_one_h3"><input type="text" readonly value="' + ore.arrma[0]['title'] + '" /></div>\
  1442. <div class="img_txt_one_url"><input type="text" readonly value="' + ore.arrma[0]['url'] + '" /></div>\
  1443. </div>\
  1444. <div class="img_txt_one_img img_txt_edit_img"><img src="' + ore.arrma[0]['image'] + '" /></div>\
  1445. </div>');
  1446. $('#description').val(excludeSpecial(ore.arrma[0]['description']));
  1447. }else{
  1448. $('.img_txt_list').html('<div class="img_txt_one img_txt_main">\
  1449. <div class="img_txt_one_tit">\
  1450. <i class="fa fa-pencil img_txt_edit_tit"></i>\
  1451. <div class="img_txt_one_h3"><input type="text" value="' + ore.arrma[0]['title'] + '" /></div>\
  1452. <i class="fa fa-chain img_txt_edit_url"></i>\
  1453. <i class="fa fa-book img_txt_edit_book"></i>\
  1454. <div class="img_txt_one_url"><input type="text" value="' + ore.arrma[0]['url'] + '" /></div>\
  1455. </div>\
  1456. <div class="img_txt_one_img img_txt_edit_img"><img src="' + ore.arrma[0]['image'] + '" /></div>\
  1457. </div>');
  1458. $('#description').val(excludeSpecial(ore.arrma[0]['description']));
  1459. }
  1460. }else{
  1461. var sLiImg=ore.sli.replace(/sli_img/g,ore.arrma[i]['image']);
  1462. sLiImg=sLiImg.replace(/sli_value/g,ore.arrma[i]['title']);
  1463. sLiImg=sLiImg.replace(/click_url/g,ore.arrma[i]['url']);
  1464. $('.img_txt_list').append(sLiImg);
  1465. }
  1466. }
  1467. }else{
  1468. if(!canedit){
  1469. $('.img_txt_list').html('<div class="img_txt_one img_txt_main">\
  1470. <div class="img_txt_one_tit">\
  1471. <i class="fa fa-pencil img_txt_edit_tit"></i>\
  1472. <div class="img_txt_one_h3"><input type="text" value="' + ore.arrma[0]['title'] + '" /></div>\
  1473. <i class="fa fa-chain img_txt_edit_url"></i>\
  1474. <i class="fa fa-book img_txt_edit_book"></i>\
  1475. <div class="img_txt_one_url"><input type="text" value="' + ore.arrma[0]['url'] + '" /></div>\
  1476. </div>\
  1477. <div class="img_txt_one_img img_txt_edit_img"><img src="' + ore.arrma[0]['image'] + '" /></div>\
  1478. </div>');
  1479. $('#description').val(excludeSpecial(ore.arrma[0]['description']));
  1480. }else{
  1481. $('.img_txt_list').html('<div class="img_txt_one img_txt_main">\
  1482. <div class="img_txt_one_tit">\
  1483. <div class="img_txt_one_h3"><input type="text" value="' + ore.arrma[0]['title'] + '" /></div>\
  1484. <div class="img_txt_one_url"><input type="text" value="' + ore.arrma[0]['url'] + '" /></div>\
  1485. </div>\
  1486. <div class="img_txt_one_img img_txt_edit_img"><img src="' + ore.arrma[0]['image'] + '" /></div>\
  1487. </div>');
  1488. $('#description').val(excludeSpecial(ore.arrma[0]['description']));
  1489. }
  1490. }
  1491. },
  1492. error:function(err){
  1493. }
  1494. });
  1495. }
  1496. }
  1497. }
  1498. return Controller;
  1499. });