Index.js 3.3 KB
/**
 * Created by Arthur on 16/5/26.
 * 品牌发券管理
 */
require('../../../common/util/datepicker');
var $ = require('jquery');
common = require('../../../common/common');
var activityTypes = ["普通活动", "APP活动"];
var status=["关闭","开启"];

$.timepicker.dateRange($('#startTimeStr'), $('#endTimeStr'));

var Bll={
    getTime: function (time) {
        var t = new Date(time * 1000);
        return common.util.__dateFormat(t, "yyyy-MM-dd hh:mm:ss");

    },
    toast:function(hint,data){
        common.dialog.confirm("温馨提示", hint, function () {
            common.util.__ajax({
                url:"/couponActivity/update",
                data:data
            }, function () {
                g.reload();
            },true);
        });
    }
};
var g = new common.grid({
    el: '#content-list',
    parms: function() {
        return {
            actName: common.util.__input("actName"),
            startTimeStr: common.util.__input("startTimeStr"),
            endTimeStr: common.util.__input("endTimeStr"),
        };
    },
    columns: [
        {
            display: 'ID',
            name: "id"
        },
        {
            display: '名称',
            name: "actName"
        }, {
            display: '类型',
            name: "activityType",
            render: function (item) {
                return activityTypes[item.activityType - 1]
            }
        }, {
            display: "活动地址",
            name: "actUrl"
        }, {
            display: "分享",
            render: function (item) {
                var arr = [];
                arr.push("<p>标题:" + item.shareTitle + "</p>");
                arr.push("<p>描述:" + item.shareDescribe+ "</p>");
                arr.push("<p>地址:" + item.shareUrl + "</p>");
                return arr.join('');
            }
        }, {
            display: "活动时间",
            render: function (item) {
               return Bll.getTime(item.startTime)+"至"+Bll.getTime(item.endTime);
            }
        },{
            display: "状态",
            render: function (item) {
               return status[item.status];
            }
        }, {
            display: '操作',
            render: function (item) {
                var HtmArr = [];
                HtmArr.push('<a data-index="' + item.__index + '" href="/couponActivity/index/update/'+item.id+'" class="btn btn-primary btn-xs info-modify">编辑</a>');
                if(item.status==0){
                    HtmArr.push('<a data-index="' + item.__index + '" id="open" href="JavaScript:;" class="btn btn-success btn-xs ">开启</a>');
                }else{
                    HtmArr.push('<a data-index="' + item.__index + '" id="close" href="JavaScript:;" class="btn btn-danger btn-xs ">关闭</a>');
                }
                return HtmArr.join('');
            }
        }]
});
g.init('/couponActivity/queryList');

//==================== 按钮点击事件 =====================//

$("#filter-btn").click(function () {
    g.reload(1);
});

$(document).on('click','#open',function(){
    var item = g.rows[$(this).data("index")];
    item.status=1;
   Bll.toast("确定开启活动吗?",item);
});
$(document).on('click','#close',function(){
    var item = g.rows[$(this).data("index")];
    item.status=0;
    Bll.toast("确定关闭活动吗?",item);
});