Authored by 王钱钧

商品基础属性- 属性值-逻辑修改

... ... @@ -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();
}
}
... ...
... ... @@ -127,159 +127,159 @@ exports.res = [
type: 'Number'
}]
},
// {
// //商品管理>【产品属性】页面渲染
// route: '/erpproduct/attribute/index',
// method: 'GET',
// view: 'pages/product/product-attr',
// //url: '/product/queryAllProductSortList',
// url:'/product/queryProductSortListByConf',
// src: '/product/attr',
// params:[{
// name: 'status',
// type: 'String',
// def:1
// }]
// },
// {
// //商品管理>【产品属性ajax获取】
// route: '/product/attr/get',
// method: 'POST',
// url: '/product/getAttr',
// },{
// //商品管理>【添加产品属性ajax】
// route: '/product/attr/add',
// method: 'POST',
// url: '/product/addProductAttribute',
// params: [
// {
// name: 'attributeName',
// type: 'String'
// },{
// name: 'saleType',
// type: 'Number'
// },{
// name: 'inputType',
// type: 'String'
// },{
// name: 'attributeType',
// type: 'String'
// },{
// name: 'isMust',
// type: 'String'
// },{
// name: 'isSearch',
// type: 'String'
// },{
// name: 'maxValueLen',
// type: 'Number'
// },{
// name: 'isAllowAlias',
// type: 'String'
// },{
// name: 'orderBy',
// type: 'Number'
// },{
// name: 'state',
// type: 'Number'
// },{
// name: 'remark',
// type: 'String'
// },{
// name: 'attributeValues',
// type: 'String'
// },{
{
//商品管理>【产品属性】页面渲染
route: '/erpproduct/attribute/index',
method: 'GET',
view: 'pages/product/product-attr',
//url: '/product/queryAllProductSortList',
url:'/product/queryProductSortListByConf',
src: '/product/attr',
params:[{
name: 'status',
type: 'String',
def:1
}]
},
{
//商品管理>【产品属性ajax获取】
route: '/product/attr/get',
method: 'POST',
url: '/product/getAttr',
},{
//商品管理>【添加产品属性ajax】
route: '/product/attr/add',
method: 'POST',
url: '/product/addProductAttribute',
params: [
{
name: 'attributeName',
type: 'String'
},{
name: 'saleType',
type: 'Number'
},{
name: 'inputType',
type: 'String'
},{
name: 'attributeType',
type: 'String'
},{
name: 'isMust',
type: 'String'
},{
name: 'isSearch',
type: 'String'
},{
name: 'maxValueLen',
type: 'Number'
},{
name: 'isAllowAlias',
type: 'String'
},{
name: 'orderBy',
type: 'Number'
},{
name: 'state',
type: 'Number'
},{
name: 'remark',
type: 'String'
},{
name: 'attributeValues',
type: 'String'
},{
// name: 'displayPosition',
// type: 'Number'
// },{
// name: 'categoryId',
// type: 'Number'
// }
// ]
// },{
// //商品管理>【更新产品属性ajax】
// route: '/product/attr/update',
// method: 'POST',
// url: '/product/updateProductAttribute',
// params: [
// {
// name: 'attributeName',
// type: 'String'
// },{
// name: 'saleType',
// type: 'Number'
// },{
// name: 'inputType',
// type: 'String'
// },{
// name: 'attributeType',
// type: 'String'
// },{
// name: 'isMust',
// type: 'String'
// },{
// name: 'isSearch',
// type: 'String'
// },{
// name: 'maxValueLen',
// type: 'Number'
// },{
// name: 'isAllowAlias',
// type: 'String'
// },{
// name: 'orderBy',
// type: 'Number'
// },{
// name: 'state',
// type: 'Number'
// },{
// name: 'remark',
// type: 'String'
// },{
// name: 'attributeValues',
// type: 'String'
// },{
name: 'displayPosition',
type: 'Number'
},{
name: 'categoryId',
type: 'Number'
}
]
},{
//商品管理>【更新产品属性ajax】
route: '/product/attr/update',
method: 'POST',
url: '/product/updateProductAttribute',
params: [
{
name: 'attributeName',
type: 'String'
},{
name: 'saleType',
type: 'Number'
},{
name: 'inputType',
type: 'String'
},{
name: 'attributeType',
type: 'String'
},{
name: 'isMust',
type: 'String'
},{
name: 'isSearch',
type: 'String'
},{
name: 'maxValueLen',
type: 'Number'
},{
name: 'isAllowAlias',
type: 'String'
},{
name: 'orderBy',
type: 'Number'
},{
name: 'state',
type: 'Number'
},{
name: 'remark',
type: 'String'
},{
name: 'attributeValues',
type: 'String'
},{
// name: 'displayPosition',
// type: 'Number'
// },{
// name: 'attributeId',
// type: 'Number'
// },{
// name: 'categoryId',
// type: 'Number'
// }
// ]
// },{
// //商品管理【根据类目ID ajax查询属性列表】
// route: '/product/attr/queryProductAttributeList',
// method: 'POST',
// url: '/product/queryProductAttributeList',
// params: [
// {
// name: 'categoryId',
// type: 'Number'
// },
// {
// name: 'page',
// type: 'Number'
// },
// {
// name: 'size',
// type: 'Number'
// }
// ]
// },{
// //商品管理【根据类目ID ajax查询属性的详细信息】
// route: '/product/attr/getProductAttribute',
// method: 'POST',
// url: '/product/getProductAttribute',
// params: [
// {
// name: 'attributeId',
// type: 'Number'
// }
// ]
// }
name: 'displayPosition',
type: 'Number'
},{
name: 'attributeId',
type: 'Number'
},{
name: 'categoryId',
type: 'Number'
}
]
},{
//商品管理【根据类目ID ajax查询属性列表】
route: '/product/attr/queryProductAttributeList',
method: 'POST',
url: '/product/queryProductAttributeList',
params: [
{
name: 'categoryId',
type: 'Number'
},
{
name: 'page',
type: 'Number'
},
{
name: 'size',
type: 'Number'
}
]
},{
//商品管理【根据类目ID ajax查询属性的详细信息】
route: '/product/attr/getProductAttribute',
method: 'POST',
url: '/product/getProductAttribute',
params: [
{
name: 'attributeId',
type: 'Number'
}
]
}
];
\ No newline at end of file
... ...
... ... @@ -167,13 +167,16 @@
</div>
</div>
<div class="form-group">
<div class="form-group" id="propValue">
<label class="col-md-3 control-label">
属性值<i class="red">*</i>
</label>
<div class="col-md-6">
<div class="col-md-6" >
<input id="attributeValues" value="{attributeValues}" class="form-control width300" type="text" placeholder="属性值" required="required">
<div id="prop-value-table" class="table-responsive" >
</div>
</div>
</div>
... ...