/* * 版 本 Learun-ADMS V7.0.6 力软敏捷开发框架(http://www.learun.cn) * Copyright (c) 2013-2020 力软信息技术(苏州)有限公司 * 创建人:超级管理员 * 日 期:2022-11-07 14:25 * 描 述:经费开支申报 */ var keyValue = request('keyValue'); // 设置权限 var setAuthorize; // 设置表单数据 var setFormData; // 验证数据是否填写完整 var validForm; // 保存数据 var save; var refreshGirdData; var acceptClick; var selectedRow; var tempdatra = new Array(); //总价计算 var pricecount = 0; var bootstrap = function ($, learun) { "use strict"; // 设置权限 setAuthorize = function (data) { if (!!data) { for (var field in data) { if (data[field].isLook != 1) {// 如果没有查看权限就直接移除 $('#' + data[field].fieldId).parent().remove(); } else { if (data[field].isEdit != 1) { $('#' + data[field].fieldId).attr('disabled', 'disabled'); if ($('#' + data[field].fieldId).hasClass('lrUploader-wrap')) { $('#' + data[field].fieldId).css({ 'padding-right': '58px' }); $('#' + data[field].fieldId).find('.btn-success').remove(); } } } } } }; var page = { init: function () { $('.lr-form-wrap').lrscroll(); $("#detailadd").on('click', function () { selectedRow = null; learun.layerForm({ id: 'formdetail', title: '新增明细', url: top.$.rootUrl + '/AssetManagementSystem/FundsApplyDetail/Form', width: 500, height: 400, callBack: function (id) { return top[id].acceptClick(refreshGirdData); } }); }); $("#detailedit").on('click', function () { var keyValue = $('#FundsApplyDetail').jfGridValue('Id'); selectedRow = $('#FundsApplyDetail').jfGridGet('rowdata'); if (learun.checkrow(keyValue)) { learun.layerForm({ id: 'formdetail', title: '编辑明细', url: top.$.rootUrl + '/AssetManagementSystem/FundsApplyDetail/Form?keyValue=' + keyValue, width: 500, height: 400, callBack: function (id) { return top[id].acceptClick(refreshGirdData); } }); } }); $("#detaildel").on('click', function () { var keyValue = $('#FundsApplyDetail').jfGridValue('Id'); if (learun.checkrow(keyValue)) { learun.layerConfirm('是否确认删除该项!', function (res, index) { if (res) { $.each(tempdatra, function (key, val) { if (tempdatra[key] && tempdatra[key].Id === keyValue) { pricecount -= tempdatra[key].Amount; tempdatra.splice(key, 1); } }); pricecount = pricecount.toFixed(2); $("#SumAmount").val(pricecount); $("#UpperAmount").val(smalltoBIG(pricecount)); $('#FundsApplyDetail').jfGridSet('refreshdata', tempdatra.sort(sortNumber)); top.layer.close(index); } }); } }); page.bind(); page.initData(); }, bind: function () { $('#IsFixedAssets').lrDataItemSelect({ code: 'YesOrNoInt' }); $('#ApplyDept').lrDataSourceSelect({ code: 'classdata', value: 'id', text: 'name' }); $('#ApplyDept').lrselectSet(learun.clientdata.get(['userinfo']).departmentId); $('#ApplyTime').val(learun.formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss')); $('#ApplyUser')[0].lrvalue = learun.clientdata.get(['userinfo']).userId; $('#ApplyUser').val(learun.clientdata.get(['userinfo']).realName); $('#FundsApplyDetail').jfGrid({ headData: [ { label: '项目内容', name: 'ProjectContent', width: 150, align: 'left' }, { label: '数量', name: 'Number', width: 150, align: 'left' }, { label: '单价(元)', name: 'Price', width: 150, align: 'left' }, { label: '金额(元)', name: 'Amount', width: 150, align: 'left' }, ], height: 400, mainId: 'AAIId', reloadSelected: false, }); }, initData: function () { if (!!keyValue) { $.lrSetForm(top.$.rootUrl + '/AssetManagementSystem/FundsApply/GetFormData?keyValue=' + keyValue, function (data) { for (var id in data) { if (!!data[id].length && data[id].length > 0) { $('#' + id).jfGridSet('refreshdata', data[id]); tempdatra = data[id]; } else { $('[data-table="' + id + '"]').lrSetFormData(data[id]); if (data[id].SumAmount) { pricecount = data[id].SumAmount; } } } }); } else { $("#EnCode").val(NewEnCode); } } }; refreshGirdData = function (temprow) { var ifnewrow = true; $.each(tempdatra, function (key, val) { if (tempdatra[key].Id === temprow.Id) { tempdatra[key] = temprow; ifnewrow = false; } }); if (ifnewrow) { tempdatra.push(temprow); } //总价计算 pricecount = 0; for (var i = 0; i < tempdatra.length; i++) { pricecount += parseFloat(tempdatra[i].Amount); } $("#SumAmount").val(pricecount.toFixed(2)); $("#UpperAmount").val(smalltoBIG(pricecount)); $('#FundsApplyDetail').jfGridSet('refreshdata', tempdatra.sort(sortNumber)); }; function sortNumber(a, b) { return a.AAIOrder - b.AAIOrder; } // 设置表单数据 setFormData = function (processId, param, callback) { if (!!processId) { $.lrSetForm(top.$.rootUrl + '/AssetManagementSystem/FundsApply/GetFormDataByProcessId?processId=' + processId, function (data) { for (var id in data) { if (!!data[id] && data[id].length > 0) { $('#' + id).jfGridSet('refreshdata', data[id]); } else { if (id == 'FundsApply' && data[id]) { keyValue = data[id].Id; } $('[data-table="' + id + '"]').lrSetFormData(data[id]); } } }); } callback && callback(); } // 验证数据是否填写完整 validForm = function () { if (!$('body').lrValidform()) { return false; } return true; }; // 保存数据 save = function (processId, callBack, i) { var postData = {}; var formData = $('[data-table="FundsApply"]').lrGetFormData(); if (!!processId) { formData.ProcessId = processId; } postData.strEntity = JSON.stringify(formData); postData.fundsApplyDetailList = JSON.stringify($('#FundsApplyDetail').jfGridGet('rowdatas')); $.lrSaveForm(top.$.rootUrl + '/AssetManagementSystem/FundsApply/SaveForm?keyValue=' + keyValue, postData, function (res) { // 保存成功后才回调 if (!!callBack) { callBack(res, i); } }); }; page.init(); function smalltoBIG(n) { var fraction = ['角', '分']; var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']; var unit = [ ['元', '万', '亿'], ['', '拾', '佰', '仟'] ]; var head = n < 0 ? '欠' : ''; n = Math.abs(n); var s = ''; for (var i = 0; i < fraction.length; i++) { s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, ''); } s = s || '整'; n = Math.floor(n); for (var i = 0; i < unit[0].length && n > 0; i++) { var p = ''; for (var j = 0; j < unit[1].length && n > 0; j++) { p = digit[n % 10] + unit[1][j] + p; n = Math.floor(n / 10); } s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s; } return head + s.replace(/(零.)*零元/, '元').replace(/(零.)+/g, '零').replace(/^整$/, '零元整'); } }