label.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. layui.use(['laypage', 'layer', 'table', 'element', 'form'], function () {
  2. var laypage = layui.laypage //分页
  3. , layer = layui.layer //弹层
  4. , table = layui.table //表格
  5. , element = layui.element //元素操作
  6. , form = layui.form
  7. , $ = layui.jquery;
  8. var tableIds = 'laballist'; //表格ID
  9. var reloadId = 'tablerReload';
  10. var type = $('input[name=type]').val();
  11. //第一个实例
  12. var tableIns = table.render({
  13. elem: '#' + tableIds
  14. , url: '/dictionarya/labelform' //数据接口
  15. , where: {token: csrfToken, type: type}
  16. , method: 'post'
  17. , page: true //开启分页
  18. , text: '数据加载中'
  19. , id: reloadId
  20. , limit: 20
  21. , cols: [[ //表头
  22. // {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left',align:'center'},
  23. {type: 'numbers'},
  24. {field: 'name', title: '物业类型', align: 'center'}
  25. , {
  26. field: 'sort',
  27. title: '排序',
  28. width: 200,
  29. align: 'center',
  30. event: 'sortData',
  31. edit: 'text',
  32. sort: true,
  33. templet: "#sortBox"
  34. }
  35. , {
  36. field: 'state', title: '审核', align: 'center', width: 100, templet: function (d) {
  37. if (d.state == 2) {
  38. return '<input type="checkbox" value="' + d.id + '" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  39. } else {
  40. return '<input type="checkbox" checked value="' + d.id + '" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  41. }
  42. }
  43. }
  44. , {fixed: 'right', title: '操作', width: 180, align: 'center', toolbar: '#operate'}
  45. ]]
  46. });
  47. table.reload('tablerReload'); //重新加载
  48. //监听指定开关
  49. form.on('switch(switchTest)', function (data) {
  50. layer.confirm('确定要修改此操作吗?', {btn: ['确定', '取消']}, function () {
  51. $.post('/dictionarya/setlabel', {id: data.value, type: 'show'}, function (data) {
  52. layer.msg(data.msg);
  53. table.reload('tablerReload');
  54. })
  55. }, function (aa) {
  56. table.reload('tablerReload'); //重新加载
  57. })
  58. });
  59. //列表操作
  60. table.on('tool(' + tableIds + ')', function (obj) {
  61. var layEvent = obj.event,
  62. data = obj.data;
  63. if (layEvent === 'edit') {
  64. layer.open({
  65. type: 2,
  66. title: '修改标签',
  67. area: ['600px', '500px'],
  68. content: '/dictionarya/labeledit?id=' + data.id, //iframe的url,no代表不显示滚动条
  69. end: function () {
  70. table.reload('tablerReload');
  71. }
  72. });
  73. } else if (layEvent === 'del') {
  74. layer.confirm('您确定要删除吗?', {btn: ['确定', '取消']}, function () {
  75. $.post('/dictionarya/labeldel', {'id': data.id}, function (data) {
  76. if (data.code == 200) {
  77. layer.msg(data.msg);
  78. table.reload('tablerReload');
  79. } else if (data.code == 300) {
  80. layer.msg(data.msg);
  81. }
  82. })
  83. })
  84. } else if (layEvent === 'sortData') { //修改排序
  85. /* 列表操作 edit 修改后执行 2018.7.24*/
  86. table.on('edit(' + tableIds + ')', function (obj) {
  87. var data = obj.data;
  88. $.post('/dictionarya/setlabel', {id: data.id, type: 'sort', sort: data.sort}, function (data) {
  89. if (data.code == 200) {
  90. layer.msg(data.msg);
  91. } else if (data.code == 300) {
  92. layer.msg(data.msg);
  93. }
  94. })
  95. })
  96. }
  97. });
  98. var $ = layui.$, active = {
  99. addData: function () { //获取选中数据
  100. layer.open({
  101. type: 2,
  102. title: '添加标签',
  103. area: ['600px', '500px'],
  104. content: '/dictionarya/labeladd?type=' + type, //iframe的url,no代表不显示滚动条
  105. end: function () {
  106. table.reload('tablerReload');
  107. }
  108. });
  109. // var checkStatus = table.checkStatus('idTest')
  110. // ,data = checkStatus.data;
  111. // layer.alert(JSON.stringify(data));
  112. }
  113. };
  114. $('.demoTable .layui-btn').on('click', function () {
  115. var type = $(this).data('type');
  116. active[type] ? active[type].call(this) : '';
  117. });
  118. //修改
  119. form.on('submit(editlabel)', function (data) {
  120. $.post('/dictionarya/labeleditform', {'data': data.field, 'token': csrfToken}, function (data) {
  121. if (data.code == 200) {
  122. layer.msg(data.msg);
  123. } else if (data.code == 300) {
  124. layer.msg(data.msg);
  125. }
  126. })
  127. return false;
  128. });
  129. //添加
  130. form.on('submit(addlabel)', function (data) {
  131. $.post('/dictionarya/labeladdform', {'data': data.field, 'token': csrfToken}, function (data) {
  132. if (data.code == 200) {
  133. layer.msg(data.msg);
  134. $("input[name='name']").val('');
  135. } else if (data.code == 300) {
  136. layer.msg(data.msg);
  137. }
  138. })
  139. return false;
  140. });
  141. });