var htKeyId;
|
var currentUserName = "";
|
var $classfy;
|
var $ztype;
|
var tabIndex;
|
initData = function () {
|
htKeyId = getQueryVariable("keyid");
|
if (window.sysid === '' && htKeyId != undefined && htKeyId !== "") {
|
$.ajax({
|
url: "/ContractToChange/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 = createTabBodyByData($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;
|
|
}
|
if (getQueryVariable("flowid") == "AF1BFE784475441C9C9EA95E00E3A494" || getQueryVariable("flowid") == "5BC2C6D6CEA34FEC862DA95F01127262"
|
|| getQueryVariable("flowid") == "D39E3EDC1FE146398DD4A95F011BABCB" || getQueryVariable("flowid") == "A018F9E8689D4E6199A7A96100ADDD9E"
|
|| getQueryVariable("flowid") == "582B1401697E4FC49766A96100BCFC10" || getQueryVariable("flowid") == "052EA48148144EE284ACA96100DB6D97"
|
|| getQueryVariable("flowid") == "AC64BE4F84BF4DC39057A96100DFA4DF" || getQueryVariable("flowid") == "A7A9F02972864A929D1BA96100E17E36"
|
|| getQueryVariable("flowid") == "41CFB9C5D521452B8F51A96600FA2CBA" || getQueryVariable("flowid") == "A92B7E1B9A11490398DCA96600FC69AD") {
|
$("#txtTitle").html($title + "合同外变更");
|
$("#oa_contractpretrial_Title").val($title + "合同外变更(" + currentUserName + ")");
|
} else {
|
$("#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);
|
$("#oa_contractpretrial_PartyBId").val(initItems.PartyBId);
|
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);
|
}
|
$("#oa_contractpretrial_Code").attr("readonly", "readonly");
|
$("#oa_contractpretrial_Title").attr("readonly", "readonly");
|
$("#oa_contractpretrial_createtime").attr("disabled", "disabled");
|
$("#oa_contractpretrial_UniqueId").attr("readonly", "readonly");
|
$("#oa_contractpretrial_Amount").attr("readonly", "readonly");
|
$("#oa_contractpretrial_ProjectId").attr("disabled", "disabled");
|
}
|
|
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);
|
}
|
|
$(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);
|
});
|
});
|
|
//计算金额
|
countmoney = function () {
|
var total = 0;
|
$('.grid').find("table .body").each(function () {
|
var price = $(this).find("#oa_contractpretrialdtl_TotalPrice").val();
|
if (price > 0)
|
total += parseFloat(price).toFixed(2);
|
});
|
$("#oa_contractpretrial_Amount").val(total);
|
}
|
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.toFixed(2));
|
}
|
|
$(document).on("click", "input[name='oa_contractpretrialdtl.MaterialCode'],input[name='oa_contractpretrialdtl.MaterialName']", function () {
|
var $supplierid = $("#oa_contractpretrial_PartyBId").val();
|
if ($supplierid == undefined || $supplierid == '') {
|
layer.alert("请先选择供应商");
|
return;
|
}
|
tabIndex = $(this).closest('tr').index();
|
if (initItems.Classfy == "06" || initItems.Classfy == "0501" || initItems.Classfy == "0505") {
|
layer.open({
|
type: 2,
|
title: '资源库',
|
shadeClose: true,
|
shade: 0.4,
|
area: ['80%', '80%'],
|
content: "/Article/index?type=" + initItems.Classfy
|
});
|
} else {
|
layer.open({
|
type: 2,
|
title: '资源库',
|
shadeClose: true,
|
shade: 0.4,
|
area: ['80%', '80%'],
|
content: "/FixedPrice/index?ordercode=" + initItems.ApplyCode + "&supplierid=" + $supplierid
|
});
|
}
|
});
|
|
setBaseInfo = function (materialCode, materialName, resourceClassificationId, resourceClassificationName, specificationModel, measurementUnit, index, measurementUnitName, resourceClassificationSupName) {
|
var $row = $("table tr:eq(" + tabIndex + ")");
|
$row.find("input[field='MaterialCode']").val(materialCode);
|
$row.find("input[field='MaterialName']").val(materialName);
|
$row.find("input[field='Unit']").val(measurementUnitName);
|
layer.closeAll();
|
}
|
|
setFixedPrice = function (mCode, mName, mUnit, mPrice, mTotal, mTaxrate, mSpecification) {
|
if (hasRepeat(mCode)) {
|
layer.alert("明细中已存在[" + mName + "(" + mCode + ")],不能重复添加!");
|
return;
|
}
|
var $row = $("table tr:eq(" + tabIndex + ")");
|
if ($row.find("input[field='MaterialCode']").length > 0) {
|
$row.find("input[field='MaterialCode']").val(mCode);
|
$row.find("input[field='MaterialName']").attr("disabled", "disabled");
|
}
|
else if ($row.find("select[field='MaterialCode']").length > 0) {
|
$row.find("select[name='oa_contractpretrialdtl.MaterialCode']").val(mCode);
|
$row.find("select[name='oa_contractpretrialdtl.MaterialCode']").attr("disabled", "disabled");
|
$row.find("select[name='oa_contractpretrialdtl.MaterialCode']").trigger("chosen:updated");
|
} else {
|
var $hidden = $('<input id="oa_contractpretrialdtl_MaterialCode" name="oa_contractpretrialdtl.MaterialCode" field="MaterialCode" type="hidden" value="' + mCode + '"/>');
|
$row.append($hidden);
|
}
|
$row.find("input[field='MaterialName']").val(mName);
|
if ($row.find("input[field='Unit']").length > 0) {
|
$row.find("input[field='Unit']").val(mUnit);
|
} else {
|
$row.find("select[name='oa_contractpretrialdtl.Unit']").val(mUnit);
|
$row.find("select[name='oa_contractpretrialdtl.Unit']").attr("disabled", "disabled");
|
$row.find("select[name='oa_contractpretrialdtl.Unit']").trigger("chosen:updated");
|
}
|
$row.find("input[field='Unit']").attr("disabled", "disabled");
|
$row.find("input[field='Quantity']").val(mTotal);
|
$row.find("input[field='UnitPrice']").val(mPrice);
|
$row.find("input[field='UnitPrice']").attr("maxValue", mPrice);
|
$row.find("select[field='TaxRate']").val(mTaxrate);
|
$row.find("select[field='TaxRate']").trigger("chosen:updated");
|
$row.find("input[field='Model']").val(mSpecification);
|
totalcompute();
|
layer.closeAll();
|
}
|
|
hasRepeat = function (value) {
|
var $array = [];
|
$(".grid tbody tr").each(function () {
|
if ($(this).find('#oa_contractpretrialdtl_MaterialCode').val() != undefined)
|
$array.push($(this).find('#oa_contractpretrialdtl_MaterialCode').val());
|
});
|
if ($array.Contains(value) && value != null && value != '')
|
return true;
|
else return false;
|
}
|
|
hasRepeat = function (value) {
|
var $array = [];
|
$(".grid tbody tr").each(function () {
|
if ($(this).find('#oa_contractpretrialdtl_MaterialCode').val() != undefined)
|
$array.push($(this).find('#oa_contractpretrialdtl_MaterialCode').val());
|
});
|
if ($array.Contains(value) && value != null && value != '')
|
return true;
|
else return false;
|
}
|
|
Array.prototype.Contains = function (val) {
|
for (var i = 0; i < this.length; i++) {
|
if (this[i] == val) {
|
return true;
|
}
|
}
|
return false;
|
};
|