js中的時間委託事件delegate
阿新 • • 發佈:2018-11-01
$(function(){
//alert(12334566);
//出庫
var s_id = localStorage.getItem("s_id");
var time = getTime();
var sign = getSign([s_id,time]);
$.ajax({
type: "POST",
url: api_url+"abroad/come",
data: {
s_id:s_id,
time:time,
sign:sign,
},
dataType: "json",
success:function(data){
var goodsda=data['goodsdata'];
var countgoods=data['countgoods'];
//console.log(goodsda);
var html='';
//console.log(goodsda);
html+='<div class="storOut_center" ><input type="hidden" name="gid[]" value="';
html+=goodsda[i]['g_id'];
html+='"><div class="storOut_center_A">';
//商品資訊主體
html+='<div class="storOut_center1">';
//圖片
html+='<div class="storOut_center1_L"><input type="hidden" name="oid[]" value="';
html+=goodsda[i]['gr_oid'];
html+='"></div>';
//圖片
//商信<input type="hidden" name="ynum[]" value="
html+='<div class="storOut_center1_R">';
//html+=goodsda[i]['go_num'];
html+='<div class="storOutT_top">';
html+='<p>';
html+=goodsda[i]['g_name'];
html+='</p>';
html+='<div>';
html+='<span>';
html+='規格:';
html+='</span>';
html+='<strong>';
html+=goodsda[i]['g_style'];
html+='</strong>';
html+='</div>';
html+='<div class="storOutT_bot sendOrdersT_bot">';
//html+=goodsda[i]['go_num'];
html+='</div>';
html+='</div>';
html+='<div class="storOutT_topR" style="width:2.5rem;height:0.6rem;margin-top:-0.4rem;">';
html+='<img src="../images/ck_add.png" class="jia" style="width:0.4rem;height:0.4rem;margin-right:0.2rem;float:left;"/>';
html+='<input name="countg[]" style="width:25px;margin-top:0;float:left;text-align:center;" id="countg" class="countg" value="';
html+=goodsda[i]['go_num'];
html+='"';
html+='data-countg="';
html+=goodsda[i]['go_num'];
html+='"/>';
html+='<img src="../images/ck_jian.png" class="jian" style="width:0.4rem;height:0.4rem;margin-left:0.2rem;float:left;margin-right:0.2rem;"/>';
html+='件';
html+='</div>';
html+='</div>';
html+='<div class="storOutT_bot"><input type="hidden" name="sum[]" value="';
html+=goodsda[i]['go_num'];
html+='"></div>';
html+='</div>';
//商信
html+=' </div>';
//商品資訊主體
//派單按鈕
//html+='<div class="sendOrders_center3">';
//html+='<div>';
//html+='</div>';
//html+=' </div>';
//派單按鈕
html+='</div></div>';
}
if(goodsda==""){
html+='';
}else{
html+='<div class="taskManagement_R_top_fahuo" style="text-align:right;margin-right:0.3rem;">';
html+='<button style="width:2rem;height:0.4rem;"' //storOut_shipments.html
html+= '>去發貨</button>';
html+='</div>';
}
$("#storOut").html(html);
$("#cgs").html(countgoods);
}else{
mui.toast(data.message);
}
}
})
//進行國外出庫
var gid=[];//商品id
var num =[];//商品所出庫商品總數量
var sum=[];//含訂單的商品數量
var gn = [];//商品id和商品數量組合
var oid=[];//訂單id
//點擊發貨
$(document).delegate("button","click",function(){
//alert(123456);
var ggid=document.getElementsByName("gid[]");
for(var g=0;g<ggid.length;g++){
gid+=';'+ggid[g].value;
}
//console.log(gid);
var ooid=document.getElementsByName("oid[]");
for(var o=0;o<ooid.length;o++){
oid+=';'+ooid[o].value;
}
//console.log(oid);
var nnum=document.getElementsByName("countg[]");
for(var n=0;n<nnum.length;n++){
num+=';'+nnum[n].value;
}
//console.log(num);
var ysum=document.getElementsByName("sum[]");
for(var y=0;y<ysum.length;y++){
sum+=';'+ysum[y].value;
}
//console.log(sum);
setTimeout(function(){
window.location.href='./storOut_shipments.html?g='+gid+'&o='+oid+'&n='+num+'&s='+sum;
},1000);
})
//點選加號
$("div").delegate(".jia","click",function(){
//var gid=$(this).next('.countg').attr('data-gid');
//alert(gid)
var countg=$(this).next('.countg').attr('data-countg');//該商品所出庫的最低數量
var coutnum=$(this).next('#countg').val();//獲取文字框裡數量
coutnum++;
$(this).next('#countg').val("");
$(this).next('#countg').val(coutnum);
return false;
});
//點選減號
$("div").delegate(".jian","click",function(){
var countg=$(this).prev('.countg').attr('data-countg');//該商品所出庫的最低數量
var coutnum=$(this).prev('#countg').val();//獲取文字框裡數量
if(coutnum<=countg){
mui.toast('不能低於該商品應出庫數量');
return false;
}else{
coutnum--;
$(this).prev('#countg').val("");
$(this).prev('#countg').val(coutnum);
}
})
//展開
var flag = true;
$('.sendOrdersT_bot').click(function(){
if( flag ){
$(this).parent('div').parent('div').next('div').show();
flag = false;
}else{
$(this).parent('div').parent('div').next('div').hide();
flag=true;
}
})
//全選
var iSelet = true;
$('.some').click(function(){
if( iSelet ){
$('.only').prop('checked',false);
iSelet = false;
}else{
$('.only').prop('checked',true);
iSelet = true;
}
})
})