Blame view

client/js/goods/partials/add-info.js 11.7 KB
liuyue authored
1 2 3 4
var $ = require('jquery'),
	common = require('../../common/common');

liuyue authored
5
var e = new common.edit('#addinfo-wrap'),
liuyue authored
6 7
	basicInfo = NETSALEDATA.baseProductInfo.baseProduct || '',
	productExtBo = NETSALEDATA.productExtBo || '',
liuyue authored
8
	comfort = NETSALEDATA.specialAttrBo ? NETSALEDATA.specialAttrBo.wearSenses : "";
liuyue authored
9
liuyue authored
10
liuyue authored
11 12

/*上架补全信息*/
liuyue authored
13 14
$('#saveAddInfo').on('click', function() {
	e.submit('/goods/product/saveAfterSaleInfo', function(option) {
liuyue authored
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
		option.data = GOLABDATA.fire('LYaddInfo');
		option.success = function(res) {
			res = res.data;
			if (res.code == '200') {
				e.$tip(res.message, function() {}, 'growl-success');
			} else {
				e.$tip(res.message);
			}
			return false;
		}
	});
});

GOLABDATA.on("LYaddInfo", function() {
	return e.submit('', function(option) {
liuyue authored
30 31 32 33 34
		$.each(option.data, function(key, value) {
			if (value) {
				option.data[key] = value.split('|').join(',');
			}
		});
liuyue authored
35
		option.data.productSkn = $('#productSkn').val();
liuyue authored
36 37
		//option.data.wearSense = sense();
		option.data.attributeProValuesTwo = JSON.stringify(attributeObj());
liuyue authored
38
liuyue authored
39
liuyue authored
40
		function sense() {
liuyue authored
41 42 43 44
			var arr = [];
			$('#wearSenseWrap').find('select').each(function() {
				if ($(this).val()) {
					arr.push({
liuyue authored
45
						id: $(this).attr('name'),
liuyue authored
46 47 48 49 50
						value: $(this).val()
					});
				}

			});
liuyue authored
51 52 53 54 55
			if (arr.length > 0) {
				return JSON.stringify(arr);
			} else {
				return '';
			}
liuyue authored
56 57 58 59 60 61 62
		}

		function attributeObj() {
			var attributeArr = [];
			$('.attribute-group').each(function() {
				attributeArr.push({
					productSkn: option.data.productSkn,
weiqingting authored
63 64
					attributeId: $(this).find('[id]').attr('id'),
					attributeValueId: $(this).find('[id]').val().split('|').join(',')
liuyue authored
65 66
				})
			});
liuyue authored
67
liuyue authored
68
			return attributeArr;
liuyue authored
69
		}
liuyue authored
70
		option.debug = true;
liuyue authored
71
	});
liuyue authored
72 73
});
liuyue authored
74 75 76 77 78
function inputDisabled(callback) {
	if ($('.contentpanel').data('type') == 'info') {
		$('.contentpanel').find('input').prop('disabled', true);
		$('.contentpanel').find('select').prop('disabled', true);
		$('.contentpanel').find('.btn').addClass('disabled');
weiqingting authored
79
		$(".attr_checkobx_class").hide();
liuyue authored
80 81 82 83
		callback && callback();
	}
}
liuyue authored
84 85
$.ajax({
	type: 'POST',
liuyue authored
86
	url: '/goods/product/queryAttributesByConf',
liuyue authored
87
	data: {
liuyue authored
88
		saleType: 2,
89
		displayPosition: 2,
liuyue authored
90
		categoryId: basicInfo.smallSortId
liuyue authored
91 92 93 94
	},
	dataType: 'json',
	success: function(res) {
		var data = res.data;
liuyue authored
95 96 97 98 99 100 101 102 103
		data.style = basicInfo.style;
		data.pattern = basicInfo.pattern;
		data.brandModel = productExtBo.brandModel;
		data.brandModelText = productExtBo.brandModelText;
		data.brandSeriesText = productExtBo.brandSeriesText;
		data.brandSeries = productExtBo.brandSeries;
		data.makeCrafts = productExtBo.makeCrafts;
		data.salesPhrase = productExtBo.salesPhrase;
		data.isHostsell = productExtBo.isHostsell;
liuyue authored
104
liuyue authored
105
		$.each(data, function(key, value) {
liuyue authored
106
			if (value) {
liuyue authored
107 108 109 110
				data[key] = value;
			} else {
				data[key] = '';
			}
liuyue authored
111 112 113
			if (typeof value == 'string') {
				data[key] = value.replace(/,/g, "|");
			}
liuyue authored
114
		});
liuyue authored
115
liuyue authored
116 117
		if (NETSALEDATA.attributeProValuesBosTwo) {
			$.each(NETSALEDATA.attributeProValuesBosTwo, function(i, value) {
liuyue authored
118
				$.each(data.data, function(i2, value2) {
liuyue authored
119 120 121 122
					if (value.attributeId == value2.attributeId) {
						value2.selectedValues = value.attributeValueId.replace(/,/g, "|");
					}
				});
liuyue authored
123 124
			});
		}
liuyue authored
125
liuyue authored
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
		$('#addinfo-wrap').html(common.util.__template2($('#addInfoTemp').html(), data));

		e.on("bind", function() {
			$('#brandModelSelect').on('change', function() {
				$('#brandModel').val($(this).val());
			});
			$('#brandSeriesSelect').on('change', function() {
				$('#brandSeries').val($(this).val());
			});
		});


		$('#wearSenseWrap').find('select').each(function() {
			$(this).val($(this).siblings('input:hidden').val());
		});

		new common.dropDown({
			el: '#brandModelSelect',
			ajax: 'queryAll4Select',
			params: {
				type: 1,
				status: 1,
				brandId: basicInfo.brandId
			}
		});

		new common.dropDown({
			el: '#brandSeriesSelect',
			ajax: 'queryAll4Select',
			params: {
				type: 2,
				status: 1,
				brandId: basicInfo.brandId
			}
		});
liuyue authored
161 162 163

		e.init();
liuyue authored
164
		inputDisabled(function() {
liuyue authored
165
			$('#addinfo-wrap').find('input').not(":checked").parents('label').hide();
liuyue authored
166
		});
liuyue authored
167 168

	}
liuyue authored
169 170 171 172 173 174
});


