|
- /* * 版 本 Learun-ADMS V7.0.6 力软敏捷开发框架(http://www.learun.cn)
- * Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
- * 创建人:超级管理员
- * 日 期:2021-09-27 11:38
- * 描 述:经费预算管理
- */
- var acceptClick;
- var keyValue = request('keyValue');
- // 设置表单数据
- var setFormData;
- // 验证数据是否填写完整
- var validForm;
- // 保存数据
- var save;
- var refreshGirdData;
- var selectedRow;
- var numm = 1;
- var calcTotalPrice;
- var tempdatra = new Array();
- var bootstrap = function ($, learun) {
- "use strict";
- var page = {
- init: function () {
- $('.lr-form-wrap').lrscroll();
- $("#detailadd").on('click', function () {
- selectedRow = null;
- learun.layerForm({
- id: 'formFundsManageChild',
- title: '新增明细',
- url: top.$.rootUrl + '/CustomFunction/FundsManageChild/Form',
- width: 540,
- height: 400,
- callBack: function (id) {
- return top[id].acceptClick(refreshGirdData);
- }
- });
- });
- $("#detailedit").on('click', function () {
- var keyValue = $('#FundsManageChild').jfGridValue('ID');
- selectedRow = $('#FundsManageChild').jfGridGet('rowdata');
- console.log('selectedRow:', selectedRow);
- if (learun.checkrow(keyValue)) {
- learun.layerForm({
- id: 'formFundsManageChild',
- title: '编辑明细',
- url: top.$.rootUrl + '/CustomFunction/FundsManageChild/Form?keyValue=' + keyValue,
- width: 540,
- height: 400,
- callBack: function (id) {
- return top[id].acceptClick(refreshGirdData);
- }
- });
- }
- });
- $("#detaildel").on('click', function () {
- var keyValue = $('#FundsManageChild').jfGridValue('ID');
- if (learun.checkrow(keyValue)) {
- learun.layerConfirm('是否确认删除该项!', function (res, index) {
- if (res) {
- $.each(tempdatra, function (key, val) {
- if (tempdatra[key].ID === keyValue) {
- tempdatra.splice(key, 1);
- }
- });
- $('#FundsManageChild').jfGridSet('refreshdata', tempdatra);
- calcTotalPrice();
- top.layer.close(index);
- }
-
- });
- }
- });
- page.bind();
- page.initData();
- },
- bind: function () {
- $('#SRProjectBasicId').lrselect({
- allowSearch: true,
- url: top.$.rootUrl + '/CustomFunction/SRProjectBasic/GetList',
- value: "ID",
- text: "EnCode"
- });
- $('#CreateTime').val(learun.formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss'));
- $('#CreateUserId')[0].lrvalue = learun.clientdata.get(['userinfo']).userId;
- $('#CreateUserId').val(learun.clientdata.get(['userinfo']).realName);
-
- $('#FundsManageChild').jfGrid({
- headData: [
- {
- label: '费用类型', name: 'Type', width: 100, align: 'left',
- formatterAsync: function (callback, value, row, op, $cell) {
- learun.clientdata.getAsync('custmerData', {
- url: '/LR_SystemModule/DataSource/GetDataTable?code=' + 'FundsTypeManage',
- key: value,
- keyId: 'id',
- callback: function (_data) {
- callback(_data['name']);
- }
- });
- }
- },
- {
- label: '费用摘要', name: 'Remark', width: 100, align: 'left'
- },
- {
- label: '费用金额', name: 'Amount', width: 100, align: 'left'
- },
- ],
- height: 270,
- mainId: 'ID'
- });
- },
- initData: function () {
- if (!!keyValue) {
- $.lrSetForm(top.$.rootUrl + '/CustomFunction/FundsManageMain/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]);
- }
- }
- });
- }
- }
- };
- 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);
- }
-
- $('#FundsManageChild').jfGridSet('refreshdata', tempdatra);
- calcTotalPrice();
- };
- //计算总金额(=单价*数量)
- calcTotalPrice = function () {
- var totalprice = 0;
- $.each(tempdatra, function (i, item) {
- totalprice += Number(item.Amount);
- });
- $('#FundsSum').val(totalprice.toFixed(2));
- };
- // 验证数据是否填写完整
- validForm = function () {
- if (!$('.lr-form-wrap').lrValidform()) {
- return false;
- }
- var datas = $('#FundsManageChild').jfGridGet('rowdatas');
- if (datas == null || datas.length == 0) {
- learun.alert.warning("申请未包含明细!请先新增明细!");
- return false;
- }
- return true;
- };
- // 保存数据
- save = function (callBack, i) {
- var postData = {};
- var formData = $('[data-table="FundsManageMain"]').lrGetFormData();
-
- postData.strEntity = JSON.stringify(formData);
- postData.FundsManageChildList = JSON.stringify($('#FundsManageChild').jfGridGet('rowdatas'));
- //var postData = {
- // strEntity: JSON.stringify($('body').lrGetFormData())
- //};
- $.lrSaveForm(top.$.rootUrl + '/CustomFunction/FundsManageMain/SaveForm?keyValue=' + keyValue, postData, function (res) {
- // 保存成功后才回调
- if (!!callBack) {
- callBack(formData, i);
- }
- });
- };
- page.init();
- }
|