/*补充合同表单Js*/
|
var htKeyId;
|
var currentUserName = "";
|
var $classfy;
|
var $ztype;
|
var tabIndex;
|
var $childTable;
|
|
/*初始执行*/
|
initData = function () {
|
htKeyId = getQueryVariable("keyid");
|
if (window.sysid === '' && htKeyId != undefined && htKeyId !== "") {
|
$.ajax({
|
url: "/Replenish/InitDataByNum?sysid=" + htKeyId,
|
async: false,
|
cache: false,
|
dataType: "json",
|
success: function (data) {
|
currentUserName = data.CurrentUserName;
|
window.initItems = data;
|
window.childrenItems = data.Children;
|
$classfy = data.Classfy;
|
$ztype = data.Type;
|
var $data = data.Children;
|
/*业务主表数据加载*/
|
|
for (var name in data) {
|
if (name !== "children") {
|
var $value = data[name];
|
if ($value != null && $value !== '') {
|
var $control = $(".main [field='" + name + "']");
|
var $controltype = $control.prop("tagName");
|
if ($controltype != null && $controltype !== '') {
|
$type = $control.attr("type");
|
if ($type !== "radio" && $type !== "checkbox") {
|
$(".main [field='" + name + "']").val($value);
|
}
|
if ($type === "radio") {
|
$(".main [field='" + name + "'][value='" + $value + "']").attr("checked", "checked");
|
}
|
if ($type === "checkbox") {
|
var $items = $(".main [field='" + name + "']");
|
var $arr = $value.split(",");
|
$.each($items, function (index, obj) {
|
var value = $(obj).attr("value");
|
if (contains($arr, value))
|
$(obj).attr("checked", "checked");
|
});
|
}
|
}
|
}
|
}
|
}
|
/*业务字表数据加载*/
|
|
if ($data != null && $data.length > 0) {
|
var $table = $('#girdtable');
|
$table.find(".body").remove();
|
$.each($data, function (index, item) {
|
var $tabelContent = InitTabBodyByData($children.columns, item);
|
$table.append($tabelContent);
|
});
|
$childTable = $children.columns[0].table;
|
}
|
}
|
});
|
var $title = "";
|
switch ($ztype) {
|
case "1":
|
$title = "主材采购";
|
break;
|
case "3":
|
$title = "施工费/措施费";
|
break;
|
case "4":
|
$title = "房产采购";
|
break;
|
case "5":
|
$title = "机械设备";
|
break;
|
case "6":
|
$title = "固定资产/周转材料";
|
break;
|
case "8":
|
$title = "行政办公设备/行政车辆";
|
break;
|
case "9":
|
$title = "设备维修/改装";
|
break;
|
case "10":
|
$title = "桩机配件采购";
|
break;
|
case "11":
|
$title = "设备部劳务班组费用";
|
break;
|
case "13":
|
$title = "运输费用";
|
break;
|
}
|
|
$("#txtTitle").html($title + "补充合同");
|
$("#oa_contractpretrial_Title").val($title + "补充合同(" + currentUserName + ")");
|
var $pcontrol = $('<input id="oa_contractpretrial_PartyBId" name="oa_contractpretrial.PartyBId" field="PartyBId" type="hidden"/>');
|
$(".main").append($pcontrol);
|
reloadAuthority();
|
} else {
|
var $pcontrol = $('<input id="oa_contractpretrial_PartyBId" name="oa_contractpretrial.PartyBId" field="PartyBId" type="hidden"/>');
|
$(".main").append($pcontrol);
|
$("#oa_contractpretrial_PartyBId").val(initItems.PartyBId);
|
|
var $title = "";
|
switch (initItems.Type) {
|
case "1":
|
$title = "主材采购";
|
break;
|
case "3":
|
$title = "施工费/措施费";
|
break;
|
case "4":
|
$title = "房产采购";
|
break;
|
case "5":
|
$title = "机械设备";
|
break;
|
case "6":
|
$title = "固定资产/周转材料";
|
break;
|
case "8":
|
$title = "行政办公设备/行政车辆";
|
break;
|
case "9":
|
$title = "设备维修/改装";
|
break;
|
case "10":
|
$title = "桩机配件采购";
|
break;
|
case "11":
|
$title = "设备部劳务班组费用";
|
break;
|
case "13":
|
$title = "运输费用";
|
break;
|
}
|
$("#txtTitle").html($title + "补充合同");
|
}
|
$(".subtradd_js").hide();
|
}
|
|
//构建表格行
|
function InitTabBodyByData(columns, item) {
|
var $row = $('<tr class="body"></tr>');
|
$.each(columns, function (index, obj) {
|
var $dfvalue = item[obj.field];
|
switch (obj.type) {
|
case "input":
|
$row.append(InitTableTextByData(obj, $dfvalue));
|
break;
|
case "combox":
|
$row.append(renderTableComboxByData(obj, $dfvalue));
|
break;
|
case "datetime":
|
$row.append(renderTableDatetimeByData(obj, $dfvalue));
|
break;
|
}
|
|
});
|
var $keyvalue = item["id"];
|
if ($keyvalue == '' || $keyvalue == undefined)
|
$keyvalue = item["Id"];
|
if ($keyvalue == '' || $keyvalue == undefined)
|
$keyvalue = item["ID"];
|
if (window.IsFirstStep)
|
var $hidden = $('<td><input type="hidden" id="id" name="id" value="' + $keyvalue + '"><a title="删除" class="subtrdel_js" style="color:red;"><i class="glyphicon glyphicon-minus"></i></a></td>');
|
else $hidden = $('<td style="display:none;"><input type="hidden" id="id" name="id" value="' + $keyvalue + '"></td>');
|
|
$row.append($hidden);
|
return $row;
|
}
|
|
//初始化表格文本框
|
function InitTableTextByData(control, dfvalue) {
|
var $row = $('<td></td>');
|
var $control = $('<input id="' + control.table + "_" + control.field + '" name="' + control.table + "." + control.field + '" type="text" class="form-control" field="' + control.field + '" disabled="disabled" />');
|
if (!!$control && !!control.verify && control.verify !== "") {
|
$control.attr('isvalid', 'yes').attr('checkexpession', control.verify);
|
}
|
if (dfvalue !== undefined && dfvalue != null) {
|
$control.attr('value', dfvalue);
|
$control.attr('maxvalue', dfvalue);
|
}
|
$row.append($control);
|
return $row;
|
}
|
|
//选择供应商
|
$(document).on("click", "input[name='oa_contractpretrial.PartyB']", function () {
|
layer.open({
|
type: 2,
|
title: '供应商单位',
|
shadeClose: true,
|
shade: 0.4,
|
area: ['90%', '90%'],
|
content: "/oa/General/company"
|
});
|
});
|
|
//供应商赋值
|
setCompanyInfo = function (id, name, userName, Phone, BankName, BankDeposit, BankAccount) {
|
$('input[name="oa_contractpretrial.PartyBId"]').val(id);
|
$('input[name="oa_contractpretrial.PartyB"]').val(name);
|
$('input[name="oa_contractpretrial.PartyBDeputy"]').val(userName);
|
layer.closeAll();
|
}
|
|
$(document).ready(function () {
|
$(".grid").on("blur", "#oa_contractpretrialdtl_TotalPrice", function () {
|
countmoney();
|
});
|
$(".grid").on("blur", "#oa_contractpretrialdtl_UnitPrice", function () {
|
totalcompute();
|
});
|
$(".grid").on("blur", "#oa_contractpretrialdtl_Quantity", function () {
|
totalcompute();
|
});
|
$(".grid").on("change", "#oa_contractpretrialdtl_TaxRate", function () {
|
var $trindex = $(this).closest("tr").index();//行索引
|
var $value = $(this).val();
|
var $unitPrice = $('#girdtable').find('tr:eq("' + $trindex + '")').find("#oa_contractpretrialdtl_UnitPrice").val();
|
var $taxPrice = (parseFloat($unitPrice) / (1 + parseFloat($value) / 100) * (parseFloat($value) / 100)).toFixed(2);
|
var $nonTaxPrice = ($unitPrice - $taxPrice).toFixed(2);
|
if ($nonTaxPrice > 0)
|
$('#girdtable').find('tr:eq("' + $trindex + '")').find("#oa_contractpretrialdtl_NonTaxPrice").val($nonTaxPrice);
|
});
|
});
|
|
//计算金额
|
totalcompute = function () {
|
var total = 0;
|
$('.grid').find("table .body").each(function () {
|
var $price = $(this).find("#oa_contractpretrialdtl_UnitPrice").val();
|
var $count = $(this).find("#oa_contractpretrialdtl_Quantity").val();
|
var $value = $(this).find("select[name='oa_contractpretrialdtl.TaxRate']").val();
|
if ($count > 0 && $price)
|
total += parseFloat($price) * parseFloat($count);
|
var $taxPrice = (parseFloat($price) / (1 + parseFloat($value) / 100) * (parseFloat($value) / 100)).toFixed(2);
|
var $nonTaxPrice = ($price - $taxPrice).toFixed(2);
|
if ($nonTaxPrice > 0)
|
$(this).find("#oa_contractpretrialdtl_NonTaxPrice").val($nonTaxPrice);
|
});
|
$("#oa_contractpretrial_Amount").val(total);
|
}
|
|
//计算金额
|
countmoney = function () {
|
var total = 0;
|
$('.grid').find("table .body").each(function () {
|
var price = $(this).find("#oa_contractpretrialdtl_TotalPrice").val();
|
if (price > 0)
|
total += parseInt(price);
|
});
|
$("#oa_contractpretrial_Amount").val(total);
|
}
|
|
//删除字表行
|
deleteMethod = function () {
|
countmoney();
|
totalcompute();
|
}
|
|
//获取URL参数
|
getQueryVariable = function (parameter) {
|
var query = window.location.search.substring(1);
|
var vars = query.split("&");
|
for (var i = 0; i < vars.length; i++) {
|
var pair = vars[i].split("=");
|
if (pair[0] === parameter) { return pair[1]; }
|
}
|
return "";
|
}
|
|
//表单权限
|
reloadAuthority = function () {
|
$.each(window.authorize, function (index, obj) {
|
if (obj.Status === 0)//编辑
|
{
|
$("[name='" + obj.Field + "']").removeAttr("disabled").addClass("edit");
|
}
|
if (obj.Status === 1)//只读
|
{
|
$("[name='" + obj.Field + "']").attr("disabled", "disabled");
|
}
|
if (obj.Status === 2)//隐藏
|
{
|
if ($("[name='" + obj.Field + "']").closest("td").length > 0) {
|
var $tdindex = $("[name='" + obj.Field + "']").closest("td").index();//列索引
|
$('#girdtable tr').find('td:eq("' + $tdindex + '")').hide();
|
}
|
}
|
});
|
setTimeout("initDateTime()", 500);
|
}
|