PublicCoupon.js 2.47 KB
/**
 * Created by jiangmin on 2016/5/30.
 */
'use strict';
var $ = require('jquery'),
    common = require('../../../common/common');
new common.dropDown({el: "#filter-status"});
var couponId = location.href.substring(location.href.lastIndexOf("/") + 1);
$("#filter-couponId").val(couponId);


var g = new common.grid({
    el: '#content-list',
    hash: false,
    async: false,
    parms: function () {
        return {
            couponId: couponId,
            isUse: common.util.__input("filter-status")
        };
    },
    columns: [
        {display: "ID", name: "id"},
        {display: "优惠券号", name: "couponCode"},
        {display: '是否发放', name: "isUse"},
        {
            display: "创建时间", name: "createTimeStr"
        }
    ]
});
g.init("/pCouponSn/queryCouponSnList");
$("#count").html(g.total);

$(document).on("click", "#filter-btn", function () {
    g.reload(1);
    $("#count").html(g.total);
});

var Bll = {
    toast:function(){
        return common.dialog.open({title:"温馨提示",content:"导出中,请稍后....请不要关闭本窗口"});
        }
};
var t;
var path;
var api; 
var f={
    check:function(){ 
        common.util.__ajax({
        url: '/checkCouponExportFileIsExist',
        data: {
            queryConf: path     
        },async:false
        },function(res) {
            if(res.data===0){
                console.log("go on");
            }else{
                console.log("over");
                clearInterval(t);
                var a = document.createElement("a");
                a.setAttribute("href", "/ajax/download?path="+path);
                a.setAttribute("id", "openwin");
                document.body.appendChild(a);
                a.click();
                api.close();              
            }
            
        },true);  
    }
} 

//导出
$(document).on('click', '#export-btn', function () {
    var total = g.total;
    if (total <= 0) {
        common.util.__tip("当前0条数据,无需导出!", "warning")
    } else {
        var queryConf = JSON.stringify(g.options.parms());
        common.util.__ajax({
        url: '/couponExport',
        data: {
            queryConf: queryConf,
            type:"pCouponSnsExport"
        }
        },function(res) {
             api=Bll.toast();
            if(res&&res.data){
                $(document).ready(function(){  
                path=res.data;
                 t=window.setInterval(f.check,2000);   
                });
            }
        }); 
    }
});