goods-sort.js 1.55 KB
var $ = require('jquery'),
	common = require('../../common/common');

if(window.NETSALEDATA) {
	var searchSortList = [];
	if(window.NETSALEDATA.searchSortList) {
		searchSortList = window.NETSALEDATA.searchSortList;
	}

	for(var i = 0; i < searchSortList.length; i++) {
		if(searchSortList[i].modelId == 1)
			$("#sort0").val(searchSortList[i].intValue);
		else if(searchSortList[i].modelId == 2)
			$("#sort1").val(searchSortList[i].intValue);
		else if(searchSortList[i].modelId == 3)
			$("#sort2").val(searchSortList[i].intValue);
	}

	var item = [];
	for (var i = 0; i < 3; i++) {
		item[i] = {
			productSkn:window.NETSALEDATA.baseProductInfo.baseProduct.productSkn,
			modelId:i + 1,
			projectId:1,
			intValue:parseInt($("#sort" + i).val())
		};
	}

	for(var i = 0; i < 3; i++) {
		for (var j = 0; j < searchSortList.length; j++) {
			if(searchSortList[j].modelId == item[i].modelId) {
				item[i].id = searchSortList[j].id;
				break;
			}
		}
	}

	window.NETSALEDATA.searchSortList = item;

	$('#sort-save').on('click', function () {
		common.util.__ajax({
			url:'/netSale/saveSearchSort',
			data:{searchSortList:JSON.stringify(window.NETSALEDATA.searchSortList)}
		},function() {
			
		});		
	});

	$("#sort0").on('change', function() {
		window.NETSALEDATA.searchSortList[0].intValue = parseInt($("#sort0").val());
	});

	$("#sort1").on('change', function() {
		window.NETSALEDATA.searchSortList[1].intValue = parseInt($("#sort1").val());
	});

	$("#sort2").on('change', function() {
		window.NETSALEDATA.searchSortList[2].intValue = parseInt($("#sort2").val());
	});
}