addSizeInfo.js
6.02 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
/**
* Created by ty on 2016/3/24.
*/
var $ = require('jquery'),
common = require('../common/common'),
util = require('../common/util');
$(document).on('click', '#searchSku', function() {
var val = $.trim($("#skuInput").val());
if(!val.match(/^[0-9]+$/)) {
util.__tip("输入不合法", "warning");
return;
}
if(val) {
common.util.__ajax({
url:'/meterManage/productSize/queryProdSizeList',
data:{productSku:val}
},function(res) {
if(res.data.list && res.data.list.length > 0) {
var e = new common.edit("#add-list");
e.on('validate', function() {
var flag = false;
$("input[name='noMeasureIds']").not("input:checked").each(function () {
$("." + $(this).val()).each(function() {
if(!$(this).val()){
flag = true;
return false;
}
});
if(flag) return false;
});
if (flag)
return "请将没有勾选无需测量的列填写完整!";
});
var item = res.data.list[0];
var headList = [];
var j = 0;//创造一个变量以供赋值
if(item.sizeRelationsList.length > 0) {
headList.push({display: "尺码", name: "sizeName"});//尺码
headList.push({
display: "参考尺码(" + item.genderName + ")", name: "referenceName", render: function (item) {//参考尺码列
var refName = item.referenceName ? item.referenceName : "";//非空判断
return '<input class="form-control refInfo" data-index="' + item.__index + '"' + 'value="' + refName + '"/>';
}
});
for (var i = 0; i < item.sizeRelationsList[0].prdSizeAttributeBoList.length; i++) {//尺码列
var sizeAttributes = item.sizeRelationsList[0].prdSizeAttributeBoList[i];// 码数组里的数据
var chkbox = '<label style="cursor: pointer;"><input type="checkbox" name="noMeasureIds" value="' + sizeAttributes.sizeAttributeId + '"/>无需测量</label>';
headList.push({
display: sizeAttributes.sizeAttributeName + "<br>" + chkbox,
name: "sizeValue",
render: function (item) {
if (j == item.prdSizeAttributeBoList.length) j = 0;//防止越界
var sizeVal = item.prdSizeAttributeBoList[j].sizeValue ? item.prdSizeAttributeBoList[j].sizeValue : "";
//j++;//
return '<input class="form-control sizeInfo '+ item.prdSizeAttributeBoList[j++].sizeAttributeId +'" data-index="' + item.__index + '"' + 'value="' + sizeVal + '"/>';
}
});
}
}
var grid=new common.grid({
el:"#content-list",
hash: false,
columns:headList
});
grid.init(item.sizeRelationsList);
$("#add-saveArea").show();
$("#add-head").html(common.util.__template2($("#modifySize-template").html(), item));
$("#noMeasureIds").val(item.noMeasureIds? item.noMeasureIds.join("|"):"");
e.init();
$(document).on('click', '#add-saveBtn', function() {
e.submit("/meterManage/productSize/saveProdSizeInfo",function(option){
//option.data;=
option.data.productSkn = item.productSkn;
option.data.noMeasureIds = $("#noMeasureIds").val()?$("#noMeasureIds").val().split("|"):[];
option.data.noMeasureIds = JSON.stringify(option.data.noMeasureIds);
option.data.sizeInfoList = [];
for(var i = 0; i < $(".sizeInfo").length; i++){
var info = $($(".sizeInfo")[i]);
option.data.sizeInfoList[i] = ({
productSkn: item.productSkn,
sizeId:grid.rows[info.data("index")].sizeId,
sizeAttributeId:grid.rows[info.data("index")].prdSizeAttributeBoList[parseInt(i%grid.rows[info.data("index")].prdSizeAttributeBoList.length)].sizeAttributeId,
sizeValue:info.val()
});
}
option.data.sizeInfoList = JSON.stringify(option.data.sizeInfoList);
option.data.productSizeReferList = [];
for(var i = 0; i < $(".refInfo").length; i++) {
var ref = $($(".refInfo")[i]);
option.data.productSizeReferList.push({
sizeId: grid.rows[ref.data("index")].sizeId,
gender: item.gender,
referenceName: ref.val()
});
}
option.data.productSizeReferList = JSON.stringify(option.data.productSizeReferList);
option.success=function(res){
util.__tip(res.data.message, 'success');
grid.reload();
};
option.error=function(res){
//dialog.close();
util.__tip(res.message);
}
});
return false;
});
}else {
util.__tip("未搜索到sku:" + val);
}
},true);
}
});