book.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'referral/book/index',
  8. info_url: 'book/book/info',
  9. table: 'book',
  10. }
  11. });
  12. var table = $("#table");
  13. // 初始化表格
  14. table.bootstrapTable({
  15. url: $.fn.bootstrapTable.defaults.extend.index_url,
  16. pk: 'id',
  17. sortName: 'idx',
  18. search: false,
  19. showToggle:false,
  20. showColumns: false,
  21. showExport: false,
  22. searchFormVisible: true,
  23. columns: [
  24. [
  25. {field: 'id', title: __('Id')},
  26. {field: 'image', title: '封面', operate:false, formatter: Controller.api.formatter.image},
  27. {field: 'name', title:'名称',operate:'LIKE',formatter:Controller.api.formatter.name_text},
  28. {field: 'sex', title:'频道',formatter: Controller.api.formatter.sex_text,searchList: {'1':'男频','2':'女频'}},
  29. {field: 'book_category_id', title: '类别',formatter: Controller.api.formatter.category_text,searchList:$.getJSON('book/category/categorylist')},
  30. {field: 'is_finish', title:'完结状态',formatter:Controller.api.formatter.is_finish_text,searchList:{'1':'完结','0':'连载'}},
  31. {field: 'state', title:'上架状态',visible:(Config.group<3),formatter:Controller.api.formatter.state_text,searchList:{'1':'上架','-1':'入库'}},
  32. {field: 'idx', title: '派单指数',operate:'BETWEEN',searchList:{'91,100':'100-91','81,90':'90-81','61,80':'80-61','0,60':'60以下'}},
  33. {field: 'keywords',title:'关键字搜索',operate:'LIKE',visible:false},
  34. {field: 'operate', title: '操作', formatter: Controller.api.formatter.tuiguang},
  35. ]
  36. ]
  37. });
  38. // 为表格绑定事件
  39. Table.api.bindevent(table);
  40. // 弹窗绑定
  41. $(document).on('click','.layer-open',function () {
  42. Fast.api.open($(this).attr('href'), $(this).text(), {});
  43. return false;
  44. })
  45. //book_but
  46. $(document).on('click','.book_but',function () {
  47. Fast.api.open($(this).attr('href'), '推广连接', {});
  48. return false;
  49. });
  50. },
  51. info: function () {
  52. // 初始化表格参数配置
  53. Table.api.init({
  54. extend: {
  55. index_url: 'referral/book/info',
  56. }
  57. });
  58. var table = $("#table");
  59. // 初始化表格
  60. table.bootstrapTable({
  61. url: $.fn.bootstrapTable.defaults.extend.index_url,
  62. pk: 'id',
  63. sortName: 'id',
  64. showColumns:false,
  65. showToggle:false,
  66. showExport:false,
  67. search:false,
  68. // commonSearch: false,
  69. columns: [
  70. [
  71. {field: 'id', title: __('Id')},
  72. {field: 'name', title: '章节',formatter: Controller.api.formatter.name},
  73. {field: 'operate', title: '操作', formatter: Controller.api.formatter.links}
  74. ]
  75. ],
  76. onLoadSuccess: function (data) {
  77. $("[data-toggle='tooltip']").tooltip();
  78. }
  79. });
  80. // 为表格绑定事件
  81. Table.api.bindevent(table);
  82. // 获取推广链接
  83. $(document).on('click','.layer-open',function () {
  84. Fast.api.open($(this).attr('href'), $(this).data('title')?$(this).data('title'):'获取推广链接', {});
  85. return false;
  86. });
  87. // 设置关注章节
  88. $(document).on('click','.set-guide-chapter-idx',function () {
  89. $this = $(this);
  90. Fast.api.ajax({
  91. 'url': $this.attr('href')
  92. }, function (data) { //success
  93. Config.guide_chapter_idx = data.guide_chapter_idx; //更新订购章节
  94. table.bootstrapTable('refresh');
  95. }, function (data) { //error
  96. });
  97. return false;
  98. });
  99. },
  100. chapter: function () {
  101. $(document).on('click', '.btn-close', function () {
  102. Fast.api.close();
  103. });
  104. },
  105. api: {
  106. bindevent: function () {
  107. Form.api.bindevent($("form[role=form]"));
  108. },
  109. formatter: {
  110. // name: function (value, row, index) {
  111. // return '<a href="/admin/book/book/info?id=' + row.id + '" style="cursor:pointer;">' + value + '</a>';
  112. // },
  113. image: function (value, row, index) {
  114. return '<div class="cover_img"><img class="img-sm img-center" src="'+ value +'" /><span><img src="'+ value +'" /></span></div>';
  115. },
  116. sex_text: function(value,row,index){return row.sex_text;},
  117. category_text: function(value,row,index){return row.category_text},
  118. state_text: function(value,row,index){return row.state_text},
  119. is_finish_text: function(value,row,index){return row.is_finish_text},
  120. tuiguang: function (value, row, index) {
  121. return '<a href="/admin/referral/book/info?id=' + row.id + '" style="cursor:pointer;" class="btn btn-xs btn-success btn-editone book_but">推广连接</a>';
  122. },
  123. //章节名称的格式化
  124. name: function (value, row, index) {
  125. bookinfo = Config.bookinfo;
  126. site = Config.site;
  127. mark = '';
  128. if(row.idx <= Config.free_chapter_num ) {
  129. if(bookinfo.article_chapter_order == row.idx || (( bookinfo.article_chapter_order == 0 ) && site.article_chapter_order ==row.idx )){
  130. mark = '<span style="background:red;color:#fff;padding:2px 5px;">推荐文案章节</span>';
  131. }
  132. if(bookinfo.attent_chapter_order == row.idx || ( (bookinfo.attent_chapter_order == 0) && site.attent_chapter_order == row.idx) ){
  133. mark = '<span style="background:green;color:#fff;padding:2px 5px;">推荐关注章节</span>';
  134. }
  135. return '<a href="/admin/book/book/chapter/book_id/' + Config.book_id + '/chapter_id/' + row.id + '" class="layer-open" data-title="章节正文">' + value + '</a>'+mark;
  136. }else{
  137. return value+' <i class="fa fa-jpy text-danger"></i>'+mark;
  138. }
  139. },
  140. links: function (value, row, index) {
  141. html = [];
  142. if(row.idx <= Config.bookinfo.referral_num){
  143. html.push('<a href="/admin/referral.referral/essay/book_id/' + Config.book_id + '/chapter_idx/' + row.idx + '" target="_blank" data-toggle="tooltip" title="文章内容到当前章节,原文链接为下一章">生成推广文案</a>');
  144. html.push('<a href="/admin/referral.referral/essayimage/book_id/' + Config.book_id + '/chapter_idx/' + row.idx + '" target="_blank" data-toggle="tooltip" title="文章内容到当前章节,原文链接为下一章">生成推广图片</a>');
  145. }
  146. if(row.idx <= Config.free_chapter_num) {
  147. html.push('<a href="/admin/referral/referral/add?book_id=' + Config.book_id + '&chapter_id=' + row.id + '" class="layer-open" data-toggle="tooltip" title="原文链接为当前章节">获取推广链接</a>');
  148. if (row.idx == Config.guide_chapter_idx) {
  149. html.push('<a href="javascript:;" class="text-green"><i class="fa fa-check-circle-o"></i>&nbsp;当前关注章节</a>')
  150. } else {
  151. html.push('<a class="set-guide-chapter-idx" href="referral/book/setguidechapteridx?book_id=' + Config.book_id + '&chapter_idx=' + row.idx + '">设为关注章节</a>');
  152. if(Config.agent_distribute){
  153. html.push('<a class="layer-open" href="referral/book/createQRCode?book_id=' + Config.book_id + '&chapter_id=' + row.id + '&book_name='+bookinfo.name+'&chapter_name='+row.name+'" title="生成关注二维码" data-title="生成关注二维码">生成关注二维码</a>');
  154. }
  155. }
  156. }
  157. return html.join('&nbsp;&nbsp;');
  158. },
  159. name_text: function(value,row,index){
  160. mark = '';
  161. if(row.corner_mark == 'hot'){
  162. mark = '<span class="rb_hot">'+row.corner_mark_text+'</span>';
  163. }else if(row.corner_mark == 'exclusive'){
  164. mark = '<span class="rb_exclusive">'+row.corner_mark_text+'</span>';
  165. }else if(row.corner_mark == 'new'){
  166. mark = '<span class="rb_new">'+row.corner_mark_text+'</span>';
  167. } else {
  168. }
  169. return value+mark;
  170. }
  171. }
  172. }
  173. };
  174. return Controller;
  175. });