Authored by lore-w

物理类目完成

  1 +/*
  2 + *@time: 2016/1/29
  3 + *@author: chenglong
  4 + */
  5 +
  6 +var $ = require('jquery');
  7 +var edit = require('../common/edit');
  8 +var Handlebars = require('yoho.handlebars');
  9 +var dropDown = require('../common/dropDown');
  10 +
  11 +var selectOption =
  12 + '{{# data}}' +
  13 + '<option value="{{id}}">{{sortName}}</option>' +
  14 + '{{/ data}}';
  15 +
  16 +var optionStr = Handlebars.compile(selectOption);
  17 +
  18 +function getAllSort(callback) {
  19 + $.ajax({
  20 + url: '/product/class/queryAllProductSortList',
  21 + type: 'POST',
  22 + dataType: 'json'
  23 + }).then(function (d) {
  24 +
  25 + var firstSort = [],
  26 + data = d.data.data,
  27 + sortLen = data.length,
  28 + i;
  29 +
  30 + for (i = 0; i < sortLen; i++) {
  31 + if (!data[i].child) {
  32 + firstSort.push(data[i]);
  33 + }
  34 + }
  35 +
  36 + callback(firstSort);
  37 + });
  38 +}
  39 +
  40 +function getChildSort(id, callback) {
  41 + $.ajax({
  42 + url: '/product/class/queryProductSortList',
  43 + type: 'POST',
  44 + dataType: 'json',
  45 + data: {
  46 + param: id
  47 + }
  48 + }).then(function (d) {
  49 +
  50 + callback(d);
  51 + });
  52 +}
  53 +
  54 +
  55 +exports.init = function () {
  56 +
  57 + new dropDown({
  58 + el:'.level-select'
  59 + });
  60 +
  61 + // 页面初始化渲染一级菜单
  62 + getAllSort(function (data) {
  63 +
  64 + $('#parentSortId').after(optionStr({
  65 + data: data
  66 + }));
  67 +
  68 + });
  69 +
  70 + // 选择一\二级菜单时渲染二\三级菜单
  71 + $('.level-select').change(function () {
  72 +
  73 + var id = $(this).val();
  74 + var thisChild = $(this).attr('data-child');
  75 +
  76 + if (!thisChild) {
  77 + return;
  78 + }
  79 +
  80 +
  81 + getChildSort(id, function (data) {
  82 +
  83 + $('#' + thisChild).find('option:first').after(optionStr(data.data));
  84 +
  85 + });
  86 + });
  87 +
  88 + // 添加品类表单验证
  89 + var newClassVerification = new edit("#new-class-form");
  90 +
  91 + $(".new-class-btn").click(function(){
  92 +
  93 + var id = $(this).attr('data-id');
  94 + var postUrl;
  95 +
  96 + if (!!id) {
  97 + postUrl = '/product/updateProductSort'
  98 + } else {
  99 + postUrl = $("#new-class-form").attr("action");
  100 + }
  101 +
  102 + newClassVerification.submit(postUrl, function(option,that) {
  103 + option.success=function(res){
  104 +
  105 + console.log(res);
  106 +
  107 + window.location.href = '/product/class/index';
  108 + };
  109 + option.error=function(res){
  110 +
  111 + console.log('error');
  112 + }
  113 + });
  114 + return false;
  115 + });
  116 +};
  117 +
  118 +