//去编辑商品名称
$('#editProductName').on('click', function() {
	$('#productName').focus();
liuyue authored
175
});
liuyue authored
176 177

/*商品参数*/
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
// var goodsParamArr = [];
// var goodsParamEdit = new common.edit('#goodsParamWrap');
// common.util.__ajax({
// 	url: '/goods/product/queryAttributesByConfEx',
// 	data: {
// 		saleType: 2,
// 		displayPosition: 3,
// 		categoryId: basicInfo.smallSortId
// 	}
// }, function(res) {
// 	var data = res.data;
// 	if (NETSALEDATA.attributeProValuesBosOne) {
// 		$.each(NETSALEDATA.attributeProValuesBosOne, function(i, value) {
// 			$.each(data, function(i2, value2) {
// 				if (value.attributeId == value2.attributeId) {
// 					value2.selectedValues = value.attributeValueId.replace(/,/g, "|");
// 				}
// 			});
// 		});
// 	}

// 	if (res.data.length == 0) {
// 		$("#goodsParams-footer").hide();
// 	}

// 	$('#goodsParamWrap').html(common.util.__template2($('#goodsParamTemp').html(), {
// 		data: data
// 	}));
// 	goodsParamEdit.init();

// 	if ($('.contentpanel').data('type') == 'info') {
// 		$('.contentpanel').find('input').prop('disabled', true);
// 		$('.contentpanel').find('select').prop('disabled', true);
// 		$('.contentpanel').find('.btn').addClass('disabled');
// 		$('#goodsParamWrap').find('input').not(":checked").parents('label').hide();
// 	}
// }, true);


// GOLABDATA.on("TYgoodsParams", function() {
// 	var a = goodsParamEdit.submit(false, function(option) {
// 		$('.goods-param-group').each(function() {
// 			goodsParamArr.push({
// 				productSkn: $('#productSkn').val(),
// 				attributeId: $(this).find('[id]').attr('id'),
// 				attributeValueId: $(this).find('[id]').val().split('|').join(',')
// 			});
// 		});
// 		option.data.attributeProValuesOne = JSON.stringify(goodsParamArr);
// 		option.data.productSkn = $('#productSkn').val();
// 		option.debug = true;
// 	});
// 	return a ? a : goodsParamEdit.errMessage;

