netsale-edit.js 4.99 KB
'use strict';
var $ = require('jquery'),
	common = require('../common/common');
require('../util/custom.js');
/*
 *	获取业务数据
 */
window.NETSALEDATA = require('./partials/data.js');

window.GOLABDATA = {
	on: function(key, callback) {
		var that = this;
		if (!that.registerEvent) {
			that.registerEvent = {};
		}
		if (!that.registerEvent[key]) {
			that.registerEvent[key] = [];
		}
		if (that.registerEvent[key].indexOf(callback) == -1) {
			that.registerEvent[key].push(callback);
		}
	},
	fire: function(key) {
		var that = this;
		if (!this.registerEvent) return;
		if (key) {
			if (!this.registerEvent[key]) return;
			var listeners = that.registerEvent[key];
			var args = [].slice.call(arguments, 1);
			for (var i in listeners) {
				return listeners[i].apply(this, args);
			}
		} else {
			var map = {},
				args = [].slice.call(arguments, 1),
				listeners = null;

			for (var key in that.registerEvent) {
				listeners = that.registerEvent[key];
				for (var i in listeners) {
					map[key] = listeners[i].apply(this, args);
				}
			}

			console.log(map);
			return map;
		}

	}
};



//获取skn
if (NETSALEDATA && NETSALEDATA.baseProductInfo && NETSALEDATA.baseProductInfo.baseProduct) {
	$('#productSkn').val(NETSALEDATA.baseProductInfo.baseProduct.productSkn);
} else {
	common.util.__tip("SKN不存在");
}


/*加载其他模块*/
require('./partials/basic-info');
require('./partials/editor_recommend');
require('./partials/model');
// require('./partials/video.js');
//require('./partials/brand-relation');
require('./partials/add-info');
require('./partials/netsale-ty.js');


if ($('.contentpanel').data('type') == 'info') {
	$('.contentpanel').find('input').prop('disabled', true);
	$('.contentpanel').find('.btn').addClass('disabled');
	$('.panel-footer').remove();
	$('#edit-recommender, #edit-descriptioner').prop('contenteditable', false);

	$('#saveAllInfo').hide();
	$(".goods-img i").remove();
	$("#search-key-list").hide();
	$(".brand-list").hide();

	// 上架审核的查看页面
	if ($('.contentpanel').data('action') != 'audit') {

		$('#passBtn').hide();
		$('#rejectBtn').hide();
	} else {
		var status = NETSALEDATA.baseProductInfo.baseProduct.status;
		//待审核状态 或者 再上架待审核
		if (status != 2 && status != 5) {
			$('#passBtn').hide();
			$('#rejectBtn').hide();
		}
	}

} else {
	$('#backBtn').hide();
	$('#passBtn').hide();
	$('#rejectBtn').hide();
}


//保存完整网销信息
var e = new common.edit('#netsaleAllInfo');
$(document).on("click", "#saveAllInfo", function() {
	var data = {};
	var error = '';
	var allData = GOLABDATA.fire();

	$.each(allData, function(key, value) {
		if (typeof value == 'string') {
			console.log(value);
			error += value;
			return;
		}
		$.extend(data, value, true);
	});

	if (error !== '') {
		common.util.__tip(error, 'warning');
	} else {
		e.submit('/product/saveNetSaleAllInfo', function(option) {
			option.data = data;
			option.success = function(res) {
				res = res.data;
				if (res.code == '200') {
					e.$tip(res.message, function() {
						history.go(-1);
					}, 'growl-success');
				} else {
					e.$tip(res.message);
				}
				return false;
			}
		});
	}

});


var Bll = {
	toast: function(content, fn) {
		common.dialog.confirm("温馨提示", content, function() {
			common.util.__ajax({
				url: '/supplier/baseproduct/auditReject',
				data: fn()
			}, function() {
				//g.reload();
				//loadTab();
				history.go(-1);
			});
		});
	}
}


// 单个驳回
$(document).on("click", "#rejectBtn", function() {
	//auditOperation([],3,)

	var data = function() {

		var reason = $('#reason').val();
		if (reason === '' || $.trim(reason) === '') {
			return "请填写驳回原因";
		}

		return {
			productSknList: JSON.stringify([NETSALEDATA.baseProductInfo.baseProduct.productSkn]),
			targetStatus: 3, // 驳回
			rejectReason: reason
		};
	}
	Bll.toast($("#template").html(), data);
});


// 单个通过
$(document).on("click", "#passBtn", function() {
	//auditOperation([],3,)

	var data = function() {

		return {
			productSknList: JSON.stringify([NETSALEDATA.baseProductInfo.baseProduct.productSkn]),
			targetStatus: 4, //通过
			rejectReason: ""
		};
	}
	Bll.toast("确定要通过该申请吗?", data);
});

//类似描点跳转,描点会影响history.go(-1)
$('.floatnav').on('click', 'li', function() {

	var name = $(this).attr('name'),
		scrollTop = $('.netsale-position[name="' + name + '"]').offset().top;

	$(window).scrollTop(scrollTop);
	return false;
});

//导航样式
$('.floatnav').on('mouseenter', function() {
	$('.floatnav').addClass('show');
}).on('mouseleave', function() {
	$('.floatnav').removeClass('show');
});
if (location.hash) {
	var hashPos = location.hash.substring(1);
	setTimeout(function() {
		$('.floatnav').find('li[name="' + hashPos + '"]').trigger('click');
	}, 500);

}

try {
	$(".floatnav li").each(function() {
		var name = $.trim($(this).data('pos')),
			that = this;

		if (name == location.hash.replace(/^#/, '')) {
			setTimeout(function() {
				$(that).click();
			}, 500);
		}
	});
} catch (e) {

}