netsale-ty.js 6.29 KB
var $ = require('jquery'),
	common = require('../../common/common'),
	util = require('../../common/util');

if (window.NETSALEDATA) {
	//{ //商品参数
	/*var baseProduct = window.NETSALEDATA.baseProductInfo.baseProduct;
	var specialAttrBo = {
		productSkn: baseProduct.productSkn,
		washTipsList: [],
		materialList: []
	};
	if (window.NETSALEDATA.specialAttrBo) {
		specialAttrBo = window.NETSALEDATA.specialAttrBo;
	}
	var washTipsList = specialAttrBo.washTipsList || [];
	var materialList = specialAttrBo.materialList || [];

	var e = new common.edit("#taoyu1");

	//材质初始化
	common.util.__ajax({
		url: '/netSale/queryAllBySortId4Select',
		data: {
			param: baseProduct.maxSortId
		}
	}, function(res) {
		$("#material-group").html(common.util.__template2($("#material-params").html(), res || {}));
		var materials = [];
		for (var i = 0; i < materialList.length; i++) {
			materials[i] = materialList[i].id;
		}
		$("#material").val(materials.join("|"));
		e.init();
	}, true);

	//洗涤提示初始化
	common.util.__ajax({
		url: '/netSale/getAll4Select',
		data: {}
	}, function(res) {
		$("#washTip-group").html(common.util.__template2($("#washTip-params").html(), res || {}));
		var washTips = [];
		for (var i = 0; i < washTipsList.length; i++) {
			washTips[i] = washTipsList[i].sortId;
		}
		$("#washTips").val(washTips.join("|"));
		e.init();
	}, true);


	$(document).on('change', '.material', function() {
		var items = $("#material").val().split("|");
		for (var i = 0; i < items.length; i++) {
			materialList[i] = {
				"id": parseInt(items[i])
			};
		}
	});

	$(document).on('change', '.washTips', function() {
		var items = $("#washTips").val().split("|");
		for (var i = 0; i < items.length; i++) {
			washTipsList[i] = {
				"sortId": parseInt(items[i])
			};
		}
	});*/

	/*$(document).on('click', "#propertySave", function() {

		var washTips = $("#washTips").val() || "";
		var productMaterial = $("#material").val() || "";

		common.util.__ajax({
			url: '/netSale/saveProductParam',
			data: {
				productSkn: specialAttrBo.productSkn,
				washTips: washTips.replace(/\|/g, ","),
				productMaterial: productMaterial.replace(/\|/g, ",")
			}
		});
		return false;
	});*/

	/*window.GOLABDATA.on('TYcaizhi', function() {
		var washTips = $("#washTips").val() || "";
		var productMaterial = $("#material").val() || "";
		return {
			"washTips": washTips.replace(/\|/g, ","),
			"productMaterial": productMaterial.replace(/\|/g, ",")
		};
	});*/
	//}


	{ //搜索关键词
		var searchKeys = "";
		if (window.NETSALEDATA.productExtBo) {
			searchKeys = window.NETSALEDATA.productExtBo.searchKeys || "";
		}

		$("#searchKeys").val(searchKeys);
		var g = new common.grid({
			el: "#search-key",
			hash: false,
			columns: [{
				display: "ID",
				name: "id"
			}, {
				display: "内容",
				name: "content"
			}, {
				display: "操作",
				name: "",
				render: function(item) {
					return '<a class="btn btn-info add" data-index="' + item.__index + '">添加</a>';
				}
			}]
		});

		g.init('/netSale/queryHotSearchTerms');

		$("#searchKeys").on('change', function() {
			searchKeys = $("#searchKeys").val();
		});

		$(document).on('click', '.add', function() {
			var item = g.rows[$(this).data("index")];
			var value = $("#searchKeys").val();
			if(value.indexOf(item.content) == -1) {
				if (value) value += ",";
				$("#searchKeys").val(value + item.content);
				searchKeys = $("#searchKeys").val();
			} else {
				util.__tip("商品关键词不能重复");
			}
		});

		$("#save-searchKey").on('click', function() {
			common.util.__ajax({
				url: '/netSale/saveNetSaleSearchKeys',
				data: {
					productSkn: window.NETSALEDATA.baseProductInfo.baseProduct.productSkn,
					searchKeys: searchKeys
				}
			});
			return false;
		});

		window.GOLABDATA.on('TYsearchKey', function() {
			var washTips = $("#washTips").val() || "";
			var productMaterial = $("#material").val() || "";
			return {
				"searchKeys": searchKeys
			};
		});
	}


	{ //尺寸信息
		var productSkn = window.NETSALEDATA.baseProductInfo.baseProduct.productSkn;
		if(productSkn) {
			common.util.__ajax({
				url: '/meterManage/productSize/queryProdSizeList',
				data: {
					productSkn: productSkn
				}
			}, function (res) {
				if (res.data.list && res.data.list.length > 0) {
					$("#body").html(common.util.__template2($("#sizeinfo-template").html(), res.data.list[0]));
				}
			}, true);
		}
	}


	{ //搜索优先级
		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;
				}
			}
		}

		searchSortList = item;

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

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

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

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

		$("#sort0").keyup(function () {
			$(this).val($(this).val().replace(/\D/g, ""));
		});
		$("#sort1").keyup(function () {
			$(this).val($(this).val().replace(/\D/g, ""));
		});
		$("#sort2").keyup(function () {
			$(this).val($(this).val().replace(/\D/g, ""));
		});

		window.GOLABDATA.on('TYsearchSort', function() {
			if (!searchSortList[0] || !searchSortList[1] || !searchSortList[2])
				return "请将搜索排序填写完整!";
			return {
				"searchSortList": JSON.stringify(searchSortList)
			};
		});
	}

}