customqrcode.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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: 'customqrcode/index',
  8. add_url: 'customqrcode/add',
  9. edit_url: 'customqrcode/edit',
  10. del_url: 'customqrcode/del',
  11. multi_url: 'customqrcode/multi',
  12. download_url: 'customqrcode/download',
  13. table: 'custom_qrcode',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'id',
  22. columns: [
  23. [
  24. {checkbox: true},
  25. {field: 'id',title:"索引"},
  26. {field: 'type', title: __('type'),searchList: {"0":__('Type0'),"1":__('Type1'),"2":__('Type2'),"3":"推广链接"},formatter: Controller.api.formatter.type_text},
  27. {field: 'title', title: __('Title')},
  28. {field: 'url', title: __('Url'),operate: false, formatter: Controller.api.formatter.formt_url_list},
  29. {field: 'all_read_uv', title: '累计阅读人数(今日阅读人数)', operate:false,formatter:function(value,row,index){
  30. return value+'('+row.day_read_uv+')';
  31. }},
  32. {
  33. field: 'all_pay_money',
  34. title: '累计充值金额(今日充值金额)',
  35. operate: false,
  36. formatter: function (value, row, index) {
  37. return value + "(" + row.day_pay_money + ")";
  38. }
  39. },
  40. {field: 'uv_per_day', title:"自定义二维码每日关注UV",operate: false},
  41. {field: 'uv', title:"自定义二维码关注UV",operate: false},
  42. {field: 'cost', title: '推广成本', operate: false},
  43. {
  44. field: 'createtime',
  45. title: '创建时间',
  46. operate: 'RANGE',
  47. addclass: 'datetimerange',
  48. formatter: Table.api.formatter.datetime
  49. },
  50. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function (value, row, index) {
  51. var that = $.extend({}, this);
  52. var table = $(that.table).clone(true);
  53. if (row.type == 2)
  54. $(table).data("operate-edit", null);
  55. that.table = table;
  56. return Table.api.formatter.operate.call(that, value, row, index);
  57. }}
  58. ]
  59. ]
  60. });
  61. // 为表格绑定事件
  62. Table.api.bindevent(table);
  63. },
  64. add: function () {
  65. Controller.api.bindevent();
  66. },
  67. edit: function () {
  68. Controller.api.bindevent();
  69. },
  70. api: {
  71. bindevent: function () {
  72. Form.api.bindevent($("form[role=form]"));
  73. //选择推广链接
  74. $(document).on('click', ".select-referral-id", function () {
  75. var obj_group = $(this).parent().parent().parent();
  76. parent.Backend.api.open($(this).attr("href") , __('Select'), {callback: function(data){
  77. obj_group.find('.c-referral_url').val(data[0].source_url);
  78. obj_group.find('.c-referral_id').val(data[0].id);
  79. }});
  80. return false;
  81. });
  82. //选择二维码主题
  83. $(document).on('click','.thumbnail',function(){
  84. $('#input_template_id').val($(this).data('template_id'));
  85. $('.thumbnail').css('border-color','');
  86. $(this).css('border-color','#18bc9c');
  87. var that = this;
  88. //生成二维码图片
  89. if ($('#input_template_id').val() > 0 && typeof Config.ids != 'undefined') {
  90. $.ajax({
  91. url: '/admin/customqrcode/createimage/ids/'+Config.ids+'/tpl_id/'+ $('#input_template_id').val(),
  92. type: 'post',
  93. success: function (res) {
  94. if (res.code == 1) {
  95. $(that).find('img').attr('src', res.data);
  96. Toastr.success(res.msg);
  97. } else {
  98. Toastr.error('生成二维码失败');
  99. }
  100. }
  101. });
  102. }
  103. });
  104. //选择自定义二维码类型
  105. $(document).on('click','input[type="radio"]',function(){
  106. switch(parseInt($(this).val())){
  107. case 0:
  108. $('.select-group').html('');
  109. break;
  110. case 1:
  111. $('.select-group').html($('.resource_select').html());
  112. break;
  113. case 3:
  114. $('.select-group').html($('.referral_select').html());
  115. break;
  116. }
  117. });
  118. //选择资源
  119. $(document).on('click', ".select-resources", function () {
  120. var obj_group = $(this).parent().parent();
  121. var key = obj_group.find("input[name='row[eventkey]']").val();
  122. parent.Backend.api.open($(this).find('a').attr("href") + "?key=" + key, __('Select'), {callback: function(data){
  123. obj_group.find("input[name='row[eventkey]']").val(data.eventkey).trigger("change");
  124. var keytitle = data.title;
  125. var cont = obj_group.find(".clickbox .create-click:first");
  126. $(".keytitle", cont).remove();
  127. if (keytitle) {
  128. cont.append('<div class="keytitle">' + __('Event key') + ':' + keytitle + '</div>');
  129. }
  130. }});
  131. return false;
  132. });
  133. //添加资源
  134. $(document).on('click', ".add-resources", function () {
  135. var obj_group = $(this).parent().parent();
  136. parent.Backend.api.open($(this).find('a').attr("href") + "?key=", __('Add'), {callback: function(data){
  137. obj_group.find("input[name='row[eventkey]']").val(data.eventkey).trigger("change");
  138. var keytitle = data.title;
  139. var cont = obj_group.find(".clickbox .create-click:first");
  140. $(".keytitle", cont).remove();
  141. if (keytitle) {
  142. cont.append('<div class="keytitle">' + __('Event key') + ':' + keytitle + '</div>');
  143. }
  144. }});
  145. return false;
  146. });
  147. $(".btn-download-img").on("click", function () {
  148. if ($('#input_template_id').val()) {
  149. var formId = 'download-form-' + $('#input_template_id').val();
  150. var $eleForm = $("<form method='get' id='"+formId+"'></form>");
  151. $eleForm.attr("action",'/admin/customqrcode/download/ids/'+Config.ids+'/tpl_id/'+ $('#input_template_id').val());
  152. $("#down-div").append($eleForm);
  153. //提交表单,实现下载
  154. $eleForm.submit();
  155. return false;
  156. } else {
  157. Toastr.error('请选择要下载的二维码');
  158. }
  159. return false;
  160. });
  161. },
  162. createBtnGroup:function(title,url){
  163. var html = '<div class="input-group input-group-sm" style="width:250px;margin-bottom: 5px;">';
  164. html+= '<span class="input-group-addon input-group-sm">'+title+'</span>';
  165. html+= '<input type="text" style="height: 29.99px;" class="form-control input-group-sm" value="'+url+'">';
  166. html+= '<span class="input-group-btn input-group-sm" style="height: 29.99px;">'
  167. html+= '<a style="height: 30px;" href="'+url+'" target="_blank" class="btn btn-default btn-sm"><i class="fa fa-link"></i></a></span></div>';
  168. return html;
  169. },
  170. formatter:{
  171. formt_url_list:function(value,row,index){
  172. var html = '';
  173. if(row.url_list[row.template_id] && row.url_list[row.template_id] != undefined){
  174. html = Controller.api.createBtnGroup('模板'+row.template_id,row.url_list[row.template_id]);
  175. }else{
  176. html = Controller.api.createBtnGroup('微&nbsp;信&nbsp;',value);
  177. }
  178. return html;
  179. },
  180. type_text: function(value,row,index){return row.type_text;},
  181. }
  182. }
  183. };
  184. return Controller;
  185. });