...
|
...
|
@@ -2,11 +2,8 @@ |
|
|
*@time: 2016/2/1
|
|
|
*@author: chenglong
|
|
|
*/
|
|
|
|
|
|
|
|
|
var $ = require('jquery');
|
|
|
common = require('../common/common');
|
|
|
|
|
|
var sortmenu = require('../common/sortmenu');
|
|
|
|
|
|
// 把Y、N转换成是、否
|
...
|
...
|
@@ -18,14 +15,10 @@ function convertNorY(val) { |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
var tableGird = new common.grid({
|
|
|
|
|
|
el: "#attr-table",
|
|
|
parms: function () {
|
|
|
|
|
|
console.log(window.sortid);
|
|
|
|
|
|
return {
|
|
|
categoryId: window.sortid
|
|
|
};
|
...
|
...
|
@@ -57,17 +50,69 @@ var tableGird = new common.grid({ |
|
|
]
|
|
|
});
|
|
|
|
|
|
var propValueGrid = new common.grid({
|
|
|
|
|
|
el: "#prop-value-table",
|
|
|
columns: [
|
|
|
{display: "ID", name: "id",
|
|
|
render: function (items) {
|
|
|
|
|
|
//items.id=items.__index+1;
|
|
|
return('<input id="id" class="form-control width110" value="'+items.id+'" type="text">');
|
|
|
}
|
|
|
},
|
|
|
{display: "属性值", name: "name",
|
|
|
render: function (items) {
|
|
|
return('<input id="name" class="form-control width110 propValue" value="'+items.name+'" data-index="'+items.__index+'" type="text" placeholder="属性值">');
|
|
|
}
|
|
|
|
|
|
},
|
|
|
{
|
|
|
display: "操作",
|
|
|
name: "categoryId",
|
|
|
render: function (items) {
|
|
|
|
|
|
var html = [];
|
|
|
if (items.__index == propValueGrid.__rows.length-1) {
|
|
|
html.push('<button data-index="' + items.__index + '" class="btn btn-success btn-xs prop-add-btn">添加</button>');
|
|
|
}
|
|
|
html.push('<button data-index="' + items.__index + '" class="btn btn-success btn-xs prop-del-btn">删除</button>');
|
|
|
|
|
|
return html.join("");
|
|
|
}
|
|
|
}
|
|
|
]
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$(document).on("change",".propValue",function(){
|
|
|
var item=propValueGrid.__rows[$(this).data("index")];
|
|
|
item.name = $(this).val();
|
|
|
});
|
|
|
|
|
|
//增加属性值
|
|
|
$(document).on('click', '.prop-add-btn', function () {
|
|
|
propValueGrid.__rows.push({name:"",id:propValueGrid.__rows.length});
|
|
|
propValueGrid.reload();
|
|
|
});
|
|
|
|
|
|
//删除属性值
|
|
|
$(document).on('click', '.prop-del-btn', function () {
|
|
|
|
|
|
var item = tableGird.rows[$(this).data('index')];
|
|
|
propValueGrid.__rows.splice($(this).data('index'),1);
|
|
|
propValueGrid.reload();
|
|
|
});
|
|
|
|
|
|
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')];
|
...
|
...
|
@@ -75,16 +120,49 @@ $(document).on('click', '.edit-class-btn', function () { |
|
|
// $("#select2-shopsId-container").val(item.)
|
|
|
});
|
|
|
|
|
|
$(document).on('change', '#inputType', function () {
|
|
|
showORHidePropValue();
|
|
|
});
|
|
|
|
|
|
|
|
|
function attributeOp(prefix, url, item) {
|
|
|
|
|
|
var a = new common.edit(".confirm");
|
|
|
common.dialog.confirm(prefix + "属性", common.util.__template($("#template").html(), item), function () {
|
|
|
|
|
|
if(item.attributeValues) {
|
|
|
propValueGrid.__rows = JSON.parse(item.attributeValues);
|
|
|
} else {
|
|
|
propValueGrid.__rows=[{ 'name':""}];
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
var inputType = $('#inputType').val();
|
|
|
|
|
|
console.log(inputType);
|
|
|
// 单行文本 或者 多行文本 时不显示表格
|
|
|
if (inputType == 'textarea' || inputType == 'text' || inputType =="") {
|
|
|
|
|
|
} else {
|
|
|
var propVlaueArr = propValueGrid.__rows.splice(0).map(function(item,inex){
|
|
|
return {id:item.id,
|
|
|
name:item.name
|
|
|
}
|
|
|
});
|
|
|
option.data.attributeValues = JSON.stringify(propVlaueArr);
|
|
|
|
|
|
}
|
|
|
|
|
|
//console.log(propVlaueArr);
|
|
|
//option.debug = true;
|
|
|
|
|
|
propValueGrid.__rows = [];
|
|
|
option.success = function (res) {
|
|
|
|
|
|
res = res.data;
|
|
|
if (res.code == "200") {
|
|
|
a.$tip("提交成功", function () {
|
...
|
...
|
@@ -104,7 +182,25 @@ function attributeOp(prefix, url, item) { |
|
|
|
|
|
|
|
|
a.init();
|
|
|
|
|
|
// 属性值列表的初始化
|
|
|
|
|
|
|
|
|
propValueGrid.init(propValueGrid.__rows);
|
|
|
showORHidePropValue();
|
|
|
}
|
|
|
|
|
|
|
|
|
function showORHidePropValue () {
|
|
|
var inputType = $('#inputType').val();
|
|
|
// 单行文本 或者 多行文本 时不显示表格
|
|
|
if (inputType == 'textarea' || inputType == 'text' || inputType =="") {
|
|
|
$('#attributeValues').show();
|
|
|
$('#prop-value-table').hide();
|
|
|
} else {
|
|
|
$('#attributeValues').hide();
|
|
|
$('#prop-value-table').show();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
|