123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464 |
- (function () {
- var addDataThat = null;
- let isTimes = []
- let viewState = z.ui.comm.getUrlParam("_o");
- let read = z.ui.comm.getUrlParam("read");
- let finance = z.ui.comm.getUrlParam("finance");
- let detailProjectIndex = 0;
- let previousAmount = z.ui.input("[name='createReqVO$totalAmount']").getValue();
- let costTypeJSON = JSON.parse(document.querySelector('#costTypeJSON').value)
- let lastProjectId = '';
- let lastProjectName = '';
- let lastProjectDeptName = '';
- window.onload = function (ex) {
- let timeObject = document.querySelector('#detailList')
- let arrays = JSON.parse(timeObject.value)
- addDataThat = $("#addData")
- $("#addData").click(function () {
- addDataThat.attr('disabled', "true");
- let obj = {
- amount: "",
- bz1: "",
- costType: "",
- commonCostId: "",
- costContent: "",
- costDate: "",
- createTime: "",
- id: "",
- invoiceNums: "",
- isvalid: "",
- latestModifyTime: "",
- projectId: "",
- projectName: "",
- projectDeptName: ""
- }
- isTimes.push(obj)
- generateTableTrHtml(isTimes.length - 1)
- buildQjsjSeq();
- })
- $("#selectProject").click(function () {
- selectProject(null, setProject);
- })
- initCompany();
- bindEvents();
- //根据返回的json对象渲染
- if (arrays.length > 0) {
- for (let i = 0; i < arrays.length; i++) {
- let obj = {
- amount: arrays[i].amount || '',
- bz1: arrays[i].bz1 || '',
- costType: arrays[i].costType || '',
- commonCostId: arrays[i].commonCostId || '',
- costContent: arrays[i].costContent || '',
- costDate: arrays[i].costDate || '',
- createTime: arrays[i].createTime || '',
- id: arrays[i].id || '',
- invoiceNums: arrays[i].invoiceNums || '',
- isvalid: arrays[i].isvalid || '',
- latestModifyTime: arrays[i].latestModifyTime || '',
- projectId: arrays[i].projectId || '',
- projectName: arrays[i].projectName || '',
- projectDeptName: arrays[i].projectDeptName || ''
- }
- isTimes.push(obj)
- }
- for (let i = 0; i < isTimes.length; i++) {
- generateTableTrHtml(i);
- }
- }
- let bz2 = z.ui.input("[name='createReqVO$bz2']").getValue();
- if(finance === "1"){
- if(!bz2){
- bz2 = 0;
- }
- let amount = Number(previousAmount) + Number(bz2);
- let previousHtml = "(原金额:"+ amount.toFixed(2) +")"
- $("#previousAmount").text(previousHtml)
- }
- if(bz2){
- let amount = Number(previousAmount) + Number(bz2);
- let previousHtml = "(原金额:"+ amount.toFixed(2) +")"
- $("#previousAmount").text(previousHtml)
- }
- }
- function generateTableTrHtml(i) {
- var trDom = document.createElement("tr");
- trDom.style.backgroundColor = "#fff";
- trDom.id = "qjsj_" + i;
- trDom.className = 'qjsjClass'
- trDom.innerHTML = '<td name="qjsj_seq">' + (i + 1) + '</td>'
- + '<td>'
- + '<div class="form-flex">'
- + '<div class="form-item" style="width: 100%;margin-right: 5px;">'
- + '<input type="hidden" name="CommonCostDetailDO[' + i + ']$projectId" value="">'
- + '<div class="z-comp-input z-readonly" id="selectProject_' + i + '" name="CommonCostDetailDO[' + i + ']$projectName">'
- + '<input readonly type="text" value="">'
- + '</div>'
- + '</div>'
- + '</div>'
- + '</td>'
- + '<td>'
- + '<div class="form-item">'
- + '<div class="z-comp-input z-readonly" name="CommonCostDetailDO[' + i + ']$xmzrbm">'
- + '<input readonly type="text" value="">'
- + '</div>'
- + '</div>'
- + '</td>'
- + '<td>'
- + '<div class="form-flex">'
- + '<div class="form-item" style="width: 100%;margin-right: 5px;">'
- + '<div class="z-comp-date" name="CommonCostDetailDO[' + i + ']$costDate">'
- + '<input type="text" value="">'
- + '</div>'
- + '</div>'
- + '</div>'
- + '</td>'
- + '<td>'
- + '<div class="form-flex">'
- + '<div class="form-item" style="width: 100%;margin-right: 5px;">'
- + '<div class="z-comp-selecttree" name="costType[' + i + ']">'
- + '<input type="hidden" name="CommonCostDetailDO[' + i + ']$costType">'
- + '<div class="z-inputselect-bar">'
- + '<span></span><i></i>'
- + '</div>'
- + '</div>'
- + '</div>'
- + '</div>'
- + '</td>'
- + '<td>'
- + '<div class="form-item">'
- + '<div class="z-comp-input" name="CommonCostDetailDO[' + i + ']$costContent">'
- + '<input type="text" value="">'
- + '</div>'
- + '</div>'
- + '</td>'
- + '<td>'
- + '<div class="form-item">'
- + '<div class="z-comp-input" name="CommonCostDetailDO[' + i + ']$invoiceNums">'
- + '<input type="number" value="">'
- + '</div>'
- + '</div>'
- + '</td>'
- + '<td>'
- + '<div class="form-item">'
- + '<div class="z-comp-input" name="CommonCostDetailDO[' + i + ']$amount">'
- + '<input type="number" value="">'
- + '</div>'
- + '</div>'
- + '</td>'
- + '<td>'
- + '<div class="form-item">'
- + '<div class="z-comp-input" name="CommonCostDetailDO[' + i + ']$bz1">'
- + '<input type="text" value="">'
- + '</div>'
- + '</div>'
- + '</td>'
- + '<td>'
- + '<div style="display: flex;white-space: nowrap">'
- + '<div id="editBtn_' + (i) + '" style="margin: 0 10px" class="table-btn editBtn_' + (i) + '" data-index="' + (i) + '">'
- + '<span>保存</span>'
- + '</div>'
- + '<div id="delBtn_' + (i) + '" style="margin: 0 10px" class="table-btn delBtn_' + (i) + '" data-index="' + (i) + '">'
- + '<span>删除</span>'
- + '</div>'
- + '</div>'
- + '</td>';
- let trFragment = document.createDocumentFragment();
- trFragment.appendChild(trDom);
- $(".tbody").append(trFragment)
- costTypeJSON.forEach(obj => {
- obj.treeName = 'CommonCostDetailDO[' + i + ']$costType';
- })
- selecttree("[name='costType[" + i + "]']", costTypeJSON, clickCostType, allowChildClick)
- z.ui.date("[name='CommonCostDetailDO[" + i + "]$costDate']").init()
- if (!(!isTimes[i].costType || isTimes[i].costType.trim() === '')) {
- z.ui.selecttree("[name='costType[" + i + "]']").setValue(isTimes[i].costType)
- $("[name='CommonCostDetailDO[" + i + "]$costType']").val(isTimes[i].costType);
- }
- if(!(!lastProjectId || lastProjectId.trim() === '')){
- $("[name='CommonCostDetailDO[" + i + "]$projectId']").val(lastProjectId);
- }
- if(!(!lastProjectName || lastProjectName.trim() === '')){
- z.ui.input("[name='CommonCostDetailDO[" + i + "]$projectName']").setValue(lastProjectName);
- }
- if(!(!lastProjectDeptName || lastProjectDeptName.trim() === '')){
- z.ui.input("[name='CommonCostDetailDO[" + i + "]$xmzrbm']").setValue(lastProjectDeptName);
- }
- if (!(!isTimes[i].projectId || isTimes[i].projectId.trim() === '')) {
- $("[name='CommonCostDetailDO[" + i + "]$projectId']").val(isTimes[i].projectId);
- }
- if (!(!isTimes[i].projectName || isTimes[i].projectName.trim() === '')) {
- z.ui.input("[name='CommonCostDetailDO[" + i + "]$projectName']").setValue(isTimes[i].projectName);
- }
- if (!(!isTimes[i].projectDeptName || isTimes[i].projectDeptName.trim() === '')) {
- z.ui.input("[name='CommonCostDetailDO[" + i + "]$xmzrbm']").setValue(isTimes[i].projectDeptName);
- }
- if (!(!isTimes[i].costDate || isTimes[i].costDate.trim() === '')) {
- z.ui.date("[name='CommonCostDetailDO[" + i + "]$costDate']").setValue(isTimes[i].costDate);
- }
- if (!(!isTimes[i].costContent || isTimes[i].costContent.trim() === '')) {
- z.ui.input("[name='CommonCostDetailDO[" + i + "]$costContent']").setValue(isTimes[i].costContent);
- }
- if (isTimes[i].invoiceNums != '') {
- z.ui.input("[name='CommonCostDetailDO[" + i + "]$invoiceNums']").setValue(isTimes[i].invoiceNums);
- }
- if (isTimes[i].amount != '') {
- z.ui.input("[name='CommonCostDetailDO[" + i + "]$amount']").setValue(isTimes[i].amount);
- }
- if (!(!isTimes[i].bz1 || isTimes[i].bz1.trim() === '')) {
- z.ui.input("[name='CommonCostDetailDO[" + i + "]$bz1']").setValue(isTimes[i].bz1);
- }
- if (!(!isTimes[i].commonCostId || isTimes[i].commonCostId.trim() === '')) {
- $("#editBtn_" + i).find("span").html("编辑")
- detailReadonly(i, false)
- $("#qjsj_" + i).addClass("form-table-disable")
- }
- $("#selectProject_" + i).click(function () {
- detailProjectIndex = i;
- selectProject(null, setProject);
- })
- detailTotalInit(i)
- $("#editBtn_" + i).click(function () {
- const span = $(this).find("span");
- const html = span.html();
- if (html === '编辑') {
- span.html('保存')
- detailWrite(i);
- addDataThat.attr('disabled', "true");
- $("#qjsj_" + i).removeClass("form-table-disable")
- return;
- }
- if (html === '保存') {
- if(!$("[name='CommonCostDetailDO[" + i + "]$projectId']").val()){
- z.ui.alertWarning(`项目不能为空!`)
- return false;
- }
- lastProjectId = $("[name='CommonCostDetailDO[" + i + "]$projectId']").val();
- lastProjectName = z.ui.input("[name='CommonCostDetailDO[" + i + "]$projectName']").getValue();
- lastProjectDeptName = z.ui.input("[name='CommonCostDetailDO[" + i + "]$xmzrbm']").getValue();
- if(!z.ui.date("[name='CommonCostDetailDO[" + i + "]$costDate']").getValue()){
- z.ui.alertWarning(`发生日期不能为空!`)
- return false;
- }
- if(!$("[name='CommonCostDetailDO[" + i + "]$costType']").val()){
- z.ui.alertWarning(`费用实际所属类型不能为空!`)
- return false;
- }
- if(!z.ui.input("[name='CommonCostDetailDO[" + i + "]$costContent']").getValue()){
- z.ui.alertWarning(`发票内容不能为空!`)
- return false;
- }
- if(!z.ui.input("[name='CommonCostDetailDO[" + i + "]$invoiceNums']").getValue()){
- z.ui.alertWarning(`单据张数不能为空!`)
- return false;
- }
- if(!z.ui.input("[name='CommonCostDetailDO[" + i + "]$amount']").getValue()){
- z.ui.alertWarning(`金额不能为空!`)
- return false;
- }
- span.html('编辑')
- detailReadonly(i, false)
- addDataThat.removeAttr('disabled')
- $("#qjsj_" + i).addClass("form-table-disable")
- return;
- }
- })
- $("#delBtn_" + i).click(function () {
- z.ui.confirm("compid").init({
- content: "确定删除吗?",
- onConfirm: function () {
- var element = document.getElementById("qjsj_" + i);
- element.remove();
- buildQjsjSeq();
- isTimes = isTimes.splice(i, 1)
- jeSumInit(i);
- addDataThat.removeAttr('disabled')
- },
- onCancel: function () {
- }
- })
- })
- if (viewState === 'v' || (read === '1'&& finance != '1')) {
- detailReadonly(i)
- }
- }
- function detailReadonly(i, isBool = true) {
- if (isBool) {
- $("#delBtn_" + i).css("display", "none");
- $("#editBtn_" + i).css("display", "none");
- }
- $("[name='costType[" + i + "]']").addClass("z-readonly");
- $("#selectProject_" + i).css("pointer-events", "none");
- $("[name='costType[" + i + "]']").css("pointer-events", "none");
- let detailElement = document.getElementById("qjsj_" + i);
- let detailInput = detailElement.getElementsByTagName("input");
- for (let j = 0; j < detailInput.length; j++) {
- detailInput[j].disabled = true;
- detailInput[j].className += "z-readonly"
- }
- }
- function detailWrite(i) {
- //财务审核时可以核减修改金额
- $("[name='costType[" + i + "]']").removeClass("z-readonly");
- $("#selectProject_" + i).css("pointer-events", "auto");
- $("[name='costType[" + i + "]']").css("pointer-events", "auto");
- let detailElement = document.getElementById("qjsj_" + i);
- let detailInput = detailElement.getElementsByTagName("input");
- for (let j = 0; j < detailInput.length; j++) {
- detailInput[j].disabled = false;
- $(detailInput[j]).removeClass("z-readonly")
- }
- }
- function detailTotalInit(i) {
- let obj = {
- amount: "",
- bz1: "",
- commonCostId: "",
- costContent: "",
- costDate: "",
- createTime: "",
- id: "",
- invoiceNums: "",
- isvalid: "",
- latestModifyTime: "",
- projectId: "",
- projectName: "",
- projectDeptName: ""
- }
- let inpsJe = $("[name='CommonCostDetailDO[" + i + "]$amount']")[0].children[0]; //金额
- let inpsPj = $("[name='CommonCostDetailDO[" + i + "]$invoiceNums']")[0].children[0];//单据张数
- inpsJe.addEventListener("blur", e => {
- let event = e || window.event;
- let inputInfo = event.target.value;
- if (!(inputInfo > 0)) {
- z.ui.alertWarning(`金额不能为负数、0`)
- inpsJe.value = ''
- } else {
- obj.amount = inputInfo
- jeSumInit()
- }
- });
- inpsPj.addEventListener("blur", e => {
- let event = e || window.event;
- let inputInfo = event.target.value;
- if (!(inputInfo > 0) || (String(inputInfo).indexOf('.') > -1)) {
- z.ui.alertWarning(`单据张数不能为负数、0、小数`)
- inpsPj.value = ''
- } else {
- obj.invoiceNums = inputInfo
- }
- });
- }
- function jeSumInit(idx) {
- let jeSum = 0 //金额汇总
- for (let i = 0; i < isTimes.length; i++) {
- if (idx == i) {
- return
- } else {
- let inpsJe = $("[name='CommonCostDetailDO[" + i + "]$amount']")[0].children[0]; //金额
- jeSum += Number(inpsJe.value)
- }
- }
- z.ui.input("[name='createReqVO$totalAmount']").setValue(jeSum.toFixed(2));
- z.ui.input("[name='createReqVO$totalAmountCn']").setValue(convertCurrency(jeSum.toFixed(2)));
- }
- //注册业务保存事件
- function bindEvents() {
- z.workflow.saveBtn.addListener("onSaveClick", saveForm);
- }
- function buildQjsjSeq() {
- let elementsByName = document.getElementsByName("qjsj_seq");
- for (let i = 0; i < elementsByName.length; i++) {
- const seqElement = elementsByName[i];
- seqElement.innerHTML = i + 1;
- }
- }
- /*
- * all 工作流js传递到业务的参数 success执行的方法
- * istransfer 工作流js传递到业务的参数 是否转件
- * */
- function saveForm(all, istransfer) {
- var postData = z.ui.form.getFormFields($("[name=createReqVO]"));
- if (postData === false) {
- all({success: false});
- return;
- }
- postData.createReqVO.instanceId = z.ui.comm.getUrlParam("flowInstanceId");
- var detailList = new Array()
- for (let key of Object.keys(postData)) {
- let mealName = postData[key];
- if (key.startsWith("CommonCostDetailDO")) {
- mealName.costDate = Date.parse(mealName.costDate);
- detailList.push(z.ui.form.childStringify(mealName));
- }
- }
- if(finance === "1"){
- if(Number(postData.createReqVO.totalAmount) > Number(previousAmount)){
- all({success: false, errorMsg: "核减后金额不能大于原来金额!"});
- return;
- }
- //发生金额变化
- if(Number(postData.createReqVO.totalAmount) != Number(previousAmount)){
- let num = Number(previousAmount) - Number(postData.createReqVO.totalAmount);
- postData.createReqVO.bz3 = '发生了核减:'+'核减'+num+'(元)';
- postData.createReqVO.bz2 = num;
- }
- }
- postData.createReqVO.detailList = detailList;
- z.ui.ajax({
- type: "post",
- url: "/CommonCost/update",
- data: JSON.stringify(postData.createReqVO),
- contentType: "application/json",
- success: function () {
- all({success: true});
- },
- error: function () {
- all({success: false});
- }
- })
- }
- function setProject(res) {
- if (res.data) {
- $("[name='CommonCostDetailDO[" + detailProjectIndex + "]$projectId']").val(res.data.id);
- z.ui.input("[name='CommonCostDetailDO[" + detailProjectIndex + "]$projectName']").setValue(res.data.xmmc);
- z.ui.input("[name='CommonCostDetailDO[" + detailProjectIndex + "]$xmzrbm']").setValue(res.data.zrbm);
- }
- }
- function initCompany() {
- z.ui.ajax({
- type: "get",
- url: "/common/company-tree",
- data: {},
- success: function (res) {
- if (res && res.data.length > 0) {
- selecttree("[name='createReqVO$paymentCompany']", res.data, clickCompany)
- }
- },
- error: function () {
- }
- })
- }
- function clickCompany(even, treeId, treeNode) {
- $("[name='createReqVO$paymentCompanyId']").val(treeNode.id);
- }
- function clickCostType(even, treeId, treeNode) {
- $("[name='" + treeNode.treeName + "']").val(treeNode.id);
- }
- }());
|