You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

183 lines
7.0 KiB

  1. /* * 版 本 Learun-ADMS V7.0.6 力软敏捷开发框架(http://www.learun.cn)
  2. * Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
  3. * 创建人:超级管理员
  4. * 日 期:2021-09-27 11:38
  5. * 描 述:经费预算管理
  6. */
  7. var acceptClick;
  8. var keyValue = request('keyValue');
  9. // 设置表单数据
  10. var setFormData;
  11. // 验证数据是否填写完整
  12. var validForm;
  13. // 保存数据
  14. var save;
  15. var refreshGirdData;
  16. var selectedRow;
  17. var numm = 1;
  18. var calcTotalPrice;
  19. var tempdatra = new Array();
  20. var bootstrap = function ($, learun) {
  21. "use strict";
  22. var page = {
  23. init: function () {
  24. $('.lr-form-wrap').lrscroll();
  25. $("#detailadd").on('click', function () {
  26. selectedRow = null;
  27. learun.layerForm({
  28. id: 'formFundsManageChild',
  29. title: '新增明细',
  30. url: top.$.rootUrl + '/CustomFunction/FundsManageChild/Form',
  31. width: 540,
  32. height: 400,
  33. callBack: function (id) {
  34. return top[id].acceptClick(refreshGirdData);
  35. }
  36. });
  37. });
  38. $("#detailedit").on('click', function () {
  39. var keyValue = $('#FundsManageChild').jfGridValue('ID');
  40. selectedRow = $('#FundsManageChild').jfGridGet('rowdata');
  41. console.log('selectedRow:', selectedRow);
  42. if (learun.checkrow(keyValue)) {
  43. learun.layerForm({
  44. id: 'formFundsManageChild',
  45. title: '编辑明细',
  46. url: top.$.rootUrl + '/CustomFunction/FundsManageChild/Form?keyValue=' + keyValue,
  47. width: 540,
  48. height: 400,
  49. callBack: function (id) {
  50. return top[id].acceptClick(refreshGirdData);
  51. }
  52. });
  53. }
  54. });
  55. $("#detaildel").on('click', function () {
  56. var keyValue = $('#FundsManageChild').jfGridValue('ID');
  57. if (learun.checkrow(keyValue)) {
  58. learun.layerConfirm('是否确认删除该项!', function (res, index) {
  59. if (res) {
  60. $.each(tempdatra, function (key, val) {
  61. if (tempdatra[key].ID === keyValue) {
  62. tempdatra.splice(key, 1);
  63. }
  64. });
  65. $('#FundsManageChild').jfGridSet('refreshdata', tempdatra);
  66. calcTotalPrice();
  67. top.layer.close(index);
  68. }
  69. });
  70. }
  71. });
  72. page.bind();
  73. page.initData();
  74. },
  75. bind: function () {
  76. $('#SRProjectBasicId').lrselect({
  77. allowSearch: true,
  78. url: top.$.rootUrl + '/CustomFunction/SRProjectBasic/GetList',
  79. value: "ID",
  80. text: "EnCode"
  81. });
  82. $('#CreateTime').val(learun.formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss'));
  83. $('#CreateUserId')[0].lrvalue = learun.clientdata.get(['userinfo']).userId;
  84. $('#CreateUserId').val(learun.clientdata.get(['userinfo']).realName);
  85. $('#FundsManageChild').jfGrid({
  86. headData: [
  87. {
  88. label: '费用类型', name: 'Type', width: 100, align: 'left',
  89. formatterAsync: function (callback, value, row, op, $cell) {
  90. learun.clientdata.getAsync('custmerData', {
  91. url: '/LR_SystemModule/DataSource/GetDataTable?code=' + 'FundsTypeManage',
  92. key: value,
  93. keyId: 'id',
  94. callback: function (_data) {
  95. callback(_data['name']);
  96. }
  97. });
  98. }
  99. },
  100. {
  101. label: '费用摘要', name: 'Remark', width: 100, align: 'left'
  102. },
  103. {
  104. label: '费用金额', name: 'Amount', width: 100, align: 'left'
  105. },
  106. ],
  107. height: 270,
  108. mainId: 'ID'
  109. });
  110. },
  111. initData: function () {
  112. if (!!keyValue) {
  113. $.lrSetForm(top.$.rootUrl + '/CustomFunction/FundsManageMain/GetFormData?keyValue=' + keyValue, function (data) {
  114. for (var id in data) {
  115. if (!!data[id].length && data[id].length > 0) {
  116. $('#' + id).jfGridSet('refreshdata', data[id]);
  117. tempdatra = data[id];
  118. }
  119. else {
  120. $('[data-table="' + id + '"]').lrSetFormData(data[id]);
  121. }
  122. }
  123. });
  124. }
  125. }
  126. };
  127. refreshGirdData = function (temprow) {
  128. var ifnewrow = true;
  129. $.each(tempdatra, function (key, val) {
  130. if (tempdatra[key].ID === temprow.ID) {
  131. tempdatra[key] = temprow;
  132. ifnewrow = false;
  133. }
  134. });
  135. if (ifnewrow) {
  136. tempdatra.push(temprow);
  137. }
  138. $('#FundsManageChild').jfGridSet('refreshdata', tempdatra);
  139. calcTotalPrice();
  140. };
  141. //计算总金额(=单价*数量)
  142. calcTotalPrice = function () {
  143. var totalprice = 0;
  144. $.each(tempdatra, function (i, item) {
  145. totalprice += Number(item.Amount);
  146. });
  147. $('#FundsSum').val(totalprice.toFixed(2));
  148. };
  149. // 验证数据是否填写完整
  150. validForm = function () {
  151. if (!$('.lr-form-wrap').lrValidform()) {
  152. return false;
  153. }
  154. var datas = $('#FundsManageChild').jfGridGet('rowdatas');
  155. if (datas == null || datas.length == 0) {
  156. learun.alert.warning("申请未包含明细!请先新增明细!");
  157. return false;
  158. }
  159. return true;
  160. };
  161. // 保存数据
  162. save = function (callBack, i) {
  163. var postData = {};
  164. var formData = $('[data-table="FundsManageMain"]').lrGetFormData();
  165. postData.strEntity = JSON.stringify(formData);
  166. postData.FundsManageChildList = JSON.stringify($('#FundsManageChild').jfGridGet('rowdatas'));
  167. //var postData = {
  168. // strEntity: JSON.stringify($('body').lrGetFormData())
  169. //};
  170. $.lrSaveForm(top.$.rootUrl + '/CustomFunction/FundsManageMain/SaveForm?keyValue=' + keyValue, postData, function (res) {
  171. // 保存成功后才回调
  172. if (!!callBack) {
  173. callBack(formData, i);
  174. }
  175. });
  176. };
  177. page.init();
  178. }