uclandingpage.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'clipboard','selectpage'], function ($, undefined, Backend, Table, Form, Clipboard,Selectpage) {
  2. var Controller = {
  3. index: function () {
  4. $(document).on('click','.layer-open',function () {
  5. Fast.api.open($(this).attr('href'), $(this).data('title')?$(this).data('title'):'配置公共信息', {});
  6. return false;
  7. });
  8. // 初始化表格参数配置
  9. Table.api.init({
  10. extend: {
  11. index_url: 'uclandingpage/index',
  12. add_url: 'uclandingpage/add',
  13. edit_url: 'uclandingpage/edit',
  14. multi_url: 'uclandingpage/multi',
  15. editwx_url: 'uclandingpage/editwx',
  16. table: 'uc_loading',
  17. },
  18. search: false
  19. });
  20. var table = $("#table");
  21. // 初始化表格
  22. table.bootstrapTable({
  23. url: $.fn.bootstrapTable.defaults.extend.index_url,
  24. pk: 'id',
  25. sortName: 'id',
  26. columns: [
  27. [
  28. {field: 'id', title: __('Id'), operate:false},
  29. {field: 'title', title: __('Title'), operate:'LIKE'},
  30. {field: 'domain', title: '域名', operate:false},
  31. {field: 'image', title: '图片', operate:false, formatter: Table.api.formatter.image},
  32. {field: 'book_id', title: __('书籍ID')},
  33. {field: 'book_name', title: '书籍名称', operate:false},
  34. {field: 'chapter_num', title: __('章节数')},
  35. {field: 'new', title: '关注(今日/累计)', operate:false, formatter: function(value){return value + '';}},
  36. {field: 'payCount', title: '支付次数(今日/累计)', operate:false, formatter: function(value){return value + '';}},
  37. {field: 'payMoney', title: '支付金额(今日/累计)', operate:false, formatter: function(value){return value + '';}},
  38. {field: 'createtime', title: __('创建时间'), operate:false, formatter:Table.api.formatter.datetime},
  39. {
  40. field: 'operate',
  41. title: __('Operate'),
  42. formatter: function (value, row, index) {
  43. return '<span class="btn btn-xs btn-success copy-url" data-domain="'+row.domain+'" data-id="'+row.id+'">复制</span><a href="/uploads/static/uc/'+row.id+'.html" target="_blank" class="btn btn-xs btn-success" data-id="'+row.id+'">预览</a><a href="/admin/uclandingpage/edit/ids/'+row.id+'" class="btn btn-xs btn-success btn-editone layer-open" data-title="编辑">编辑</a>';
  44. }
  45. }
  46. ]
  47. ]
  48. });
  49. var clipboard = new Clipboard(".copy-url", {
  50. text: function (trigger) {
  51. return Config.scheme + '://' + $(trigger).data('domain') + '/uploads/static/uc/' + $(trigger).data('id') + '.html';
  52. }
  53. });
  54. var clipboard1 = new Clipboard(".copy-pay", {
  55. text: function () {
  56. return Config.pay_url;
  57. }
  58. });
  59. clipboard1.on('success',function () {
  60. Toastr.success('复制成功');
  61. }).on('error',function () {
  62. Toastr.error('复制失败');
  63. });
  64. clipboard.on('success',function () {
  65. Toastr.success('复制成功');
  66. }).on('error',function () {
  67. Toastr.error('复制失败');
  68. });
  69. // 为表格绑定事件
  70. Table.api.bindevent(table);
  71. },
  72. add: function () {
  73. var selectdata = '';
  74. $('#c-book_book_name').selectPage({
  75. eAjaxSuccess : function(d){
  76. if(selectdata && JSON.stringify(selectdata) != JSON.stringify(d)){
  77. $('#c-book_id').val('');
  78. }
  79. selectdata = d;
  80. return d ? d : '';
  81. },
  82. eSelect : function(d){
  83. selectdata = '';
  84. $('#c-book_book_name').val(d.name);
  85. $('#c-book_id').val(d.id);
  86. },
  87. eClear : function(){
  88. $('#c-book_id').val('');
  89. }
  90. });
  91. Controller.api.bindevent();
  92. },
  93. edit: function () {
  94. var selectdata = '';
  95. $('#c-book_book_name').selectPage({
  96. eAjaxSuccess : function(d){
  97. if(selectdata && JSON.stringify(selectdata) != JSON.stringify(d)){
  98. $('#c-book_id').val('');
  99. }
  100. selectdata = d;
  101. return d ? d : '';
  102. },
  103. eSelect : function(d){
  104. selectdata = '';
  105. $('#c-book_book_name').val(d.name);
  106. $('#c-book_id').val(d.id);
  107. },
  108. eClear : function(){
  109. $('#c-book_id').val('');
  110. }
  111. });
  112. if(Config.bnotin.length>0){
  113. if(Config.bnotin.indexOf(parseInt($('#c-book_id').val())) != -1){
  114. $('#c-book_id').val('');
  115. $('#c-book_book_name').val('');
  116. }
  117. }
  118. Controller.api.bindevent();
  119. },
  120. editwx: function () {
  121. Controller.api.bindevent();
  122. },
  123. callbacktime: function () {
  124. Controller.api.bindevent();
  125. },
  126. api: {
  127. bindevent: function () {
  128. Form.api.bindevent($("form[role=form]"));
  129. }
  130. }
  131. };
  132. return Controller;
  133. });