operations.webshare.Edit.js 3.31 KB
webpackJsonp([133],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	/**
	 * Created by ty on 2016/7/6.
	 * 活动分享编辑
	 */

	var $ = __webpack_require__(1),
	    common = __webpack_require__(2);

	var id = $("#edit-content").data("id"),
	    url = $("#edit-content").attr("url"),
	    module = {},
	    edit = new common.edit2("#edit-content",{bucket: "taobaocms"});

	var startTimeObj;
	var endTimeObj;

	//通用对象
	var Bll = {
	    //渲染界面
	    render: function () {
	        $("#edit-content").html(common.util.__template2($("#edit-template").html(), module));

	        Bll.__editRender();

	    },
	    //转换时间格式
	    getTime: function (time) {
	        var t = new Date(time * 1000);
	        return common.util.__dateFormat(t, "yyyy-MM-dd hh:mm:ss");
	    },
	    //验证
	    __editRender: function () {
	        edit.init();
	        $("#choose-status").show();
	        new common.dropDown({el: "#status"});
	        startTimeObj = $("#couponStartTime").datetimepicker({
	            timeFormat: 'HH:mm:ss',
	            showSecond: true
	        }).data("datepicker");
	        endTimeObj = $("#couponEndTime").datetimepicker({
	            timeFormat: 'HH:mm:ss',
	            showSecond: true
	        }).data("datepicker");
	        edit.on("file_onComplete", function (obj) {
	            var names = obj.field;
	            module = common.util.__buildobj(names, '.', module, function (o, name) {
	                o[name] = obj.data;
	            });

	        });
	    }
	};

	if(id){
	    common.util.__ajax({
	        async: false,
	        url: "/webShare/selectWebShare",
	        data: {id: id}
	    }, function (res) {
	        module = res.data;
	        if(module.couponId === 0){
	            module.couponId = null;
	        }
	        if(module.couponStartTime === 0){
	            module.couponStartTime = null;
	        }
	        if(module.couponEndTime === 0){
	            module.couponEndTime = null;
	        }
	        if(module.couponStartTime){
	            module.couponStartTime=Bll.getTime(module.couponStartTime);
	        }
	        if(module.couponEndTime){
	            module.couponEndTime=Bll.getTime(module.couponEndTime);
	        }

	    },true);
	}

	Bll.render();

	function checkCouponId() {
	    var value = $('input[name="coupon_id"]').val();
	    if(isNaN(value)){
	        common.util.__tip("劵ID必须为数字!");
	        return false;
	    }else{
	        return true;
	    }
	}

	//保存数据
	$(document).on("click", "#save_btn", function () {
	    module.couponStartTime = ((new Date(module.couponStartTime).getTime())) / 1000 || "";
	    module.couponEndTime = ((new Date(module.couponEndTime).getTime())) / 1000 || "";
	    if(edit.validate()) {
	        if(checkCouponId()){
	            common.util.__ajax({
	                url: url,
	                data: module
	            }, function () {
	                setTimeout(function () {
	                    location.href = "/operations/webshare/index";
	                },600);
	            });
	        }

	    }
	});

	/**
	 * 监听输入值的变化
	 */
	$(document).on("change", ".observe", function () {
	    var $this = $(this);
	    var name = $this.data("field");
	    module = common.util.__buildobj(name, '.', module, function (obj, name) {
	        obj[name] = $this.val();
	    });
	});

/***/ }
]);