...
|
...
|
@@ -10,12 +10,12 @@ var dropDown = require('../common/dropDown'); |
|
|
|
|
|
var selectOption =
|
|
|
'{{# data}}' +
|
|
|
'<option value="{{id}}">{{sortName}}</option>' +
|
|
|
'<option value="{{id}}" {{# select}}selected{{/ select}}>{{sortName}}</option>' +
|
|
|
'{{/ data}}';
|
|
|
|
|
|
var optionStr = Handlebars.compile(selectOption);
|
|
|
|
|
|
function getAllSort(callback) {
|
|
|
function getAllSort(callback, selectId) {
|
|
|
$.ajax({
|
|
|
url: '/product/class/queryAllProductSortList',
|
|
|
type: 'POST',
|
...
|
...
|
@@ -26,9 +26,15 @@ function getAllSort(callback) { |
|
|
data = d.data.data,
|
|
|
sortLen = data.length,
|
|
|
i;
|
|
|
var resData;
|
|
|
|
|
|
for (i = 0; i < sortLen; i++) {
|
|
|
if (!data[i].child) {
|
|
|
|
|
|
if (data[i].id === selectId) {
|
|
|
data[i].select = true;
|
|
|
}
|
|
|
|
|
|
firstSort.push(data[i]);
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -37,7 +43,7 @@ function getAllSort(callback) { |
|
|
});
|
|
|
}
|
|
|
|
|
|
function getChildSort(id, callback) {
|
|
|
function getChildSort(id, callback, selectId) {
|
|
|
$.ajax({
|
|
|
url: '/product/class/queryProductSortList',
|
|
|
type: 'POST',
|
...
|
...
|
@@ -47,64 +53,161 @@ function getChildSort(id, callback) { |
|
|
}
|
|
|
}).then(function (d) {
|
|
|
|
|
|
callback(d);
|
|
|
});
|
|
|
}
|
|
|
var data = d.data.data;
|
|
|
var dataLen = data.length;
|
|
|
var i;
|
|
|
|
|
|
for (i = 0; i < dataLen; i++) {
|
|
|
|
|
|
exports.init = function () {
|
|
|
if (data[i].id === selectId) {
|
|
|
data[i].select = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
new dropDown({
|
|
|
el:'.level-select'
|
|
|
callback(data);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 页面初始化渲染一级菜单
|
|
|
var $editInput = $('#editId');
|
|
|
var editLevel = $editInput.attr('level');
|
|
|
var toNum = 1;
|
|
|
|
|
|
function createLevelOneOption(selectedId, callback) {
|
|
|
getAllSort(function (data) {
|
|
|
|
|
|
$('#parentSortId').after(optionStr({
|
|
|
data: data
|
|
|
}));
|
|
|
|
|
|
});
|
|
|
new dropDown({
|
|
|
el:'#firstSortId'
|
|
|
});
|
|
|
|
|
|
if (callback) {
|
|
|
callback();
|
|
|
}
|
|
|
|
|
|
}, selectedId*toNum);
|
|
|
}
|
|
|
|
|
|
// 选择一\二级菜单时渲染二\三级菜单
|
|
|
$('.level-select').change(function () {
|
|
|
function createLevelTwoOption(parentId, selectedId) {
|
|
|
|
|
|
var id = $(this).val();
|
|
|
var thisChild = $(this).attr('data-child');
|
|
|
getChildSort(parentId*toNum, function (data) {
|
|
|
|
|
|
$('#secondSortId').find('option:first').after(optionStr({
|
|
|
data: data
|
|
|
}));
|
|
|
|
|
|
new dropDown({
|
|
|
el:'#secondSortId'
|
|
|
});
|
|
|
|
|
|
if (!thisChild) {
|
|
|
return;
|
|
|
}, selectedId*toNum);
|
|
|
}
|
|
|
|
|
|
exports.init = function () {
|
|
|
|
|
|
console.log(editLevel);
|
|
|
|
|
|
// 编辑
|
|
|
if (editLevel) {
|
|
|
|
|
|
switch (editLevel) {
|
|
|
case "1":
|
|
|
createLevelOneOption($editInput.val(), function () {
|
|
|
getChildSort($editInput.val()*toNum, function (data) {
|
|
|
$('#secondSortId').find('option:first').after(optionStr({
|
|
|
data: data
|
|
|
}));
|
|
|
});
|
|
|
});
|
|
|
new dropDown({
|
|
|
el:'#secondSortId'
|
|
|
});
|
|
|
break;
|
|
|
case "2":
|
|
|
createLevelOneOption($editInput.attr('pid'), function () {
|
|
|
createLevelTwoOption($editInput.attr('pid'), $editInput.val());
|
|
|
});
|
|
|
break;
|
|
|
default :
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
// 添加
|
|
|
getAllSort(function (data) {
|
|
|
$('#parentSortId').after(optionStr({
|
|
|
data: data
|
|
|
}));
|
|
|
});
|
|
|
|
|
|
// 选择一\二级菜单时渲染二
|
|
|
$('.level-select').change(function () {
|
|
|
|
|
|
var id = $(this).val()*toNum;
|
|
|
|
|
|
getChildSort(id, function (data) {
|
|
|
getChildSort(id, function (data) {
|
|
|
|
|
|
$('#' + thisChild).find('option:first').after(optionStr(data.data));
|
|
|
$('#childSortId').after(optionStr({
|
|
|
data: data
|
|
|
}));
|
|
|
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
|
|
|
new dropDown({
|
|
|
el:'#firstSortId'
|
|
|
});
|
|
|
new dropDown({
|
|
|
el:'#secondSortId'
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 添加品类表单验证
|
|
|
var newClassVerification = new edit("#new-class-form");
|
|
|
|
|
|
newClassVerification.init();
|
|
|
|
|
|
$(".new-class-btn").click(function(){
|
|
|
|
|
|
var id = $(this).attr('data-id');
|
|
|
var postUrl;
|
|
|
var $this = $(this);
|
|
|
|
|
|
var pid = $('#secondSortId').val();
|
|
|
var ppid = $('#firstSortId').val();
|
|
|
|
|
|
if (ppid*toNum) {
|
|
|
$('#parentId').val(ppid);
|
|
|
}
|
|
|
if (pid*toNum) {
|
|
|
$('#parentId').val(pid);
|
|
|
}
|
|
|
|
|
|
if (!!id) {
|
|
|
postUrl = '/product/updateProductSort'
|
|
|
postUrl = '/product/sort/update'
|
|
|
} else {
|
|
|
postUrl = $("#new-class-form").attr("action");
|
|
|
}
|
|
|
|
|
|
newClassVerification.submit(postUrl, function(option,that) {
|
|
|
option.beforeSend = function () {
|
|
|
$this.attr('disabled', 'disabled');
|
|
|
};
|
|
|
option.success=function(res){
|
|
|
|
|
|
console.log(res);
|
|
|
|
|
|
window.location.href = '/erpproduct/sort/index';
|
|
|
if (res.data.code === 200) {
|
|
|
|
|
|
newClassVerification.$tip('提交成功');
|
|
|
$this.removeAttr('disabled');
|
|
|
|
|
|
setTimeout(function () {
|
|
|
//window.location.href = '/erpproduct/sort/index';
|
|
|
}, 1000);
|
|
|
}
|
|
|
};
|
|
|
option.error=function(res){
|
|
|
|
...
|
...
|
|