// 	var data = null;
// 	if (!goodsParamEdit.validate(true)) {
// 		return goodsParamEdit.errMessage;
// 	} else {
// 		data = {};
// 		$('.goods-param-group').each(function() {
// 			goodsParamArr.push({
// 				productSkn: $('#productSkn').val(),
// 				attributeId: $(this).find('[id]').attr('id'),
// 				attributeValueId: $(this).find('[id]').val().split('|').join(',')
// 			});
// 		});
// 		data.attributeProValuesOne = JSON.stringify(goodsParamArr);
// 		data.productSkn = $('#productSkn').val();
// 		return data;
// 	}
// });

251 252 253 254 255 256 257 258 259 260
var common_columns = [{
	display: "名称",
	width: '10%',
	name: "attributeName",
	render: function(item) {
		item.required = item.isMust == "Y" ? "required" : "";
		var arr = [];
		arr.push(item.attributeName);
		if (item.required) {
			arr.push("<span class='red'>*</span>");
261
		}
262 263 264
		return arr.join('');
	}
}]
weiqingting authored
265 266 267 268 269

/*陈超*/

var ag = new common.grid({
	el: "#attributeTable",
270
	hash: false,
weiqingting authored
271
	columns: common_columns.concat([{
272 273 274
		display: "属性",
		render: function(item) {
			item.required = item.isMust == "Y" ? "required" : "";
liuyue authored
275
276 277 278 279
			var attrs = NETSALEDATA.productStandardRelationBoList;
			if (attrs) {
				for (var i in attrs) {
					if (attrs[i].standardId == item.attributeId) {
weiqingting authored
280
						item.val = attrs[i].parameterMakeId;
liuyue authored
281
						item.__val = attrs[i].parameterMakeId;
282 283 284 285
					}
				}
			}
286
			item.__name = "attributeTable";
287 288
			return common.util.__template2($("#template33").html(), item);
		}
weiqingting authored
289
	}]),
290 291 292 293 294 295
	complete: function() {
		ag.__edit.init();
	}
});
ag.__edit = new common.edit("#attributeTable");
liuyue authored
296
common.util.__ajax({
297
	url: '/base/goods/queryAllProductAttr',
liuyue authored
298
	data: {
299 300
		param: basicInfo.smallSortId,
		displayPosition: 1
liuyue authored
301 302
	}
}, function(res) {
303
	ag.init(res.data);
liuyue authored
304 305 306
	inputDisabled(function() {
		$('#attributeTable').find('input').not(":checked").parents('label').hide();
	});
307
}, true);
liuyue authored
308
陶雨 authored
309
liuyue authored
310
liuyue authored
311
/*马力*/
312 313
var ag2 = new common.grid({
	el: "#goodsParamWrap",
314
	hash: false,
weiqingting authored
315
	columns: common_columns.concat([{
316 317 318
		display: "属性",
		render: function(item) {
			item.required = item.isMust == "Y" ? "required" : "";
liuyue authored
319
			item.id = item.parameterMakeId;
320 321 322
			var attrs = NETSALEDATA.attributeProValuesBosOne;
			if (attrs) {
				for (var i in attrs) {
liuyue authored
323
					if (attrs[i].attributeId == item.attributeId) {
weiqingting authored
324
						item.val = attrs[i].attributeValueId;
liuyue authored
325
						item.__val = attrs[i].attributeValueId.replace(/,/g, '|');
326 327 328
					}
				}
			}
329
			item.__name = "goodsParamWrap";
330 331
			return common.util.__template2($("#template33").html(), item);
		}
weiqingting authored
332
	}]),
333 334 335 336
	complete: function() {
		ag2.__edit.init();
	}
});
liuyue authored
337
ag2.__edit = new common.edit("#goodsParamWrap");
liuyue authored
338
339 340 341 342 343 344 345 346 347
common.util.__ajax({
	url: '/goods/product/queryAttributesByConfEx',
	data: {
		saleType: 2,
		displayPosition: 3,
		categoryId: basicInfo.smallSortId
	}
}, function(res) {
	ag2.init(res.data);
liuyue authored
348 349 350
	inputDisabled(function() {
		$('#goodsParamWrap').find('input').not(":checked").parents('label').hide();
	});
liuyue authored
351 352
}, true);
weiqingting authored
353 354 355

