<script type="text/javascript">
$(function(){
var image_length = 0;
var imgArry = [];
//删除上传的图片
$(document).on('click', '.del', function(event) {
var cc = $(this).siblings('input').val();
cc = cc.replace(/^http:\/\/[^/]+/, "");
var url = "<?php echo urlCShop('member_exchange_order', 'delImg');?>";
$.post(url,{
delimg:cc,
form_submit:'ok'
},function(data){
}
);
//imgArry.pop(cc);
//不知道数组下标的情况下,删除数组对应元素
imgArry.splice($.inArray(cc,imgArry),1);
var dd = $(this).parent().parent().parent();
dd.remove();
image_length--;
});
//图片上传
$(".input-fileq").fileupload({
dataType: 'json',
url : "<?php echo urlCShop('member_exchange_order', 'upload');?>",
formData: "",
add : function(e, data) {
if(data.originalFiles[0].size > 5120*1024){
showError("图片大小不可超过5M");
return false;
}
var exchange_order_goods_id = $(".rec_id").val();
data.formData = {exchange_order_goods_id:exchange_order_goods_id};
data.submit();
},
done: function (e, data) {
if(data.result.state == 'true') {
var image_info = '';
image_info += template.render('evaluation_image_item',data.result);
imgArry.push(data.result.file_path);
$('#image_ul').append(image_info);
image_length++;
//alert(image_length);
} else {
showError(data.result.message);
}
}
});
$('.order-infor-file').on('click',function(){
if(image_length>2){
showError('最多能够上传3张图片!');
return false;
}else{
$('.upload-thumb').eq(image_length).show();
}
});
var flag = true;
var goods_num = "<?php echo $output['goodsinfo']['goods_num'];?>";
var goods_num = parseFloat(goods_num);
$("input[name='goods_num']").blur(function(){
vals = $(this).val();
if(vals.replace(/(^\s*)|(\s*$)/g, "").length ==0){
$(this).after('<span class="red">换货数量不能为空</span>');
flag = false;
return false;
}
var val = parseFloat(vals);
if(goods_num < val){
$(this).after('<span class="red">换货数量超出</span>');
flag=false;
return false;
}
if(val<=0){
$(this).after('<span class="red">换货数量不能是0或负数</span>');
flag=false;
return false;
}
flag = true;
});
$('input[name="goods_num"]').focus(function(){
$('li').find('.red').remove();
});
$('#confirm_button').click(function(){
if($('.goods_num').val() == ''){
showDialog("换货数量不能为空", 'notice', '提示信息', null, true, null, '', '', '', 3);
return false;
}
if(flag==false){
showDialog("换货数量不正确", 'notice', '提示信息', null, true, null, '', '', '', 3);
return false;
}
if( $('.exchange_reason').val().replace(/(^\s*)|(\s*$)/g, "").length ==0){
showDialog("换货原因不可为空", 'notice', '提示信息', null, true, null, '', '', '', 3);
return false;
}
if((flag == true) && $('.exchange_reason').val() == ''){
showDialog("换货原因不能为空", 'notice', '提示信息', null, true, null, '', '', '', 3);
return false;
}
var url = $('#exchange_goods').attr('action');
var rec_id = $(".rec_id").val();
var goods_num = $('.goods_num').val();
var exchange_reason = $('.exchange_reason').val();
$.post(url,{
exchange_order_goods_id:rec_id,
form_submit:'ok',
goods_num:goods_num,
exchange_reason:exchange_reason,
upload_img:imgArry
},function(data){
// alert(imgArry)
var data=eval('(' + data + ')');
if(data.state==1){
$('#fwin_change_state').hide();
$('.mask').hide();
showDialog(data.msg,'succ');
}else{
showError(data.msg);
}
window.location.reload();
});
return false;
});
$('.dialog_close_button').click(function(){
$('.mask').hide();
});
});
</script>