$paytype = 0; //获取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 listtypeoptions = []; var type = 0; ///绑定费用类型 var gettype = function (type) { switch (type) { case 41: $('#txtTitle').html('项目主材付款单'); listtypeoptions.push(''); listtypeoptions.push(''); listtypeoptions.push(''); listtypeoptions.push(''); listtypeoptions.push(''); listtypeoptions.push(''); listtypeoptions.push(''); break; case 42: $('#txtTitle').html('项目辅材付款单'); listtypeoptions.push(''); listtypeoptions.push(''); listtypeoptions.push(''); listtypeoptions.push(''); break; case 43: $('#txtTitle').html('项目施工费/措施费付款单'); listtypeoptions.push(''); listtypeoptions.push(''); break; case 44: $('#txtTitle').html('办公消耗品付款单'); listtypeoptions.push(''); break; case 45: $('#txtTitle').html('房产付款单'); listtypeoptions.push(''); break; case 46: $('#txtTitle').html('机械设备付款单'); listtypeoptions.push(''); break; case 47: $('#txtTitle').html('固定资产/周转材料付款单'); listtypeoptions.push(''); listtypeoptions.push(''); listtypeoptions.push(''); break; case 48: $('#txtTitle').html('行政办公设备/车辆付款单'); listtypeoptions.push(''); listtypeoptions.push(''); break; case 49: $('#txtTitle').html('设备维修/改装付款单'); listtypeoptions.push(''); listtypeoptions.push(''); break; case 50: $('#txtTitle').html('设备部劳务班组费用付款单'); listtypeoptions.push(''); break; case 51: $('#txtTitle').html('周转材料付款单'); listtypeoptions.push(''); break; case 52: $('#txtTitle').html('桩机配件采购付款单'); listtypeoptions.push(''); listtypeoptions.push(''); listtypeoptions.push(''); break; case 54: $('#txtTitle').html('运输费付款单'); listtypeoptions.push(''); break; case 4801: $('#txtTitle').html('行政办公设备付款单'); listtypeoptions.push(''); listtypeoptions.push(''); break; case 4802: $('#txtTitle').html('行政车辆付款单'); listtypeoptions.push(''); listtypeoptions.push(''); break; case 4803: $('#txtTitle').html('电脑/打印机/会议系统付款单'); listtypeoptions.push(''); listtypeoptions.push(''); break; case 4901: $('#txtTitle').html('设备委外维修付款单'); listtypeoptions.push(''); listtypeoptions.push(''); break; case 4902: $('#txtTitle').html('设备改造付款单'); listtypeoptions.push(''); listtypeoptions.push(''); break; } if ($.trim(sysid) == '') { $('select[name="fm_otherexpenditureinfo_dtl.ExpenditureTypeName"]').eq(0).html(listtypeoptions.join('')); $('select[name="fm_otherexpenditureinfo_dtl.ExpenditureTypeName"]').eq(0).trigger("chosen:updated"); } if (listtypeoptions.length <= 1)//只有一项一下,禁用选择 { $('select[name="fm_otherexpenditureinfo_dtl.ExpenditureTypeName"]').attr('disabled', 'disabled'); } } var setpaytype = function (ntype) { switch (ntype) { case 41: $paytype = 1; break; case 42: $paytype = 2; break; case 43: $paytype = 3; break; case 45: $paytype = 4; break; case 46: $paytype = 5; break; case 47: $paytype = 6; break; case 51: $paytype = 7; break; case 48: $paytype = 8; break; case 49: $paytype = 9; break; case 52: $paytype = 10; break; case 50: $paytype = 11; break; case 54: $paytype = 13; break; case 4801: $paytype = 801; break; case 4802: $paytype = 802; break; case 4803: $paytype = 803; break; case 4901: $paytype = 901; break; case 4902: $paytype = 902; break; } } // 金额转大写 var changeMoneyToChinese = function (money) { //汉字的数字 var cnNums = new Array('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'); //基本单位 var cnIntRadice = new Array('', '拾', '佰', '仟'); //对应整数部分扩展单位 var cnIntUnits = new Array('', '万', '亿', '兆'); //对应小数部分单位 var cnDecUnits = new Array('角', '分', '毫', '厘'); //整数金额时后面跟的字符 var cnInteger = '整'; //整型完以后的单位 var cnIntLast = '元'; //最大处理的数字 var maxNum = 999999999999999.9999; //金额整数部分 var integerNum; //金额小数部分 var decimalNum; //输出的中文金额字符串 var chineseStr = ''; //分离金额后用的数组,预定义 var parts; if (money == '') { return ''; } money = parseFloat(money); if (money >= maxNum) { //超出最大处理数字 toastr.warning("付款总额超出最大范围"); return ''; } if (money == 0) { chineseStr = cnNums[0] + cnIntLast + cnInteger; return chineseStr; } //转换为字符串 money = money.toString(); if (money.indexOf('.') == -1) { integerNum = money; decimalNum = ''; } else { parts = money.split('.'); integerNum = parts[0]; decimalNum = parts[1].substr(0, 4); } //获取整型部分转换 if (parseInt(integerNum, 10) > 0) { var zeroCount = 0; var IntLen = integerNum.length; for (var i = 0; i < IntLen; i++) { var n = integerNum.substr(i, 1); var p = IntLen - i - 1; var q = p / 4; var m = p % 4; if (n == '0') { zeroCount++; } else { if (zeroCount > 0) { chineseStr += cnNums[0]; } //归零 zeroCount = 0; chineseStr += cnNums[parseInt(n)] + cnIntRadice[m]; } if (m == 0 && zeroCount < 4) { chineseStr += cnIntUnits[q]; } } chineseStr += cnIntLast; } //小数部分 if (decimalNum != '') { var decLen = decimalNum.length; for (var i = 0; i < decLen; i++) { var n = decimalNum.substr(i, 1); if (n != '0') { chineseStr += cnNums[Number(n)] + cnDecUnits[i]; } } } if (chineseStr == '') { chineseStr += cnNums[0] + cnIntLast + cnInteger; } else if (decimalNum == '') { chineseStr += cnInteger; } return chineseStr; } //获取默认单据号与名称 var getusername = function (type) { if ($.trim(sysid) == '') { $.ajax({ url: "/oa/General/GetLoad", async: false, cache: false, dataType: "json", success: function (data) { $('input[name="fm_otherexpenditureinfo.Code"]').val(data.orderCode); $('select[name="fm_otherexpenditureinfo.DepartmentID"]').val(data.deptid); $('select[name="fm_otherexpenditureinfo.DepartmentID"]').trigger("chosen:updated"); switch (type) { case 41: $('input[name="fm_otherexpenditureinfo.Title"]').val('项目主材付款(' + data.username + ')'); break; case 42: $('input[name="fm_otherexpenditureinfo.Title"]').val('项目辅材付款(' + data.username + ')'); break; case 43: $('input[name="fm_otherexpenditureinfo.Title"]').val('项目施工费/措施费付款(' + data.username + ')'); break; case 44: $('input[name="fm_otherexpenditureinfo.Title"]').val('办公消耗品付款(' + data.username + ')'); break; case 45: $('input[name="fm_otherexpenditureinfo.Title"]').val('房产付款(' + data.username + ')'); break; case 46: $('input[name="fm_otherexpenditureinfo.Title"]').val('机械设备付款(' + data.username + ')'); break; case 47: $('input[name="fm_otherexpenditureinfo.Title"]').val('固定资产/周转材料付款(' + data.username + ')'); break; case 48: $('input[name="fm_otherexpenditureinfo.Title"]').val('行政办公设备/车辆付款(' + data.username + ')'); break; case 49: $('input[name="fm_otherexpenditureinfo.Title"]').val('设备维修/改装付款(' + data.username + ')'); break; case 50: $('input[name="fm_otherexpenditureinfo.Title"]').val('设备部劳务班组费用付款(' + data.username + ')'); break; case 51: $('input[name="fm_otherexpenditureinfo.Title"]').val('周转材料付款(' + data.username + ')'); break; case 52: $('input[name="fm_otherexpenditureinfo.Title"]').val('桩机配件采购付款(' + data.username + ')'); break; case 54: $('input[name="fm_otherexpenditureinfo.Title"]').val('运输费付款(' + data.username + ')'); break; case 4801: $('input[name="fm_otherexpenditureinfo.Title"]').val('行政办公设备付款(' + data.username + ')'); break; case 4802: $('input[name="fm_otherexpenditureinfo.Title"]').val('行政车辆付款(' + data.username + ')'); break; case 4803: $('input[name="fm_otherexpenditureinfo.Title"]').val('电脑/打印机/会议系统付款(' + data.username + ')'); break; case 4901: $('input[name="fm_otherexpenditureinfo.Title"]').val('设备委外维修付款(' + data.username + ')'); break; case 4902: $('input[name="fm_otherexpenditureinfo.Title"]').val('设备改造付款(' + data.username + ')'); break; } } }); } } var orderCode = ''; //选择供应商后绑定数据 var setCompanyInfo = function (id, name, UserName, Phone, BankName, BankDeposit, BankAccount) { $('#fm_otherexpenditureinfo_IncomeUnitID').val(id); $('#fm_otherexpenditureinfo_IncomeUnitName').val(name); $('#fm_otherexpenditureinfo_AccountOpenBankAccount').val(BankName); $('#fm_otherexpenditureinfo_CashBankName').val(BankDeposit); $('#fm_otherexpenditureinfo_ReceivablesAccount').val(BankAccount); loadHt($.trim(initItems.Code)); layer.closeAll(); } //收入单位选择 var getcompanyinfo = function () { layer.open({ type: 2, title: '收款单位', shadeClose: true, shade: 0.4, area: ['90%', '90%'], content: "/oa/General/company" }); } //加载项目和供应商之间的合同信息 var loadHt = function (ordercodes) { var projectid = $.trim($('#fm_otherexpenditureinfo_ProjectID').val()); var PartyBId = $('#fm_otherexpenditureinfo_IncomeUnitID').val(); var IsFinish = $('input:radio[name="fm_otherexpenditureinfo.IsFinish"]:checked').val(); var isCY = false; if (getUrlParam('isCY') == '1') { isCY = true; } $.ajax({ url: '/oa/General/GetHtOfProjectAndGYS?type=' + $paytype + '&&projectid=' + projectid + '&&PartyBId=' + PartyBId + '&&ordercodes=' + $.trim(ordercodes) + '&fukuantype=' + IsFinish + '&isCY=' + isCY, async: false, cache: false, dataType: "json", success: function (data) { var aryoptions = []; var defaultOption = ''; aryoptions.push(defaultOption); if (data.length > 0) { $.each(data, function (i, r) { var options = ''; if ($.trim(r.orderCode) != '') { aryoptions.push(options); } if (i == 0) { $('#fm_otherexpenditureinfo_sumpaymoney').val(r.paymoney); $('#fm_otherexpenditureinfo_balance').val(r.balance); $('#fm_otherexpenditureinfo_TotalExpenditure').val(r.balance); $('#fm_otherexpenditureinfo_CapitalizationTotalExpenditure').val(changeMoneyToChinese(r.balance)); } }); } else { $('#fm_otherexpenditureinfo_sumpaymoney').val(0); $('#fm_otherexpenditureinfo_balance').val(0); $('#fm_otherexpenditureinfo_TotalExpenditure').val(0); $('#fm_otherexpenditureinfo_CapitalizationTotalExpenditure').val(changeMoneyToChinese(0)); } $('#fm_otherexpenditureinfo_SettlementNumber').html(aryoptions.join('')); $('#fm_otherexpenditureinfo_SettlementNumber').trigger("chosen:updated"); } }); } function JsonDateToDate(jsondate) { var date = new Date(parseInt(jsondate.replace("/Date(", "").replace(")/", ""), 10)); return date; } Date.prototype.Format = function (formatStr) { var str = formatStr; var Week = ['日', '一', '二', '三', '四', '五', '六']; var mt = this.getMonth() + 1; str = str.replace(/yyyy|YYYY/, this.getFullYear()); str = str.replace(/yy|YY/, (this.getYear() % 100) > 9 ? (this.getYear() % 100).toString() : '0' + (this.getYear() % 100)); str = str.replace(/MM/, mt > 9 ? mt : '0' + mt); str = str.replace(/M/g, mt); str = str.replace(/w|W/g, Week[this.getDay()]); str = str.replace(/dd|DD/, this.getDate() > 9 ? this.getDate().toString() : '0' + this.getDate()); str = str.replace(/d|D/g, this.getDate()); str = str.replace(/hh|HH/, this.getHours() > 9 ? this.getHours().toString() : '0' + this.getHours()); str = str.replace(/h|H/g, this.getHours()); str = str.replace(/mm/, this.getMinutes() > 9 ? this.getMinutes().toString() : '0' + this.getMinutes()); str = str.replace(/m/g, this.getMinutes()); str = str.replace(/ss|SS/, this.getSeconds() > 9 ? this.getSeconds().toString() : '0' + this.getSeconds()); str = str.replace(/s|S/g, this.getSeconds()); return str; } var ShowDtl = function (id) { $.ajax({ url: '/OA/General/GetcontractpretrialUrl?ordercode=' + id, //data: search, type: 'Get', success: function (data) { if (data != null && $.trim(data) != '') { var url = '/WorkFlowRun/Index' + "?flowid=" + data.FlowId + '&taskid=' + data.TaskId; var inputs = ''; $('#fm_otherexpenditureinfo_SettlementNumber').after(inputs); $('#fm_otherexpenditureinfo_SettlementNumber').parent().on('click', function () { var href = $('#todetail').attr('href'); console.log(href); appendTabByUrl(href, "查看单据详情"); }); } }, error: function (data) { }, complete: function () { } }); } ///数据加载 var initData = function () { var url = window.location.href; type = parseInt(getUrlParam('type')); if (getUrlParam('isCY') == '1') { var hiddenHtml = ''; $("[name='fm_otherexpenditureinfo.Code']").after(hiddenHtml); } if ($.trim(sysid) != '' && initItems != null) { type = parseInt(initItems.ExpenditureBusinessTypeID); } if (type == 42) { $('#fm_otherexpenditureinfo_SettlementNumber').parent().parent().remove(); } setpaytype(type); gettype(type); var ExpenditureBusinessTypeName = $('#txtTitle').html().replace('付款单', ''); if (sysid != '' && initItems != null) { ExpenditureBusinessTypeName = initItems.ExpenditureBusinessTypeName; } var inputs = ''; inputs += ''; $('input[name="fm_otherexpenditureinfo.Code"]').after(inputs); inputs = ''; $('input[name="fm_otherexpenditureinfo.Code"]').after(inputs); var SettlementMethodName = (initItems != null && $.trim(initItems.SettlementMethodName) != '') ? initItems.SettlementMethodName : $('select[name="fm_otherexpenditureinfo.SettlementMethodID"]').find('option:eq(0)').text(); inputs = ''; $('select[name="fm_otherexpenditureinfo.SettlementMethodID"]').after(inputs); $('select[name="fm_otherexpenditureinfo.SettlementMethodID"]').bind('change', function () { var text = $(this).find('option:selected').text(); $('input[name="fm_otherexpenditureinfo.SettlementMethodName"]').val(text); }); inputs = ''; $('#fm_otherexpenditureinfo_ProjectID').after(inputs); if ($.trim(initItems.ProjectName) != '') { $('input[name="fm_otherexpenditureinfo.ProjectName"]').val(initItems.ProjectName); } inputs = ''; $('#fm_otherexpenditureinfo_IncomeUnitName').after(inputs); if ($.trim(initItems.IncomeUnitID) != '') { $('input[name="fm_otherexpenditureinfo.IncomeUnitID"]').val(initItems.IncomeUnitID); } $('input[name="fm_otherexpenditureinfo.IsInPlan"]:eq(0)').attr("value", '1'); $('input[name="fm_otherexpenditureinfo.IsInPlan"]:eq(1)').attr("value", '2'); if ($.trim(sysid) != '' && initItems != null) { var sprintbtn = '表单打印'; sprintbtn += '审核意见打印'; $('#txtTitle').append(sprintbtn); } getusername(type); //绑定收款单位改变触发事件 $('#fm_otherexpenditureinfo_IncomeUnitName').bind('focus', function () { getcompanyinfo(); }); //绑定金额改变触发事件 $('#fm_otherexpenditureinfo_TotalExpenditure').bind('change', function () { var isfinish = $.trim($(':radio[name="fm_otherexpenditureinfo.IsFinish"]:checked').val()); isfinish = isfinish == '' ? 0 : parseInt(isfinish); var money = $.trim($(this).val()); money = money == '' ? 0 : money; if (isfinish == 1) { var yue = $.trim($('#fm_otherexpenditureinfo_balance').val()); yue = yue == '' ? 0 : yue; if (parseFloat(money) > parseFloat(yue))//输入金额>合同应付余额 money = yue; } $('#fm_otherexpenditureinfo_TotalExpenditure').val(money); $('#fm_otherexpenditureinfo_CapitalizationTotalExpenditure').val(changeMoneyToChinese(money)); }); //绑定项目改变触发事件 $('#fm_otherexpenditureinfo_ProjectID').bind('change', function () { var projectname = $('#fm_otherexpenditureinfo_ProjectID').find('option:selected').text(); $('#fm_otherexpenditureinfo_ProjectName').val(projectname); loadHt($.trim(initItems.Code)); }); //绑定合同改变触发事件 $('#fm_otherexpenditureinfo_SettlementNumber').bind('change', function () { var yue = $.trim($('#fm_otherexpenditureinfo_SettlementNumber').find('option:selected').attr('balance')); $('#fm_otherexpenditureinfo_TotalExpenditure').val(yue); $('#fm_otherexpenditureinfo_CapitalizationTotalExpenditure').val(changeMoneyToChinese(yue)); var allpay = $.trim($('#fm_otherexpenditureinfo_SettlementNumber').find('option:selected').attr('paymoney')); $('#fm_otherexpenditureinfo_sumpaymoney').val(allpay); $('#fm_otherexpenditureinfo_balance').val(yue); }); //付款分类改变触发事件 $('input[name="fm_otherexpenditureinfo.IsFinish"]').bind('change', function () { var isfinish = $(this).val(); var money = $.trim($('#fm_otherexpenditureinfo_TotalExpenditure').val()); money = money == '' ? 0 : money; if (parseInt(isfinish) == 1)//结算付款要判断金额 { var yue = $.trim($('#fm_otherexpenditureinfo_balance').val()); yue = yue == '' ? 0 : yue; if (parseFloat(money) > parseFloat(yue))//输入金额>合同应付余额 money = yue; } $('#fm_otherexpenditureinfo_TotalExpenditure').val(money); $('#fm_otherexpenditureinfo_CapitalizationTotalExpenditure').val(changeMoneyToChinese(money)); }); if (sysid != '') { loadHt(initItems.Code); if (parseInt(type) != 42) { $('#fm_otherexpenditureinfo_SettlementNumber').val(initItems.SettlementNumber); $('#fm_otherexpenditureinfo_SettlementNumber').trigger("chosen:updated"); var yue = $.trim($('#fm_otherexpenditureinfo_SettlementNumber').find('option:selected').attr('balance')); var allpay = $.trim($('#fm_otherexpenditureinfo_SettlementNumber').find('option:selected').attr('paymoney')); $('#fm_otherexpenditureinfo_sumpaymoney').val(allpay); $('#fm_otherexpenditureinfo_balance').val(yue); } else { } $('#fm_otherexpenditureinfo_TotalExpenditure').val(initItems.TotalExpenditure); $('#fm_otherexpenditureinfo_CapitalizationTotalExpenditure').val(initItems.CapitalizationTotalExpenditure); } else { var projectname = $('#fm_otherexpenditureinfo_ProjectID').find('option:selected').text(); $('#fm_otherexpenditureinfo_ProjectName').val(projectname); } if (type == 45 || type == 48 || type == 4801 || type == 4802 || type == 4803) { $('#fm_otherexpenditureinfo_ProjectID').parent().parent().remove(); } if (type != 50 && type != 41 && type != 42 && type != 43) { $('input[name="fm_otherexpenditureinfo.IsFinish"][value="1"]').parent().remove(); $('input[name="fm_otherexpenditureinfo.balance"]').parent().parent().remove(); } else { $('input[name="fm_otherexpenditureinfo.IsFinish"][value="3"]').parent().remove(); } $('input:radio[name="fm_otherexpenditureinfo.IsFinish"]').change(function () { loadHt($.trim(initItems.Code)); }); var isdisabled = $('#fm_otherexpenditureinfo_SettlementNumber').attr('disabled'); var sSettlementNumber = $.trim(initItems.SettlementNumber); if (isdisabled == 'disabled' && sSettlementNumber != '') { ShowDtl(initItems.SettlementNumber); } }