You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

246 lines
7.7 KiB
JavaScript

var formEdit = $('#formEdit')[0];
var formHD = $('#formHD')[0];
var layerIndex = parent.layer.getFrameIndex(window.name);
//货代下拉框
var selhd0 = document.createElement("select");
$(selhd0).attr('id', 'sh0');
SetSelect($(selhd0), 'hd');
//船公司下拉框
var selc0 = document.createElement("select");
$(selc0).attr('id', 'sc0');
SetSelect($(selc0), 'cgs');
SetSelect($('#selPORTDISCHARGE'), 'port');
SetSelect($('#selDESTINATION'), 'port');
$('#txtEtd').zdate();
$('#txtYXQ').zdate();
//
SetSelect($("#selgroup"), 'tdcust');
$("#selgroup").select2({ width: "100%" });
$(function () {
//#region 加载表单
var pdata = parent.$('#formEdit').serializeFormJSON();
var tid = pdata.GID;
var date = getFormatDate();
$("input[name='SENDDATE']").val(date);
var url = '/MvcShipping/MsOpSeaeTD/GetData_XJ';
var data = { tid: tid };
$.ajax({
url: url,
type: 'POST',
dataType: 'json',
data: data,
timeout: 10000,
cache: false,
success: function (t) {
if (t.Success) {
var data1 = eval(t).data1;
if (data1.GID == '*') {
SetData(formEdit, pdata);
$("input[name='GID']").val('*');
$("input[name='TID']").val(tid);
$("input[name='FREEDAYS']").val(0);
$("textarea[name='Remarks']").val(pdata.DingCangYaoQiu);
} else {
var data2 = eval(t).data2;
SetData(formEdit, data1);
SetBodyForm(formHD,data2);
}
}
}
})
//#endregion
$('#selPORTDISCHARGE').select2({
});
$('#selDESTINATION').select2({
});
var icnt = 99;
$('#btnAdd').click(function () {
icnt++;
var id1 = 'sh' + icnt;
var id2 = 'so' + icnt;
var id3 = 'sc' + icnt;
var id6 = 'gid' + icnt;
var dvRow = document.createElement("div");
$(dvRow).addClass('row');
//货代
var selhd = $(selhd0).clone();
$(selhd).attr('id', id1);
$(selhd).attr('name', 'HDCOMNAME');
$(selhd).addClass('sel2');
//操作
var selop = document.createElement("select");
$(selop).attr('id', id2);
$(selop).attr('name', 'HDXSID');
$(selop).addClass('sel2');
//船公司
var selcgs = $(selc0).clone();
$(selcgs).attr('id', id3);
$(selcgs).attr('name', 'CARRIERID');
$(selcgs).addClass('sel2');
//GID
var txtGID = document.createElement("INPUT");
$(txtGID).attr('id', id6);
$(txtGID).attr('type', 'hidden');
$(txtGID).attr('name', 'GID');
$(txtGID).addClass('form-control');
$(txtGID).attr('autocomplete', 'off');
$(txtGID).val('*');
var dvCol1 = document.createElement("div");
$(dvCol1).addClass('col-sm-6');
$(dvCol1).append(selhd);
$(dvCol1).append(txtGID);
var dvCol2 = document.createElement("div");
$(dvCol2).addClass('col-sm-2');
$(dvCol2).append(selop);
var dvCol3 = document.createElement("div");
$(dvCol3).addClass('col-sm-4');
$(dvCol3).append(selcgs);
$(dvRow).append(dvCol1, dvCol2, dvCol3);
$(formHD).append(dvRow);
$(selhd).select2({ width: "100%" });
$(selop).select2({ width: "100%"});
$(selcgs).select2({ width: "100%" });
//select事件
$(selhd).on("select2:select", function (e) {
var comname = e.currentTarget.selectedOptions[0].value;
SetSelect($(selop), 'op', "comname='" + comname+"'");
});
})
$('#btnSend').click(function () {
var hddata = BSRowToJsonArray($('#formHD'))
var url = '/MvcShipping/MsOpSeaeTD/SendXj';
var data1 = JSON.stringify($('#formEdit').serializeFormJSON());
var data2 = JSON.stringify(hddata);
alert(data2);
var data = { data1: data1, data2: data2 };
$.ajax({
url: url,
type: 'POST',
dataType: 'json',
data: data,
timeout: 10000,
cache: false,
success: function (t) {
if (t.Success) {
parent.LoadForm();
layer.msg('发送成功');
} else {
layer.msg(t.Message);
}
}
})
})
$('#btnGroup').click(function () {
layer.open({
type: 1,
shade: false,
title: false, //不显示标题
content: $("#dvcust"), //捕获的元素注意最好该指定的元素要存放在body最外层否则可能被其它的相对元素所影响
cancel: function () {}
});
})
$('#btnSelGroup').click(function () {
var gid = $("#selgroup").val();
var url = '/MvcShipping/MsOpSeaeTD/GetHDListWithTCustID?gid=' + gid;
$.ajax({
url: url,
type: 'POST',
dataType: 'json',
data: data,
timeout: 10000,
cache: false,
success: function (t) {
if (t.Success) {
var data = eval(t).data;
SetBodyForm(formHD, data);
layer.closeAll();
} else {
layer.msg(t.Message);
}
}
})
})
})
function SetBodyForm(form, data) {
var timestamp = Date.parse(new Date());
setTimeout(function () {
$.each(data, function (index, d) {
var id1 = 'sh' + timestamp+ index;
var id2 = 'so' + timestamp + index;
var id3 = 'sc' + timestamp + index;
var id6 = 'gid' + timestamp + index;
var dvRow = document.createElement("div");
$(dvRow).addClass('row');
//货代
var selhd = $(selhd0).clone();
$(selhd).attr('id', id1);
$(selhd).attr('name', 'HDCOMNAME');
$(selhd).addClass('sel2');
$(selhd).val(d.HDCOMNAME);
//操作
var selop = document.createElement("select");
$(selop).attr('id', id2);
$(selop).attr('name', 'HDXSID');
$(selop).addClass('sel2');
SetSelect($(selop), 'op', "comname='" + d.HDCOMNAME + "'");
$(selop).val(d.HDXSID);
//船公司
var selcgs = $(selc0).clone();
$(selcgs).attr('id', id3);
$(selcgs).attr('name', 'CARRIERID');
$(selcgs).addClass('sel2');
$(selcgs).val(d.CARRIERID);
//GID
var txtGID = document.createElement("INPUT");
$(txtGID).attr('id', id6);
$(txtGID).attr('type', 'hidden');
$(txtGID).attr('name', 'GID');
$(txtGID).addClass('form-control');
$(txtGID).attr('autocomplete', 'off');
$(txtGID).val(d.GID);
var dvCol1 = document.createElement("div");
$(dvCol1).addClass('col-sm-6');
$(dvCol1).append(selhd);
$(dvCol1).append(txtGID);
var dvCol2 = document.createElement("div");
$(dvCol2).addClass('col-sm-2');
$(dvCol2).append(selop);
var dvCol3 = document.createElement("div");
$(dvCol3).addClass('col-sm-4');
$(dvCol3).append(selcgs);
$(dvRow).append(dvCol1, dvCol2, dvCol3);
$(formHD).append(dvRow);
$(selhd).select2({ width: "100%" });
$(selop).select2({ width: "100%" });
$(selcgs).select2({ width: "100%" });
})
}, 1000);
}