function createRoleList(arr, isAdd, $row) { var name = arr[0].name; var account = arr[0].id; var code = arr[0].code; var title = arr[0].title || ''; if (isAdd) { var list = $("#tpl-list"); var html = list.html(); html = html.replace("%{item.name}", name); html = html.replace("%{item.title}", title); html = html.replace("%{item.id}", account); html = html.replace("%{item.code}", code); html = html.replace("%{item.duty}", ""); html = html.replace("%{item.price}", ""); html = html.replace("%{item.hours}", ""); html = html.replace("%{item.ffbz}", ""); html = html.replace("%{item.ffyj}", ""); let titleIndex = layui.$('.roleMoney').children().length; html = html.replaceAll("%{item.titleIndex}", titleIndex); if (!!$row) { html = html.replace("%{item.addShow}", "none"); html = html.replace("%{item.delShow}", "block"); $row.after(html); } else { html = html.replace("%{item.addShow}", "block"); html = html.replace("%{item.delShow}", "none"); $(".roleMoney").append(html); } xmSelect.render({ el: '#sessionState' + titleIndex, name: 'title', data: xnUtil.getDictDataByDictTypeCode('professional_title', null), layVerify: 'required', layVerType: 'tips', radio: true, clickClose: true, model: {icon: 'hidden', label: {type: 'text'}}, prop: { name: 'name', value: 'code' }, tips: '请选择职称' }, {async: false}); } else { var row = $(".role-row"); for (var i = 0; i < row.length; i++) { var val = row.eq(i).find(".role>a").text(); if (name === val) { row[i].remove(); } } } } let role = []; if (editData !== null && editData !== undefined) { form.val('addOrUpdateForm', editData); var row = JSON.parse(editData.roleAllowance); let repetition = unquire(row, 'account') allowance(repetition) function allowance(row) { for (var j = 0; j < row.length; j++) { role.push(row[j][0]) for (var i = 0; i < row[j].length; i++) { var list = $("#tpl-list"); var html = list.html(); html = html.replace("%{item.id}", row[j][i].account); html = html.replace("%{item.name}", row[j][i].name); html = html.replace("%{item.title}", row[j][i].title); html = html.replace("%{item.duty}", row[j][i].duty); html = html.replace("%{item.code}", row[j][i].code || ""); html = html.replace("%{item.price}", row[j][i].price); html = html.replace("%{item.hours}", row[j][i].hours); html = html.replace("%{item.ffbz}", row[j][i].ffbz); html = html.replace("%{item.ffyj}", row[j][i].ffyj); let titleIndex = layui.$('.roleMoney').children().length; html = html.replaceAll("%{item.titleIndex}", titleIndex); if (row[j][i] == row[j][0]) { //判断数组除第一项外都是删除 html = html.replace("%{item.addShow}", "block"); html = html.replace("%{item.delShow}", "none"); } else { html = html.replace("%{item.addShow}", "none"); html = html.replace("%{item.delShow}", "block"); } $(".roleMoney").append(html); var titles = xmSelect.render({ el: '#sessionState' + titleIndex, name: 'title', data: xnUtil.getDictDataByDictTypeCode('professional_title', null), layVerify: 'required', layVerType: 'tips', initValue: row[j][i].title ? [row[j][i].title] : [], radio: true, clickClose: true, model: {icon: 'hidden', label: {type: 'text'}}, prop: { name: 'name', value: 'code' }, tips: '请选择职称' }, {async: false}); } } } roleAllowanceInc.setValue(role); parent.setValue([{"name": editData.pidName, "id": editData.pid}]); $("#type").val(editData.type); $("#name").val(editData.name); $("#remark").val(editData.remark); parent.setValue([{"pidName": editData.parentName, "pid": editData.parent}]); budgetDepartment.setValue(JSON.parse(editData.budgetDepartment)); approver.setValue([{"name": editData.spName, "account": editData.spCode}]); layui.form.render(); //主要处理方式 function unquire(arr, key) {//把相同的数组放到一起 let concatArr = [] arr.sort((a, b) => { var x = a[key].toLowerCase(); var y = b[key].toLowerCase(); if (x < y) return -1 if (x > y) return 1; return 0; }); //排序 for (let i = 0; i < arr.length; i++) { if (arr[0][key] === arr[arr.length - 1][key]) { //如果第一项等于最后一项 , 代表整个数组都相同 concatArr.push(arr) break; } else if (arr[0][key] !== arr[i][key]) { //获取与第一项不同的元素的下标 concatArr.push(arr.splice(0, i)) //将数组截取 concatArr.push(...unquire(arr, key)) //截取后的数组进行递归 , 由于上一步用的为push , 所以返回的为复杂数组[[]] , 所以需要使用展开运算符进行扁平化 break; } } return concatArr } }
表单新增列的图标,以及编辑表单时的渲染列后面的添加和删除的图标
最新推荐文章于 2024-08-16 22:57:43 发布