@@ -76,12 +76,8 @@ exports.init = function () { @@ -76,12 +76,8 @@ exports.init = function () {
76 } 76 }
77 }).then(function (data) { 77 }).then(function (data) {
78 78
79 -  
80 -  
81 if (data.code === 200) { 79 if (data.code === 200) {
82 80
83 - console.log(data);  
84 -  
85 if ($target.hasClass('btn-danger')) { 81 if ($target.hasClass('btn-danger')) {
86 $target.text('开启'); 82 $target.text('开启');
87 $target.removeClass('btn-danger') 83 $target.removeClass('btn-danger')
@@ -103,22 +99,6 @@ exports.init = function () { @@ -103,22 +99,6 @@ exports.init = function () {
103 el:'.level-select' 99 el:'.level-select'
104 }); 100 });
105 101
106 - // 添加品类表单验证  
107 - var newClassVerification = new edit("#new-class-form");  
108 -  
109 - $(".new-class-btn").click(function(){  
110 -  
111 - newClassVerification.submit($("#new-class-form").attr("action"), function(option,that) {  
112 - option.success=function(res){  
113 - //todo  
114 - };  
115 - option.error=function(res){  
116 - //todo  
117 - }  
118 - });  
119 - return false;  
120 - });  
121 -  
122 //产品属性列表三级导航 102 //产品属性列表三级导航
123 103
124 var $navItem = $('.list-group-item'); 104 var $navItem = $('.list-group-item');
@@ -4,7 +4,7 @@ var env = process.env.NODE_ENV || 'development'; @@ -4,7 +4,7 @@ var env = process.env.NODE_ENV || 'development';
4 4
5 var domain = { 5 var domain = {
6 development:'http://localhost:30011', 6 development:'http://localhost:30011',
7 - //development:'http://172.16.6.210:8083/yohobuy-platform-web', 7 + //development:'http://172.16.6.227:8083/yohobuy-platform-web',
8 test:'http://192.168.102.205:18025/yoho-adminportal-web', 8 test:'http://192.168.102.205:18025/yoho-adminportal-web',
9 preview:'http://192.168.81.13:8189/yoho-admin-portal', 9 preview:'http://192.168.81.13:8189/yoho-admin-portal',
10 production:'http://192.168.81.6:8189/yoho-admin-portal' 10 production:'http://192.168.81.6:8189/yoho-admin-portal'
@@ -15,33 +15,119 @@ exports.domain = domain[env]; @@ -15,33 +15,119 @@ exports.domain = domain[env];
15 15
16 //路由配置 16 //路由配置
17 exports.res = [ 17 exports.res = [
18 - { 18 + {
19 //产品管理【品类列表】页面渲染 19 //产品管理【品类列表】页面渲染
20 route: '/product/class/index', 20 route: '/product/class/index',
21 method: 'GET', 21 method: 'GET',
22 view: 'pages/product/index', 22 view: 'pages/product/index',
  23 + src: '/product/index',
  24 + url: '/product/queryAllProductSortList',
  25 + isJsonRaw:true
  26 + },{
  27 + //产品管理【ajax查询所有品类】
  28 + route: '/product/class/queryAllProductSortList',
  29 + method: 'POST',
  30 + url: '/product/queryAllProductSortList',
  31 + isJsonRaw:true
  32 + },{
  33 + //产品管理【根据ID ajax查询子品类列表】
  34 + route: '/product/class/queryProductSortList',
  35 + method: 'POST',
23 url: '/product/queryProductSortList', 36 url: '/product/queryProductSortList',
24 - src: '/product/index' 37 + isJsonRaw:true,
  38 + params: [
  39 + {
  40 + name: 'param',
  41 + type: 'Number'
  42 + }
  43 + ]
25 },{ 44 },{
26 //产品管理>【品类列表ajax更新】 45 //产品管理>【品类列表ajax更新】
27 route: '/product/class/update', 46 route: '/product/class/update',
28 method: 'POST', 47 method: 'POST',
29 - url: '/product/update',  
30 - isJsonRaw:true 48 + url: '/product/updateProductSort',
  49 + isJsonRaw:true,
  50 + params: [
  51 + {
  52 + name: 'param',
  53 + type: 'Number'
  54 + },{
  55 + name: 'sortName',
  56 + type: 'String'
  57 + },{
  58 + name: 'sortInitials',
  59 + type: 'String'
  60 + },{
  61 + name:'firstSortId',
  62 + type: 'String'
  63 + },{
  64 + name: 'secondSortId',
  65 + type: 'String'
  66 + },{
  67 + name: 'thirdSortId',
  68 + type: 'String'
  69 + },{
  70 + name: 'orderBy',
  71 + type: 'Number'
  72 + },{
  73 + name: 'status',
  74 + type: 'Number'
  75 + }
  76 + ]
31 },{ 77 },{
32 //产品管理>【添加品类】页面渲染 78 //产品管理>【添加品类】页面渲染
33 route: '/product/class/new', 79 route: '/product/class/new',
34 method: 'GET', 80 method: 'GET',
35 view: 'pages/product/new-class', 81 view: 'pages/product/new-class',
36 noApi:true, 82 noApi:true,
37 - src: '/product/index' 83 + src: '/product/add'
  84 + },{
  85 + //产品管理>【添加品类】ajax请求接口
  86 + route: '/product/class/addProductSort',
  87 + method: 'POST',
  88 + url: '/product/addProductSort',
  89 + isJsonRaw:true,
  90 + params: [
  91 + {
  92 + name: 'param',
  93 + type: 'Number'
  94 + },{
  95 + name: 'sortName',
  96 + type: 'String'
  97 + },{
  98 + name: 'sortInitials',
  99 + type: 'String'
  100 + },{
  101 + name:'firstSortId',
  102 + type: 'String'
  103 + },{
  104 + name: 'secondSortId',
  105 + type: 'String'
  106 + },{
  107 + name: 'thirdSortId',
  108 + type: 'String'
  109 + },{
  110 + name: 'orderBy',
  111 + type: 'Number'
  112 + },{
  113 + name: 'status',
  114 + type: 'Number'
  115 + }
  116 + ]
38 },{ 117 },{
39 //产品管理>【编辑品类】页面 118 //产品管理>【编辑品类】页面
40 - route: '/product/class/edit', 119 + route: '/product/class/edit/:param',
41 method: 'GET', 120 method: 'GET',
42 view: 'pages/product/new-class', 121 view: 'pages/product/new-class',
  122 + url: '/product/getProductSort',
43 src: '/product/index', 123 src: '/product/index',
44 - url: '/product/edit' 124 + isJsonRaw:true,
  125 + params: [
  126 + {
  127 + name: 'param',
  128 + type: 'Number'
  129 + }
  130 + ]
45 },{ 131 },{
46 //产品管理>【产品属性】页面渲染 132 //产品管理>【产品属性】页面渲染
47 route: '/product/attr/index', 133 route: '/product/attr/index',
1 module.exports = { 1 module.exports = {
2 - '/product/update': function (req, res) { 2 + '/product/updateProductSort': function (req, res) {
3 res.json({ 3 res.json({
4 code: 200, 4 code: 200,
5 message: '' 5 message: ''
6 }) 6 })
7 }, 7 },
8 - '/product/edit': function (req, res) { 8 + '/product/class/addProductSort': function (req, res) {
  9 + res.json({
  10 + code: 200,
  11 + message: ''
  12 + })
  13 + },
  14 + '/product/getProductSort': function (req, res) {
9 res.json({ 15 res.json({
10 data: { 16 data: {
11 - className: '上衣',  
12 - classAbbr: 'acccc',  
13 - firstClass: '一级分类',  
14 - secondClass: '二级分类',  
15 - thirdClass: '三级分类',  
16 - classSort: 10,  
17 - classStatus: true 17 + sortName: '上衣',
  18 + sortInitials: 'acccc',
  19 + orderBy: 10,
  20 + status: true
18 } 21 }
19 }) 22 })
20 }, 23 },
21 - '/product/index': function (req, res) { 24 + '/product/queryAllProductSortList': function (req, res) {
22 res.json({ 25 res.json({
23 - list: [{  
24 - value: 1,  
25 - parentValue: 0,  
26 - isChild: false, 26 + data: [{
27 id: 1, 27 id: 1,
28 - level: 1,  
29 - className: '上衣',  
30 - classAbbr: 'abc',  
31 - classSort: 100,  
32 - classStatus: true  
33 - },{  
34 - value: 2,  
35 - parentValue: 1,  
36 - isChild: true,  
37 - id: 121,  
38 - level: 2,  
39 - className: '上衣',  
40 - classAbbr: 'abc',  
41 - classSort: 100,  
42 - classStatus: true  
43 - },{  
44 - value: 3,  
45 - parentValue: 2,  
46 - isChild: true,  
47 - id: 1111,  
48 - level: 3,  
49 - className: '上衣',  
50 - classAbbr: 'abc',  
51 - classSort: 100,  
52 - classStatus: true  
53 - },{  
54 - value: 4,  
55 - parentValue: 0,  
56 - isChild: false,  
57 - id: 21,  
58 - level: 1,  
59 - className: '上衣',  
60 - classAbbr: 'abc',  
61 - classSort: 100,  
62 - classStatus: true 28 + parentId: 0,
  29 + child: false,
  30 + sortLevel: 1,
  31 + sortName: '上衣',
  32 + sortInitials: 'abc',
  33 + orderBy: 100,
  34 + status: true
  35 + }]
  36 + })
  37 + },
  38 + '/product/queryProductSortList': function (req, res) {
  39 + res.json({
  40 + data: [{
  41 + "createTime": 0,
  42 + "gender": 3,
  43 + "id": 14,
  44 + "isHot": "N",
  45 + "orderBy": 2,
  46 + "parentId": 1,
  47 + "sortCode": "1,14,0",
  48 + "sortInitials": "bx",
  49 + "sortLevel": 2,
  50 + "sortName": "背心",
  51 + "status": 1,
  52 + "updateTime": 0
63 }] 53 }]
64 }) 54 })
65 }, 55 },
@@ -44,7 +44,7 @@ @@ -44,7 +44,7 @@
44 <tbody> 44 <tbody>
45 45
46 {{# data}} 46 {{# data}}
47 - <tr class="level{{sortLevel}} {{# child}}hidden{{/ child}}" data-parent="{{parentId}}" data-val="{{id}}"> 47 + <tr class="level{{sortLevel}} {{# child}}hidden{{/ child}}" data-parent="{{parentId}}" data-val="{{id}}" data-status="close">
48 <td class="toggle-td"><span class="glyphicon glyphicon-folder-close"></span></td> 48 <td class="toggle-td"><span class="glyphicon glyphicon-folder-close"></span></td>
49 <td>{{id}}</td> 49 <td>{{id}}</td>
50 <td>{{sortName}}</td> 50 <td>{{sortName}}</td>
@@ -56,7 +56,7 @@ @@ -56,7 +56,7 @@
56 {{^ classStatus}}关闭{{/ classStatus}} 56 {{^ classStatus}}关闭{{/ classStatus}}
57 </td> 57 </td>
58 <td data-id="{{id}}"> 58 <td data-id="{{id}}">
59 - <a href="/product/class/edit" class="btn btn-success btn-xs edit-class-btn">编辑</a> 59 + <a href="/product/class/edit/{{id}}" class="btn btn-success btn-xs edit-class-btn">编辑</a>
60 <a href="" class="btn btn-xs open-close-btn {{# classStatus}}btn-danger{{/ classStatus}} {{^ classStatus}}btn-warning{{/ classStatus}}"> 60 <a href="" class="btn btn-xs open-close-btn {{# classStatus}}btn-danger{{/ classStatus}} {{^ classStatus}}btn-warning{{/ classStatus}}">
61 {{# classStatus}}关闭{{/ classStatus}} 61 {{# classStatus}}关闭{{/ classStatus}}
62 {{^ classStatus}}开启{{/ classStatus}} 62 {{^ classStatus}}开启{{/ classStatus}}
@@ -27,14 +27,14 @@ @@ -27,14 +27,14 @@
27 27
28 <div class="panel-body nopadding"> 28 <div class="panel-body nopadding">
29 29
30 - <form id="new-class-form" class="form-horizontal form-bordered" method="post" action="/product/class/update"> 30 + <form id="new-class-form" class="form-horizontal form-bordered" method="post" action="/product/class/addProductSort">
31 <div class="form-group"> 31 <div class="form-group">
32 <label class="col-md-1 control-label"> 32 <label class="col-md-1 control-label">
33 物理类目<i>*</i> 33 物理类目<i>*</i>
34 </label> 34 </label>
35 35
36 <div class="col-md-5"> 36 <div class="col-md-5">
37 - <input value="{{data.className}}" id="class-name" type="text" placeholder="品类名称" class="form-control" required> 37 + <input id="sortName" class="form-control" required type="text" value="{{data.sortName}}" placeholder="品类名称">
38 </div> 38 </div>
39 </div> 39 </div>
40 40
@@ -44,7 +44,7 @@ @@ -44,7 +44,7 @@
44 </label> 44 </label>
45 45
46 <div class="col-md-5"> 46 <div class="col-md-5">
47 - <input value="{{data.classAbbr}}" id="class-abbr" type="text" placeholder="品类缩写" class="form-control" required> 47 + <input id="sortInitials" class="form-control" required type="text" value="{{data.sortInitials}}" placeholder="品类缩写">
48 </div> 48 </div>
49 </div> 49 </div>
50 50
@@ -54,13 +54,8 @@ @@ -54,13 +54,8 @@
54 </label> 54 </label>
55 55
56 <div class="col-md-5"> 56 <div class="col-md-5">
57 - <select class="level-select width300" data-placeholder="" value="{{data.firstClass}}">  
58 - <option value="">111</option>  
59 - <option value="">111</option>  
60 - <option value="">2222</option>  
61 - <option value="">2222</option>  
62 - <option value="">2222</option>  
63 - <option value="">2222</option> 57 + <select id="firstSortId" class="level-select width300" required data-child="secondSortId" data-placeholder="">
  58 + <option id="parentSortId" value="0">请选择</option>
64 </select> 59 </select>
65 </div> 60 </div>
66 </div> 61 </div>
@@ -71,9 +66,8 @@ @@ -71,9 +66,8 @@
71 </label> 66 </label>
72 67
73 <div class="col-md-5"> 68 <div class="col-md-5">
74 - <select class="level-select width300" data-placeholder="" value="{{data.secondClass}}">  
75 - <option value="">111</option>  
76 - <option value="">111</option> 69 + <select id="secondSortId" class="level-select width300" required data-child="thirdSortId" data-placeholder="">
  70 + <option value="0">请选择</option>
77 </select> 71 </select>
78 </div> 72 </div>
79 </div> 73 </div>
@@ -84,9 +78,8 @@ @@ -84,9 +78,8 @@
84 </label> 78 </label>
85 79
86 <div class="col-md-5"> 80 <div class="col-md-5">
87 - <select class="level-select width300" data-placeholder="" value="{{data.thirdClass}}">  
88 - <option value="">111</option>  
89 - <option value="">111</option> 81 + <select id="thirdSortId" class="level-select width300" required data-placeholder="">
  82 + <option value="0">请选择</option>
90 </select> 83 </select>
91 </div> 84 </div>
92 </div> 85 </div>
@@ -95,7 +88,7 @@ @@ -95,7 +88,7 @@
95 <label class="col-md-1 control-label">排序</label> 88 <label class="col-md-1 control-label">排序</label>
96 89
97 <div class="col-md-5"> 90 <div class="col-md-5">
98 - <input value="{{data.classSort}}" id="class-sort" type="text" placeholder="0" class="form-control"> 91 + <input id="orderBy" class="form-control" required value="{{data.orderBy}}" type="text" placeholder="">
99 </div> 92 </div>
100 </div> 93 </div>
101 94
@@ -103,20 +96,20 @@ @@ -103,20 +96,20 @@
103 <label class="col-md-1 control-label">状态</label> 96 <label class="col-md-1 control-label">状态</label>
104 <div class="col-md-5"> 97 <div class="col-md-5">
105 <div class="radio"> 98 <div class="radio">
106 - <label><input type="radio" value="true" name="class-status">关闭</label> 99 + <label><input type="radio" value="1" name="status">关闭</label>
107 </div> 100 </div>
108 <div class="radio"> 101 <div class="radio">
109 - <label><input type="radio" value="false" name="class-status">开启</label> 102 + <label><input type="radio" value="0" name="status">开启</label>
110 </div> 103 </div>
111 - <input type="hidden" value="{{data.classStatus}}" id="class-status" for="radio"> 104 + <input id="status" type="hidden" value="{{data.status}}" for="radio">
112 </div> 105 </div>
113 </div> 106 </div>
114 </form> 107 </form>
115 </div> 108 </div>
116 109
117 <div class="panel-footer"> 110 <div class="panel-footer">
118 - <button type="submit" data-loading-text="保存中..." class="btn btn-info btn-xs new-class-btn">保存</button>  
119 - <a href="" class="btn btn-default btn-xs">取消</a> 111 + <button type="submit" class="btn btn-info btn-xs new-class-btn" data-id="{{data.id}}">保存</button>
  112 + <a href="/product/class/index" class="btn btn-default btn-xs">取消</a>
120 </div> 113 </div>
121 </div> 114 </div>
122 </div> 115 </div>