Authored by lore-w

物理类目完成

/*
*@time: 2016/1/29
*@author: chenglong
*/
var $ = require('jquery');
var edit = require('../common/edit');
var Handlebars = require('yoho.handlebars');
var dropDown = require('../common/dropDown');
var selectOption =
'{{# data}}' +
'<option value="{{id}}">{{sortName}}</option>' +
'{{/ data}}';
var optionStr = Handlebars.compile(selectOption);
function getAllSort(callback) {
$.ajax({
url: '/product/class/queryAllProductSortList',
type: 'POST',
dataType: 'json'
}).then(function (d) {
var firstSort = [],
data = d.data.data,
sortLen = data.length,
i;
for (i = 0; i < sortLen; i++) {
if (!data[i].child) {
firstSort.push(data[i]);
}
}
callback(firstSort);
});
}
function getChildSort(id, callback) {
$.ajax({
url: '/product/class/queryProductSortList',
type: 'POST',
dataType: 'json',
data: {
param: id
}
}).then(function (d) {
callback(d);
});
}
exports.init = function () {
new dropDown({
el:'.level-select'
});
// 页面初始化渲染一级菜单
getAllSort(function (data) {
$('#parentSortId').after(optionStr({
data: data
}));
});
// 选择一\二级菜单时渲染二\三级菜单
$('.level-select').change(function () {
var id = $(this).val();
var thisChild = $(this).attr('data-child');
if (!thisChild) {
return;
}
getChildSort(id, function (data) {
$('#' + thisChild).find('option:first').after(optionStr(data.data));
});
});
// 添加品类表单验证
var newClassVerification = new edit("#new-class-form");
$(".new-class-btn").click(function(){
var id = $(this).attr('data-id');
var postUrl;
if (!!id) {
postUrl = '/product/updateProductSort'
} else {
postUrl = $("#new-class-form").attr("action");
}
newClassVerification.submit(postUrl, function(option,that) {
option.success=function(res){
console.log(res);
window.location.href = '/product/class/index';
};
option.error=function(res){
console.log('error');
}
});
return false;
});
};
... ...
... ... @@ -76,12 +76,8 @@ exports.init = function () {
}
}).then(function (data) {
if (data.code === 200) {
console.log(data);
if ($target.hasClass('btn-danger')) {
$target.text('开启');
$target.removeClass('btn-danger')
... ... @@ -103,22 +99,6 @@ exports.init = function () {
el:'.level-select'
});
// 添加品类表单验证
var newClassVerification = new edit("#new-class-form");
$(".new-class-btn").click(function(){
newClassVerification.submit($("#new-class-form").attr("action"), function(option,that) {
option.success=function(res){
//todo
};
option.error=function(res){
//todo
}
});
return false;
});
//产品属性列表三级导航
var $navItem = $('.list-group-item');
... ...
... ... @@ -4,7 +4,7 @@ var env = process.env.NODE_ENV || 'development';
var domain = {
development:'http://localhost:30011',
//development:'http://172.16.6.210:8083/yohobuy-platform-web',
//development:'http://172.16.6.227:8083/yohobuy-platform-web',
test:'http://192.168.102.205:18025/yoho-adminportal-web',
preview:'http://192.168.81.13:8189/yoho-admin-portal',
production:'http://192.168.81.6:8189/yoho-admin-portal'
... ... @@ -15,33 +15,119 @@ exports.domain = domain[env];
//路由配置
exports.res = [
{
{
//产品管理【品类列表】页面渲染
route: '/product/class/index',
method: 'GET',
view: 'pages/product/index',
src: '/product/index',
url: '/product/queryAllProductSortList',
isJsonRaw:true
},{
//产品管理【ajax查询所有品类】
route: '/product/class/queryAllProductSortList',
method: 'POST',
url: '/product/queryAllProductSortList',
isJsonRaw:true
},{
//产品管理【根据ID ajax查询子品类列表】
route: '/product/class/queryProductSortList',
method: 'POST',
url: '/product/queryProductSortList',
src: '/product/index'
isJsonRaw:true,
params: [
{
name: 'param',
type: 'Number'
}
]
},{
//产品管理>【品类列表ajax更新】
route: '/product/class/update',
method: 'POST',
url: '/product/update',
isJsonRaw:true
url: '/product/updateProductSort',
isJsonRaw:true,
params: [
{
name: 'param',
type: 'Number'
},{
name: 'sortName',
type: 'String'
},{
name: 'sortInitials',
type: 'String'
},{
name:'firstSortId',
type: 'String'
},{
name: 'secondSortId',
type: 'String'
},{
name: 'thirdSortId',
type: 'String'
},{
name: 'orderBy',
type: 'Number'
},{
name: 'status',
type: 'Number'
}
]
},{
//产品管理>【添加品类】页面渲染
route: '/product/class/new',
method: 'GET',
view: 'pages/product/new-class',
noApi:true,
src: '/product/index'
src: '/product/add'
},{
//产品管理>【添加品类】ajax请求接口
route: '/product/class/addProductSort',
method: 'POST',
url: '/product/addProductSort',
isJsonRaw:true,
params: [
{
name: 'param',
type: 'Number'
},{
name: 'sortName',
type: 'String'
},{
name: 'sortInitials',
type: 'String'
},{
name:'firstSortId',
type: 'String'
},{
name: 'secondSortId',
type: 'String'
},{
name: 'thirdSortId',
type: 'String'
},{
name: 'orderBy',
type: 'Number'
},{
name: 'status',
type: 'Number'
}
]
},{
//产品管理>【编辑品类】页面
route: '/product/class/edit',
route: '/product/class/edit/:param',
method: 'GET',
view: 'pages/product/new-class',
url: '/product/getProductSort',
src: '/product/index',
url: '/product/edit'
isJsonRaw:true,
params: [
{
name: 'param',
type: 'Number'
}
]
},{
//产品管理>【产品属性】页面渲染
route: '/product/attr/index',
... ...
module.exports = {
'/product/update': function (req, res) {
'/product/updateProductSort': function (req, res) {
res.json({
code: 200,
message: ''
})
},
'/product/edit': function (req, res) {
'/product/class/addProductSort': function (req, res) {
res.json({
code: 200,
message: ''
})
},
'/product/getProductSort': function (req, res) {
res.json({
data: {
className: '上衣',
classAbbr: 'acccc',
firstClass: '一级分类',
secondClass: '二级分类',
thirdClass: '三级分类',
classSort: 10,
classStatus: true
sortName: '上衣',
sortInitials: 'acccc',
orderBy: 10,
status: true
}
})
},
'/product/index': function (req, res) {
'/product/queryAllProductSortList': function (req, res) {
res.json({
list: [{
value: 1,
parentValue: 0,
isChild: false,
data: [{
id: 1,
level: 1,
className: '上衣',
classAbbr: 'abc',
classSort: 100,
classStatus: true
},{
value: 2,
parentValue: 1,
isChild: true,
id: 121,
level: 2,
className: '上衣',
classAbbr: 'abc',
classSort: 100,
classStatus: true
},{
value: 3,
parentValue: 2,
isChild: true,
id: 1111,
level: 3,
className: '上衣',
classAbbr: 'abc',
classSort: 100,
classStatus: true
},{
value: 4,
parentValue: 0,
isChild: false,
id: 21,
level: 1,
className: '上衣',
classAbbr: 'abc',
classSort: 100,
classStatus: true
parentId: 0,
child: false,
sortLevel: 1,
sortName: '上衣',
sortInitials: 'abc',
orderBy: 100,
status: true
}]
})
},
'/product/queryProductSortList': function (req, res) {
res.json({
data: [{
"createTime": 0,
"gender": 3,
"id": 14,
"isHot": "N",
"orderBy": 2,
"parentId": 1,
"sortCode": "1,14,0",
"sortInitials": "bx",
"sortLevel": 2,
"sortName": "背心",
"status": 1,
"updateTime": 0
}]
})
},
... ...
... ... @@ -44,7 +44,7 @@
<tbody>
{{# data}}
<tr class="level{{sortLevel}} {{# child}}hidden{{/ child}}" data-parent="{{parentId}}" data-val="{{id}}">
<tr class="level{{sortLevel}} {{# child}}hidden{{/ child}}" data-parent="{{parentId}}" data-val="{{id}}" data-status="close">
<td class="toggle-td"><span class="glyphicon glyphicon-folder-close"></span></td>
<td>{{id}}</td>
<td>{{sortName}}</td>
... ... @@ -56,7 +56,7 @@
{{^ classStatus}}关闭{{/ classStatus}}
</td>
<td data-id="{{id}}">
<a href="/product/class/edit" class="btn btn-success btn-xs edit-class-btn">编辑</a>
<a href="/product/class/edit/{{id}}" class="btn btn-success btn-xs edit-class-btn">编辑</a>
<a href="" class="btn btn-xs open-close-btn {{# classStatus}}btn-danger{{/ classStatus}} {{^ classStatus}}btn-warning{{/ classStatus}}">
{{# classStatus}}关闭{{/ classStatus}}
{{^ classStatus}}开启{{/ classStatus}}
... ...
... ... @@ -27,14 +27,14 @@
<div class="panel-body nopadding">
<form id="new-class-form" class="form-horizontal form-bordered" method="post" action="/product/class/update">
<form id="new-class-form" class="form-horizontal form-bordered" method="post" action="/product/class/addProductSort">
<div class="form-group">
<label class="col-md-1 control-label">
物理类目<i>*</i>
</label>
<div class="col-md-5">
<input value="{{data.className}}" id="class-name" type="text" placeholder="品类名称" class="form-control" required>
<input id="sortName" class="form-control" required type="text" value="{{data.sortName}}" placeholder="品类名称">
</div>
</div>
... ... @@ -44,7 +44,7 @@
</label>
<div class="col-md-5">
<input value="{{data.classAbbr}}" id="class-abbr" type="text" placeholder="品类缩写" class="form-control" required>
<input id="sortInitials" class="form-control" required type="text" value="{{data.sortInitials}}" placeholder="品类缩写">
</div>
</div>
... ... @@ -54,13 +54,8 @@
</label>
<div class="col-md-5">
<select class="level-select width300" data-placeholder="" value="{{data.firstClass}}">
<option value="">111</option>
<option value="">111</option>
<option value="">2222</option>
<option value="">2222</option>
<option value="">2222</option>
<option value="">2222</option>
<select id="firstSortId" class="level-select width300" required data-child="secondSortId" data-placeholder="">
<option id="parentSortId" value="0">请选择</option>
</select>
</div>
</div>
... ... @@ -71,9 +66,8 @@
</label>
<div class="col-md-5">
<select class="level-select width300" data-placeholder="" value="{{data.secondClass}}">
<option value="">111</option>
<option value="">111</option>
<select id="secondSortId" class="level-select width300" required data-child="thirdSortId" data-placeholder="">
<option value="0">请选择</option>
</select>
</div>
</div>
... ... @@ -84,9 +78,8 @@
</label>
<div class="col-md-5">
<select class="level-select width300" data-placeholder="" value="{{data.thirdClass}}">
<option value="">111</option>
<option value="">111</option>
<select id="thirdSortId" class="level-select width300" required data-placeholder="">
<option value="0">请选择</option>
</select>
</div>
</div>
... ... @@ -95,7 +88,7 @@
<label class="col-md-1 control-label">排序</label>
<div class="col-md-5">
<input value="{{data.classSort}}" id="class-sort" type="text" placeholder="0" class="form-control">
<input id="orderBy" class="form-control" required value="{{data.orderBy}}" type="text" placeholder="">
</div>
</div>
... ... @@ -103,20 +96,20 @@
<label class="col-md-1 control-label">状态</label>
<div class="col-md-5">
<div class="radio">
<label><input type="radio" value="true" name="class-status">关闭</label>
<label><input type="radio" value="1" name="status">关闭</label>
</div>
<div class="radio">
<label><input type="radio" value="false" name="class-status">开启</label>
<label><input type="radio" value="0" name="status">开启</label>
</div>
<input type="hidden" value="{{data.classStatus}}" id="class-status" for="radio">
<input id="status" type="hidden" value="{{data.status}}" for="radio">
</div>
</div>
</form>
</div>
<div class="panel-footer">
<button type="submit" data-loading-text="保存中..." class="btn btn-info btn-xs new-class-btn">保存</button>
<a href="" class="btn btn-default btn-xs">取消</a>
<button type="submit" class="btn btn-info btn-xs new-class-btn" data-id="{{data.id}}">保存</button>
<a href="/product/class/index" class="btn btn-default btn-xs">取消</a>
</div>
</div>
</div>
... ...