Blame view

dist/yohobuy-portal-fe/5.0.2/jquery/operations.couponActivity.Edit.js 3.82 KB
xuhongyun authored
1
webpackJsonp([104],[
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
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	/**
	 * Created by jiangmin on 16/5/26.
	 * 品牌发券管理
	 */
	var $ = __webpack_require__(1);
	common = __webpack_require__(2);
	var e1 = new common.edit2("#basicForm");
	var activity = {};
	var activityId = location.href.substring(location.href.lastIndexOf("/") + 1);

	/**
	 * 监听输入值的变化
	 */
	$(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 = {
	    //获取数据,并转换相应格式
	    getData: function () {
	        common.util.__ajax({
	            url: "/couponActivity/queryById",
	            data: {id: activityId},
	            async: false
	        }, function (res) {
	            activity = res.data;
	        }, true);
	        var ids=[];
	        activity.couponIds=[];
	        if(activity.couponId){
	            ids = activity.couponId.split(",");
	        }
	        if(ids.length==0){
	            activity.couponIds.push({id: ""});
	        }else{
	            for (var i = 0; i < ids.length; i++) {
	                activity.couponIds.push({id: ids[i]});
	            }
	        }
	        if(activity.startTime){
	            activity.startTime=Bll.getTime(activity.startTime);
	        }
	        if(activity.endTime){
	            activity.endTime=Bll.getTime(activity.endTime);
	        }
	    },
	    //渲染界面
	    render: function () {
	        console.log("activity",activity);
	        $("#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"
	        });
xuhongyun authored
72 73 74
	        startTimeObj = $("#startTime").datetimepicker({
	            timeFormat: 'HH:mm:ss',
	            showSecond: true
75
	        }).data("datepicker");
xuhongyun authored
76 77 78
	        endTimeObj = $("#endTime").datetimepicker({
	            timeFormat: 'HH:mm:ss',
	            showSecond: true
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
	        }).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.getData();
	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/update",
	            data:activity
	        }, function (){
	            location.href = "/couponActivity/index";
	        } )
	    }
	});



/***/ }
]);