operations.couponActivity.Add.js 3.35 KB
webpackJsonp([83],{

/***/ 0:
/***/ function(module, exports, __webpack_require__) {

	/**
	 * Created by jiangmin on 16/5/26.
	 * 品牌发券管理
	 */

	var $ = __webpack_require__(1);
	common = __webpack_require__(2);
	var activity = __webpack_require__(43);
	var startTimeObj;
	var endTimeObj;

	var e1 = new common.edit2("#basicForm");
	/**
	 * 监听输入值的变化
	 */
	$(document).on("change", ".observe", function () {
	    var $this = $(this);
	    var name = $this.data("field");
	    activity = common.util.__buildobj(name, '.', activity, function (obj, name) {
	        obj[name] = $this.val();
	    });
	});
	//通用对象
	var Bll = {
	    //渲染界面
	    render: function () {
	        $("#basicForm").html(common.util.__template2($("#couponListAdd-template").html(), activity));
	        Bll.__editRender();
	    },
	    //转换时间格式
	    getTime: function (time) {
	        var t = new Date(time * 1000);
	        return common.util.__dateFormat(t, "yyyy-MM-dd hh:mm:ss");
	    },
	    //验证
	    __editRender: function () {
	        e1.init();
	        new common.dropDown({
	            el: "#filter-activityType"
	        });
	        startTimeObj = $("#startTime").fdatepicker({
	            format: 'yyyy-mm-dd hh:ii:ss',
	            pickTime: true
	        }).data("datepicker");
	        endTimeObj = $("#endTime").fdatepicker({
	            format: 'yyyy-mm-dd hh:ii:ss',
	            pickTime: true
	        }).data("datepicker");
	        e1.on("file_onComplete", function (obj) {
	            var names = obj.field;
	            activity = common.util.__buildobj(names, '.', activity, function (o, name) {
	                o[name] = obj.data;
	            });
	        });
	    }
	};
	Bll.render();

	/*添加一行*/
	$(document).on("click", ".addBtn", function () {
	    activity.couponIds.push({
	        "id": ""
	    });
	    Bll.render();
	});
	/**
	 * 删除行
	 */
	$(document).on("click", ".delBtn", function () {
	    var index = $(this).data("index");
	    if (activity.couponIds.length <= 1) {
	        common.util.__tip("至少有一张优惠券", "warning")
	    }
	    else {
	        activity.couponIds.splice(index, 1);
	        Bll.render();
	    }
	});

	/**
	 * 保存
	 */
	$(document).on('click', "#save_brand", function () {
	    var ids = [];
	    if (activity.couponIds.length > 0) {
	        for (var index in activity.couponIds) {
	            ids.push(activity.couponIds[index].id)
	        }
	    }
	    if (ids.length > 0) {
	        activity.couponId = ids.join(",");
	    }
	    activity.startTime = ((new Date(activity.startTime).getTime())) / 1000 || "";
	    activity.endTime = ((new Date(activity.endTime).getTime())) / 1000 || "";
	    if (e1.validate()) {
	        common.util.__ajax({
	            url: "/couponActivity/add",
	            data: activity
	        }, function () {
	            location.href = "/couponActivity/index";
	        })
	    }
	});


/***/ },

/***/ 43:
/***/ function(module, exports) {

	/**
	 * Created by jiangmin  on 2016/5/27.
	 */
	var activity = {
	    actName: "",
	    activityType: 0,
	    actUrl: "",
	    startTime: "",
	    endTime: "",
	    bgImageUrl: "",
	    shareTitle: "",
	    shareDescribe: "",
	    sharePic: "",
	    shareUrl: "",
	    isVerify: "N",
	    instructions: "",
	    isNewUser: 0,
	    couponId: "",
	    couponIds:[{"id":""}]

	};

	module.exports = activity;

/***/ }

});