var $type = 0;
var $ordercode = '';
//获取href里面的参数
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
var r = window.location.search.substr(1).match(reg); //匹配目标参数
if (r != null) return unescape(r[2]); return null; //返回参数值
}
//计算总金额
var countmoney = function () {
var count = 0;
var applymoney = 0;
$.each($('input[name="fm_reimbursement_dtl.applymoney"]'), function () {
//实际报销金额是否显示
var obj = $(this).parent().parent().find('input[name="fm_reimbursement_dtl.money"]').parent().css('display');
//实际报销金额是否可编辑
var isdisabled = $(this).parent().parent().find('input[name="fm_reimbursement_dtl.money"]').attr('disabled');
var thisobj = $(this).parent().css('display');
var thisisdisabled = $(this).attr('disabled');
if (obj == 'none' || isdisabled == 'disabled') {
var val = $.trim($(this).val());
val = isNaN(val) ? 0 : val;
val = val == '' ? 0 : parseFloat(val);
applymoney += val;
var taxrate = parseInt($(this).parent().parent().find('select[name="fm_reimbursement_dtl.taxrate"]').val()) * 0.01;
var tax = (val / (1 + taxrate) * taxrate).toFixed(2);;
$(this).parent().parent().find('input[name="fm_reimbursement_dtl.tax"]').val(tax);
}
else {
applymoney = initItems.applymoney;
var val = $(this).parent().parent().find('input[name="fm_reimbursement_dtl.money"]').val();
val = isNaN(val) ? 0 : val;
val = val == '' ? 0 : parseFloat(val);
count += val;
var taxrate = parseInt($(this).parent().parent().find('select[name="fm_reimbursement_dtl.taxrate"]').val()) * 0.01;
var tax = (val / (1 + taxrate) * taxrate).toFixed(2);;
$(this).parent().parent().find('input[name="fm_reimbursement_dtl.tax"]').val(tax);
}
});
if (applymoney != 0) {
$('input[name="fm_reimbursement.applymoney"]').val(applymoney.toFixed(2));
}
if (count != 0) {
$('input[name="fm_reimbursement.money"]').val(count.toFixed(2));
}
}
//选择计算金额
$(document).on('change', $('input[name="fm_reimbursement_dtl.applymoney"],input[name="fm_reimbursement_dtl.money"],select[name="fm_reimbursement_dtl.taxrate"]'), function (i, r) {
countmoney();
});
var listoptions = [];
var getbaoxiaotype = function () {
$.ajax({
url: "/oa/Fm_reimbursement/GetBaoXiaoType", async: false, cache: false, dataType: "json",
success: function (data) {
listoptions = [];
$.each(data, function (i, r) {
var options = '';
listoptions.push(options);
})
}
});
}
//获取默认单据号与名称
var getusername = function () {
if ($.trim(sysid) == '') {
$.ajax({
url: "/erp/Erp_purchaseorders/GetByCode?ordercode=" + $ordercode + "&&type=" + $type, async: false, cache: false, dataType: "json",
success: function (data) {
$('#txtTitle').html(data.bxName.split('(')[0]);
$('input[name="fm_reimbursement.orderCode"]').val(data.bxCode);
$('input[name="fm_reimbursement.name"]').val(data.bxName);
$('input[name="fm_reimbursement.createtime"]').val(data.bxTime);
$('input[name="fm_reimbursement.ApplyCode"]').val(data.orderCode);
$('input[name="fm_reimbursement.applymoney"]').val(data.money);
if (data.project_id > 0) {
$('select[name="fm_reimbursement.objectid"]').val(data.project_id);
$('select[name="fm_reimbursement.objectid"]').trigger("chosen:updated");
}
else {
$('select[name="fm_reimbursement.project_id"]').parent().parent().remove();
}
if (data.listDtl.length > 0) {
$.each(data.listDtl, function (i, r) {
if (i == 0) {
$('select[name="fm_reimbursement_dtl.treeName"]').eq(i).html(listoptions.join(''));
var tname = $('select[name="fm_reimbursement_dtl.treeName"]').eq(i).find('option[CodeSn="' + r.type + '"]').val();
$('select[name="fm_reimbursement_dtl.treeName"]').eq(i).val(tname);
$('select[name="fm_reimbursement_dtl.treeName"]').eq(i).trigger("chosen:updated");
$('input[name="fm_reimbursement_dtl.remarks"]').eq(i).val(r.name);
$('input[name="fm_reimbursement_dtl.applymoney"]').eq(i).val(r.amount);
}
else {
$('.subtradd_js').click();
$('select[name="fm_reimbursement_dtl.treeName"]').eq(i).html(listoptions.join(''));
var tname = $('select[name="fm_reimbursement_dtl.treeName"]').eq(i).find('option[CodeSn="' + r.type + '"]').val();
$('select[name="fm_reimbursement_dtl.treeName"]').eq(i).val(tname);
$('select[name="fm_reimbursement_dtl.treeName"]').eq(i).trigger("chosen:updated");
$('input[name="fm_reimbursement_dtl.remarks"]').eq(i).val(r.name);
$('input[name="fm_reimbursement_dtl.applymoney"]').eq(i).val(r.amount);
}
});
countmoney();
}
}
});
}
}
//删除事件回调操作
deleteMethod = function () {
}
//添加事件回调操作
createMethod = function () {
var ntr = $('select[name="fm_reimbursement_dtl.treeName"]').length;
var inputs = '';
$('input[name="fm_reimbursement_dtl.costtype"]').eq(ntr - 1).after(inputs);
//财务科目选择后触发
$('input[name="fm_reimbursement_dtl.costtype"]').eq(ntr - 1).bind('focus', function (i, r) {
getCWinfo(this);
});
}
var getCWinfo = function (obj) {
thisobj = obj;
layer.open({
type: 2,
title: '财务科目',
shadeClose: true,
shade: 0.4,
area: ['90%', '90%'],
content: "/Article/CWindex"
});
}
//选择财务科目后触发
var setCWInfo = function (SubjectEncode, SubjectName) {
$(thisobj).parent().parent().find('input[name="fm_reimbursement_dtl.costtype"]').val(SubjectName);
$(thisobj).parent().parent().find('input[name="fm_reimbursement_dtl.costtypeid"]').val(SubjectEncode);
layer.closeAll();
}
///数据加载
var initData = function () {
getbaoxiaotype();
if (sysid == '') {
$type = getUrlParam('type');
$ordercode = getUrlParam('orderCode');
getusername();
}
else {
$('#txtTitle').html(initItems.name.split('(')[0]);
$type = parseInt(initItems.type);
}
var inputs = '';
$('input[name="fm_reimbursement.orderCode"]').after(inputs);
inputs = '';
$('input[name="fm_reimbursement.orderCode"]').after(inputs);
if ($.trim(sysid) != '' && initItems != null) {
var sprintbtn = '
表单打印';
sprintbtn += '
审核意见打印';
$('#txtTitle').append(sprintbtn);
}
if ($.trim(sysid) != '' && initItems.Children != null && initItems.Children != undefined && initItems.Children.length > 0) {
$.each(initItems.Children, function (i, r) {
var inputs = '';
$('input[name="fm_reimbursement_dtl.costtype"]').eq(i).after(inputs);
});
}
if (sysid == '') {
var inputs = '';
$('input[name="fm_reimbursement_dtl.costtype"]').after(inputs);
}
//财务科目选择后触发
$('input[name="fm_reimbursement_dtl.costtype"]').bind('focus', function (i, r) {
getCWinfo(this);
});
$('input[name="fm_reimbursement.IsInPlan"]:eq(0)').attr("value", '1');
$('input[name="fm_reimbursement.IsInPlan"]:eq(1)').attr("value", '2');
$('.subtradd_js').hide();
$('.subtrdel_js').hide();
}