Files
OMS/app/logistics/view/admin/create_rule.html
2025-12-28 23:13:25 +08:00

390 lines
17 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!--
Copyright © ShopeX http://www.shopex.cn. All rights reserved.
See LICENSE file for license details.
-->
<style>
.areabox{padding:2px;}
.spectype{padding:6px;width:40px;}
.weight_rule li{float:left;padding:4px;text-align:left;}
.weight_rule ul{width:600px;}
.weight_left{width:200px;}
.weight_right{width:380px;}
select{width:80px;}
</style>
新增规则设置<br>
<div class="tableform">
<form method="POST" id='area_form' action='index.php?app=logistics&ctl=admin_rule&act=saveRule&finder_id=<{$env.get.finder_id}>'>
<div class="division">
<table border="0" cellpadding="0" cellspacing="0" class="girdlist">
<tr>
<th style="vertical-align: middle;"><span style='color: red'>*</span>规则名称:</th>
<td><{input type="text" name='rule_name' id='rule_name' vtype="required"}><span id='chkrule_name' style='color: red'></span></td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" class="girdlist">
<tr>
<th style="vertical-align: middle;"><span style='color:red'>*</span>规则类型:</th>
<td>
<input type='radio' class='first_rule_weight' name='set_type' value='shop' checked onclick="showArea(this.value)">按店铺设置
<input type='radio' class='first_rule_weight' name='set_type' value='noweight' onclick="showArea(this.value)">按任意重量设置
<input type='radio' class='first_rule_weight' name='set_type' value='weight' onclick="showArea(this.value)">按重量区间设置
</td>
</tr>
</table>
</div>
<div class="division" style="min-height: 420px;">
<table border="0" cellpadding="0" cellspacing="0" class="girdlist" id='first_city_table' style="display:none">
<tr>
<th><span style='color: red'>*</span>一级地区:</th>
<td>
<{input type="text" id='first_city' name='first_city' readonly=true class="lnk" onclick='regionSelect(this)' size="60"}>
<input type='hidden' id='p_region_id' name='p_region_id' value='<{$area.region_id}>' />
</td>
</tr>
</table>
<div id='type_weight' style='display:none'>
<table border="0" cellpadding="0" cellspacing="0" class="girdlist">
<tr>
<th>规则详情:</th>
<td>区间类型:
<span class="spectype"><input type="radio" name="addspectype" class="addspectype" value="weight" checked >普通区间</span>
<span class="spectype"><input type="radio" name="addspectype" value="above" class="addspectype">"以上"区间</span>
<input type="button" id ='addspec' value='添加'>
<{help}>重量请输入整数,<br>请输入连续的区间,重量区间表示:左区间<=重量<右区间<{/help}>
<{if $rule.set_type=='weight'}>
<{foreach from=$rule.item_list item=item_list}>
<div class='weight_rule' id="<{$item_list.item_id}>">
<ul>
<li class="weight_left">重量:<input type="text" name="min_weight[]" size=8 value="<{$item_list.min_weight}>" vtype="required&&unsigned">g&nbsp;&nbsp;
<{if $item_list.max_weight=='-1'}>
&nbsp;&nbsp以上
<input type="hidden" name="max_weight[]" size=6 value="-1" >
<{else}>
<input type="text" name="max_weight[]" size=8 value="<{$item_list.max_weight}>" vtype="required&&unsigned">g
<{/if}>
</li>
<li class="weight_right">首选物流公司:
<select name="corp_id[]" id="dlyCorpWeight<{$item_list.item_id}>" onchange="dlyCorpChange('Weight<{$item_list.item_id}>')">
<option value='0'>--请选择--</option>
<{foreach from=$dly_corp item=dlyCorp1}>
<option value='<{$dlyCorp1.corp_id}>'><{$dlyCorp1.name}></option>
<{/foreach}>
</select>
<span id="secondSpanWeight<{$item_list.item_id}>" style="display:none;">次选物流公司:
<select name='second_corp_id[]' id="secondDlyCorpWeight<{$item_list.item_id}>">
<option value='0'>--请选择--</option>
<{foreach from=$dlyCorpNormal item=dlyCorp2}>
<option value='<{$dlyCorp2.corp_id}>'><{$dlyCorp2.name}></option>
<{/foreach}>
</select>
</span>
<a onclick='deleteArea($(this).getParent("div"))'>删除</a>
</li>
</ul>
</div>
<input type="hidden" name="item_id[]" value="<{$item_list.item_id}>">
<{/foreach}>
<{/if}>
<div id="spec_body"></div>
</td>
</tr>
</table>
</div>
<div id='type_noweight' style='display:none'>
<table border="0" cellpadding="0" cellspacing="0" class="girdlist">
<tr>
<th>规则详情:</th>
<td>首选物流公司:
<select name='default_corp_id' id='dlyCorpNoweight' onchange="dlyCorpChange('Noweight')">
<option value='0'>--请选择--</option>
<{foreach from=$dly_corp item=dlyCorp1}>
<option value='<{$dlyCorp1.corp_id}>'><{$dlyCorp1.name}></option>
<{/foreach}>
</select>
<span id="secondSpanNoweight" style="display:none;">次选物流公司:
<select name='default_second_corp_id' id='secondDlyCorpNoweight'>
<option value='0'>--请选择--</option>
<{foreach from=$dlyCorpNormal item=dlyCorp2}>
<option value='<{$dlyCorp2.corp_id}>'><{$dlyCorp2.name}></option>
<{/foreach}>
</select>
</span>
</td>
</tr>
</table>
</div>
<div id="type_shop">
<table border="0" cellpadding="0" cellspacing="0" class="girdlist">
<tr>
<th style="vertical-align: middle;"><span style='color: red'>*</span>指定店铺:</th>
<td>
<select name="shop_selected[]" multiple="multiple" data-search="fuzzy_search" style="width: 400px; height: 120px;">
<{foreach item=item_shop from=$shops}>
<option value="<{$item_shop.shop_id}>" <{if $item_shop.disabled}>disabled="disabled"<{/if}>><{$item_shop.name}></option>
<{/foreach}>
</select>
</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" class="girdlist">
<tr>
<th style="vertical-align: middle;"><span style='color: red'>*</span>指定物流公司:</th>
<td>
<select name='shop_corp_id'>
<option value="0">--请选择--</option>
<{foreach from=$dly_corp item=dlyCorpItem}>
<option value='<{$dlyCorpItem.corp_id}>'><{$dlyCorpItem.name}></option>
<{/foreach}>
</select>
</td>
</tr>
</table>
</div>
<table border="0" cellpadding="0" cellspacing="0" class="girdlist">
<tr>
<th style="vertical-align: middle;">权重:</th>
<td><input type='text' name='weight' value='' size="1" class="x-input"/><span>&nbsp;&nbsp;&nbsp;&nbsp;(数值越大表示优先级越高。如不填写,默认为0)</span></td>
</tr>
</table>
</div>
<div class="table-action"><{button type="button" label="保存" id="create_rule_save" }></div>
<input type="hidden" name="rule_type" value="default">
<input type="hidden" name="branch_id" value="<{$branch_id}>">
<input type="hidden" id='relationflag' name="relationflag" value='0'>
</form>
</div>
<script>
$('rule_name').addEvent('change',function(e){
var rule_name = this.value;
new Request({
url:'index.php?app=logistics&ctl=admin_rule&act=checkRuleName&rule_name='+rule_name+'&branch_id=<{$branch_id}>&finder_id=<{$env.get.finder_id}>',
onComplete:function(rs){
if(rs){
rs=JSON.decode(rs);
$('chkrule_name').set('html',rs.message)
}else{
$('chkrule_name').set('html','')
}
}
}).send();
});
function showArea(setType){
if(setType == "shop"){
$('type_noweight').setStyle('display','none');
$('type_weight').setStyle('display','none');
$('first_city_table').setStyle('display','none');
$('type_shop').setStyle('display','');
}else{
$('first_city_table').setStyle('display','');
$('type_shop').setStyle('display','none');
if(setType=='weight'){
$('type_weight').setStyle('display','');
$('type_noweight').setStyle('display','none');
}
if(setType=='noweight'){
$('type_noweight').setStyle('display','');
$('type_weight').setStyle('display','none');
}
}
}
function regionSelect(el){
var el=$(el);
Ex_Loader('modedialog',function(){
new ModeDialog('index.php?app=logistics&ctl=admin_area&act=showRegionTreeList&p[0]='+el.uid+'&p[1]=<{$branch_id}>&finder_id=<{$env.get.finder_id}>',{
width:800,height:600,params:{iptText:el,iptHidden:el.getParent().getElement('input[type=hidden]')}});
});
}
var corp_id = <{$dly_corp_list}>;
var dlyCorpNormal = <{$dlyCorpNormalJson}>;
var electronIds = <{$electronIds}>;
var getTemp = function(type,index){
temp='<div class="weight_rule"><ul><li class="weight_left">重量:<input type="text" name="min_weight[]" size=8 vtype="required&&number">g&nbsp;&nbsp;至';
if(type=='weight'){
temp+='<input type="text" name="max_weight[]" size=8 vtype="required&&number">g&nbsp;&nbsp;&nbsp;&nbsp;';
}else{
temp+='以上<input type="hidden" name="max_weight[]" size=10 value="-1">';
}
temp+='</li><li class="weight_right">首选物流公司:';
temp+='<select name="corp_id[]" id="dlyCorp'+index+'" onchange="dlyCorpChange('+index+')">';
temp+='<option value="0">--请选择--</option>';
if(corp_id){
corp_id.each(function(i,index){
temp+='<option value='+i.corp_id+'>'+i.name+'</option>';
});
}
temp+="</select>";
temp+='<span id="secondSpan'+index+'" style="display:none;">次选物流公司:<select name="second_corp_id[]" id="secondDlyCorp'+index+'">';
temp+='<option value="0">--请选择--</option>';
if(dlyCorpNormal){
dlyCorpNormal.each(function(i,index){
temp+='<option value='+i.corp_id+'>'+i.name+'</option>';
});
}
temp+="</select></span>";
temp+="<a onclick='deleteArea($(this).getParent(\"div\"))' >删除</a>";
temp+="</li></ul></div>";
return temp;
};
function dlyCorpChange(index) {
var dlyCorp = 'dlyCorp'+index;
var secondDlyCorp = 'secondDlyCorp'+index;
var secondSpan = 'secondSpan'+index;
var val = $(dlyCorp).value;
if(electronIds.contains(val)) {
$(secondSpan).show();
} else {
$(secondSpan).hide();
}
$(secondDlyCorp).selectedIndex = 0;
}
$('addspec').addEvent('click',function(e){
var add_above=0;
$$('.weight_left').each(function(etd){
above_max_weight = etd.getChildren('input[name^=max_weight]').get('value')/1;
if(above_max_weight=='-1'){
add_above++;
}
});
var spectype = $('type_weight').getElement("input[name='addspectype']:checked").value;
var index = uniqueID();
if(add_above>=1){
return MessageBox.error('<{t}>以上区间存在不可以再添加!<{/t}>');
}else{
var newRow=new Element('div[class="areabox"]',{html:getTemp(spectype,index)}).inject($('spec_body'));
}
});
function deleteArea(d){
if (!confirm('删除后无法恢复,确定要删除吗?')){
return;
}
d.remove();
if(d.get('id')){
new Request({url:'index.php?app=logistics&ctl=admin_area_rule&act=deleteRule&item_id='+d.get('id')+'&finder_id=<{$env.get.finder_id}>',
onComplete:function(rs){
var json = Json.evaluate(rs);
if (typeof(json.error) != 'undefined'){
alert('删除失败');
}else{
alert('删除成功');
}
}}).send();
}
}
uniqueID = (function () {
var id = 0;
return function () {
return id++;
};
})();
// 初始化 tail.select
tail.select('select[data-search="fuzzy_search"]', {
search: true,
hideDisabled: true,
zIndex: 9999,
height: 300,
});
$('create_rule_save').addEvent('click',function(e){
var set_type=$('area_form').getElements("input[name='set_type']:checked").get('value');
if(set_type == "shop"){//按店铺
var shop_select = $('area_form').getElement("select[name='shop_selected[]']");
var shop_selected_checked = shop_select.getSelected ? shop_select.getSelected() : shop_select.getElements('option:checked');
if(shop_selected_checked.length>0){
}else{
return MessageBox.error('<{t}>请选择指定店铺<{/t}>');
}
}else{//按任意重量 和 按重量区间
if($('first_city').value==''){
return MessageBox.error('<{t}>请选择一级区域<{/t}>');
}
}
if(set_type=='weight'){
var above_set=0;
if($$('.weight_left').length<=0){
return MessageBox.error('<{t}>请选择对应的重量区间!<{/t}>');
}
compareValueFlag = $$('.weight_left').every(function(etd){
min_weight = etd.getChildren('input[name^=min_weight]').get('value')/1;
max_weight = etd.getChildren('input[name^=max_weight]').get('value')/1;
if(max_weight=='-1'){
above_set++;
}
if(((min_weight>max_weight) || (min_weight==max_weight)) && max_weight!='-1'){
return false;
}
return true;
});
if( !compareValueFlag )return MessageBox.error('<{t}>重量最小值不可以大于最大值<{/t}>');
if(above_set>=2) return MessageBox.error('<{t}>以上区间只能有一个<{/t}>');
//区间判断重复
var length=$$('.weight_left').length;
for(i=0;i<length;i++){
imin = $$('.weight_left')[i].getChildren('input[name^=min_weight]').get('value');
imax = $$('.weight_left')[i].getChildren('input[name^=max_weight]').get('value');
for(j=i+1;j<length;j++){
min=$$('.weight_left')[j].getChildren('input[name^=min_weight]').get('value')/1;
max=$$('.weight_left')[j].getChildren('input[name^=max_weight]').get('value')/1;
if(imax=='-1'){
if(min>imin/1){
return MessageBox.error(min+'大于'+imin+',<{t}>大于以上区间重量最小值<{/t}>');
}
}
if(imax>min){
return MessageBox.error(imax+'大于'+min+'<{t}>重复区间存在<{/t}>');
}
}
}
}
//判断是否有排它规则存在
var relationRule='';
new Request({
url:'index.php?app=logistics&ctl=admin_area_rule&act=areaFilter&oper=ckarea&branch_id=<{$branch_id}>&p_region_id='+$('p_region_id').value+'&finder_id=<{$env.get.finder_id}>',async:false,
onComplete:function(rs){
if(rs){
rs=JSON.decode(rs);
rs.each(function(i,index){
relationRule+='['+i.region_name+']';
relationRule+='\n';
});
}
}
}).send();
if(relationRule!=''){
var relationflag = confirm('系统检测到'+relationRule+'\n 有下级地区规则存在,是否带出?');
if(relationflag==false){
$('relationflag').set('value',1);
}
}
var form=this.getParent('form');
var _this=this;
$('area_form').store('target',{
onRequest:function(){
_this.disabled=true;
},
onComplete:function(jsontext){
try{
var json = Json.evaluate(jsontext);
if (typeof(json.error) != 'undefined'){
_this.disabled=false;
}else{
_this.disabled=true;
$('area_form').getParent('.dialog').retrieve('instance').close();
_this.getParent('.dialog').retrieve('instance').close();
}
}catch(e){}
}
});
$('area_form').fireEvent('submit',e);
});
</script>