var ag3 = new common.grid({
	el: "#goodsParamWrap2",
356
	hash: false,
weiqingting authored
357 358 359 360 361 362
	columns: common_columns.concat([{
		display: "属性",
		render: function(item) {
			item.required = item.isMust == "Y" ? "required" : "";
			item.id = item.parameterMakeId;
			var attrs = NETSALEDATA.specialAttrBo;
363 364
			if (attrs && attrs.materialList) {
				var _arr = [];
weiqingting authored
365 366 367 368 369 370
				for (var i in attrs.materialList) {
					_arr.push(attrs.materialList[i].id);
				}
				item.__val = _arr.join('|');
			}
371
			item.__name = "goodsParamWrap2";
weiqingting authored
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
			return common.util.__template2($("#template33").html(), item);
		}
	}]),
	complete: function() {
		ag3.__edit.init();
	}
});
ag3.__edit = new common.edit("#goodsParamWrap2");
common.util.__ajax({
	url: '/base/goods/queryMaterialList',
	data: {
		categoryId: basicInfo.maxSortId
	}
}, function(res) {
	ag3.init([res.data]);
387 388 389
	inputDisabled(function() {
		$('#goodsParamWrap2').find('input').not(":checked").parents('label').hide();
	});
weiqingting authored
390 391 392
}, true);

liuyue authored
393 394 395 396
$(document).on("change", "#goodsParamWrap .attr_input", function() {
	var item = ag2.rows[$(this).data("index")];
	item.val = $(this).val();
});
weiqingting authored
397
liuyue authored
398 399 400 401 402
$(document).on("change", "#attributeTable .attr_input", function() {
	var item = ag.rows[$(this).data("index")];
	item.val = $(this).val();
});
weiqingting authored
403 404 405 406 407 408 409 410 411 412
$(document).on("change", "#goodsParamWrap .attr_checkobx_class", function() {
	var item = ag2.rows[$(this).data("index")];
	item.val = $("#goodsParamWrap_attr_" + $(this).data("index")).val().replace(/\|/g, ',');
})

$(document).on("change", "#goodsParamWrap2 .attr_checkobx_class", function() {
	var item = ag3.rows[$(this).data("index")];
	item.val = $("#goodsParamWrap2_attr_" + $(this).data("index")).val().replace(/\|/g, ',');
})
liuyue authored
413
414
/*保存*/
liuyue authored
415
GOLABDATA.on("TYgoodsParams", function() {
liuyue authored
416
	var data = {};
417 418 419 420
	if (!ag.__edit.validate(true)) {
		return ag.__edit.errMessage;
	}
	if (!ag2.__edit.validate(true)) {
weiqingting authored
421 422 423 424
		return ag2.__edit.errMessage;
	}
	if (!ag3.__edit.validate(true)) {
		return ag3.__edit.errMessage;
425 426 427 428 429 430
	}

	var productStandardRelationStr = [];
	if (ag.rows.length > 0) {
		for (var i in ag.rows) {
			if (ag.rows[i].val) {
liuyue authored
431 432
				var idNameList = ag.rows[i].idNameList;
				for (var x in idNameList) {
433 434 435 436 437 438 439
					if (ag.rows[i].val == idNameList[x].id) {
						productStandardRelationStr.push({
							standardId: ag.rows[i].attributeId,
							standardVal: idNameList[x].text,
							parameterMakeId: idNameList[x].id
						});
					}
440
				}
liuyue authored
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
			}
		}
	}
	data.productStandardRelationStr = JSON.stringify(productStandardRelationStr);

	var goodsParamArr = [];
	if (ag2.rows.length > 0) {
		for (var i in ag2.rows) {
			if (ag2.rows[i].val) {

				goodsParamArr.push({
					attributeId: ag2.rows[i].attributeId,
					productSkn: $('#productSkn').val(),
					attributeValueId: ag2.rows[i].val
				});
456 457 458

			}
		}
liuyue authored
459
	}
liuyue authored
460
	data.attributeProValuesOne = JSON.stringify(goodsParamArr);
weiqingting authored
461
462
	data.productMaterial = "";
weiqingting authored
463
	if (ag3.rows.length > 0) {
464
		data.productMaterial = ag3.rows[0].val;
weiqingting authored
465 466
	}
liuyue authored
467 468
	data.productSkn = $('#productSkn').val();
	return data;
469
liuyue authored
470 471 472 473 474
});

$("#propertySave").on('click', function() {
	common.util.__ajax({
		url: '/netSale/saveProductParam',
liuyue authored
475
		data: GOLABDATA.fire('TYgoodsParams')
liuyue authored
476
	}, function() {});
liuyue authored
477
});