| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- ;
- layui.define(['form','table','element','laytpl','upload'], function (e) {
- var s = layui.$,
- l = (layui.layer, layui.laytpl, layui.setter, layui.view, layui.admin),
- table = layui.table,
- laytpl = layui.laytpl,
- form = layui.form,
- upload = layui.upload,
- pid = s('input[name=pid]').val(),
- position = 'admin';
- upload.render({
- elem: '.file'
- ,url: '/admin/file/upload'
- ,done: function(res){
- //上传完毕回调
- if (!res.code) {
- var name = s(this.item).data('name');
- s('input[name="'+name+'"]').val(res.data.src);
- s(this.item).attr('src',res.data.src);
- }
- }
- })
- //导航列表
- table.render({
- elem:'#navi-table'
- ,url:'load.html?level=2'
- ,where:{pid:pid,position:position}
- ,toolbar:'#topToolbar'
- ,cols: [[
- {field:'cname', title: '名称'}
- ,{field:'sort', title: '排序',edit: 'text'}
- ,{field:'action', title: '动作'}
- ,{title:'操作', fixed: 'right', width:250, align:'center', toolbar: '#toolbar'}
- ]]
- ,id: 'navi-table'
- ,page: false
- ,done:function(){
- position = s('select[name=position]').val();
- }
- });
- table.on('toolbar(navi)',function(obj){
- switch(obj.event){
- case "add":
- layer.open({
- type: 2,
- title: '添加导航',
- shadeClose: true,
- shade: true,
- area: ['80%', '80%'],
- content: 'add.html?position='+position+'&pid='+pid
- });
- break;
- }
- })
- table.on('tool(navi)', function(obj){
- var data = obj.data; //获得当前行数据
- var tr = obj.tr;
- switch(obj.event){
- case 'add':
- layer.open({
- type: 2,
- title: '添加导航',
- shadeClose: true,
- shade: true,
- area: ['80%', '80%'],
- content: 'add.html?position='+position+'&pid='+data['id']
- });
- break;
- case 'edit':
- layer.open({
- type: 2,
- title: '编辑导航',
- shadeClose: true,
- shade: true,
- area: ['80%', '80%'],
- content: 'edit.html?id='+data['id']
- });
- break;
- case 'delete':
- layer.confirm('您确定要删除该行数据吗?', {
- btn: ['确定','取消'] //按钮
- }, function(index){
- s.post('delete.html',{id:data['id']},function(r){
- if(r.code){
- layer.msg(r.msg);
- }else{
- obj.del();
- layer.close(index);
- }
- });
- });
- break;
- case 'children':
- location.href = Think.ADMIN+'/navi/index.html?position='+position+'&pid='+data['id'];
- break;
- }
- });
- table.on('edit(navi)', function(obj){
- var value = obj.value //得到修改后的值
- ,data = obj.data //得到所在行所有键值
- ,field = obj.field; //得到字段
- s.post(layui.setter.host + 'admin/navi/sort.html',{id:data.id,sort:value},function(r){
- if(!r.code){
- table.reload('navi-table')
- }else{
- layer.msg(r.msg);
- }
- });
- });
- form.on('select(position)',function(data){
- table.reload('navi-table',{
- where:{position:s('select[name=position]').val()}
- })
- })
- form.on('submit(LAY-navi-edit)',function(data){
- s.post('edit.html',data.field,function(r){
- if (!r.code) {
- var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
- parent.layer.close(index); //再执行关闭
- parent.layui.table.reload('navi-table')
- }else{
- layer.msg(r.msg)
- }
- });
- return false;
- });
- form.on('submit(LAY-navi-add)',function(data){
- var index = layer.load();
- s.post('add.html',data.field,function(r){
- if (!r.code) {
- var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
- parent.layer.close(index); //再执行关闭
- parent.layui.table.reload('navi-table')
- }else{
- layer.msg(r.msg)
- }
- layer.close(index);
- });
- return false;
- });
- e('navi', {})
- })
|