index.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. (function () {
  2. var addDataThat = null;
  3. let isTimes = []
  4. let viewState = z.ui.comm.getUrlParam("_o");
  5. let read = z.ui.comm.getUrlParam("read");
  6. let finance = z.ui.comm.getUrlParam("finance");
  7. let detailProjectIndex = 0;
  8. let previousAmount = z.ui.input("[name='createReqVO$totalAmount']").getValue();
  9. let costTypeJSON = JSON.parse(document.querySelector('#costTypeJSON').value)
  10. let lastProjectId = '';
  11. let lastProjectName = '';
  12. let lastProjectDeptName = '';
  13. window.onload = function (ex) {
  14. let timeObject = document.querySelector('#detailList')
  15. let arrays = JSON.parse(timeObject.value)
  16. addDataThat = $("#addData")
  17. $("#addData").click(function () {
  18. addDataThat.attr('disabled', "true");
  19. let obj = {
  20. amount: "",
  21. bz1: "",
  22. costType: "",
  23. commonCostId: "",
  24. costContent: "",
  25. costDate: "",
  26. createTime: "",
  27. id: "",
  28. invoiceNums: "",
  29. isvalid: "",
  30. latestModifyTime: "",
  31. projectId: "",
  32. projectName: "",
  33. projectDeptName: ""
  34. }
  35. isTimes.push(obj)
  36. generateTableTrHtml(isTimes.length - 1)
  37. buildQjsjSeq();
  38. })
  39. $("#selectProject").click(function () {
  40. selectProject(null, setProject);
  41. })
  42. initCompany();
  43. bindEvents();
  44. //根据返回的json对象渲染
  45. if (arrays.length > 0) {
  46. for (let i = 0; i < arrays.length; i++) {
  47. let obj = {
  48. amount: arrays[i].amount || '',
  49. bz1: arrays[i].bz1 || '',
  50. costType: arrays[i].costType || '',
  51. commonCostId: arrays[i].commonCostId || '',
  52. costContent: arrays[i].costContent || '',
  53. costDate: arrays[i].costDate || '',
  54. createTime: arrays[i].createTime || '',
  55. id: arrays[i].id || '',
  56. invoiceNums: arrays[i].invoiceNums || '',
  57. isvalid: arrays[i].isvalid || '',
  58. latestModifyTime: arrays[i].latestModifyTime || '',
  59. projectId: arrays[i].projectId || '',
  60. projectName: arrays[i].projectName || '',
  61. projectDeptName: arrays[i].projectDeptName || ''
  62. }
  63. isTimes.push(obj)
  64. }
  65. for (let i = 0; i < isTimes.length; i++) {
  66. generateTableTrHtml(i);
  67. }
  68. }
  69. let bz2 = z.ui.input("[name='createReqVO$bz2']").getValue();
  70. if(finance === "1"){
  71. if(!bz2){
  72. bz2 = 0;
  73. }
  74. let amount = Number(previousAmount) + Number(bz2);
  75. let previousHtml = "(原金额:"+ amount.toFixed(2) +")"
  76. $("#previousAmount").text(previousHtml)
  77. }
  78. if(bz2){
  79. let amount = Number(previousAmount) + Number(bz2);
  80. let previousHtml = "(原金额:"+ amount.toFixed(2) +")"
  81. $("#previousAmount").text(previousHtml)
  82. }
  83. }
  84. function generateTableTrHtml(i) {
  85. var trDom = document.createElement("tr");
  86. trDom.style.backgroundColor = "#fff";
  87. trDom.id = "qjsj_" + i;
  88. trDom.className = 'qjsjClass'
  89. trDom.innerHTML = '<td name="qjsj_seq">' + (i + 1) + '</td>'
  90. + '<td>'
  91. + '<div class="form-flex">'
  92. + '<div class="form-item" style="width: 100%;margin-right: 5px;">'
  93. + '<input type="hidden" name="CommonCostDetailDO[' + i + ']$projectId" value="">'
  94. + '<div class="z-comp-input z-readonly" id="selectProject_' + i + '" name="CommonCostDetailDO[' + i + ']$projectName">'
  95. + '<input readonly type="text" value="">'
  96. + '</div>'
  97. + '</div>'
  98. + '</div>'
  99. + '</td>'
  100. + '<td>'
  101. + '<div class="form-item">'
  102. + '<div class="z-comp-input z-readonly" name="CommonCostDetailDO[' + i + ']$xmzrbm">'
  103. + '<input readonly type="text" value="">'
  104. + '</div>'
  105. + '</div>'
  106. + '</td>'
  107. + '<td>'
  108. + '<div class="form-flex">'
  109. + '<div class="form-item" style="width: 100%;margin-right: 5px;">'
  110. + '<div class="z-comp-date" name="CommonCostDetailDO[' + i + ']$costDate">'
  111. + '<input type="text" value="">'
  112. + '</div>'
  113. + '</div>'
  114. + '</div>'
  115. + '</td>'
  116. + '<td>'
  117. + '<div class="form-flex">'
  118. + '<div class="form-item" style="width: 100%;margin-right: 5px;">'
  119. + '<div class="z-comp-selecttree" name="costType[' + i + ']">'
  120. + '<input type="hidden" name="CommonCostDetailDO[' + i + ']$costType">'
  121. + '<div class="z-inputselect-bar">'
  122. + '<span></span><i></i>'
  123. + '</div>'
  124. + '</div>'
  125. + '</div>'
  126. + '</div>'
  127. + '</td>'
  128. + '<td>'
  129. + '<div class="form-item">'
  130. + '<div class="z-comp-input" name="CommonCostDetailDO[' + i + ']$costContent">'
  131. + '<input type="text" value="">'
  132. + '</div>'
  133. + '</div>'
  134. + '</td>'
  135. + '<td>'
  136. + '<div class="form-item">'
  137. + '<div class="z-comp-input" name="CommonCostDetailDO[' + i + ']$invoiceNums">'
  138. + '<input type="number" value="">'
  139. + '</div>'
  140. + '</div>'
  141. + '</td>'
  142. + '<td>'
  143. + '<div class="form-item">'
  144. + '<div class="z-comp-input" name="CommonCostDetailDO[' + i + ']$amount">'
  145. + '<input type="number" value="">'
  146. + '</div>'
  147. + '</div>'
  148. + '</td>'
  149. + '<td>'
  150. + '<div class="form-item">'
  151. + '<div class="z-comp-input" name="CommonCostDetailDO[' + i + ']$bz1">'
  152. + '<input type="text" value="">'
  153. + '</div>'
  154. + '</div>'
  155. + '</td>'
  156. + '<td>'
  157. + '<div style="display: flex;white-space: nowrap">'
  158. + '<div id="editBtn_' + (i) + '" style="margin: 0 10px" class="table-btn editBtn_' + (i) + '" data-index="' + (i) + '">'
  159. + '<span>保存</span>'
  160. + '</div>'
  161. + '<div id="delBtn_' + (i) + '" style="margin: 0 10px" class="table-btn delBtn_' + (i) + '" data-index="' + (i) + '">'
  162. + '<span>删除</span>'
  163. + '</div>'
  164. + '</div>'
  165. + '</td>';
  166. let trFragment = document.createDocumentFragment();
  167. trFragment.appendChild(trDom);
  168. $(".tbody").append(trFragment)
  169. costTypeJSON.forEach(obj => {
  170. obj.treeName = 'CommonCostDetailDO[' + i + ']$costType';
  171. })
  172. selecttree("[name='costType[" + i + "]']", costTypeJSON, clickCostType, allowChildClick)
  173. z.ui.date("[name='CommonCostDetailDO[" + i + "]$costDate']").init()
  174. if (!(!isTimes[i].costType || isTimes[i].costType.trim() === '')) {
  175. z.ui.selecttree("[name='costType[" + i + "]']").setValue(isTimes[i].costType)
  176. $("[name='CommonCostDetailDO[" + i + "]$costType']").val(isTimes[i].costType);
  177. }
  178. if(!(!lastProjectId || lastProjectId.trim() === '')){
  179. $("[name='CommonCostDetailDO[" + i + "]$projectId']").val(lastProjectId);
  180. }
  181. if(!(!lastProjectName || lastProjectName.trim() === '')){
  182. z.ui.input("[name='CommonCostDetailDO[" + i + "]$projectName']").setValue(lastProjectName);
  183. }
  184. if(!(!lastProjectDeptName || lastProjectDeptName.trim() === '')){
  185. z.ui.input("[name='CommonCostDetailDO[" + i + "]$xmzrbm']").setValue(lastProjectDeptName);
  186. }
  187. if (!(!isTimes[i].projectId || isTimes[i].projectId.trim() === '')) {
  188. $("[name='CommonCostDetailDO[" + i + "]$projectId']").val(isTimes[i].projectId);
  189. }
  190. if (!(!isTimes[i].projectName || isTimes[i].projectName.trim() === '')) {
  191. z.ui.input("[name='CommonCostDetailDO[" + i + "]$projectName']").setValue(isTimes[i].projectName);
  192. }
  193. if (!(!isTimes[i].projectDeptName || isTimes[i].projectDeptName.trim() === '')) {
  194. z.ui.input("[name='CommonCostDetailDO[" + i + "]$xmzrbm']").setValue(isTimes[i].projectDeptName);
  195. }
  196. if (!(!isTimes[i].costDate || isTimes[i].costDate.trim() === '')) {
  197. z.ui.date("[name='CommonCostDetailDO[" + i + "]$costDate']").setValue(isTimes[i].costDate);
  198. }
  199. if (!(!isTimes[i].costContent || isTimes[i].costContent.trim() === '')) {
  200. z.ui.input("[name='CommonCostDetailDO[" + i + "]$costContent']").setValue(isTimes[i].costContent);
  201. }
  202. if (isTimes[i].invoiceNums != '') {
  203. z.ui.input("[name='CommonCostDetailDO[" + i + "]$invoiceNums']").setValue(isTimes[i].invoiceNums);
  204. }
  205. if (isTimes[i].amount != '') {
  206. z.ui.input("[name='CommonCostDetailDO[" + i + "]$amount']").setValue(isTimes[i].amount);
  207. }
  208. if (!(!isTimes[i].bz1 || isTimes[i].bz1.trim() === '')) {
  209. z.ui.input("[name='CommonCostDetailDO[" + i + "]$bz1']").setValue(isTimes[i].bz1);
  210. }
  211. if (!(!isTimes[i].commonCostId || isTimes[i].commonCostId.trim() === '')) {
  212. $("#editBtn_" + i).find("span").html("编辑")
  213. detailReadonly(i, false)
  214. $("#qjsj_" + i).addClass("form-table-disable")
  215. }
  216. $("#selectProject_" + i).click(function () {
  217. detailProjectIndex = i;
  218. selectProject(null, setProject);
  219. })
  220. detailTotalInit(i)
  221. $("#editBtn_" + i).click(function () {
  222. const span = $(this).find("span");
  223. const html = span.html();
  224. if (html === '编辑') {
  225. span.html('保存')
  226. detailWrite(i);
  227. addDataThat.attr('disabled', "true");
  228. $("#qjsj_" + i).removeClass("form-table-disable")
  229. return;
  230. }
  231. if (html === '保存') {
  232. if(!$("[name='CommonCostDetailDO[" + i + "]$projectId']").val()){
  233. z.ui.alertWarning(`项目不能为空!`)
  234. return false;
  235. }
  236. lastProjectId = $("[name='CommonCostDetailDO[" + i + "]$projectId']").val();
  237. lastProjectName = z.ui.input("[name='CommonCostDetailDO[" + i + "]$projectName']").getValue();
  238. lastProjectDeptName = z.ui.input("[name='CommonCostDetailDO[" + i + "]$xmzrbm']").getValue();
  239. if(!z.ui.date("[name='CommonCostDetailDO[" + i + "]$costDate']").getValue()){
  240. z.ui.alertWarning(`发生日期不能为空!`)
  241. return false;
  242. }
  243. if(!$("[name='CommonCostDetailDO[" + i + "]$costType']").val()){
  244. z.ui.alertWarning(`费用实际所属类型不能为空!`)
  245. return false;
  246. }
  247. if(!z.ui.input("[name='CommonCostDetailDO[" + i + "]$costContent']").getValue()){
  248. z.ui.alertWarning(`发票内容不能为空!`)
  249. return false;
  250. }
  251. if(!z.ui.input("[name='CommonCostDetailDO[" + i + "]$invoiceNums']").getValue()){
  252. z.ui.alertWarning(`单据张数不能为空!`)
  253. return false;
  254. }
  255. if(!z.ui.input("[name='CommonCostDetailDO[" + i + "]$amount']").getValue()){
  256. z.ui.alertWarning(`金额不能为空!`)
  257. return false;
  258. }
  259. span.html('编辑')
  260. detailReadonly(i, false)
  261. addDataThat.removeAttr('disabled')
  262. $("#qjsj_" + i).addClass("form-table-disable")
  263. return;
  264. }
  265. })
  266. $("#delBtn_" + i).click(function () {
  267. z.ui.confirm("compid").init({
  268. content: "确定删除吗?",
  269. onConfirm: function () {
  270. var element = document.getElementById("qjsj_" + i);
  271. element.remove();
  272. buildQjsjSeq();
  273. isTimes = isTimes.splice(i, 1)
  274. jeSumInit(i);
  275. addDataThat.removeAttr('disabled')
  276. },
  277. onCancel: function () {
  278. }
  279. })
  280. })
  281. if (viewState === 'v' || (read === '1'&& finance != '1')) {
  282. detailReadonly(i)
  283. }
  284. }
  285. function detailReadonly(i, isBool = true) {
  286. if (isBool) {
  287. $("#delBtn_" + i).css("display", "none");
  288. $("#editBtn_" + i).css("display", "none");
  289. }
  290. $("[name='costType[" + i + "]']").addClass("z-readonly");
  291. $("#selectProject_" + i).css("pointer-events", "none");
  292. $("[name='costType[" + i + "]']").css("pointer-events", "none");
  293. let detailElement = document.getElementById("qjsj_" + i);
  294. let detailInput = detailElement.getElementsByTagName("input");
  295. for (let j = 0; j < detailInput.length; j++) {
  296. detailInput[j].disabled = true;
  297. detailInput[j].className += "z-readonly"
  298. }
  299. }
  300. function detailWrite(i) {
  301. //财务审核时可以核减修改金额
  302. $("[name='costType[" + i + "]']").removeClass("z-readonly");
  303. $("#selectProject_" + i).css("pointer-events", "auto");
  304. $("[name='costType[" + i + "]']").css("pointer-events", "auto");
  305. let detailElement = document.getElementById("qjsj_" + i);
  306. let detailInput = detailElement.getElementsByTagName("input");
  307. for (let j = 0; j < detailInput.length; j++) {
  308. detailInput[j].disabled = false;
  309. $(detailInput[j]).removeClass("z-readonly")
  310. }
  311. }
  312. function detailTotalInit(i) {
  313. let obj = {
  314. amount: "",
  315. bz1: "",
  316. commonCostId: "",
  317. costContent: "",
  318. costDate: "",
  319. createTime: "",
  320. id: "",
  321. invoiceNums: "",
  322. isvalid: "",
  323. latestModifyTime: "",
  324. projectId: "",
  325. projectName: "",
  326. projectDeptName: ""
  327. }
  328. let inpsJe = $("[name='CommonCostDetailDO[" + i + "]$amount']")[0].children[0]; //金额
  329. let inpsPj = $("[name='CommonCostDetailDO[" + i + "]$invoiceNums']")[0].children[0];//单据张数
  330. inpsJe.addEventListener("blur", e => {
  331. let event = e || window.event;
  332. let inputInfo = event.target.value;
  333. if (!(inputInfo > 0)) {
  334. z.ui.alertWarning(`金额不能为负数、0`)
  335. inpsJe.value = ''
  336. } else {
  337. obj.amount = inputInfo
  338. jeSumInit()
  339. }
  340. });
  341. inpsPj.addEventListener("blur", e => {
  342. let event = e || window.event;
  343. let inputInfo = event.target.value;
  344. if (!(inputInfo > 0) || (String(inputInfo).indexOf('.') > -1)) {
  345. z.ui.alertWarning(`单据张数不能为负数、0、小数`)
  346. inpsPj.value = ''
  347. } else {
  348. obj.invoiceNums = inputInfo
  349. }
  350. });
  351. }
  352. function jeSumInit(idx) {
  353. let jeSum = 0 //金额汇总
  354. for (let i = 0; i < isTimes.length; i++) {
  355. if (idx == i) {
  356. return
  357. } else {
  358. let inpsJe = $("[name='CommonCostDetailDO[" + i + "]$amount']")[0].children[0]; //金额
  359. jeSum += Number(inpsJe.value)
  360. }
  361. }
  362. z.ui.input("[name='createReqVO$totalAmount']").setValue(jeSum.toFixed(2));
  363. z.ui.input("[name='createReqVO$totalAmountCn']").setValue(convertCurrency(jeSum.toFixed(2)));
  364. }
  365. //注册业务保存事件
  366. function bindEvents() {
  367. z.workflow.saveBtn.addListener("onSaveClick", saveForm);
  368. }
  369. function buildQjsjSeq() {
  370. let elementsByName = document.getElementsByName("qjsj_seq");
  371. for (let i = 0; i < elementsByName.length; i++) {
  372. const seqElement = elementsByName[i];
  373. seqElement.innerHTML = i + 1;
  374. }
  375. }
  376. /*
  377. * all 工作流js传递到业务的参数 success执行的方法
  378. * istransfer 工作流js传递到业务的参数 是否转件
  379. * */
  380. function saveForm(all, istransfer) {
  381. var postData = z.ui.form.getFormFields($("[name=createReqVO]"));
  382. if (postData === false) {
  383. all({success: false});
  384. return;
  385. }
  386. postData.createReqVO.instanceId = z.ui.comm.getUrlParam("flowInstanceId");
  387. var detailList = new Array()
  388. for (let key of Object.keys(postData)) {
  389. let mealName = postData[key];
  390. if (key.startsWith("CommonCostDetailDO")) {
  391. mealName.costDate = Date.parse(mealName.costDate);
  392. detailList.push(z.ui.form.childStringify(mealName));
  393. }
  394. }
  395. if(finance === "1"){
  396. if(Number(postData.createReqVO.totalAmount) > Number(previousAmount)){
  397. all({success: false, errorMsg: "核减后金额不能大于原来金额!"});
  398. return;
  399. }
  400. //发生金额变化
  401. if(Number(postData.createReqVO.totalAmount) != Number(previousAmount)){
  402. let num = Number(previousAmount) - Number(postData.createReqVO.totalAmount);
  403. postData.createReqVO.bz3 = '发生了核减:'+'核减'+num+'(元)';
  404. postData.createReqVO.bz2 = num;
  405. }
  406. }
  407. postData.createReqVO.detailList = detailList;
  408. z.ui.ajax({
  409. type: "post",
  410. url: "/CommonCost/update",
  411. data: JSON.stringify(postData.createReqVO),
  412. contentType: "application/json",
  413. success: function () {
  414. all({success: true});
  415. },
  416. error: function () {
  417. all({success: false});
  418. }
  419. })
  420. }
  421. function setProject(res) {
  422. if (res.data) {
  423. $("[name='CommonCostDetailDO[" + detailProjectIndex + "]$projectId']").val(res.data.id);
  424. z.ui.input("[name='CommonCostDetailDO[" + detailProjectIndex + "]$projectName']").setValue(res.data.xmmc);
  425. z.ui.input("[name='CommonCostDetailDO[" + detailProjectIndex + "]$xmzrbm']").setValue(res.data.zrbm);
  426. }
  427. }
  428. function initCompany() {
  429. z.ui.ajax({
  430. type: "get",
  431. url: "/common/company-tree",
  432. data: {},
  433. success: function (res) {
  434. if (res && res.data.length > 0) {
  435. selecttree("[name='createReqVO$paymentCompany']", res.data, clickCompany)
  436. }
  437. },
  438. error: function () {
  439. }
  440. })
  441. }
  442. function clickCompany(even, treeId, treeNode) {
  443. $("[name='createReqVO$paymentCompanyId']").val(treeNode.id);
  444. }
  445. function clickCostType(even, treeId, treeNode) {
  446. $("[name='" + treeNode.treeName + "']").val(treeNode.id);
  447. }
  448. }());