123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- //编辑按钮
- $(document).on('click','.btn-editone',function(){
- var url = $(this).data('tourl');
- var sendtime = Number($(this).data('sendtime'));
- if((sendtime - Date.parse(new Date())/1000)<300){
- $(this).hide();
- return false;
- }else{
- Fast.api.open(url, __('Edit'), $(this).data() || {});
- }
- });
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'custom/index',
- add_url: 'custom/add',
- edit_url: 'custom/edit',
- del_url: 'custom/del',
- multi_url: 'custom/multi',
- table: 'custom',
- },
- search:false,
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id',
- columns: [
- [
- {checkbox: true},
- // {field: 'id', title: __('Id')},
- {field: 'title', title: __('标题'),operate: 'LIKE %...%'},
- {field: 'sendtime', title: __('Sendtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
- {field: 'statue', title: __('Statue'),visible:false,operate:false},
- {field: 'statue_text', title: __('Statue'), operate:false},
- {field: 'send_num', title: '发送人数', operate:false},
- {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
- // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
- // {field: 'edit', title: __('编辑'), table: table, events: Table.api.events.operate,formatter: Controller.api.editCustom},
- {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- add: function () {
- Controller.api.bindevent();
- $('.s_time_box span:eq(1)').click();
- },
- edit: function () {
- Controller.api.bindevent();
- },
- api: {
- getStatue: function (value, row, index) {
- if(value == 'normal'){
- if (row.sendtime < Date.parse(new Date())/1000){
- return '<span style="color:red">发送失败</span>';
- }else{
- return '未发送';
- }
- }else{
- return '<span style="color:green">已发送</span>';
- }
- },
- editCustom: function (value, row, index) {
- if(row.statue == 'normal' && (Number(row.sendtime) - Date.parse(new Date())/1000)>300){
- //5分钟外的
- return '<a href="javascript:;" class="btn btn-xs btn-success btn-editone" data-sendtime="'+row.sendtime+'" data-tourl="/admin/custom/edit/ids/'+row.id+'" data-table-id="table" data-field-index="8" data-row-index="2" data-button-index="1"><i class="fa fa-pencil"></i></a>';
- }
- },
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- //资源管理
- var ore={
- arrma:[
- {
- 'title':'',
- 'image':'',
- 'url':'http://'
- }
- ],
- imglis:[],
- titlist:[],
- sli:'<div class="img_txt_li img_txt_main">\
- <div class="img_txt_li_img img_txt_edit_img"><img src="sli_img" /></div>\
- <div class="img_txt_li_txt">\
- <i class="fa fa-pencil img_txt_edit_tit"></i>\
- <div class="img_txt_li_h3"><input type="text" value="sli_value" /></div>\
- <i class="fa fa-chain img_txt_edit_url"></i>\
- <i class="fa fa-book img_txt_edit_book"></i>\
- <div class="img_txt_li_url"><input type="text" value="click_url" /></div>\
- </div>\
- <div class="fa img_txt_remvoe"></div>\
- </div>'
- };
- /**
- * form表单验证
- */
- $("form[role=form]").data("validator-options", {
- ignore: ':hidden',
- beforeSubmit: function (form) {
- var $imgTxtMain = $('.img_txt_main');
- var reg = /^(http[s]?|ftp):\/\/[^\/\.]+?\..+\w/;
- var sList = '';
- ore.arrma = [];
- //标题
- if($.trim($('#title').val()).length == 0){
- Toastr.error("标题不能为空");
- return false;
- }
- for(var i=0; i<$imgTxtMain.length; i++){
- ore.arrma.push({});
- //标题
- if($('.img_txt_main:eq('+ i +') input:eq(0)').val().length > 0){
- ore.arrma[i].title = $('.img_txt_main:eq('+ i +') input:eq(0)').val();
- }else{
- Toastr.error("图文标题不能为空");
- return false;
- }
- //链接
- if(reg.test($('.img_txt_main:eq('+ i +') input:eq(1)').val())){
- ore.arrma[i].url = $('.img_txt_main:eq('+ i +') input:eq(1)').val();
- }else{
- Toastr.error("请填写图文正确的跳转链接");
- return false;
- }
- //图片
- if($('.img_txt_main:eq('+ i +') img').attr('src').length > 0){
- ore.arrma[i].image = $('.img_txt_main:eq('+ i +') img').attr('src');
- }else{
- Toastr.error("请填写图文正确的跳转链接");
- return false;
- }
- }
- //发送时间必须大于当前时间
- var sdatatime=$('#c-sendtime').val()+'';
- sdatatime = sdatatime.replace(/-/g,'/');
- sdatatime =new Date(sdatatime).getTime();
- if(sdatatime <= new Date().getTime()){
- Toastr.error("发送时间必须大于当前时间");
- return false;
- }
- sList = JSON.stringify(ore.arrma);
- $('.img_txt_hidde_input').val(sList);
- // console.log('验证');
- // return false;
- }
- });
- Form.api.bindevent($("form[role=form]"),
- function (data) {
- Fast.api.close(data);
- },
- function (data) {
- console.log('error', data);
- }
- );
- /**
- * 资源类型管理
- */
- $(document).on('click', "input[name='row[type]']", function () {
- var type = $(this).val();
- if (type=='all'){
- var tagObj = {
- all:"1"
- }
- }else{
- var tagObj ={
- sex:-1,
- tag:-1,
- consume:-1,
- kandian: -1,
- subscribe_time:-1,
- all:"0"
- }
- }
- var ucon = JSON.stringify(tagObj);
- $('#usercondition').val(ucon);
- $('.group-tag-type').addClass('hide');
- $('.group-tag-type input').attr('disabled');
- $('#group-tag-type-' + type).removeClass('hide');
- $('#group-tag-type-' + type+' input').removeAttr('disabled');
- });
- /**
- * 插入链接
- */
- $(document).on('click', ".btn-insertlink", function () {
- var textarea = $("textarea[name='row[content]']");
- var cursorPos = textarea.prop('selectionStart');
- var v = textarea.val();
- var textBefore = v.substring(0, cursorPos);
- var textAfter = v.substring(cursorPos, v.length);
- Layer.prompt({title: '请输入显示的文字', formType: 3}, function (text, index) {
- Layer.close(index);
- Layer.prompt({title: '请输入跳转的链接URL(包含http/https)', formType: 3}, function (link, index) {
- text = text == '' ? link : text;
- textarea.val(textBefore + '<a href="' + link + '">' + text + '</a>' + textAfter);
- Layer.close(index);
- });
- });
- });
- if ($('#usercondition').val().length > 0) {
- $tagval = JSON.parse($('#usercondition').val());
- if ($tagval.all == 1){ //选择所有用户
- $('#type-all').attr('checked',true);
- var type = 'all';
- $('.group-tag-type').addClass('hide');
- $('.group-tag-type input').attr('disabled');
- $('#group-tag-type-' + type).removeClass('hide');
- $('#group-tag-type-' + type+' input').removeAttr('disabled');
- }
- }
- $.ajax({
- type:'get',
- url:'/admin/custom/ajaxcategory',
- cache:false,
- async:false,
- success:function(res){
- data = res.data;
- var htmlstr = '';
- for(var i=0;i<data.length;i++){
- htmlstr+='<span data-cid="'+data[i].id+'" >'+data[i].name+'</span>';
- }
- $('#ctag').append(htmlstr);
- $('#mustbe').html('约'+res.ids+'人');
- if ($('#usercondition').val().length > 0){
- $tagval = JSON.parse($('#usercondition').val());
- $("#sex span[data-sex='"+$tagval.sex+"']").addClass('s_s_tag').siblings().removeClass('s_s_tag');
- $("#ctag span[data-cid='"+$tagval.tag+"']").addClass('s_s_tag').siblings().removeClass('s_s_tag');
- $("#consume span[data-fee='"+$tagval.consume+"']").addClass('s_s_tag').siblings().removeClass('s_s_tag');
- $("#kandian span[data-kandian='"+$tagval.kandian+"']").addClass('s_s_tag').siblings().removeClass('s_s_tag');
- $("#subTime span[data-week='"+$tagval.subscribe_time+"']").addClass('s_s_tag').siblings().removeClass('s_s_tag');
- console.log($tagval);
- }else{
- var tagObj1 ={
- sex:-1,
- tag:-1,
- consume:-1,
- kandian: -1,
- subscribe_time:-1,
- all:"0"
- };
- var ucon1 = JSON.stringify(tagObj1);
- $('#usercondition').val(ucon1);
- }
- },
- error:function(err){
- }
- });
- $.ajax({
- type:'get',
- url:'/admin/manage/cover/ajax?sort=id&order=desc&offset=0&limit=10&filter={"status":"normal"}',
- cache:false,
- async:false,
- success:function(data){
- // console.log(data)
- ore.imglis = data.rows;
- },
- error:function(err){
- }
- });
- $.ajax({
- type:'get',
- url:'/admin/manage/title/ajax?sort=id&order=desc&offset=0&limit=10&filter={"status":"normal"}',
- cache:false,
- async:false,
- success:function(data){
- // console.log(data)
- ore.titlist = data.rows;
- ore.arrma[0]['image'] = ore.imglis[parseInt(Math.random()*ore.imglis.length)]['image'];
- ore.arrma[0]['title'] = ore.titlist[parseInt(Math.random()*ore.titlist.length)]['title'];
- console.log($('.img_txt_hidde_input').val());
- if($('.img_txt_hidde_input').val().length > 0){
- ore.arrma = JSON.parse($('.img_txt_hidde_input').val());
- for(var i=0; i<ore.arrma.length; i++){
- if(i==0){
- $('.img_txt_list').html('<div class="img_txt_one img_txt_main">\
- <div class="img_txt_one_tit">\
- <i class="fa fa-pencil img_txt_edit_tit"></i>\
- <div class="img_txt_one_h3"><input type="text" value="' + ore.arrma[0]['title'] + '" /></div>\
- <i class="fa fa-chain img_txt_edit_url"></i>\
- <i class="fa fa-book img_txt_edit_book"></i>\
- <div class="img_txt_one_url"><input type="text" value="' + ore.arrma[0]['url'] + '" /></div>\
- </div>\
- <div class="img_txt_one_img img_txt_edit_img"><img src="' + ore.arrma[0]['image'] + '" /></div>\
- </div>');
- }else{
- var sLiImg=ore.sli.replace(/sli_img/g,ore.arrma[i]['image']);
- sLiImg=sLiImg.replace(/sli_value/g,ore.arrma[i]['title']);
- sLiImg=sLiImg.replace(/click_url/g,ore.arrma[i]['url']);
- $('.img_txt_list').append(sLiImg);
- }
- }
- }else{
- $('.img_txt_list').html('<div class="img_txt_one img_txt_main">\
- <div class="img_txt_one_tit">\
- <i class="fa fa-pencil img_txt_edit_tit"></i>\
- <div class="img_txt_one_h3"><input type="text" value="' + ore.arrma[0]['title'] + '" /></div>\
- <i class="fa fa-chain img_txt_edit_url"></i>\
- <i class="fa fa-book img_txt_edit_book"></i>\
- <div class="img_txt_one_url"><input type="text" value="' + ore.arrma[0]['url'] + '" /></div>\
- </div>\
- <div class="img_txt_one_img img_txt_edit_img"><img src="' + ore.arrma[0]['image'] + '" /></div>\
- </div>');
- }
- },
- error:function(err){
- }
- });
- var flag = 0;
- //测试发送
- $('.test_fans_but').click(function(){
- if(flag == 1){
- return false;
- }
- flag = 1;
- var $imgTxtMain = $('.img_txt_main');
- var reg = /^(http[s]?|ftp):\/\/[^\/\.]+?\..+\w/;
- var sList = '';
- ore.arrma = [];
- //标题
- if($.trim($('#title').val()).length == 0){
- Toastr.error("标题不能为空");
- flag = 0;
- return false;
- }
- for(var i=0; i<$imgTxtMain.length; i++){
- ore.arrma.push({});
- //标题
- if($('.img_txt_main:eq('+ i +') input:eq(0)').val().length > 0){
- ore.arrma[i].title = $('.img_txt_main:eq('+ i +') input:eq(0)').val();
- }else{
- Toastr.error("图文标题不能为空");
- return false;
- }
- //链接
- if(reg.test($('.img_txt_main:eq('+ i +') input:eq(1)').val())){
- ore.arrma[i].url = $('.img_txt_main:eq('+ i +') input:eq(1)').val();
- }else{
- Toastr.error("请填写图文正确的跳转链接");
- return false;
- }
- //图片
- if($('.img_txt_main:eq('+ i +') img').attr('src').length > 0){
- ore.arrma[i].image = $('.img_txt_main:eq('+ i +') img').attr('src');
- }else{
- Toastr.error("请填写图文正确的跳转链接");
- return false;
- }
- }
- sList = JSON.stringify(ore.arrma);
- if($.trim($('#userId').val()) == ''){
- Toastr.error("请填写测试粉丝ID");
- flag = 0;
- return false;
- }
- var sentData = {
- admin_id:$('#admin_id').val(),
- user_id:$('#userId').val(),
- cdata:sList
- };
- $.ajax({
- type:'post',
- url:'/admin/custom/sent',
- data:sentData,
- dataType:'json',
- cache:false,
- async:false,
- success:function(data){
- flag = 0;
- if (data.error == 1){
- Toastr.error(data.msg);
- };
- if(data.error == 0){
- Toastr.success(data.msg);
- }
- },
- error:function(err){
- flag = 0;
- }
- })
- });
- //发送消息时间
- $(document).on('click','.s_time_box span',function(){
- var $this = $(this);
- var nval = parseInt($this.attr('stime'));
- var ntime = Date.parse(new Date());
- var nt = ntime + nval;
- $('#c-sendtime').val(GetRTime(nt));
- });
- $(document).on('click','.s_tag_li_list span',function(){
- var $this = $(this);
- $this.addClass('s_s_tag').siblings('span').removeClass('s_s_tag');
- var tagObj ={
- sex:$('#sex span.s_s_tag').data('sex'),
- tag:$('#ctag span.s_s_tag').data('cid'),
- consume:$('#consume span.s_s_tag').data('fee'),
- kandian: $('#kandian span.s_s_tag').data('kandian'),
- subscribe_time:$('#subTime span.s_s_tag').data('week'),
- all:"0"
- }
- var uconditon = JSON.stringify(tagObj);
- $('#usercondition').val(uconditon);
- });
- var ofansopen=true;
- //tag切换
- $(document).on('click','.s_tag_fans_num',function(){
- var $this = $(this);
- //防止重复点击
- if(!ofansopen){
- return false;
- }
- ofansopen = false;
- $('.s_tag_footer').addClass('s_tag_fans_show');
- var tagObj ={
- sex:$('#sex span.s_s_tag').data('sex'),
- tag:$('#ctag span.s_s_tag').data('cid'),
- consume:$('#consume span.s_s_tag').data('fee'),
- kandian: $('#kandian span.s_s_tag').data('kandian'),
- subscribe_time:$('#subTime span.s_s_tag').data('week'),
- all:"0"
- }
- var uconditon = JSON.stringify(tagObj);
- $('#usercondition').val(uconditon);
- //console.log(tagObj);
- $.ajax({
- type:'post',
- data:tagObj,
- //dataType:'json',
- url:'/admin/custom/ajaxcustom',
- success:function(data){
- //console.log(data);
- $('#mustbe').html('约'+data.ids+'人');
- ofansopen = true;
- $('.s_tag_footer').removeClass('s_tag_fans_show');
- },
- error:function(err){
- ofansopen = true;
- $('.s_tag_footer').removeClass('s_tag_fans_show');
- }
- });
- });
- $(document).on('click','.img_txt_add_but',function(){
- var $List=$('.img_txt_main');
- var oNowData = {
- image:ore.imglis[parseInt(Math.random()*ore.imglis.length)]['image'],
- title:ore.titlist[parseInt(Math.random()*ore.titlist.length)]['title'],
- url:'http://'
- };
- var sLiImg=ore.sli.replace(/sli_img/g,oNowData['image']);
- sLiImg=sLiImg.replace(/sli_value/g,oNowData['title']);
- sLiImg=sLiImg.replace(/click_url/g,'http://');
- if($List.length<8){
- $('.img_txt_list').append(sLiImg);
- ore.arrma.push(oNowData);
- }else{
- Toastr.error("不能超过8篇");
- }
- });
- $(document).on('click','.img_txt_remvoe',function(){
- var $this=$(this);
- $this.parent().remove();
- });
- //修改title
- $(document).on('click','.img_txt_edit_tit',function(){
- var $this=$(this);
- Fast.api.open('manage/title/select', '选择', {
- callback: function (data) {
- // console.log('展示title回调', data);
- $this.parent().find('input').eq(0).val(data.title);
- }
- });
- });
- //修改url
- $(document).on('click','.img_txt_edit_url',function(){
- var $this=$(this);
- Fast.api.open('referral/referral/select?one=1', '选择', {
- callback: function (data) {
- var data = data[0];
- // console.log('展示title回调', data);
- $this.parent().find('input').eq(1).val(data.source_url);
- }
- });
- });
- //修改book
- $(document).on('click','.img_txt_edit_book',function(){
- var $this=$(this);
- Fast.api.open('book.book/select?one=1', '选择', {
- callback: function (data) {
- var data = data[0];
- $this.parent().find('input').eq(1).val(data.current_book_url);
- }
- });
- });
- //修改图片
- $(document).on('click','.img_txt_edit_img',function(){
- var $this=$(this);
- Fast.api.open('manage/cover/select', '选择', {
- callback: function (data) {
- // console.log('展示image回调', data);
- $this.find('img').attr('src',data.image);
- }
- });
- });
- //修改跳转链接
- $(document).on('click','.img_txt_main a',function(){
- var $this=$(this);
- var nIndex = $this.parents('.img_txt_main').index();
- layer.prompt({
- formType: 2,
- value: ore.arrma[nIndex].url,
- title: '请输入跳转链接地址(http://)',
- area: ['300px', '100px'] //自定义文本域宽高
- }, function(value, index, elem){
- var reg=/^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\/])+$/;
- if(reg.test(value)){
- layer.close(index);
- ore.arrma[nIndex].url = value;
- $this.html(value);
- }else{
- Toastr.error("请输入正确的跳转地址。");
- }
- });
- });
- function GetRTime(time){
- var stime;
- time = new Date(time);
- var year = time.getYear() + 1900;
- var month = time.getMonth()+1;
- var day = time.getDate();
- var hours = time.getHours();
- var minutes = time.getMinutes();
- var seconds = time.getSeconds();
- stime = year + '-' +
- (month < 10 ? '0'+month : month) + '-' +
- (day < 10 ? '0'+day : day) + ' ' +
- (hours < 10 ? '0'+hours : hours) + ':' +
- (minutes < 10 ? '0'+minutes : minutes) + ':' +
- (seconds < 10 ? '0'+seconds : seconds);
- return stime;
- }
- }
- }
- };
- return Controller;
- });
|