attr.js
2.74 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
/*
*@time: 2016/2/1
*@author: chenglong
*/
var $ = require('jquery');
common = require('../common/common');
var sortmenu = require('../common/sortmenu');
// 把Y、N转换成是、否
function convertNorY(val) {
if (val === 'N') {
return '否';
} else {
return '是';
}
}
var tableGird = new common.grid({
el: "#attr-table",
parms: function () {
console.log(window.sortid);
return {
categoryId: window.sortid
};
},
columns: [
{display: "属性名称", name: "attributeName"},
{display: "属性类型", name: "attributeValues"},
{display: "输入类型", name: "inputType"},
{
display: "是否必选",
name: "isMust",
render: function (item) {
return convertNorY(item.isMust);
}
}, {
display: "是否可搜索",
name: "isSearch",
render: function (item) {
return convertNorY(item.isSearch);
}
}, {
display: "操作",
name: "categoryId",
render: function (items) {
return ('<button data-index="' + items.__index + '" class="btn btn-success btn-xs edit-class-btn">编辑</button>');
}
}
]
});
sortmenu.init(function () {
tableGird.init('/product/attr/queryProductAttributeList');
});
$('#add-attri').click(function () {
attributeOp("添加", '/product/attr/add', {categoryId: window.sortid});
});
// 编辑产品属性
$(document).on('click', '.edit-class-btn', function () {
var item = tableGird.rows[$(this).data('index')];
attributeOp("修改", '/product/attr/update', item);
// $("#select2-shopsId-container").val(item.)
});
function attributeOp(prefix, url, item) {
var a = new common.edit(".confirm");
common.dialog.confirm(prefix + "属性", common.util.__template($("#template").html(), item), function () {
return a.submit(url, function (option) {
option.data.categoryId = item.categoryId;
option.data.attributeId = item.attributeId;
option.success = function (res) {
res = res.data;
if (res.code == "200") {
a.$tip("提交成功", function () {
tableGird.reload();
}, 'growl-success');
} else {
a.$tip(res.message);
}
return false;
},
option.error = function (res) {
a.$tip(res.message);
}
});
});
a.init();
}