| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- layui.use([ 'element', 'table', 'laydate', 'form' ], function() {
- var $ = layui.jquery;
- var table = layui.table;
- var laydate = layui.laydate;
- var element = layui.element;
- var form = layui.form;
- // 生成表格
- table.render({
- elem : '#searchTable',
- url : '../../../getKeyWordsList',
- toolbar : '#toolbarDemo',
- title : '关键字表',// 导出文件名
- id : 'searchTableAll',
- // 开启分页
- page : {
- layout : [ 'count', 'prev', 'page', 'next', 'skip', 'limit' ]
- },
- /*request : {
- 'limitName' : 'pageSize' // 分页每页条数默认字段改为pageSize
- },*/
- where:{
- proTypeLabel :'',
- },
- cellMinWidth : 80, // 全局定义常规单元格的最小宽度,layui 2.2.1 新增
- cols : [ [ {
- type : 'numbers',
- title : '序号',
- width : 50,
- fixed : "left"
- },{
- field : 'proTypeLabel',
- width : 150,
- algin : 'center',
- title : '产品名称'
- },{
- field : 'likeProTypeLabel',
- title : '关键字',
- edit : 'text'
- },{
- field : 'url',
- title : '菜单URL',
- width : 250,
- edit : 'text'
- },{
- field : 'userStatus',
- title : '状态',
- width : 120,
- templet : '#statusTpl',
- },{
- field : 'createDate',
- title : '创建时间',
- width : 120,
- templet : function(d) {
- return d.createDate != null ?layui.util.toDateString(d.createDate, "yyyy-MM-dd") : "";
- }
- }, {
- field : 'updateDate',
- title : '更新时间',
- width : 120,
- templet : function(d) {
- return d.updateDate != null ?layui.util.toDateString(d.updateDate, "yyyy-MM-dd") : "";
- }
- } ] ],
- parseData : function(res) { //将原始数据解析成 table 组件所规定的数据
- return {
- "code" : 0, //解析接口状态
- "msg" : "", //解析提示文本
- "count" : res.total,//解析数据长度
- "data" : res.list//解析数据列表
- };
- }
- });
- //点击查询按钮,重载表格
- $('#searchBtn').on('click', function() {
- table.reload('searchTableAll', {
- method : 'post',
- where : {
- proTypeLabel : $("#proTypeLabel").val()
- },
- page : {
- curr : 1
- }
- });
- return false;
- });
-
- //监听状态按钮
- form.on('switch(statusDemo)', function(obj){
- layer.tips(this.value + ' ' + this.name + ':'+ obj.elem.checked, obj.othis);
- $.ajax({
- url : "../../../changeKeyWordsStatus",
- dataType : 'json',
- data : {
- 'id':obj.value
- },
- type : 'post',
- success : function(data) {
- if (data.code == 200) {
- layer.msg('状态修改成功!',{icon:6,offset:"auto",time:2000});//提示框
- }else{
- layer.msg('状态修改失败!',{icon:5,offset:"auto",time:2000});//提示框
- }
- setTimeout(function(){
- location.reload();//重新加载页面
- }, 2100);
- }
- })
- })
- // 监听头部工作栏的 新增
- table.on('toolbar(searchTable)', function(obj) {
- var checkStatus = table.checkStatus(obj.config.id);
- switch (obj.event) {
- case 'add':
- layer.open({
- type : 2,
- title : "添加产品关键字",
- fix: false, //不固定
- maxmin: true,
- area : [ '45%', '70%' ],
- content : './addSearchPro.jsp',
- });
- break;
- }
- ;
- });
- // 监听编辑关键字
- table.on('edit(searchTable)', function(obj){
- var value = obj.value, //得到修改后的值
- field = obj.field; //得到字段
- var data = obj.data,//得到所在行所有键值
- id = data.id;
- $.ajax({
- url:"../../../updateKeyWord",
- data:{
- id : id,
- value : value,
- field : field,
- },
- type:"post",
- //dataType:"json",
- success:function (data) {
- if (data.code == 200) {
- layer.msg('成功!',{icon:6,offset:"auto",time:1000});//提示框
- }else{
- layer.msg('失败!',{icon:5,offset:"auto",time:1000});//提示框
- }
- }
- });
- })
- });
|