productEdit.html 24.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 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 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8"/>
    <title>Yoho!Buy运营平台</title>
    <script src="/ufoPlatform/js/include.js"></script>
    <script src="/ufoPlatform/js/ajaxfileupload.js"></script>
    <style>
    	.product-detail-page ul, .product-detail-page li {
    		list-style: none;
    		padding: 0;
    		margin: 0;
    	}
    
    	.product-detail-page .container > li {
    		border-bottom: 1px solid #eee;
    		padding-bottom: 20px;
    	}
    
    	.product-detail-page .container {
    		padding: 0 30px;
    	}

    	.product-detail-page .base-info li,
    	.product-detail-page .keyword {
    		display: flex;
			align-items: center;
			margin-bottom: 10px;
    	}
    	
    	.product-detail-page .label {
    		width: 120px;
    		font-size: 14px;
    		text-align: right;    		
    	}
    	
		.product-detail-page .red {
			color: red;
		}
   	
   		.product-detail-page .group-color, .product-detail-page .group-size {
			display: flex;
			align-items: center;
			margin-bottom: 20px;
		}
    	
    	.product-detail-page .group-color li {
    		margin-right: 5px;
			float: left;
			line-height: 30px;
			margin-left: 5px;
			padding: 0 5px;
			position: relative;
    	}
    	
    	.product-detail-page .group-color .actived:before {
    		content: '';
    		width: 100%;
    		height: 100%;
    		display: block;
    		position: absolute;
    		top: 0;
			background: #000;
			opacity: 0.5;
			border-radius: 5px;
    	}
    	
    	.product-detail-page .group-size .size {
    		float:left;
    		margin-left: 10px;
    	}

		.product-detail-page .goods-image {
			display: flex;
		}

    	.product-detail-page .goods-image .img {
    		width: 104px;
    		height: 104px;
    		margin-right: 10px;
    		background-size: cover;
			background-repeat: no-repeat;
			background-position: center;
			position: relative;
    	}
    	
    	.product-detail-page .goods-image .img:hover:before {
    		content: "删除";
    		width: 100%;
    		display: block;
    		position: absolute;
    		top: 0;
    		background: #000;
    		opacity: 0.5;
    		color: #fff;
    		text-align: center;
    		line-height: 104px;
    	}
    </style>
</head>
<body class="easyui-layout product-detail-page" fit="true">
<div region="north">
    <script>
        document.write(addHead('商品管理 /基础商品 /商品创建', ''));
    </script>
</div>
<div region="center" style="overflow-y: scroll; top: 65px; padding-top: 10px;">
<form id="productDetail">
	<ul class="container">
		<li>
			<h2>基本信息</h2>
			<ul class="base-info">
				<li>
					<div class="label">品牌 <span class="red">*</span></div>
					<div class="base-info-item">
						<input id="editBrandId" type="text" name="brandId"> 系列:<input id="editSeriesId" name="seriesId" type="text">
					</div>
				</li>
				<li>
					<div class="label">商品名称 <span class="red">*</span></div>
					<div class="base-info-item">
						<input id="editProductName" type="text" name="productName"/>
					</div>
				</li>
				<li>
					<div class="label">发售日期 <span class="red">*</span></div>
					<div class="base-info-item">
						<input id="editSaleTime" type="text" name="saleTime"/>
					</div>
				</li>
				<li>
					<div class="label">性别 <span class="red">*</span></div>
					<div class="base-info-item">
						<label for="boy"><input id="boy" type="radio" value="1" name="gender" checked></label>
						<label for="girl"><input id="girl" type="radio" value="2" name="gender"></label>
						<label for="all"><input id="all" type="radio" value="3" name="gender">通用</label>
					</div>
				</li>
				<li>
					<div class="label">分类 <span class="red">*</span></div>
					<div class="base-info-item">
						<input id="editMaxSortId" type="text" name="maxSortId"/>
						<input id="editMidSortId" type="text" name="midSortId"/>
						 货号 <span class="red">*</span><input id="editProductCode" type="text" name="productCode"/>
					</div>
				</li>
				<li>
					<div class="label">商品价格限制 <span class="red">*</span></div>
					<div class="base-info-item">
						<input id="editMinPrice" type="text" name="minPrice"/>
						<span style="margin-right: 20px;c"></span>
						<input id="editMaxPrice" type="text" name="maxPrice"/>
					</div>
				</li>
			</ul>
		</li>
		
		<li>
			<h2>颜色尺码</h2>
			<div class="group-color">
				<div class="label">*颜色</div>
				<ul style="float: left; margin-left: 10px;">
				</ul>
			</div>
			<div class="group-size">
				<div class="label">*尺寸</div>
				<div class="size"></div>
			</div>
			
			<table id="colorSizeTable" style="width:100%;height:auto"></table>
		</li>
		
		<li>
			<h2>商品图片</h2>
			<div class="goods-image">
				<div id="imageUpload"></div>
			</div>
		</li>
		
		<li>
			<h2>商品关键词</h2>
			<div class="keyword">
				<div class="label" style="width: 120px;">商品关键词:</div>
				<div class="keyword-right">
					<input type="text" id="keyword" name="keyWords">
				</div>
			</div>
			<div class="red" style="margin-left:120px;">*每个关键词用英文逗号隔开</div>
		</li>
		<li style="text-align: center; margin-top: 20px;">
			<a id="submitBtn" class="easyui-linkbutton btn-success">提交</a>
			<a id="cancelBtn" class="easyui-linkbutton btn-default">取消</a>
		</li>
	</ul>
