book.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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. commonSearch: false,
  23. columns: [
  24. [
  25. {field: 'id', title: __('Id')},
  26. {field: 'image', title: '封面', operate:false, formatter: Controller.api.formatter.image},
  27. {field: 'name', title: '名称', operate:false, formatter: Controller.api.formatter.name_text},
  28. {field: 'price', title: '单价(元)', operate:false, formatter: Controller.api.formatter.price},
  29. {field: 'sex', title:'频道',formatter: Controller.api.formatter.sex_text,searchList: {'1':'男频','2':'女频'},operate:false,},
  30. {field: 'book_category_id', title: '类别',formatter: Controller.api.formatter.category_text,searchList:$.getJSON('book/category/categorylist'),operate:false,},
  31. {field: 'is_finish', title:'完结状态',formatter:Controller.api.formatter.is_finish_text,searchList:{'1':'完结','0':'连载'},operate:false,},
  32. {field: 'state', title:'上架状态',visible:(Config.group<3),formatter:Controller.api.formatter.state_text,searchList:{'1':'上架','-1':'入库'},operate:false,},
  33. {field: 'idx', title: '派单指数',operate:'BETWEEN',searchList:{'91,100':'100-91','81,90':'90-81','61,80':'80-61','0,60':'60以下'},operate:false,},
  34. {field: 'keywords',title:'关键字搜索',operate:false,visible:false},
  35. {field: 'operate', title: '操作', formatter: Controller.api.formatter.tuiguang},
  36. ]
  37. ]
  38. });
  39. // 为表格绑定事件
  40. Table.api.bindevent(table);
  41. // 弹窗绑定
  42. $(document).on('click','.layer-open',function () {
  43. Fast.api.open($(this).attr('href'), $(this).text(), {});
  44. return false;
  45. });
  46. $(document).on('click','.book_but',function () {
  47. Fast.api.open($(this).attr('href'), '推广连接', {});
  48. return false;
  49. });
  50. require(['vue','component','ELEMENT'], function (Vue, component, ELEMENT) {
  51. Vue.use(ELEMENT);
  52. Vue.use(component);
  53. var refreshTable = function (form) {
  54. var options = table.bootstrapTable('getOptions');
  55. options.pageNumber = 1;
  56. options.queryParams = function (params) {
  57. var submit = $.extend({
  58. sort: params.sort,
  59. order: params.order,
  60. offset: params.offset,
  61. limit: params.limit,
  62. name: name
  63. }, form);
  64. return submit;
  65. };
  66. table.bootstrapTable('refresh', {});
  67. }
  68. var Main = {
  69. el: '#book',
  70. data: function () {
  71. return {
  72. list_value: [
  73. {
  74. type: "input",
  75. data: {
  76. input: '',
  77. placeholder: '书籍ID/名称/主角名搜索',
  78. size: 'medium',
  79. field: 'name'
  80. }
  81. },
  82. {
  83. type: "pick",
  84. data: {
  85. label: '小说属性:',
  86. data: Config.filter.property,
  87. active: '',
  88. field: 'corner_mark',
  89. }
  90. },
  91. {
  92. type: "pick",
  93. data: {
  94. label: '读者性别:',
  95. data: Config.filter.sex,
  96. active: '',
  97. field: 'sex',
  98. }
  99. },
  100. {
  101. type: "pick",
  102. data: {
  103. label: '连载状态:',
  104. data: Config.filter.is_finish,
  105. active: '',
  106. field: 'is_finish',
  107. }
  108. },
  109. {
  110. type: "pick",
  111. data: {
  112. label: '字数筛选:',
  113. data: Config.filter.word_count,
  114. active: '',
  115. field: 'word_count',
  116. }
  117. },
  118. {
  119. type: "pick",
  120. data: {
  121. label: '上架状态:',
  122. data: Config.filter.state,
  123. active: '',
  124. field: 'state',
  125. }
  126. },
  127. {
  128. type: "pick",
  129. data: {
  130. label: '小说类型:',
  131. data: Config.filter.category_all,
  132. active: '',
  133. field: 'book_category_id',
  134. }
  135. },
  136. {
  137. type: "pick",
  138. data: {
  139. label: '派单指数:',
  140. data: Config.filter.idx,
  141. active: '',
  142. field: 'idx',
  143. }
  144. }
  145. ]
  146. }
  147. },
  148. methods: {
  149. commit: function (form) {
  150. if (form.sex) {
  151. if (form.sex == 2) {
  152. this.list_value[6].data.data = Config.filter.category_girl
  153. } else {
  154. this.list_value[6].data.data = Config.filter.category_boy
  155. }
  156. } else {
  157. this.list_value[6].data.data = Config.filter.category_all
  158. }
  159. refreshTable(form)
  160. }
  161. }
  162. };
  163. new Vue(Main)
  164. });
  165. },
  166. info: function () {
  167. // 初始化表格参数配置
  168. Table.api.init({
  169. extend: {
  170. index_url: 'referral/book/info',
  171. }
  172. });
  173. var table = $("#table");
  174. var tableOptions = {
  175. url: $.fn.bootstrapTable.defaults.extend.index_url,
  176. pk: 'id',
  177. sortName: 'id',
  178. showColumns:false,
  179. showToggle:false,
  180. showExport:false,
  181. search:false,
  182. // commonSearch: false,
  183. columns: [
  184. [
  185. {field: 'id', title: __('Id')},
  186. {field: 'name', title: '章节',formatter: Controller.api.formatter.name},
  187. {field: 'operate', title: '操作', formatter: Controller.api.formatter.links},
  188. ]
  189. ],
  190. onLoadSuccess: function (data) {
  191. $("[data-toggle='tooltip']").tooltip();
  192. }
  193. };
  194. if (Config.show_all_select) {
  195. tableOptions.columns[0].push({field: 'uv', title: '阅读人数'})
  196. tableOptions.columns[0].push({field: 'uv_rate', title: '占比', formatter: function (value) {
  197. if (value !== undefined) {
  198. return value + '%'
  199. }
  200. }})
  201. }
  202. // 初始化表格
  203. table.bootstrapTable(tableOptions);
  204. // 为表格绑定事件
  205. Table.api.bindevent(table);
  206. // 获取推广链接
  207. $(document).on('click','.layer-open',function () {
  208. Fast.api.open($(this).attr('href'), $(this).data('title')?$(this).data('title'):'获取推广链接', {});
  209. return false;
  210. });
  211. // 设置关注章节
  212. $(document).on('click','.set-guide-chapter-idx',function () {
  213. $this = $(this);
  214. Fast.api.ajax({
  215. 'url': $this.attr('href')
  216. }, function (data) { //success
  217. Config.guide_chapter_idx = data.guide_chapter_idx; //更新订购章节
  218. table.bootstrapTable('refresh');
  219. }, function (data) { //error
  220. });
  221. return false;
  222. });
  223. },
  224. chapter: function () {
  225. $(document).on('click', '.btn-close', function () {
  226. Fast.api.close();
  227. });
  228. },
  229. api: {
  230. bindevent: function () {
  231. Form.api.bindevent($("form[role=form]"));
  232. },
  233. formatter: {
  234. // name: function (value, row, index) {
  235. // return '<a href="/admin/book/book/info?id=' + row.id + '" style="cursor:pointer;">' + value + '</a>';
  236. // },
  237. image: function (value, row, index) {
  238. return '<div class="cover_img" style="width:auto !important; height:auto !important;">' +
  239. '<a href="/admin/referral/book/info?id=' + row.id + '" style="cursor:pointer;" class="btn btn-xs btn-editone book_but ">' +
  240. '<img class="img-sm img-center" style="width:100px !important; height:auto !important; display:block; border:0;" src="' + value + '" />' +
  241. '</a>' +
  242. '<span><img src="' + value + '" /></span></div>';
  243. },
  244. sex_text: function(value,row,index){return '<span style="white-space: nowrap;">' + row.sex_text + '</span>';},
  245. category_text: function(value,row,index){return '<span style="white-space: nowrap;">' + row.category_text + '</span>'},
  246. state_text: function(value,row,index){return '<span style="white-space: nowrap;">' + row.state_text + '</span>'},
  247. is_finish_text: function(value,row,index){return '<span style="white-space: nowrap;">' + row.is_finish_text + '</span>'},
  248. tuiguang: function (value, row, index) {
  249. return '<a href="/admin/referral/book/info?id=' + row.id + '" style="cursor:pointer;" class="btn btn-xs btn-success btn-editone book_but ">推广连接</a>';
  250. },
  251. //章节名称的格式化
  252. name: function (value, row, index) {
  253. bookinfo = Config.bookinfo;
  254. site = Config.site;
  255. mark = '';
  256. if(row.idx <= Config.free_chapter_num ) {
  257. if(bookinfo.article_chapter_order == row.idx || (( bookinfo.article_chapter_order == 0 ) && site.article_chapter_order ==row.idx )){
  258. mark = '<span style="background:red;color:#fff;padding:2px 5px;">推荐文案章节</span>';
  259. }
  260. if(bookinfo.attent_chapter_order == row.idx || ( (bookinfo.attent_chapter_order == 0) && site.attent_chapter_order == row.idx) ){
  261. mark = '<span style="background:green;color:#fff;padding:2px 5px;">推荐关注章节</span>';
  262. }
  263. return '<a href="/admin/book/book/chapter/book_id/' + Config.book_id + '/chapter_id/' + row.id + '" class="layer-open" data-title="章节正文">' + value + '</a>'+mark;
  264. }else{
  265. return value+' <i class="fa fa-jpy text-danger"></i>'+mark;
  266. }
  267. },
  268. price: function (value, row, index) {
  269. if (value > 0) {
  270. return value + '/' + (row.billing_type == 1 ? '章' : '本');
  271. } else {
  272. return Config.site.book_chapter_price + '/章';
  273. }
  274. },
  275. links: function (value, row, index) {
  276. html = [];
  277. if (Config.show_all_select == 1) {
  278. if(row.idx == 1 && Config.guide_switch){
  279. if(Config.not_ban != 1){
  280. html.push('<a href="/admin/referral/referral/add?book_id=' + Config.book_id + '&chapter_id=' + row.id + '&type=3' + '" class="layer-open" data-toggle="tooltip" title="生成落地页推广">生成落地页推广</a>');
  281. }
  282. }
  283. if(row.idx <= Config.bookinfo.referral_num){
  284. if(Config.not_ban != 1){
  285. html.push('<a href="/admin/referral.referral/essay/book_id/' + Config.book_id + '/chapter_idx/' + row.idx + '" target="_blank" data-toggle="tooltip" title="文章内容到当前章节,原文链接为下一章">生成推广文案</a>');
  286. html.push('<a href="/admin/referral.referral/essayimage/book_id/' + Config.book_id + '/chapter_idx/' + row.idx + '" target="_blank" data-toggle="tooltip" title="文章内容到当前章节,原文链接为下一章">生成推广图片</a>');
  287. html.push('<a href="/admin/referral.referral/background/book_id/' + Config.book_id + '/chapter_idx/' + row.idx + '" target="_blank" data-toggle="tooltip" title="文章内容到当前章节,原文链接为下一章">背景图模式</a>');
  288. }
  289. }
  290. }
  291. if(row.idx <= Config.free_chapter_num) {
  292. if(Config.not_ban != 1) {
  293. html.push('<a href="/admin/referral/referral/add?book_id=' + Config.book_id + '&chapter_id=' + row.id + '&chapter_idx=' + row.idx + '" class="layer-open" data-toggle="tooltip" title="原文链接为当前章节">获取推广链接</a>');
  294. }
  295. if (row.idx == Config.guide_chapter_idx) {
  296. html.push('<a href="javascript:;" class="text-green"><i class="fa fa-check-circle-o"></i>&nbsp;当前关注章节</a>')
  297. } else {
  298. html.push('<a class="set-guide-chapter-idx" href="referral/book/setguidechapteridx?book_id=' + Config.book_id + '&chapter_idx=' + row.idx + '">设为关注章节</a>');
  299. }
  300. }
  301. return html.join('&nbsp;&nbsp;');
  302. },
  303. name_text: function(value,row,index){
  304. mark = '';
  305. if(row.corner_mark == 'hot'){
  306. mark = '<span class="rb_hot">'+row.corner_mark_text+'</span>';
  307. }else if(row.corner_mark == 'exclusive'){
  308. mark = '<span class="rb_exclusive">'+row.corner_mark_text+'</span>';
  309. }else if(row.corner_mark == 'new'){
  310. mark = '<span class="rb_new">'+row.corner_mark_text+'</span>';
  311. } else {
  312. }
  313. //endregion
  314. //region 是否完本
  315. is_finish = row.is_finish == '1' ? '已完结' : '连载中';
  316. is_finish = "【" + is_finish + "】";
  317. //endregion
  318. //章节数
  319. chapter_num = ' 共' + row.chapter_num + '章(共'+Math.floor(row.word_count / 10000)+'万字)';
  320. //推荐关注章节
  321. site = Config.site;
  322. if (row.attent_chapter_order == null || row.attent_chapter_order == 0) {
  323. attent_chapter_order = site.attent_chapter_order;
  324. } else {
  325. attent_chapter_order = row.attent_chapter_order;
  326. }
  327. str_attent_chapter_order = ' 第' + attent_chapter_order + '章开始关注';
  328. //region 最新章节
  329. last_chapter = ' 最新章节:' + row.last_chapter_name + (row.is_finish == '1' ? '(大结局)' : '') + '&nbsp;';
  330. str_last_chapter_utime = '<br/> ' + Moment.unix(row.last_chapter_utime).format('YYYY-MM-DD HH:mm:ss');
  331. last_chapter += str_last_chapter_utime;
  332. //endregion
  333. //主编推荐语
  334. editor_recommand = '';
  335. if(row.editor_recommand !== null && row.editor_recommand !== ''){
  336. var editor_text = row.editor_recommand;
  337. if (editor_text.length > 150) {
  338. editor_text = editor_text.substr(0, 150) + '...';
  339. }
  340. editor_recommand = '<br/><span title="' + row.editor_recommand + '"> 主编推荐语:' + editor_text + '</span>';
  341. }
  342. var free_text = '';
  343. var current_time = new Date().getTime() / 1000;
  344. if (current_time > row.free_stime && current_time < row.free_etime) {
  345. free_text = '<span class="free_time">限免:'+Moment.unix(row.free_stime).format('MM.DD') + '-' + Moment.unix(row.free_etime).format('MM.DD') + '</span><p>';
  346. }
  347. if(row.book_tags_text){
  348. return '<div style="text-align: left;"><p><span style="color#03f;font-size:16px;vertical-align: middle;">' +
  349. '<a href="/admin/referral/book/info?id=' + row.id + '" style="cursor:pointer;font-size:16px;">' +
  350. value + '</a>' + '</span><span style="font-size:16px;vertical-align: middle;">' + is_finish + '</span>' + row.book_tags_text + '</p>' +free_text+ chapter_num + '<br/>' + str_attent_chapter_order +
  351. '<br>' + last_chapter + '' + editor_recommand +'</div>';
  352. }else{
  353. return '<div style="text-align: left;"><p><span style="color#03f;font-size:16px;vertical-align: middle;">' +
  354. '<a href="/admin/referral/book/info?id=' + row.id + '" style="cursor:pointer;font-size:16px;">' +
  355. value + '</a>' + '</span><span style="font-size:16px;vertical-align: middle;">' + is_finish + '</span>' + mark + '</p>' +free_text+ chapter_num + '<br/>' + str_attent_chapter_order +
  356. '<br>' + last_chapter + '' + editor_recommand + '</div>';
  357. }
  358. }
  359. }
  360. }
  361. };
  362. return Controller;
  363. });