123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427 |
- var ExcelData;
- function ConfirmImport() {
- $.ajax({
- type: "POST",
- url: "/Admin/Col/Import?r=" + Math.random(1),
- data: "ExcelData=" + encodeURIComponent(JSON.stringify(ExcelData)),
- dataType: "text",
- success: function (data) {
- if (data == "success") {
- layer.msg("导入成功", { time: 2000 }, function () {
- window.location.reload();
- });
- } else {
- layer.msg(data);
- }
- }
- });
- }
- layui.config({
- base: '/layuiadmin/' //静态资源所在路径
- }).extend({
- myexcel: 'layui/lay/modules/excel',
- index: 'lib/index' //主入口模块
- }).use(['index', 'table', 'excel', 'laydate', 'treeTable'], function () {
- var $ = layui.$
- , form = layui.form
- , table = layui.table
- , treeTable = layui.treeTable;
- //- 筛选条件-日期
- var laydate = layui.laydate;
- //excel导入
- var excel = layui.excel;
- $('#ExcelFile').change(function (e) {
- var files = e.target.files;
- excel.importExcel(files, {}, function (data) {
- ExcelData = data[0].Sheet1;
- });
- });
- //监听单元格编辑
- table.on('edit(LAY-list-manage)', function (obj) {
- var value = obj.value //得到修改后的值
- , data = obj.data //得到所在行所有键值
- , field = obj.field; //得到字段
- if (field == "Sort") {
- $.ajax({
- type: "POST",
- url: "/Admin/Col/Sort?r=" + Math.random(1),
- data: "Id=" + data.Id + "&Sort=" + value,
- dataType: "text",
- success: function (data) {
- }
- });
- }
- });
- //列表数据
- // table.render({
- // elem: '#LAY-list-manage'
- // , url: '/Admin/Col/IndexData' //模拟接口
- // , where: { CurColId: CurColId }
- // , cols: [[
- // { type: 'checkbox', fixed: 'left' }
- // , { field: 'Id', fixed: 'left', title: 'ID', width: 80, sort: true, unresize: true }
- // , { field: 'ColId', title: '编码' }
- // , { field: 'ColName', title: '名称' }
- // , { field: 'Status', title: '状态' }
- // , { field: 'Sort', fixed: 'right', title: '排序', width: 80, edit: 'text' }
- // , { title: '操作', width: 370, align: 'center', fixed: 'right', toolbar: '#table-list-tools' }
- // ]]
- // , page: true
- // , limit: 3000
- // , height: 'full'
- // , text: '对不起,加载出现异常!'
- // , done: function (res, curr, count) {
- // $(".layui-none").text("无数据");
- // }
- // });
- var re = treeTable.render({
- elem: '#LAY-list-manage',
- url: '/Admin/Col/IndexData?CurColId='+CurColId,
- icon_key: 'title',
- is_checkbox: true,
- end: function(e){
- form.render();
- },
- cols: [
- {
- key: 'title',
- title: '名称',
- template: function(item){
- return '<span style="color:#333;">'+item.title+'</span>';
- }
- },
- {
- key: 'id',
- title: 'ID',
- width: '100px',
- align: 'center',
- },
- {
- key: 'pid',
- title: '父ID',
- width: '100px',
- align: 'center',
- },
- {
- key: 'Status',
- title: '状态',
- width: '100px',
- align: 'center',
- },
- {
- title: '操作',
- width: '350px',
- align: 'center',
- template: function (item) {
- var tmp = '';
- tmp += '<a class="layui-btn layui-btn-primary layui-btn-xs" lay-filter="addsub">添加子栏目</a>';
- tmp += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-filter="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>';
- tmp += '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-filter="del"><i class="layui-icon layui-icon-delete"></i>删除</a>';
- tmp += '<a class="layui-btn layui-btn-normal layui-btn-xs" href="'+item.url+'" target="_blank">预览</a>';
- tmp += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-href="/Admin/ColFields/Index?ColId='+item.id+'&right='+right+'">字段管理</a>';
- return tmp;
- }
- }
- ]
- });
- treeTable.on('tree(addsub)', function (res) {
- var data = res.item;
- if (data.ColId.length >= 12) {
- layer.msg("请勿创建超过3级栏目,如有需要请联系管理员");
- return;
- }
- var perContent = layer.open({
- type: 2
- , title: '分类设置-添加子栏目'
- , content: 'Add?CurColId=' + CurColId + '&PColId=' + data.ColId
- , maxmin: false
- , area: ['500px', '450px']
- , btn: ['确定', '取消']
- , yes: function (index, layero) {
- var iframeWindow = window['layui-layer-iframe' + index]
- , submitID = 'LAY-list-front-submit'
- , submit = layero.find('iframe').contents().find('#' + submitID);
- //详细内容
- iframeWindow.Contentsedit.sync();
- //监听提交
- iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
- var field = data.field; //获取提交的字段
- var userdata = "";
- for (var prop in field) {
- userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
- }
- //提交 Ajax 成功后,静态更新表格中的数据
- //$.ajax({});
- $.ajax({
- type: "POST",
- url: "/Admin/Col/Add?r=" + Math.random(1),
- data: userdata,
- dataType: "text",
- success: function (data) {
- layer.close(index); //关闭弹层
- if (data == "success") {
- treeTable.render(re);
- } else {
- layer.msg(data);
- }
- }
- });
- });
- submit.trigger('click');
- }
- });
- layer.full(perContent);
- });
- treeTable.on('tree(edit)', function (res) {
- var data = res.item;
- var perContent = layer.open({
- type: 2
- , title: '分类设置-编辑'
- , content: 'Edit?CurColId=' + CurColId + '&PColId=' + data.ColId.substring(0, data.ColId.length - 3) + '&ColId=' + data.ColId
- , maxmin: false
- , area: ['500px', '450px']
- , btn: ['确定', '取消']
- , yes: function (index, layero) {
- var iframeWindow = window['layui-layer-iframe' + index]
- , submitID = 'LAY-list-front-submit'
- , submit = layero.find('iframe').contents().find('#' + submitID);
-
- //详细内容
- iframeWindow.Contentsedit.sync();
- //监听提交
- iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
- var field = data.field; //获取提交的字段
- var userdata = "";
- for (var prop in field) {
- userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
- }
- //提交 Ajax 成功后,静态更新表格中的数据
- //$.ajax({});
- $.ajax({
- type: "POST",
- url: "/Admin/Col/Edit?r=" + Math.random(1),
- data: userdata,
- dataType: "text",
- success: function (data) {
- layer.close(index); //关闭弹层
- if (data == "success") {
- treeTable.render(re);
- } else {
- layer.msg(data);
- }
- }
- });
- });
- submit.trigger('click');
- }
- , success: function (layero, index) {
- }
- });
- layer.full(perContent);
- });
- treeTable.on('tree(del)', function (res) {
- var data = res.item;
- layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
- $.ajax({
- type: "POST",
- url: "/Admin/Col/Delete?r=" + Math.random(1),
- data: "Id=" + data.id,
- dataType: "text",
- success: function (data) {
- if (data == "success") {
- treeTable.render(re);
- layer.close(index);
- } else {
- parent.layer.msg(data);
- }
- }
- });
- });
- });
- treeTable.on('tree(status)', function (res) {
- console.log(res);
- });
- //事件
- var active = {
- batchdel: function () {
- var ids = treeTable.checked(re).join(',');
- if (ids == '') {
- parent.layer.msg("请选择要删除的项");
- } else {
- var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
- $.ajax({
- type: "POST",
- url: "/Admin/Col/Delete?r=" + Math.random(1),
- data: "Id=" + ids,
- dataType: "text",
- success: function (data) {
- layer.close(index);
- if (data == "success") {
- treeTable.render(re);
- } else {
- layer.msg(data);
- }
- }
- });
- });
- }
- }
- , add: function () {
- var perContent = layer.open({
- type: 2
- , title: '分类设置-添加'
- , content: 'Add?CurColId=' + CurColId
- , maxmin: true
- , area: ['500px', '450px']
- , btn: ['确定', '取消']
- , yes: function (index, layero) {
- var iframeWindow = window['layui-layer-iframe' + index]
- , submitID = 'LAY-list-front-submit'
- , submit = layero.find('iframe').contents().find('#' + submitID);
- if (CurColId.substring(1, 3) == '001' || CurColId.substring(1, 3) == '002' || CurColId.substring(1, 3) == '003') {
- //详细内容
- iframeWindow.Contentsedit.sync();
- }
- //监听提交
- iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
- var field = data.field; //获取提交的字段
- var userdata = "";
- for (var prop in field) {
- userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
- }
- //提交 Ajax 成功后,静态更新表格中的数据
- //$.ajax({});
- $.ajax({
- type: "POST",
- url: "/Admin/Col/Add?r=" + Math.random(1),
- data: userdata,
- dataType: "text",
- success: function (data) {
- layer.close(index); //关闭弹层
- if (data == "success") {
- treeTable.render(re);
- } else {
- layer.msg(data);
- }
- }
- });
- });
- submit.trigger('click');
- }
- });
- layer.full(perContent);
- }
- , ImportData: function () {
- layer.open({
- type: 2,
- title: '导入',
- maxmin: false,
- area: ['460px', '180px'],
- content: $('#excelForm'),
- cancel: function () {
- }
- });
- }
- , ExportExcel: function () {
- var userdata = '';
- $(".layuiadmin-card-header-auto input").each(function (i) {
- userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
- });
- $(".layuiadmin-card-header-auto select").each(function (i) {
- userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
- });
- $.ajax({
- type: "GET",
- url: "/Admin/Col/ExportExcel?r=" + Math.random(1),
- data: userdata,
- dataType: "json",
- success: function (data) {
- data.Obj.unshift(data.Fields);
- excel.exportExcel(data.Obj, data.Info, 'xlsx');
- }
- });
- }
- , Open: function () {
- var ids = treeTable.checked(re).join(',');
- if (ids == '') {
- parent.layer.msg("请选择要开启的项");
- } else {
- var index = layer.confirm('确定要开启吗?', function (index) {
- $.ajax({
- type: "POST",
- url: "/Admin/Col/Open?r=" + Math.random(1),
- data: "Id=" + ids,
- dataType: "text",
- success: function (data) {
- layer.close(index);
- if (data == "success") {
- treeTable.render(re);
- } else {
- layer.msg(data);
- }
- }
- });
- });
- }
- }
- , Close: function () {
- var ids = treeTable.checked(re).join(',');
- if (ids == '') {
- parent.layer.msg("请选择要关闭的项");
- } else {
- var index = layer.confirm('确定要关闭吗?', function (index) {
- $.ajax({
- type: "POST",
- url: "/Admin/Col/Close?r=" + Math.random(1),
- data: "Id=" + ids,
- dataType: "text",
- success: function (data) {
- layer.close(index);
- if (data == "success") {
- treeTable.render(re);
- } else {
- layer.msg(data);
- }
- }
- });
- });
- }
- }
- , Unfold: function () {
- treeTable.openAll(re);
- }
- , PackUp: function () {
- treeTable.closeAll(re);
- }
- };
- $('.layui-btn').on('click', function () {
- var type = $(this).data('type');
- active[type] ? active[type].call(this) : '';
- });
- });
|