Blame view

code/static/js.jquery/module/operations/exchangeCoupon/Index.js 7.44 KB
shuaiguo authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
/**
 * Created by JiangMin on 2016/4/19.
 */
var $ = require('jquery'),
    common = require('../../../common/common');

var ZeroClipboard = require("../../../common/util/ZeroClipboard.min");
ZeroClipboard.config({swfPath: "http://cdn.yoho.cn/yohobuy-portal/assets/images/ZeroClipboard.swf"});
/**
 * 列表显示数据
 * @type {common.grid}
 */
var g = new common.grid({
    el: '#content-list',
    hash: false,
    //查询参数
    parms: function () {
        return {
            name: common.util.__input('name-filter')
        };
    },
    //列表显示
    columns: [
        {
            display: "创建时间",
            name: "createTime"
        },
        {
            display: "兑券名称",
            name: "name"
        },
        {
            display: "副标题",
            name: "subName"
        },
        {
            display: "优惠券ID",
            name: "sendCouponId",
            // render: function (item) {
            //     var couponsIds = [];
            //     for (var i = 0; i < item.couponsIds.length; i++) {
            //         couponsIds.push(item.couponsIds[i].id);
            //     }
            //     return couponsIds.join(",");
            // }
        },
        {
            display: "兑换有货币数量",
            name: "exchangeYohoCoinNum"
        },
        {
            display: "token值",
            name: "token",
            render: function (item) {
                return '<div class="col-sm-12" style="padding-left: 0">' +
                    '<input class="col-sm-10" style="border: 0px;padding-left: 0" value="' + item.token + '" readonly/> <br/>'
                    + '<a data-index="' + item.__index + '" href="JavaScript:;" class="btn btn-xs info-copy" data-clipboard-text="' + item.token + '" id="copy-' + item.__index + '">复制链接</a></div>';
            }
        },
        {
            display: "操作",
            name: "",
            render: function (item) {
                var arr = [];
                arr.push('<a class="btn btn-xs btn-info update" data-index="' + item.__index + '">编辑</a>');
                arr.push('<a class="btn btn-xs btn-danger delete" data-index="' + item.__index + '">删除</a>');
                return arr.join('');
            }
        }
    ],
    complete: function () {
        new ZeroClipboard($(".info-copy"));
    }
});
g.init("/exchangeCouponManager/query/list");
/*验证*/
var edit = new common.edit2(".modal-body");
var Bll = {
    module: null,
    __render: function (selecter, templater, data) {
        $(selecter).html(common.util.__template2($("#" + templater).html(), data));
    },
    //弹框
    toast: function (module, hint) {
        Bll.module = module;
        var d = new common.dialog({
            title: hint + "发券",
            content: common.util.__template2($("#template").html(), Bll.module),
            width: '70%',
            button: [
                {
                    value: "保存",
                    callback: function () {
                        var couponIds = Bll.module.couponsIds || [];
                        var flag = true;
                        var ids = [];
                        for (var i = 0; i < couponIds.length; i++) {
                            ids.push(couponIds[i].id);
                        }
                        if (ids.join(",").indexOf("-1") > -1) {
                            flag = false;
                            common.util.__tip("请正确选择优惠券ID", "warning");
                        } else {
                            Bll.module.couponsIds = ids.join(",");
                        }
                        if (edit.validate() && flag) {
                            common.util.__ajax({
                                url: "/exchangeCouponManager/addOrUpdate",
                                data: Bll.module
                            }, function (res) {
                                if (res.code == '200') {
                                    g.reload();
                                    d.close();
                                }
                                else {
                                    common.util.__tip(res.message, "warning");
                                }
                            });
                        }
                        return false;
                    },
                    css: "btn-primary"
                },
                {
                    "value": "取消",
                    "css": "btn-info"
                }
            ]
        });
        Bll.__editRender();
    },
    renderDialog: function (templater) {
        Bll.__render(".modal-body", templater, Bll.module);
        Bll.__editRender();
    },
    __editRender: function () {
        edit.init();
        new common.dropDown({
            el: '.couponsIds',
            ajax: 'couponID'
        });
    }
};

/**
 * 监听输入框变化
 */
$(document).on("change", ".observe", function () {
    var $this = $(this);
    var name = $this.data("field");
    Bll.module = common.util.__buildobj(name, '.', Bll.module, function (obj, name1) {
        if (name.indexOf('id') > -1) {
            obj[name1] = $this.val();
            obj["text"] = $this.find("option[value='" + $this.val() + "']").text();
        }
        obj[name1] = $this.val();
    });
});

/*添加一行*/
$(document).on("click", ".addBtn", function () {
    Bll.module.couponsIds.push({
        "id": "",
        "text": ""
    });
    Bll.renderDialog("template");
});

/**
 * 删除行
 */
$(document).on("click", ".delBtn", function () {
    var index = $(this).data("index");
    if (Bll.module.couponsIds.length <= 1) {
        common.util.__tip("至少有一张优惠券", "warning")
    }
    else {
        Bll.module.couponsIds.splice(index, 1);
        Bll.renderDialog("template");
    }
});

/**
 * 添加--点击事件
 */
$('#add-content').on('click', function () {
    var item = {
        "id": "",
        "name": "",
        "couponsIds": [
            {
                "id": "",
                "text": ""
            }
        ],
        "status": 1
    };
    Bll.toast(item, "添加");
});

/**
 * 编辑--点击事件
 */
$(document).on('click', '.update', function () {
    var item = g.rows[$(this).data("index")];
    var item1 = $.extend(true, {}, item);
    Bll.toast(item1, "修改");
});

/**
 * 删除--点击事件
 */
$(document).on('click', '.delete', function () {
    var item = g.rows[$(this).data("index")];
    common.dialog.confirm("警告",
        "确认删除?",
        function () {
            common.util.__ajax({
shuaiguo authored
219
                url: '/exchangeCouponManager/delete',
shuaiguo authored
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
                data: {
                    id: item.id,
                }
            }, function () {
                g.reload();
            });
        });
});

/**
 * 查询按钮--点击事件
 */
$(document).on('click', '#filter-btn', function () {
    g.reload(1);
});

/**
 * 复制token点击事件
 */
$(document).on('click', '.info-copy', function () {
    common.util.__tip("Token链接已复制好,可贴粘", "success")
});

/**
 * 查看token使用方法
 */
$(document).on('click', '#token', function () {
    var a = new common.dialog({
        title: "<h4>token使用方法</h4>",
        width: '50%',
        content: '<p>活动开发人员使用Token时,按照对应格式写在页面中,示例代码:</p>&lt;a class="yoho-conpon" ' +
        'href="javascript:;" data-token="29-6ea9ab1baa0efb9e19094440c317e21b"&gt;领券按钮&lt;/a&gt;<h5>注:必须引入 JS 插件</h5>'
    });
});