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.
 
 
 
 
 
 

265 lines
11 KiB

  1. /* * 版 本 Learun-ADMS V7.0.6 力软敏捷开发框架(http://www.learun.cn)
  2. * Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
  3. * 创建人:超级管理员
  4. * 日 期:2022-11-07 14:25
  5. * 描 述:经费开支申报
  6. */
  7. var keyValue = request('keyValue');
  8. // 设置权限
  9. var setAuthorize;
  10. // 设置表单数据
  11. var setFormData;
  12. // 验证数据是否填写完整
  13. var validForm;
  14. // 保存数据
  15. var save;
  16. var refreshGirdData;
  17. var acceptClick;
  18. var selectedRow;
  19. var tempdatra = new Array();
  20. //总价计算
  21. var pricecount = 0;
  22. var bootstrap = function ($, learun) {
  23. "use strict";
  24. // 设置权限
  25. setAuthorize = function (data) {
  26. if (!!data) {
  27. for (var field in data) {
  28. if (data[field].isLook != 1) {// 如果没有查看权限就直接移除
  29. $('#' + data[field].fieldId).parent().remove();
  30. }
  31. else {
  32. if (data[field].isEdit != 1) {
  33. $('#' + data[field].fieldId).attr('disabled', 'disabled');
  34. if ($('#' + data[field].fieldId).hasClass('lrUploader-wrap')) {
  35. $('#' + data[field].fieldId).css({ 'padding-right': '58px' });
  36. $('#' + data[field].fieldId).find('.btn-success').remove();
  37. }
  38. }
  39. }
  40. }
  41. }
  42. };
  43. var page = {
  44. init: function () {
  45. $('.lr-form-wrap').lrscroll();
  46. $("#detailadd").on('click', function () {
  47. selectedRow = null;
  48. learun.layerForm({
  49. id: 'formdetail',
  50. title: '新增明细',
  51. url: top.$.rootUrl + '/AssetManagementSystem/FundsApplyDetail/Form',
  52. width: 500,
  53. height: 400,
  54. callBack: function (id) {
  55. return top[id].acceptClick(refreshGirdData);
  56. }
  57. });
  58. });
  59. $("#detailedit").on('click', function () {
  60. var keyValue = $('#FundsApplyDetail').jfGridValue('Id');
  61. selectedRow = $('#FundsApplyDetail').jfGridGet('rowdata');
  62. if (learun.checkrow(keyValue)) {
  63. learun.layerForm({
  64. id: 'formdetail',
  65. title: '编辑明细',
  66. url: top.$.rootUrl + '/AssetManagementSystem/FundsApplyDetail/Form?keyValue=' + keyValue,
  67. width: 500,
  68. height: 400,
  69. callBack: function (id) {
  70. return top[id].acceptClick(refreshGirdData);
  71. }
  72. });
  73. }
  74. });
  75. $("#detaildel").on('click', function () {
  76. var keyValue = $('#FundsApplyDetail').jfGridValue('Id');
  77. if (learun.checkrow(keyValue)) {
  78. learun.layerConfirm('是否确认删除该项!', function (res, index) {
  79. if (res) {
  80. $.each(tempdatra, function (key, val) {
  81. if (tempdatra[key] && tempdatra[key].Id === keyValue) {
  82. pricecount -= tempdatra[key].Amount;
  83. tempdatra.splice(key, 1);
  84. }
  85. });
  86. pricecount = pricecount.toFixed(2);
  87. $("#SumAmount").val(pricecount);
  88. $("#UpperAmount").val(smalltoBIG(pricecount));
  89. $('#FundsApplyDetail').jfGridSet('refreshdata', tempdatra.sort(sortNumber));
  90. top.layer.close(index);
  91. }
  92. });
  93. }
  94. });
  95. page.bind();
  96. page.initData();
  97. },
  98. bind: function () {
  99. $('#Path').lrUploader({ isUpload: false });
  100. $('#IsFixedAssets').lrDataItemSelect({ code: 'YesOrNoInt' });
  101. $('#ApplyDept').lrDataSourceSelect({ code: 'classdata', value: 'id', text: 'name' });
  102. $('#ApplyDept').lrselectSet(learun.clientdata.get(['userinfo']).departmentId);
  103. $('#ApplyTime').val(learun.formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss'));
  104. $('#ApplyUser')[0].lrvalue = learun.clientdata.get(['userinfo']).userId;
  105. $('#ApplyUser').val(learun.clientdata.get(['userinfo']).realName);
  106. $('#FundsApplyDetail').jfGrid({
  107. headData: [
  108. {
  109. label: '项目明细', name: 'ProjectContent', width: 150, align: 'left'
  110. },
  111. {
  112. label: '数量', name: 'Number', width: 120, align: 'left'
  113. },
  114. {
  115. label: '单位', name: 'Unit', width: 120, align: 'left',
  116. formatterAsync: function (callback, value, row, op, $cell) {
  117. learun.clientdata.getAsync('dataItem', {
  118. key: value,
  119. code: 'sldw',
  120. callback: function (_data) {
  121. callback(_data.text);
  122. }
  123. });
  124. }
  125. },
  126. {
  127. label: '单价(元)', name: 'Price', width: 150, align: 'left', formatter: function (cellvalue) {
  128. return cellvalue.toString().indexOf(".") > 0 ? Number(cellvalue).toFixed(2) : Number(cellvalue).toFixed(2);
  129. }
  130. },
  131. {
  132. label: '金额(元)', name: 'Amount', width: 150, align: 'left', formatter: function (cellvalue) {
  133. return cellvalue.toString().indexOf(".") > 0 ? Number(cellvalue).toFixed(2) : Number(cellvalue).toFixed(2);
  134. }
  135. },
  136. ],
  137. height: 240,
  138. mainId: 'Id',
  139. reloadSelected: false,
  140. });
  141. },
  142. initData: function () {
  143. if (!!keyValue) {
  144. $.lrSetForm(top.$.rootUrl + '/AssetManagementSystem/FundsApply/GetFormData?keyValue=' + keyValue, function (data) {
  145. for (var id in data) {
  146. if (!!data[id].length && data[id].length > 0) {
  147. $('#' + id).jfGridSet('refreshdata', data[id]);
  148. tempdatra = data[id];
  149. }
  150. else {
  151. $('[data-table="' + id + '"]').lrSetFormData(data[id]);
  152. if (data[id].SumAmount) {
  153. pricecount = data[id].SumAmount;
  154. $("#SumAmount").val(pricecount.toFixed(2));
  155. }
  156. }
  157. }
  158. });
  159. } else {
  160. $("#EnCode").val(NewEnCode);
  161. }
  162. }
  163. };
  164. refreshGirdData = function (temprow) {
  165. var ifnewrow = true;
  166. $.each(tempdatra, function (key, val) {
  167. if (tempdatra[key].Id === temprow.Id) {
  168. tempdatra[key] = temprow;
  169. ifnewrow = false;
  170. }
  171. });
  172. if (ifnewrow) {
  173. tempdatra.push(temprow);
  174. }
  175. //总价计算
  176. pricecount = 0;
  177. for (var i = 0; i < tempdatra.length; i++) {
  178. pricecount += parseFloat(tempdatra[i].Amount);
  179. }
  180. $("#SumAmount").val(pricecount.toFixed(2));
  181. $("#UpperAmount").val(smalltoBIG(pricecount));
  182. $('#FundsApplyDetail').jfGridSet('refreshdata', tempdatra.sort(sortNumber));
  183. };
  184. function sortNumber(a, b) {
  185. return a.AAIOrder - b.AAIOrder;
  186. }
  187. // 设置表单数据
  188. setFormData = function (processId, param, callback) {
  189. if (!!processId) {
  190. $.lrSetForm(top.$.rootUrl + '/AssetManagementSystem/FundsApply/GetFormDataByProcessId?processId=' + processId, function (data) {
  191. for (var id in data) {
  192. if (!!data[id] && data[id].length > 0) {
  193. $('#' + id).jfGridSet('refreshdata', data[id]);
  194. }
  195. else {
  196. if (id == 'FundsApply' && data[id]) {
  197. keyValue = data[id].Id;
  198. }
  199. $('[data-table="' + id + '"]').lrSetFormData(data[id]);
  200. if (data[id].SumAmount) {
  201. pricecount = data[id].SumAmount;
  202. $("#SumAmount").val(pricecount.toFixed(2));
  203. }
  204. }
  205. }
  206. });
  207. }
  208. callback && callback();
  209. }
  210. // 验证数据是否填写完整
  211. validForm = function () {
  212. if (!$('body').lrValidform()) {
  213. return false;
  214. }
  215. return true;
  216. };
  217. // 保存数据
  218. save = function (processId, callBack, i) {
  219. var postData = {};
  220. var formData = $('[data-table="FundsApply"]').lrGetFormData();
  221. if (!!processId) {
  222. formData.ProcessId = processId;
  223. }
  224. postData.strEntity = JSON.stringify(formData);
  225. postData.fundsApplyDetailList = JSON.stringify($('#FundsApplyDetail').jfGridGet('rowdatas'));
  226. $.lrSaveForm(top.$.rootUrl + '/AssetManagementSystem/FundsApply/SaveForm?keyValue=' + keyValue, postData, function (res) {
  227. // 保存成功后才回调
  228. if (!!callBack) {
  229. callBack(res, i);
  230. }
  231. });
  232. };
  233. page.init();
  234. function smalltoBIG(n) {
  235. var fraction = ['角', '分'];
  236. var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
  237. var unit = [
  238. ['元', '万', '亿'],
  239. ['', '拾', '佰', '仟']
  240. ];
  241. var head = n < 0 ? '欠' : '';
  242. n = Math.abs(n);
  243. var s = '';
  244. for (var i = 0; i < fraction.length; i++) {
  245. s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');
  246. }
  247. s = s || '整';
  248. n = Math.floor(n);
  249. for (var i = 0; i < unit[0].length && n > 0; i++) {
  250. var p = '';
  251. for (var j = 0; j < unit[1].length && n > 0; j++) {
  252. p = digit[n % 10] + unit[1][j] + p;
  253. n = Math.floor(n / 10);
  254. }
  255. s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;
  256. }
  257. return head + s.replace(/(零.)*零元/, '元').replace(/(零.)+/g, '零').replace(/^整$/, '零元整');
  258. }
  259. }