logis-provider-1.0.0.js 2.74 KB
(function() {
	var e = function(options) {
		this.init(options);
	};
	e.areas = {};
	e.prototype = {
		init : function(options) {
			e.areas = options.areas;

		},
		dialog : function(pos, checked, disabled) {
			var areas =  $.extend(true,{}, e.areas);

			if (checked && checked.length) {
				for (k in areas.group) {
					var a = areas.group[k].areas;
					for (j in a) {
						var g = '' + areas.group[k].areas[j].code
						if ($.inArray(g, checked) != -1) {
							areas.group[k].areas[j].checked = true;
						}
					}
				}
			}

			if (disabled && disabled.length) {
				for (k in areas.group) {
					var a = areas.group[k].areas;
					for (j in a) {
						var g = '' + areas.group[k].areas[j].code
						if ($.inArray(g, disabled) != -1) {
							areas.group[k].areas[j].disabled = true;
						}
					}
				}
			}

			var o = $('#J_AreaTemplate').tpl(areas),
				content = '<form method="post">' + o + '<div class="btns"><button type="button" class="J_Submit">确定</button><button type="button" class="J_Cancel">取消</button></div></form>',
				dialog = new AreaDialog(pos, '选择区域', content, e.areas, checked);
			dialog.show();
		},
		delRule: function(o){
			if (confirm('确定要删除当前地区的设置吗?')) {
				var tr = $(o).parents('tr')[0];
				$(tr).remove()
			}
		},
		addRule: function(o){
			var div = $(o).parents('.J_PostageDetail')[0];
			var i = $(div).find('tbody tr').length + 1,
				rid = 'n' + i,
				express = $(div).attr('data-delivery'),
				type = this.getType(),
				data = {
					rid: rid,
					express: express,
					type: type[0],
					typeUnit: type[1],
				};

			if (i == 1) { // 第一个
				var firstRuleTpl = $('#J_FirstRuleTemplate').tpl(data);
				$(div).find('.tbl-except').html(firstRuleTpl)
			} else {
				ruleTpl = $('#J_RuleTemplate').tpl(data);
				$(div).find('tbody').append(ruleTpl)
			}
		},
		toggle: function(o) {
			var i = $(o).parents('.J_Section')[0];
			var s = $(i).find('.J_PostageDetail');
			if ($(o).prop('checked')) {
				if (s.length > 0) {
					s.show()
				} else {
					var type = this.getType();
					var express = $(i).find('.J_Delivery').attr('data-type'),
						data = {
							express: express,
							type: type[0],
							typeUnit: type[1],
						},
						ruleTpl = $('#J_InitRuleTemplate').tpl(data);
					$(i).append(ruleTpl)
				}
			} else {
				if (s.length > 0) {
					s.hide()
				}
			}
		},
		getType: function () {
			var v = $('input[name="valuation"]:checked').val(),
				n = '',
				m = '';
			if (v == undefined) {
				v = $('input[name="valuation"]').val();
			}

			if (v == 1) {
				n = '件';
				m = '件';
			} else if (v == 2) {
				n = '重';
				m = 'kg';
			} else if (v == 3) {
				n = '体积';
				m = 'm³';
			}
			return [n, m];
		}
	}



	window.LogisProvider = e
})();