activity.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'custommain'], function ($, undefined, Backend, Table, Form, Custommain) {
  2. Custommain.checkbox_relation('#dyhradio', '#dyhcheck');
  3. $('.btnlink').click(function(){
  4. var id = $(this).data('id');
  5. $.get('/admin/activity/sorturl?ids='+id,{},function(data){
  6. if(data.error == 0){
  7. window.location.reload();
  8. }else{
  9. layer.msg("短链生成失败")
  10. }
  11. })
  12. });
  13. $(document).on('click', '.btn-config', function () {
  14. layer.open({
  15. type: 2,
  16. title: '活动配置管理',
  17. maxmin: true,
  18. area: ['90%', '90%'],
  19. shadeClose: true, //点击遮罩关闭层
  20. content: '/admin/activity/config?type='+Config.activity_type
  21. });
  22. });
  23. $(document).on('click', '.btn-resource-manange', function () {
  24. layer.open({
  25. type: 2,
  26. title: '活动配置管理',
  27. maxmin: true,
  28. area: ['90%', '90%'],
  29. shadeClose: true, //点击遮罩关闭层
  30. content: '/admin/resource/index?aid=0&resource_type='+Config.activity_type
  31. });
  32. });
  33. $(document).on('click','.btn-edit-row',function(){
  34. //btn-edit-row
  35. Fast.api.open($(this).data('href'), "编辑活动", {
  36. callback: function (data) {
  37. if(data.code){
  38. window.location.reload();
  39. }
  40. }
  41. });
  42. });
  43. $(document).on('change','.pop_status',function(){
  44. //btn-edit-row
  45. if ($(this).val() == 1) {
  46. $(".position-div").removeClass("hide");
  47. } else {
  48. $(".position-div").addClass("hide");
  49. }
  50. });
  51. $(document).on('click', '.btn-resource-manage', function () {
  52. var url = $(this).data('source-url');
  53. var title = $(this).data('pop-type') == 'edit' ? '编辑资源' : '添加资源';
  54. Fast.api.open(url, title, {
  55. callback: function (data) {
  56. }
  57. });
  58. return false;
  59. });
  60. //启动和暂停按钮
  61. //$(document).on("click", ".btn-start,.btn-pause", function () {
  62. // //在table外不可以使用添加.btn-change的方法
  63. // //只能自己调用Table.api.multi实现
  64. // var id = $(this).data('id');
  65. // var thisvalue = $(this).val();
  66. // var status = 1;
  67. // if(thisvalue=='点击打开'){
  68. // status = 1;
  69. // }else{
  70. // status = 0;
  71. // }
  72. // var textval = thisvalue.substring(2,4);
  73. // layer.confirm('确定要'+textval+'吗?', {
  74. // btn: ['确定','取消'] //按钮
  75. // }, function(){
  76. // $.post('/admin/activity/changestatus',{id:id,status:status},function(data){
  77. // if(data == 1){
  78. // layer.msg('操作成功');
  79. // table.bootstrapTable('refresh');
  80. // }else{
  81. // layer.msg('操作失败');
  82. // }
  83. // });
  84. //
  85. // }, function(){
  86. // layer.close();
  87. // });
  88. //});
  89. var Controller = {
  90. shwoActivityField:function(table){
  91. var field = new Array();
  92. field.push({checkbox: true});
  93. field.push({field: 'id', title: __('Id')});
  94. if(parseInt(Config.activity_type)){
  95. field.push({field: 'admin_id', title: '渠道ID'});
  96. }
  97. field.push({field: 'name', title: __('Name')});
  98. field.push({field: 'copywriting', title: __('Copywriting')});
  99. field.push({field: 'starttime', title: __('Starttime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime});
  100. field.push({field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime});
  101. field.push({field:'activitstatus', title:'活动状态',formatter: Controller.api.formatter.activitstatus});
  102. field.push({field:'money',title:'今日充值',formatter:Controller.api.formatter.money});
  103. field.push({field:'allmoney',title:'累计充值',formatter:Controller.api.formatter.allmoney});
  104. field.push({field: 'changestatus', title: __('显示状态'),addClass:'btn-start',formatter: Controller.api.formatter.changestatus});
  105. field.push({field: 'popstatus', title: __('弹窗状态'),formatter: Controller.api.formatter.popstatus});
  106. field.push({field: 'pop_range', title: __('弹窗位置'),formatter: function (value, row, index) {
  107. if (row.pop_status == '0') {
  108. return "-";
  109. } else {
  110. var popRangeVal = '';
  111. if (row.pop_range.length > 0 || row.pop_range == '0') {
  112. var popRangeKey = row.pop_range.split(',');
  113. for (let k in popRangeKey) {
  114. var j = popRangeKey[k];
  115. popRangeVal += Config.popRangeList[j] + ' ';
  116. }
  117. } else {
  118. popRangeVal = '-';
  119. }
  120. return popRangeVal;
  121. }
  122. }});
  123. if(!parseInt(Config.activity_type) || Config.activity_type == 2){
  124. field.push({field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate});
  125. field.push({field:'resource', title:'资源管理',formatter: Controller.api.formatter.resource});
  126. }
  127. return field;
  128. },
  129. index: function () {
  130. // 初始化表格参数配置
  131. Table.api.init({
  132. extend: {
  133. index_url: 'activity/index?type='+Config.activity_type,
  134. add_url: 'activity/add?type='+Config.activity_type,
  135. edit_url: 'activity/edit?type='+Config.activity_type,
  136. del_url: 'activity/del',
  137. multi_url: 'activity/multi',
  138. table: 'activity',
  139. },
  140. showToggle: false,
  141. showColumns: false,
  142. showExport: false,
  143. commonSearch: false,
  144. operate: false,
  145. search:false,
  146. });
  147. var table = $("#table");
  148. // 初始化表格
  149. table.bootstrapTable({
  150. url: $.fn.bootstrapTable.defaults.extend.index_url,
  151. pk: 'id',
  152. sortName: 'id',
  153. columns: [Controller.shwoActivityField(table)]
  154. });
  155. // 为表格绑定事件
  156. Table.api.bindevent(table);
  157. $(document).on('click','.btn-add-activity',function(){
  158. Fast.api.open('activity/add?type='+Config.activity_type, "添加活动", {
  159. callback: function (data) {
  160. if(data.code){
  161. window.location.reload();
  162. }
  163. }
  164. });
  165. });
  166. //启动和暂停按钮
  167. $(document).on("click", ".btn-start,.btn-pause", function () {
  168. //在table外不可以使用添加.btn-change的方法
  169. //只能自己调用Table.api.multi实现
  170. var id = $(this).data('id');
  171. var thisvalue = $(this).val();
  172. var status = 1;
  173. if(thisvalue=='点击打开'){
  174. status = 1;
  175. }else{
  176. status = 0;
  177. }
  178. var textval = thisvalue.substring(2,4);
  179. var reloadfrom = $(this).data('reload');
  180. layer.confirm('确定要'+textval+'吗?', {
  181. btn: ['确定','取消'] //按钮
  182. }, function(){
  183. $.post('/admin/activity/changestatus',{id:id,status:status},function(data){
  184. if(data == 1){
  185. layer.msg('操作成功');
  186. if (reloadfrom == 1) {
  187. window.location.reload();
  188. } else {
  189. table.bootstrapTable('refresh');
  190. }
  191. }else{
  192. layer.msg('操作失败');
  193. }
  194. });
  195. }, function(){
  196. layer.close();
  197. });
  198. });
  199. //启动和暂停按钮
  200. $(document).on("click", ".btn-pop-start", function () {
  201. //在table外不可以使用添加.btn-change的方法
  202. //只能自己调用Table.api.multi实现
  203. var id = $(this).data('id');
  204. var thisvalue = $(this).val();
  205. var status = 1;
  206. var textval = thisvalue.substring(2,4);
  207. var reloadfrom = $(this).data('reload');
  208. if(thisvalue=='点击开启'){
  209. $("#dyhradio").find('input:checkbox').prop("checked", false);
  210. $("#dyhcheck").find('input:checkbox').prop("checked", false);
  211. status = 1;
  212. var has_select = $(this).data("pop-range");
  213. var stis_pay = $(this).data("ispay");
  214. if(stis_pay == 1){
  215. $('#ispay_1').prop("checked", true);
  216. }else if (stis_pay == 2){
  217. $('#ispay_2').prop("checked", true);
  218. }else if (stis_pay == 3){
  219. $('#ispay_3').prop("checked", true);
  220. }
  221. if (has_select.length > 0 || has_select >= 0) {
  222. has_select+=',';
  223. }
  224. var selectArr = has_select.length > 0 ? has_select.split(',') : [];
  225. $("#dyhcheck").find('input:checkbox').each(function (i, item) {
  226. var val = $(item).val();
  227. if (selectArr.indexOf(val) != -1) {
  228. $(item).prop("checked", true);
  229. }
  230. });
  231. if (selectArr.length > 7) {
  232. $("#dyhradio").find('input:checkbox').prop("checked", true);
  233. }
  234. layer.open({
  235. type: 1,
  236. title: '选择弹窗位置',
  237. maxmin: true,
  238. area: ['60%', '80%'],
  239. btn: ['确定', '取消'],
  240. shadeClose: true, //点击遮罩关闭层
  241. content: $(".pop_position"),
  242. yes: function (data) {
  243. var newSelect = [];
  244. $("#dyhcheck").find('input:checkbox').each(function (i, item) {
  245. if ($(item).is(":checked")) {
  246. newSelect.push($(item).val());
  247. }
  248. });
  249. var popRange = '';
  250. if (newSelect.length > 0) {
  251. popRange = newSelect.join(',');
  252. }
  253. var ppval=$('input:radio[name="row[pop_ispay]"]:checked').val();
  254. $.post('/admin/activity/set_pop_range',{id:id,status:status,pop_range:popRange,pop_ispay:ppval},function(data){
  255. if(data == 1){
  256. layer.msg('操作成功');
  257. if (reloadfrom == 1) {
  258. window.location.reload();
  259. } else {
  260. table.bootstrapTable('refresh');
  261. }
  262. }else{
  263. layer.msg('操作失败');
  264. }
  265. });
  266. layer.closeAll();
  267. }
  268. });
  269. }else{
  270. status = 0;
  271. layer.confirm('确定要'+textval+'吗?', {
  272. btn: ['确定','取消'] //按钮
  273. }, function(){
  274. $.post('/admin/activity/changepopstatus',{id:id,status:status},function(data){
  275. if(data == 1){
  276. layer.msg('操作成功');
  277. if (reloadfrom == 1) {
  278. window.location.reload();
  279. } else {
  280. table.bootstrapTable('refresh');
  281. }
  282. }else{
  283. layer.msg('操作失败');
  284. }
  285. });
  286. }, function(){
  287. layer.close();
  288. });
  289. }
  290. });
  291. $(document).on("click", '.js_recharge_on', function () {
  292. var id = $(this).data('id');
  293. upShowRechargePage(id, 'on');
  294. });
  295. $(document).on("click", '.js_recharge_off', function () {
  296. var id = $(this).data('id');
  297. upShowRechargePage(id, 'off');
  298. });
  299. function upShowRechargePage(id, status) {
  300. var msg = status == 'on' ? '确定要在充值页面显示此活动吗?' : '确定要在充值页面移除此活动吗?';
  301. layer.confirm(msg, {
  302. btn: ['确定', '取消']
  303. }, function () {
  304. $.post('/admin/activity/showrechargepage', {id: id, status: status}, function (data) {
  305. if (data == 1) {
  306. layer.msg('操作成功');
  307. window.location.reload();
  308. } else {
  309. layer.msg('操作失败');
  310. }
  311. });
  312. }, function () {
  313. layer.close();
  314. });
  315. }
  316. },
  317. config:function(){
  318. $('#config_id').val(Controller.api.formatter.getUid());
  319. //btn-add-resource
  320. $('.btn-add-resource').on('click',function(){
  321. Fast.api.open("/admin/resource/index?aid=0&resource_type="+Config.activity_type, "选择活动资源", null);
  322. });
  323. $(document).on('click','.btn-del-money',function(){
  324. $(this).parent().parent().remove();
  325. });
  326. $('.btn-append-money').on('click',function(){
  327. var html = $('#money-list-model').html().replace(/uid_value/ig, Controller.api.formatter.getUid());
  328. $('#money-list-container').append(html);
  329. });
  330. $(document).on("click", '.fachoose-resource_id', function () {
  331. let this_obj = $(this);
  332. Fast.api.open("/admin/resource/select?aid=0&resource_type="+Config.activity_type, "选择活动资源", {
  333. callback: function (data) {
  334. this_obj.parent().parent().find('input').val(data.id)
  335. }
  336. });
  337. return false;
  338. });
  339. Controller.api.bindevent();
  340. },
  341. add: function () {
  342. Form.api.bindevent($("form[role=form]"), function (data, ret) {
  343. Fast.api.close(ret);
  344. return true;
  345. });
  346. //Controller.api.bindevent();
  347. },
  348. addchannel: function () {
  349. Controller.api.bindevent();
  350. },
  351. pop_range: function () {
  352. Controller.api.bindevent();
  353. },
  354. edit: function () {
  355. Form.api.bindevent($("form[role=form]"), function (data, ret) {
  356. Fast.api.close(ret);
  357. return true;
  358. });
  359. },
  360. select: function () {
  361. Table.api.init({
  362. extend: {
  363. index_url: 'activity/select',
  364. table: 'activity',
  365. },
  366. showToggle: false,
  367. showColumns: false,
  368. showExport: false,
  369. searchFormVisible: true,
  370. search: false,
  371. commonSearch:true,
  372. });
  373. var table = $("#table");
  374. // 初始化表格
  375. table.bootstrapTable({
  376. queryParams: function (params) {
  377. //自定义搜索条件
  378. params.type = Config.type;
  379. return params;
  380. },
  381. url: $.fn.bootstrapTable.defaults.extend.index_url,
  382. pk: 'id',
  383. sortName: 'weigh',
  384. columns: [
  385. [
  386. {field: 'name', title: __('Name'), operate: false},
  387. {field: 'copywriting', title: __('copywriting'), operate: false},
  388. {field: 'starttime', title: __('Starttime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  389. {field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  390. {
  391. field: 'operate', title: __('Operate'), events: {
  392. 'click .btn-chooseone': function (e, value, row, index) {
  393. Fast.api.close([row]);
  394. },
  395. }, formatter: function () {
  396. return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  397. }
  398. }
  399. ]
  400. ]
  401. });
  402. // 为表格绑定事件
  403. Table.api.bindevent(table);
  404. Controller.api.bindevent();
  405. },
  406. api: {
  407. bindevent: function () {
  408. Form.api.bindevent($("form[role=form]"));
  409. },formatter: {
  410. activitstatus: function (value, row, index) {
  411. if(row.starttime > Config.time){
  412. return '未开始';
  413. }else if (row.starttime<Config.time && row.endtime>Config.time){
  414. return '进行中';
  415. }else if (row.endtime < Config.time){
  416. return '已结束';
  417. }
  418. },
  419. resource: function (value, row, index) {
  420. if(!parseInt(Config.activity_type) || Config.activity_type == 2){
  421. if (row.resource_id > 0) {
  422. return '<a href="javascript:;" data-source-url="/admin/resource/edit?ids='+row.resource_id+'&aid='+row.id+'&resource_type='+ Config.activity_type +'&business_line='+Config.business_line+'" data-pop-type="edit" class="label label-success btn-resource-manage">编辑资源管理</a>';
  423. } else {
  424. return '<a href="javascript:;" data-source-url="/admin/resource/add?aid='+row.id+'&resource_type='+ Config.activity_type +'&business_line='+Config.business_line+'" data-pop-type="add" class="label label-success btn-resource-manage">资源管理</a>';
  425. }
  426. }
  427. },
  428. changestatus:function(value,row,index){
  429. var showName = '';
  430. if (row.status == 0){
  431. return '<b>隐藏</b>&nbsp;&nbsp;<input type="button" class="btn-start btn btn-success" data-id="'+row.id+'" data-pop-range="'+row.pop_range+'" value="点击打开" />';
  432. }else{
  433. return '<b>打开</b>&nbsp;&nbsp;<input type="button" class="btn-start btn btn-warning" data-id="'+row.id+'" value="点击隐藏" />';
  434. }
  435. },
  436. popstatus:function(value,row,index){
  437. var showName = '';
  438. if (row.pop_status == '0'){
  439. return '<b>关闭</b>&nbsp;&nbsp;<input type="button" class="btn-pop-start btn btn-success" data-id="'+row.id+'" data-pop-range="'+row.pop_range+'" data-ispay="'+row.pop_ispay+'" value="点击开启" />';
  440. }else{
  441. return '<b>开启</b>&nbsp;&nbsp;<input type="button" class="btn-pop-start btn btn-warning" data-id="'+row.id+'" value="点击关闭" />';
  442. }
  443. },
  444. money:function(value, row, index) {
  445. if (value){
  446. return value;
  447. }else{
  448. return '0.00';
  449. }
  450. },
  451. allmoney:function(value, row, index) {
  452. if (value){
  453. return value;
  454. }else{
  455. return '0.00';
  456. }
  457. },
  458. getUid:function(){
  459. return Math.random().toString().substr(3,5) + (new Date()).getTime();
  460. }
  461. }
  462. }
  463. };
  464. return Controller;
  465. });