</form>
</div>
<script>
	/* 新增,修改公用页面
	    editImage代表图片是否修改过,新增固定传1。修改的时候根据是否修改,修改传1,无修改传0
	    1.新增,所有参数之前为空值,
	                   提交地址:product/addOrUpdate
	                   提交参数:{"brandId":78,"colorId":1,"colorName":"红色","editImage":1,"gender":3,"goodsName":"自定义红色","imageUrlList":["https://img10.static.yhbimg.com/goodsimg/2018/08/25/16/01e99496407347514356e5fe327d1f661d.jpg","https://img12.static.yhbimg.com/goodsimg/2018/08/25/16/0292fcebd071444401e6de340bcf2d8c19.jpg"],"keyWords":"球鞋,adidas","maxPrice":"899","maxSortId":10,"midSortId":18,"minPrice":"599","productCode":"009-009-009","productName":"测试商品009","saleTime":"2018-11-11","seriesId":8,"sizeIdList":[28,29]}
	    2.修改:首先根据传进来的id,获取商品信息把页面控件填写好。hidden记录id、goodsId、等参数
	                  提交参数:{"brandId":78,"colorId":2,"colorName":"蓝色","editImage":1,"gender":3,"goodsId":6,"goodsName":"自定义蓝色","id":10000004,"imageUrlList":["https://img10.static.yhbimg.com/goodsimg/2018/08/25/16/01e99496407347514356e5fe327d1f661d.jpg","https://img12.static.yhbimg.com/goodsimg/2018/08/25/16/0292fcebd071444401e6de340bcf2d8c19.jpg"],"keyWords":"球鞋,adidas2","maxPrice":"898","maxSortId":10,"midSortId":18,"minPrice":"598","productCode":"009-009-009-e","productName":"测试商品009-e","saleTime":"2018-11-12","seriesId":8}
	                 不可修改:品牌、分类、颜色、尺码、SKU(颜色展示名称除外:goodsName)
	*/             
	var productDetail = {
		initDom: function() {
			this.dom = {
				editBrandId: $('#editBrandId'),
				editProductName: $('#editProductName'),
				editSaleTime: $('#editSaleTime'),
				editMinPrice: $('#editMinPrice'),
				editMaxPrice: $('#editMaxPrice'),
				editProductCode: $('#editProductCode'),
				editMaxSortId: $('#editMaxSortId'),
				editMidSortId: $('#editMidSortId'),
				editSeriesId: $('#editSeriesId'),
				imageUpload: $('#imageUpload'),
				keyword: $('#keyword'),
				colorSizeTable: $('#colorSizeTable')
			};
		},
	    initFormData: function(detail) {
			var that = this;

			this.dom.editBrandId.combobox('select', detail.brandId)
			this.dom.editProductName.textbox('setValue', detail.productName);
			this.dom.editSaleTime.myDatebox('setValue', detail.saleTime);
			this.dom.editMinPrice.textbox('setValue', detail.minPrice);
			this.dom.editMaxPrice.textbox('setValue', detail.maxPrice);
			this.dom.editProductCode.textbox('setValue', detail.productCode);
			this.dom.editMaxSortId.combobox('select', detail.maxSortId);
			this.dom.editMidSortId.combobox('select', detail.midSortId);
			if (detail.seriesId && detail.seriesId != 0) {
				this.dom.editSeriesId.combobox('select', detail.seriesId);
			}
			
			this.dom.keyword.textbox('setValue', detail.keyWords);
			$('input[name=gender]').eq(detail.gender - 1).attr('checked','true');
			$('.group-color li[data-id=' + detail.colorId + ']').addClass('actived');

			if (detail.imageUrlList && detail.imageUrlList.length > 0) {
				detail.imageUrlList.map(function(item) {
					that.dom.imageUpload.before('<div class="img" data-url="' + item + '" style="background-image:url(' + item + ');">');
				});
			}
	    },
	    initForm: function() {
			var that = this;

			this.dom.editProductName.textbox({
                required: true,
                missingMessage: "商品名称不能为空",
                prompt: "商品名称",
                width: 460
         	});

			this.dom.keyword.textbox({
				width: 700
			});

			this.dom.editBrandId.combobox({
				editable: false,
		        prompt: "选择品牌",
		        width: 200,
		        valueField: "id",
		        textField: "text",
		        onSelect: function(data) {
					that.dom.editSeriesId.combobox('enable');
					that.dom.editSeriesId.myCombobox('reload', contextPath + '/brandSeries/querySeriesByBrandId?brandId=' + data.id);
					that.dom.editSeriesId.combobox('select')
		        }
			});

			this.dom.editSeriesId.myCombobox({
		        method: "get",
	            editable: false,
	            prompt: "请选择",
	            width: 200,
	            valueField: "id",
	            textField: "text",
	            loadFilter: function (data) {
					if (data && data.code == 200 && data.data.length > 0) {
						//that.dom.editSeriesId.combobox('select', data.data[0].id);
					}

	                return defaultLoadFilter(data);
	            }
	        });

			this.dom.editMaxSortId.myCombobox({
                editable: false,
                valueField: 'id',
                textField: 'text',
                prompt:"一级分类",
                onSelect: function (rec) {
					that.dom.editMidSortId.combobox('clear');
					that.dom.editMidSortId.combobox('reload', contextPath + "/productSort/getLevel2SortBySortId?sortId=" + rec.id);
					if (!that.productId) {
						that.dom.editMidSortId.combobox('enable');
					}
                }
            });

			this.dom.editSaleTime.myDatebox({
				prompt : "发售时间"
			});

			this.dom.editMidSortId.myCombobox({
				method: 'get',
	            editable: false,
	            valueField: 'id',
	            textField: 'text',
	            prompt:"二级分类",
	            loadFilter: function(data) {
					if (data && data.code == 200 && data.data.length > 0) {
						//that.dom.editMidSortId.combobox('select', data.data[0].id);
					}

					return defaultLoadFilter(data);
	            },
	            onSelect: function(opt) {
					that.getSizeInfo(opt.id);
	            }
	        });

	        this.dom.editProductCode.textbox({
				prompt : "请输入",
				required: true,
				missingMessage: "货号不能为空"
			});
	        this.dom.editMinPrice.textbox({
				prompt : "最低价",
				required: true,
				missingMessage: "最低价不能为空"
			});
	        this.dom.editMaxPrice.textbox({
				prompt : "最高价",
				required: true,
				missingMessage: "最高价不能为空"
			});	        
	        this.dom.colorSizeTable.myDatagrid({
	            fit: false,
	            fitColumns: true,
	            autoRowHeight: true,
	            nowrap: false,
	            columns: [[{
	                title: "色系名称",
	                field: "colorName",
	                width: 40,
	                align: "center"
	            }, {
	                title: "颜色展示名称",
	                field: "goodsName",
	                width: 80,
	                height: 50,
	                align: "center",
	                formatter: function(value) {
	                		return '<input type="text" class="goods-name" value="' + value + '">';
	                }
	            }, {
	                title: "尺码",
	                field: "size",
	                width: 100,
	                align: "center"
	            }, {
	                title: "SKU",
	                field: "sku",
	                width: 80,
	                align: "center"
	            },{
	                title: "平台建议售价",
	                field: "suggestPrice",
	                width: 80,
	                align: "center"
	            }]],
	            cache: false,
	            pagination: false,
	            idField: "id",
	            singleSelect: false,
	            checkOnSelect: false,
	            onLoadSuccess: function() {
					$('.goods-name').textbox({
						width: 100
					});
	            }
	        });

	        if (!this.productId) {
				this.dom.editSeriesId.combobox('disable');
				
			} else {
				this.dom.editBrandId.combobox('disable');
				this.dom.editMaxSortId.combobox('disable');
			}
			this.dom.editMidSortId.combobox('disable');
	    },
		init: function() {
			var that = this;

			this.productId = this.getUrlParam('id');
			this.detailData = {};
			this.submitFlag = false;
			this.colorSizeTableData = {
				total: 0,
				rows: []
			};
			this.initDom();
			this.initForm();

			this.dom.imageUpload.imageUpload({
	            width: 104,
	            height: 104,
	            realInputName: "goodsImage",
	            url: contextPath + '/fileupload/upload',
	            queryParams: {
	                bucket: "goodsimg"
	            },
	            onBeforeSubmit: function () {
	                $.messager.progress({
	                    title: "正在执行",
	                    msg: "正在执行,请稍后...",
	                    interval: 500,
	                    text: ""
	                });
	            },
	            filterFileName: function (data) {
	                if (!data || data.code != 200) {
	                    $.messager.progress("close");
	                    $.messager.alert("错误", data.message);
	                    return "";
	                }
	                return data.data.url;
	            },
	            onLoadSuccess: function (data) {
	                $.messager.progress("close");
	                $(document).find('.file-close').click();
	                that.dom.imageUpload.before('<div class="img" data-url="' + data.data + '" style="background-image:url(' + data.data + ');">');
	                return false;
	            }
	        });

			$.when(this.getBrandList(), this.getMaxSortList(), this.getColorInfo()).then(function(brand, maxSort, colors) {
				var brandId = '';
				
				brand = brand[0];
				maxSort = maxSort[0];
				colors = colors[0] || [];

				if (brand && brand.code == 200) {
					that.dom.editBrandId.combobox({
				        data: brand.data || []
					});
				}

				if (maxSort && maxSort.code == 200) {
					that.dom.editMaxSortId.combobox({
				        data: maxSort.data || []
					});
				}

				if (colors && colors.code == 200) {
					colors.data.map(function(item) {
						var color = item.colorValue ? 'background: url('+item.colorValue+')' : 'background:#' + item.colorCode;

     					$('.group-color ul').append('<li data-id="' + item.id + '"><i style="float: left;width: 30px; height: 30px;border-radius: 50%; margin-right: 3px;' + color + ';background-size: contain;"></i>' + item.colorName + '</li>');
					});
				}

				if (that.productId) {
					that.getDetailInfo();
				} else {
					that.getSizeInfo();
				}
			});

			$(document).on('click', '.group-color li', function() {
				if (that.productId) {
					$.messager.alert('操作提示', "颜色不可修改!");
					return;
				}

				if (!$(this).hasClass('actived')) {
					var colorName = $(this).text();

					if (that.colorSizeTableData.rows.length > 0) {
						that.colorSizeTableData.rows.map(function(item) {
							item.colorName = colorName;
							item.goodsName = colorName;
						});
					} else {
						that.colorSizeTableData.rows.push({
							colorName: colorName,
							goodsName: colorName,
							size: '',
							sku: '-',
							suggestPrice: '-'
						});
					}

					that.mergeCells();
					
					$(this).siblings().removeClass('actived');
					$(this).addClass('actived');
				}
			});

			$(document).on('click', '.group-size input', function(item) {
				var colorName = goodsName = '';

				if (that.productId && $(item).attr('exist') == 'true') {
					$.messager.alert('操作提示', '尺码不可修改!');
					return false;
				}

				if ($('.group-color .actived').length == 0) {
					$.messager.alert('操作提示', '请先选择颜色!');
					return false;
				}

				if (that.colorSizeTableData.rows.length > 0) {
					colorName = that.colorSizeTableData.rows[0].colorName;
					goodsName = that.colorSizeTableData.rows[0].goodsName;
				} else {
					colorName = goodsName = $('.group-color .actived').text();
				}

				that.colorSizeTableData.rows = [];
				$('.size-item:checked').each(function(index, item) {
					that.colorSizeTableData.rows.push({
						colorName: colorName,
						goodsName: goodsName,
						size: $(item).parent().text(),
						sku: '-',
						suggestPrice: '-'
					});
				});

				if ($('.size-item:checked').length == 0 && colorName) {
					that.colorSizeTableData.rows.push({
						colorName: colorName,
						goodsName: goodsName,
						size: '',
						sku: '-',
						suggestPrice:'-'
					});
				}
				that.mergeCells();
			});

			$(document).on('click', '.goods-image .img', function() {
				$(this).remove();
			});

			$('#cancelBtn').linkbutton({
				onClick: function() {
					window.location.href = contextPath + "/html/product/productList.html";
				}
			});

			$('#submitBtn').linkbutton({
	            onClick: function () {
					var imageUrlList = [];
					var sizeIdList = [];
					var editImage = 0;

					if (that.submitFlag) {
						return;
					}

					that.submitFlag = true;

					$('.goods-image .img').each(function(index, item) {
						imageUrlList.push($(item).data('url'));
					});

					if (that.productId) {
						if (that.detailData.imageUrlList && imageUrlList.length == that.detailData.imageUrlList.length) {
							$.each(imageUrlList, function(index, item) {
								if (item != that.detailData.imageUrlList[index]) {
									editImage = 1;
								}
							});
						} else {
							editImage = 1;
						}

						$('.group-size input:checked').each(function(index, item) {
							if ($(item).attr('exist') != 'true') {
								sizeIdList.push(+$(item).val());
							}
						});
					} else {
						editImage = 1;
						$('.group-size input:checked').each(function(index, item) {
							sizeIdList.push(+$(item).val());
						});
					}

					var ajaxData = {
						brandId: +that.dom.editBrandId.textbox('getValue'),
						colorId: +$('.group-color .actived').data('id'),
						colorName: $('.group-color .actived').text(),
						editImage: editImage,
						gender: +$('input[name="gender"]:checked').val(),
						goodsName: $('.goods-name').length>0 && $('.goods-name').textbox('getValue') || '',
						imageUrlList: imageUrlList,
						keyWords: that.dom.keyword.textbox('getValue'),
						maxPrice: that.dom.editMaxPrice.textbox('getValue'),
						maxSortId: +that.dom.editMaxSortId.combobox('getValue'),
						midSortId: +that.dom.editMidSortId.combobox('getValue'),
						minPrice: that.dom.editMinPrice.textbox('getValue'),
						productCode: that.dom.editProductCode.textbox('getValue'),
						productName: that.dom.editProductName.textbox('getValue'),
						saleTime: that.dom.editSaleTime.myDatebox('getValue'),
						seriesId: +that.dom.editSeriesId.combobox('getValue')
					};
					
					if (!ajaxData.brandId) {
						$.messager.alert('操作提示', '请选择品牌!');
						that.submitFlag = false;
						return false;
					}
					
					if (!ajaxData.saleTime) {
						$.messager.alert('操作提示', '请选择发售时间!');
						that.submitFlag = false;
						return false;
					}
					
					if (!ajaxData.maxSortId) {
						$.messager.alert('操作提示', '请选择一级分类!');
						that.submitFlag = false;
						return false;
					}
					
					if (!ajaxData.midSortId) {
						$.messager.alert('错误提示', '请选择二级分类!');
						that.submitFlag = false;
						return false;
					}
					
					if (imageUrlList.length == 0) {
						$.messager.alert('操作提示', '至少添加一张图片!');
						that.submitFlag = false;
						return false;
					}
					
					if (!$('#productDetail').form("validate")) {
						that.submitFlag = false;
						return false;
					}
					
					if (!that.productId) {
						ajaxData.sizeIdList = sizeIdList;

						if (!ajaxData.colorName) {
							$.messager.alert('错误提示', '请选择颜色!');
							that.submitFlag = false;
							return false;
						}
						
						if (sizeIdList.length ==0) {
							$.messager.alert('错误提示', '请选择尺码!');
							that.submitFlag = false;
							return false;
						}
					} else {
						ajaxData.sizeIdList = sizeIdList;
						ajaxData.id = that.detailData.id;
						ajaxData.goodsId = that.detailData.goodsId;
					}

					$.messager.progress({
                         title: "正在执行",
                         msg: "正在执行,请稍后...",
                         interval: 500,
                         text: ""
                     });

	                $.ajax({
						url: contextPath + '/product/addOrUpdate',
						contentType: "application/json",
						dataType: "json",
						type: "POST",
						data: JSON.stringify(ajaxData),
						success: function(ret) {
							$.messager.progress("close");
							that.submitFlag = false;

							if (ret && ret.code == 200) {
								$.messager.alert('操作提示', '提交成功!');
								window.location.href = contextPath + "/html/product/productList.html";
							} else {
								$.messager.alert('操作提示', ret.message || '提交失败');
							}
						},
						error: function(err) {
							that.submitFlag = false;
							$.messager.progress("close");
							$.messager.alert('操作提示', err.message || '提交失败');
						}
	                });
	            }
	        });
		},
		mergeCells: function() {
			this.colorSizeTableData.total = this.colorSizeTableData.rows.length;

			this.dom.colorSizeTable.datagrid('loadData', this.colorSizeTableData);
			this.dom.colorSizeTable.datagrid('mergeCells', {index: 0, field: 'colorName', rowspan: this.colorSizeTableData.total});
			this.dom.colorSizeTable.datagrid('mergeCells', {index: 0, field: 'goodsName', rowspan: this.colorSizeTableData.total});
			this.dom.colorSizeTable.datagrid('resize');
		},
		getUrlParam: function(name) {
		    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
		    var r = window.location.search.substr(1).match(reg);

		    if (r != null) {
		        return unescape(r[2]);
		    }

		    return null; 
		},
		getDetailInfo: function() {
			var that = this;

			// 编辑的情况需要根据id查询商品信息
			$.get(contextPath + '/product/find?id=' + this.productId).then(function(ret) {
				if (ret && ret.code == 200) {
					ret = ret.data || {};

					that.initFormData(ret);
					that.detailData = ret;
				}
			});
	        
		},
		getBrandList: function() {
			// 获取所有品牌
			return $.get(contextPath + '/brand/getBrandName');
		},
		getMaxSortList: function() {
			// 获取一级分类
			return $.get(contextPath + "/productSort/getLevel1SortIdAndName");
		},
		getSizeInfo: function(sortId) {
			var that = this;
			sortId = sortId || 0;

			// 获取所有尺寸
			$.get(contextPath + '/size/queryAllSecondSize4Goods?sortId=' + sortId, function(ret) {
				if (ret && ret.code == 200) {
					$('.group-size .size').html('');
     				$.each(ret.data || [], function(index, item) {
     					if (item.id) {
     						$('.group-size .size').append('<label for="size" style="margin-right: 5px;" data-id="' + item.id + '"><input type="checkbox" value="' + item.id + '" class="size-item">'+item.text+'</label>');
     					}
     				});
     				
     				if (that.detailData.sizeIdList) {
     					/* that.detailData.sizeIdList.map(function(item) {
							$('.group-size label[data-id=' + item + '] input').attr('checked','true');
							that.colorSizeTableData.rows.push({
								colorName: $('.group-color li[data-id='+that.detailData.colorId+']').text(),
								goodsName: that.detailData.goodsName,
								size: $('.group-size label[data-id=' + item + ']').text(),
								sku: '-'
							});
						}); */
     					for ( var i = 0; i <that.detailData.sizeIdList.length; i++){
     						item = that.detailData.sizeIdList[i];
     						$('.group-size label[data-id=' + item + '] input').attr('checked','true').attr('exist','true');
							that.colorSizeTableData.rows.push({
								colorName: $('.group-color li[data-id='+that.detailData.colorId+']').text(),
								goodsName: that.detailData.goodsName,
								size: $('.group-size label[data-id=' + item + ']').text(),
								sku: that.detailData.storageIdList[i],
								suggestPrice: that.detailData.suggestPriceList[i]
							});
     					}
					}
     				that.mergeCells();
     			}
			});
		},
		getColorInfo: function() {
			// 获取所有颜色
			return $.get(contextPath + '/productColor/getAllColor');
		}
	};

    $(function () {
		productDetail.init();
    });

</script>
</body>
</html>