Authored by chenchao

1. fix order by id

2. remove useless
... ... @@ -16,20 +16,7 @@ window.PromotionInfo=window.ViewModel.data;
console.log(window.PromotionInfo);
var ENUM = {
status: {
'0': '已下架',
'1': '已上架',
'2': '待审核',
'3': '上架驳回',
'4': '通过',
'5': '再上架待审核',
'6': '再上架驳回',
'7': '再上架通过',
'8': '待上架',
'9': '下架驳回',
'10':'下架待审核'
},
var ENUM = {
tab: {
'1': 0,
'2': 0,
... ... @@ -168,577 +155,4 @@ var t = new common.tab2({
//默认加载
loadTabHtml(t.options.columns[t.options.active].name);
var PromotionEditor11 =
{
/**
* 节点索引
*/
nodeIndex : 1,
/**
* 子节点索引
*/
nodeCIndex : 1,
/**
* 页面一级新增按钮
*/
nextIndexOfLevel1:1,
/**
* 数据
*/
condition_param_data:null,
brandList:null,
promotionFlagList:null,
sortTree:{},
setBrandList:function(){
var _g=this;
if(_g.brandList===null){
common.util.__ajax2({url:"/erpproduct/brands/getBrandNames",async:false},function(data){
_g.brandList=data.data;
},function(data){
});
}
},
setPromotionFlagList:function(){
var _g=this;
if(_g.promotionFlagList===null){
common.util.__ajax2({url:"/promotion/getpromotionProductFlags",async:false},function(data){
_g.promotionFlagList=data.data;
},function(data){
});
}
},
productSortList:null,
setProductSortList:function(){
var _g=this;
if(_g.productSortList===null){
common.util.__ajax2({url:"/product/class/queryAllProductSortList",async:false},function(data){
_g.productSortList=data.data;
},function(data){
});
}
},
preBuildDiv:function(_params){
var base_div_id= _params.base_div_id,
pnodeIndex = _params.pnodeIndex,
_conditions= _params._conditions
;
var pre_id=base_div_id;
var next_id;
for(var _key_level_2 in _conditions){
next_id=conditionEdit.base_conf.preffixName + conditionEdit.base_conf.splitor
+ pnodeIndex + conditionEdit.base_conf.splitor + _key_level_2;
var _next_div=$("#"+ base_div_id).clone();
_next_div.attr("id",next_id);
$("#"+ pre_id).after(_next_div);
pre_id=next_id;
}
$("#"+base_div_id).remove();
},
getMaxIndex:function(_conditions){
var max=0;
for(var _key_level_2 in _conditions){
//
if(Number(_key_level_2)>max){
max=Number(_key_level_2);
}
}
return max;
},
getJsonSize:function(_conditions){
var size_l2=0;
for(var _key_level_2 in _conditions){
size_l2++;
}
return size_l2;
},
load:function(_config){
var _g=this;
if(PromotionInfo.promotionParams&&PromotionInfo.promotionParams.conditionParam){
_g.condition_param_data=PromotionInfo.promotionParams.conditionParam;
var __data=_g.condition_param_data;
if(__data["aggregator"]){
_g.setFormElementVal({pObj: $("#condition_combine"), type: "select", name: "aggregator", data: __data});
}
if(__data["value"]) _g.setFormElementVal({pObj: $("#condition_combine"), type: "select", name: "value", data: __data});
//第二级条件
if(__data["conditions"]){
var _conditions_level_1=__data["conditions"];
var size_l2= _g.getJsonSize(_conditions_level_1);
if(size_l2>0){
_g.preBuildDiv({base_div_id : "rule_condition_0_1", pnodeIndex : conditionEdit.base_conf.firstLevelIndex, _conditions : _conditions_level_1});
}
var max = _g.getMaxIndex(_conditions_level_1);
//第二级下标
_g.nextIndexOfLevel1 = max+1;
_g.loadConditions_l1({conditions_level_1: _conditions_level_1});
}
var edit=new common.edit2(".contentpanel");
edit.__dropDownRender();
}
},
/**
* 加载第一级
*/
loadConditions_l1:function(_params){
var _g=this;
var l1_id_prefix_name= conditionEdit.base_conf.preffixName + conditionEdit.base_conf.splitor + conditionEdit.base_conf.firstLevelIndex + conditionEdit.base_conf.splitor;
var _conditions_level_1 = _params.conditions_level_1,
_l2_div_id,
_conditions_level_2,
_data_level_2;
var _sel=$("<input value=\"\"/>");
var type_l2;
var _parent_div;
for(var _key_level_2 in _conditions_level_1){
_data_level_2=_conditions_level_1[_key_level_2];
//构造一个对象(任意的HTML元素),用来存放value,作为loadOneCondition参数
type_l2=_data_level_2["type"];
_sel.val(type_l2);
//替换默认显示的div id
_l2_div_id = l1_id_prefix_name + _key_level_2;
_g.loadOneCondition(_sel.get(0), conditionEdit.base_conf.firstLevelIndex, Number(_key_level_2));
//
_parent_div=$("#"+_l2_div_id);
if((conditionEdit.condition_type_list[0].child[conditionEdit.base_conf.productIndex].name||"condition_product")===type_l2){
_g.setFormElementVal({pObj: _parent_div, type: "select", name: "aggregator", data: _data_level_2});
_g.setFormElementVal({pObj: _parent_div, type: "select", name: "operatobj", data: _data_level_2});
_g.setFormElementVal({pObj: _parent_div, type: "select", name: "operator", data: _data_level_2});
_parent_div.find("input[name=\"value\"]").val(_data_level_2["value"]);
}
// 支付
if("condition_payment"===type_l2){
_g.setFormElementVal({pObj: _parent_div, type: "select", name: "operator", data: _data_level_2});
_g.setFormElementVal({pObj: _parent_div, type: "select", name: "value", data: _data_level_2});
}
//取第三级conditions
if(_data_level_2["conditions"]){
_conditions_level_2=_data_level_2["conditions"];
var _params_l2 = {
_conditions_level_2 : _conditions_level_2,
_key_level_2 : Number(_key_level_2)
};
_g.loadConditions_l2(_params_l2);
}
}
//移除多余的一级新增按钮
var l1_tail_add_btn_id= l1_id_prefix_name + _g.nextIndexOfLevel1;
var allAddDivs=$("div[id=\""+ l1_tail_add_btn_id +"\"]");
if(allAddDivs.length > 1){
allAddDivs.last().siblings("#"+l1_tail_add_btn_id).remove();
}
},
setFormElementVal:function(_props){
if(_props){
if(_props.type && _props.type==="select"){
_props.pObj.find(_props.type+"[name=\""+ _props.name +"\"]").attr("value",_props.data[_props.name]);
}
}
},
/**
* 加载第二级
*/
loadConditions_l2: function(_params){
var _g=this;
var div_id_preffix_name = conditionEdit.base_conf.preffixName + conditionEdit.base_conf.splitor;
var _conditions_level_2=_params._conditions_level_2,
_data_level_3,
_l3_div_id,
_key_level_2 = _params._key_level_2;
var _sel=$("<input value=\"\"/>");
//
var size_l1= _g.getJsonSize(_conditions_level_2);
if(size_l1>0){
//先在父级节点追加一个
var sub_div_id = div_id_preffix_name + _key_level_2 + conditionEdit.base_conf.splitor + "1";
var sub_div=$("<div><div>");
sub_div.attr("id",sub_div_id);
$("#"+div_id_preffix_name + _key_level_2 + conditionEdit.base_conf.splitor + 0).after(sub_div);
//
var _level_3_index;
var _type_l3;
for(var _key_level_3=0; _key_level_3< _conditions_level_2.length; _key_level_3++){
_level_3_index = _key_level_3+1;
_data_level_3=_conditions_level_2[_key_level_3];
_type_l3= _data_level_3["type"]
_sel.val(_type_l3);
//
_l3_div_id = div_id_preffix_name
+ _key_level_2
+ conditionEdit.base_conf.splitor
+ _level_3_index;
_g.loadOneCondition(_sel.get(0), _key_level_2, Number(_level_3_index));
//todo 分类 品牌 促销
/**
* {
name:'condition_product_sort',
caption :'分类'
},*/
var _parent=$("div#"+_l3_div_id);
if("condition_product_sort"===_type_l3){
_g.setFormElementVal({pObj: _parent, type: "select", name: "operator", data: _data_level_3});
_g.setProductSortList();
//
var suffixIndex=_key_level_2 + conditionEdit.base_conf.splitor + _level_3_index;
var _sortTree = _g.sortTree[suffixIndex];
var sort_id=_data_level_3["value"];
if(sort_id){
var sort_data = _g.buildSortDataById(Number(sort_id), _g.productSortList);
_sortTree.init(sort_data);
}
}
/*
{
name:'condition_product_brand' ,
caption :'品牌'
},*/
/*
{
name:'condition_promotion_flag',
caption :'促销标记'
},*/
if("condition_product_brand"===_type_l3 || "condition_promotion_flag" === _type_l3){
_g.setFormElementVal({pObj: _parent, type: "select", name: "operator", data: _data_level_3});
_g.setFormElementVal({pObj: _parent, type: "select", name: "value", data: _data_level_3});
}
/*
{
name:'condition_special_product',
caption :'特定产品'
}
*/
if("condition_special_product"===_type_l3){
_g.setFormElementVal({pObj: _parent, type: "select", name: "operator", data: _data_level_3});
_parent.find("textarea[name=\"value\"]").text(_data_level_3["value"]);
}
}
}
},
bindEvent:function(){
$(document).on('click','#save',function(){return this.save()});
/*
$(document).on('click','#createLevel1',function(){
return this.loadTypeSel("condition_combine",this.nodeIndex,this.nodeCIndex);
});*/
},
/**
* 加载类型选择
*/
loadTypeSel : function(pType, pNodeIndex, curNodeIndex) {
var _g=this;
if(pType){
var _typeList=[];
switch(pType){
case conditionEdit.condition_type_list[0].name:
_g.nextIndexOfLevel1++;
_typeList=conditionEdit.condition_type_list[0].child
break;
default:
_typeList=conditionEdit.condition_type_list[0].child[0].child;
break;
}
if(_typeList.length===0){
common.util.__tip("pType:"+pType+"不在"+JSON.stringify(conditionEdit.condition_type_list)+"之中", "warning");
}
var _type_data={
typeList: _typeList,
pnodeindex:pNodeIndex,
curnodeIndex:curNodeIndex
}
var html_select =common.util.__template2($("#fm_condition_type").html(), _type_data);
var _tail_id="rule_condition_"+ pNodeIndex +"_"+curNodeIndex;
var _tail=$("#"+_tail_id);
_tail.html(html_select);
}else{
common.util.__tip("pType:"+pType+"不在"+JSON.stringify(conditionEdit.condition_type_list)+"之中", "warning");
}
},
buildAddHtml:function(_typeText,_curNodeIndex,_nextNodeIndex2){
var _add_html;
var _id="rule_condition_" + _curNodeIndex +'_' + _nextNodeIndex2 ;
var _form_group=$("<div></div>");
_form_group.attr("class","form-group");
_form_group.attr("id",_id);
//pnodeindex
_form_group.attr("pnodeIndex",_curNodeIndex);
//nodeindex
_form_group.attr("nodeIndex",_nextNodeIndex2);
var _content=$("<div></div>");
_content.attr("class","col-sm-6");
//<button class="btn btn-primary" onclick="PromotionEditor.loadTypeSel('condition_combine', 0, 1);">新增</button>
var _click_function ="PromotionEditor.loadTypeSel(\""+ _typeText +"\"," + _curNodeIndex + ',' + _nextNodeIndex2 + ");"
var _add_btn=$("<button class=\"btn btn-primary\">新增</button>");
_add_btn.attr("onclick",_click_function);
//
_content.html(_add_btn);
//
var _label=$("<label class=\"col-sm-4 control-label\">&nbsp;&nbsp;&nbsp;&nbsp;第2级操作</label>");
_form_group.append(_label);
_form_group.append(_content);
return _form_group[0].outerHTML;
},
/**
* 加载一个条件
*/
loadOneCondition : function(obj, pNodeIndex, curNodeIndex) {
var _g=this;
var type = $(obj).val();
this.nodeIndex ++;
var _html ;
var _data={};
switch(type){
case conditionEdit.condition_type_list[0].child[0].name||"condition_product":
//增加一条新的
//第一级选择,创建出来的元素为子元素
_g.creatLevel1Elements({
pNodeIndex:pNodeIndex,
curNodeIndex:curNodeIndex,
cNodeIndex:0,
type:"condition_product",
html_id:"fm_condition_product"
});
break;
case conditionEdit.condition_type_list[0].child[conditionEdit.base_conf.paymentIndex].name || "condition_payment"://支付方式
_data={
nodeIndex:pNodeIndex,
curnodeIndex:curNodeIndex,
html_id:"fm_condition_payment"
}
var _html=common.util.__template2($("#"+_data.html_id).html(), _data);
//原来选择器的div 替换一级
$('#rule_condition_' + pNodeIndex + "_" + curNodeIndex).replaceWith(_html);
//第一级新增按钮HTML fm_add_level_1
var html_add_level_1 = common.util.__template2($("#fm_add_level_1").html(),{nextIndex: _g.nextIndexOfLevel1});
var tail_div_id="rule_condition_"+pNodeIndex+ "_" + curNodeIndex;
$("#"+tail_div_id).after(html_add_level_1);
break;
case conditionEdit.condition_type_list[0].child[conditionEdit.base_conf.productIndex].child[conditionEdit.base_conf.product_sort_index].name || 'condition_product_sort' :
var nextNodeIndex = curNodeIndex + 1;
_g.creatLevel2Elements({
pNodeIndex:pNodeIndex,
curNodeIndex:curNodeIndex,
nextNodeIndex:nextNodeIndex,
type:"condition_product",
html_id:"fm_condition_product_sort"
});
//页面元素渲染出来后加载
var suffixIndex=pNodeIndex+"_"+curNodeIndex;
var _sortTree = new common.tabTree("#sortTree"+"_"+suffixIndex);
_g.sortTree[suffixIndex]=_sortTree;
break;
case conditionEdit.condition_type_list[0].child[conditionEdit.base_conf.productIndex].child[conditionEdit.base_conf.product_brand_index].name || "condition_product_brand":
//加载品牌 fm_condition_product_brand
var nextNodeIndex = curNodeIndex + 1;
_g.setBrandList();
_g.creatLevel2Elements({
pNodeIndex:pNodeIndex,
curNodeIndex:curNodeIndex,
nextNodeIndex:nextNodeIndex,
type:"condition_product",
html_id:"fm_condition_product_brand"
});
break;
case conditionEdit.condition_type_list[0].child[conditionEdit.base_conf.productIndex].child[conditionEdit.base_conf.promotion_flag_index].name||'condition_promotion_flag':
var nextNodeIndex = curNodeIndex + 1;
_g.setPromotionFlagList();
_g.creatLevel2Elements({
pNodeIndex:pNodeIndex,
curNodeIndex:curNodeIndex,
nextNodeIndex:nextNodeIndex,
type:"condition_product",
html_id:"fm_condition_promotion_flag"
});
break;
case conditionEdit.condition_type_list[0].child[conditionEdit.base_conf.productIndex].child[conditionEdit.base_conf.special_product_index].name||'condition_special_product':
var nextNodeIndex = curNodeIndex + 1;
_g.creatLevel2Elements({
pNodeIndex:pNodeIndex,
curNodeIndex:curNodeIndex,
nextNodeIndex:nextNodeIndex,
type:"condition_product",
html_id:"fm_condition_special_product"
});
break;
}
},
/**
* 创建一级内容
*
*
*/
creatLevel1Elements:function(_params){
var _g=this;
var pNodeIndex=_params.pNodeIndex,
curNodeIndex=_params.curNodeIndex,
cNodeIndex=_params.cNodeIndex;
var _data={
nodeIndex:_params.pNodeIndex,
curnodeIndex:_params.curNodeIndex
}
var _html=common.util.__template2($("#"+_params.html_id).html(), _data);
//子元素:父节点编号;取传入的父级的当前编号curNodeIndex
_html+=_g.buildAddHtml(_params.type,curNodeIndex,cNodeIndex);
//原来选择器的div 替换一级
$('#rule_condition_' + pNodeIndex + "_" + curNodeIndex).replaceWith(_html);
//第一级新增按钮HTML fm_add_level_1
var html_add_level_1 = common.util.__template2($("#fm_add_level_1").html(),{nextIndex: _g.nextIndexOfLevel1});
var tail_div_id="rule_condition_"+curNodeIndex+ "_" + cNodeIndex;
$("#"+tail_div_id).after(html_add_level_1);
},
/**
*
* 创建第二级
*
*
*/
creatLevel2Elements:function(_params){
var _g=this;
var _data={
nodeIndex:_params.pNodeIndex,
curnodeIndex:_params.curNodeIndex
};
if(_g.brandList && _g.brandList.length>0){
_data.brandList=_g.brandList;
}
if(_g.promotionFlagList && _g.promotionFlagList.length>0){
_data.promotionFlagList=_g.promotionFlagList;
}
var pNodeIndex=_params.pNodeIndex,
curNodeIndex=_params.curNodeIndex,
_type=_params.type,
nextNodeIndex=_params.nextNodeIndex,
_html=common.util.__template2($("#"+_params.html_id).html(), _data);
//同一级元素,同一个父ID:pNodeIndex
_html+=_g.buildAddHtml(_type,pNodeIndex,nextNodeIndex);
//原来选择器的div 替换一级
$('#rule_condition_' + pNodeIndex + "_" + curNodeIndex).replaceWith(_html);
},
/**
* 删除条件
* @param liDomId
*/
delCondition : function(pnodeIndex,nodeIndex) {
if(pnodeIndex===0){
$('div[pnodeIndex="' + nodeIndex+'"]').remove();
}
$('div[pnodeIndex="' + pnodeIndex+'"][nodeIndex="'+ nodeIndex +'"]').remove();
},
findSortById:function(_sortId,_productSortList){
var _g=this;
if(_sortId){
if(!_productSortList|| _productSortList===null){
return;
}
var _sort_list = _productSortList;
var _c_sort;
var _subList;
for(var sortId in _sort_list){
_c_sort=null;
if(_sort_list[sortId].id===_sortId){
_c_sort=_sort_list[sortId];
}else{
if(!_sort_list[sortId].subList){
continue;
}
_c_sort = _g.findSortById(_sortId, _sort_list[sortId].subList);
}
if(_c_sort){
return _c_sort;
}
}
}
},
buildSortDataById:function(_sortId,_productSortList){
var _g=this, sortsData=[];
var _c_sort = _g.findSortById(_sortId,_productSortList);
if(_c_sort){
sortsData[_c_sort.sortLevel-1]=_c_sort;
if(_c_sort.sortLevel > 1 && _c_sort.sortCode.indexOf(",")>0){
var _len = _c_sort.sortLevel-1;
var _sortIds = _c_sort.sortCode.split(",", _len);
for(var _id in _sortIds){
var _sort = _g.findSortById(Number(_sortIds[_id]),_productSortList);
if(_sort){
sortsData[_sort.sortLevel-1]=_sort;
}
}
}
}
return sortsData;
}
};
document.PromotionEditor=conditionEdit;
\ No newline at end of file
... ...
... ... @@ -305,7 +305,7 @@ var conditionEdit={
$("#"+ pre_id).after(_next_div);
pre_id=next_id;
}
$("#"+base_div_id).last().remove();
$("div[id=\""+ base_div_id +"\"]").last().remove();
},
getMaxIndex:function(_conditions){
... ...