layui和vue父子级页面及操作

最近在老项目里面添加一些页面,项目太老只能在原有的项目基础和插件上添加代码

html

html 复制代码
//表格        
<table id="dataTable">
   <thead>
      <tr><th>序号</th><th>名称</th><th></th></tr>
   </thead>
   <tbody></tbody>
</table>
<div id="pagination"></div>//layui分页

js

javascript 复制代码
<script>
    function toggleChildRow(rowId) {
        console.log(rowId,'rowId')
        var childRow = document.querySelector('.child-row[data-parent-id="'+rowId+'"]');
        var btn = document.querySelector('.toggle-btn[data-row="'+rowId+'"]');
        if(childRow.style.display === 'none') {
            childRow.style.display = 'table-row';
            btn.textContent = '▶';//展开
        } else {
            childRow.style.display = 'none';
            btn.textContent = '▼';//折叠
        }
    }
   function viewChildRow(row){//查看操作
        vue.rptCoProfileAccountList = []
        vue.rptCoProfileAccountList.push(row)
        vue.tlttt = '查看'
    }
  var vue = new Vue({//使用vue
        el: '#vue',
        data: {
           },
        computed: {

        },
        created(){
            this.getlist()//列表接口
        },
        methods: {
             getlist:function (){
                layui.table.render({
                    elem: '#pagination'//分页id
                    , url:'/api/rptCoProAccount/list'
                    , totalRow: true
                    ,id:'idTest'
                    , cols: []
                    , page: true
                    ,done: function(res, curr, count) {
                        vue.getsylist(res.data)//数据进行渲染
                    }
                });
            },
            getsylist:function(mockData){//数据渲染到页面
                var tbody = document.querySelector('#dataTable tbody');
                tbody.innerHTML = '';

                mockData.forEach((item,index) => {//数据循环
                    var parentRow = document.createElement('tr');
                    parentRow.className = 'parent-row';
                    parentRow.dataset.id = item.orgId;

                    var toggleCell = document.createElement('td');
                    toggleCell.innerHTML = '<button class="toggle-btn" data-                          row="'+item.orgId+'" onclick="toggleChildRow(\''+item.orgId+'\')">▼</button>';//展开按钮

                    var idCell = document.createElement('td');
                    idCell.textContent = index + 1;//序号

                    var nameCell = document.createElement('td');
                    nameCell.textContent = item.orgName;//名称

                    parentRow.append(idCell, nameCell, toggleCell);
                    tbody.appendChild(parentRow);
                      //子数据
                    if(item.children && item.children.length > 0) {
                        var childRow = document.createElement('tr');
                        childRow.className = 'child-row';
                        childRow.dataset.parentId = item.orgId;
                        childRow.style.display = 'none';

                        var containerCell = document.createElement('td');
                        containerCell.colSpan = 4;

                        var childTable = document.createElement('table');
                        childTable.className = 'child-table';

                        var thead = document.createElement('thead');
                        thead.innerHTML = '<tr><th>名称</th><th>开户行</th><th>开户行账号</th><th>操作</th></tr>';

                        var childTbody = document.createElement('tbody');
                        item.children.forEach(function(child) {
                            var row = document.createElement('tr');
                            row.innerHTML = '' +
                                '<td>' + child.accountName + '</td>' +
                                '<td>' + child.openingBank + '</td>'+
                                '<td>' + child.accountNum + '</td>'+
                                '<td> <a class="layui-btn layui-btn-xs" onclick="viewChildRow('+JSON.stringify(child).replace(/"/g, '&quot;')+')" lay-event="resetPwd">\n' +
                                '                <img src="../../../../assets/img/look.png" alt=""/>\n' +
                                '                <span>查看</span>\n' +
                                '            </a>\n' +
                                '            <a class="layui-btn layui-btn-xs" onclick="editChildRow('+JSON.stringify(child).replace(/"/g, '&quot;')+')" lay-event="edit">\n' +
                                '                <img src="../../../../assets/img/edit.png" alt=""/>\n' +
                                '                <span>修改</span>\n' +
                                '            </a>\n' +
                                '            <a class="layui-btn layui-btn-xs" onclick="scChildRow('+JSON.stringify(child).replace(/"/g, '&quot;')+')" lay-event="del">\n' +
                                '                <img src="../../../../assets/img/delete.png" alt="">\n' +
                                '                <span>删除</span>\n' +
                                '            </a></td>'
                            ;
                            childTbody.appendChild(row);
                        });

                        childTable.append(thead, childTbody);
                        containerCell.appendChild(childTable);
                        childRow.appendChild(containerCell);
                        tbody.appendChild(childRow);
                    }
                });
            },
        }
  })
</script>
相关推荐
云空4 分钟前
《Three.js 3D坦克对战【AI单机版】》
javascript·人工智能·3d·three.js
默_笙11 分钟前
🚲 手写一个"Claude Code":我用 LangChain + ReAct 循环,让 AI 自己读文件、解释代码
前端·javascript
星河耀银海24 分钟前
框架结合:Vue+HTML5+AI实现智能前端应用开发
前端·vue.js·html5
等咸鱼的狸猫1 小时前
# JS 核心六大主题:闭包内存模型、原型链查找、事件流机制与 Promise / Event Loop 实现视角复盘
前端·javascript
英勇无比的消炎药1 小时前
还在手写对话面板?TinyRobot Container 一个组件装下整个 AI 聊天
vue.js
gis开发之家2 小时前
vue3直击架构痛点 依赖倒置与接口隔离——打造坚如磐石的插件与高阶组件(HOC)模式
javascript·架构·typescript·前端框架·vue3
柒和远方2 小时前
LeetCode 139. 单词拆分 —— 从暴力回溯到 DP 完全背包
javascript·python·算法
用户2930750976692 小时前
流式输出:Vue 3 + DeepSeek API 实战
vue.js
先吃饱再说2 小时前
流式输出完全指南:让 AI 对话像打字机一样流畅
javascript·vue.js
এ慕ོ冬℘゜3 小时前
原生 JS 实现自定义单选日历组件(无 UI 库、纯手写、禁用过去日期)
开发语言·javascript·ui