tel.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. layui.use([ 'laypage', 'layer', 'table', 'element','form','treetable'], function(){
  2. var laypage = layui.laypage //分页
  3. ,$ = layui.jquery
  4. ,layer = layui.layer //弹层
  5. ,table = layui.table //表格
  6. ,element = layui.element //元素操作
  7. ,form = layui.form
  8. ,treetable = layui.treetable;
  9. //第一个实例
  10. table.render({
  11. elem: '#menulist'
  12. ,url: '/othertel/homeform' //数据接口
  13. ,where:{token:csrfToken}
  14. ,method:'post'
  15. ,page: true //开启分页
  16. ,height:600
  17. ,id:'tablerReload'
  18. ,limit:20
  19. ,text:'数据加载中'
  20. ,cols: [[ //表头
  21. {type:'numbers',title:'序号'}
  22. ,{field: 'name', title: '方案名称', align:'center',width:200}
  23. ,{field: 'tel', title: '内容',align:'left'}
  24. ,{title:'操作', width: 200 ,align:'center', toolbar: '#operate'}
  25. ]]
  26. });
  27. table.reload('tablerReload'); //重新加载
  28. if($('#citytellist').attr('lay-filter') == 'citytellist'){
  29. var renderTable = function (wheres = {}) {
  30. treetable.render({
  31. treeColIndex: 1,
  32. treeSpid:0,
  33. treeIdName: 'id',
  34. treePidName: 'pid',
  35. treeDefaultClose: true,
  36. treeLinkage: false,
  37. elem: '#citytellist',
  38. url: '/othertel/citytelhomeform',
  39. page: false,
  40. height:600,
  41. where:wheres,
  42. id:'tablerReload',
  43. cols: [[
  44. {type:'numbers'}
  45. // {field: 'id', title: 'ID', width:80, sort: true,align:'center'}
  46. ,{field: 'city_name', title: '区域名称',align:'center'}
  47. ,{field: 'name', title: '方案名称',align:'center'}
  48. ,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'}
  49. ]],
  50. done: function () {
  51. layer.closeAll('loading');
  52. }
  53. });
  54. };
  55. renderTable();
  56. }
  57. //列表操作
  58. table.on('tool(menulist)', function(obj){
  59. var layEvent = obj.event,
  60. data = obj.data;
  61. if(layEvent === 'edit'){
  62. layer.open({
  63. type: 2,
  64. title: '修改方案',
  65. closeBtn: 1, //不显示关闭按钮
  66. shade: [0],
  67. area: ['600px', '500px'],
  68. anim: 2,
  69. content:'/othertel/edit?id='+data.id,
  70. end:function () {
  71. table.reload('tablerReload');
  72. }
  73. });
  74. } else if(layEvent === 'del') {
  75. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  76. $.post('/othertel/del',{'id':data.id},function (data) {
  77. layer.msg(data.msg);
  78. table.reload('tablerReload');
  79. })
  80. })
  81. }else if(layEvent === 'tel_city'){
  82. layer.open({
  83. type: 2,
  84. title: '添加区域',
  85. closeBtn: 1, //不显示关闭按钮
  86. shade: [0],
  87. area: ['600px', '500px'],
  88. anim: 2,
  89. content:'/othertel/cityascription?id='+data.id, //iframe的url,no代表不显示滚动条
  90. });
  91. }
  92. });
  93. table.on('tool(citytellist)', function(obj){
  94. var layEvent = obj.event,
  95. data = obj.data;
  96. if(layEvent === 'tel_city'){
  97. layer.open({
  98. type: 2,
  99. title: '加载方案',
  100. closeBtn: 1, //不显示关闭按钮
  101. shade: [0],
  102. area: ['600px', '500px'],
  103. anim: 2,
  104. content:'/othertel/cityascription?id='+data.id,
  105. end:function () {
  106. renderTable();
  107. }
  108. });
  109. }
  110. });
  111. var $ = layui.$, active = {
  112. addData: function(){ //获取选中数据
  113. layer.open({
  114. type: 2,
  115. title: '添加电话',
  116. closeBtn: 1, //不显示关闭按钮
  117. shade: [0],
  118. area: ['600px', '500px'],
  119. anim: 2,
  120. content: '/othertel/add', //iframe的url,no代表不显示滚动条
  121. end: function(){ //此处用于演示
  122. table.reload('tablerReload');
  123. }
  124. });
  125. },
  126. reloadb:function () {
  127. var form = pfgs_serialize($('form'));
  128. var city = '';
  129. var name = '';
  130. if(form.province != ''){
  131. city = form.province;
  132. }
  133. if(form.name != ''){
  134. name = form.name;
  135. }
  136. // if(form.city != ''){
  137. // city = form.city;
  138. // }
  139. renderTable({id:city,name:name});
  140. }
  141. };
  142. $('.demoTable .layui-btn').on('click', function(){
  143. var type = $(this).data('type');
  144. active[type] ? active[type].call(this) : '';
  145. });
  146. form.on('submit(edittel)', function(data){
  147. $.post('/othertel/editform',{'data':data.field},function (data) {
  148. if(data.code == 200)
  149. {
  150. layer.msg(data.msg);
  151. parent.layui.table.reload('menulist');
  152. } else if(data.code == 300 ) {
  153. layer.msg(data.msg);
  154. layer.msg(ReturnInfo(data.data),{icon:5});
  155. }
  156. })
  157. return false;
  158. });
  159. form.on('submit(tijiao)', function(data){
  160. $.post('/othertel/addform',{'data':data.field},function (data) {
  161. if(data.code == 200)
  162. {
  163. layer.msg(data.msg);
  164. parent.layui.table.reload('menulist');
  165. // TableClose();
  166. } else if(data.code == 300 ) {
  167. layer.msg(data.msg);
  168. layer.msg(ReturnInfo(data.data),{icon:5});
  169. }
  170. })
  171. return false;
  172. });
  173. form.on('submit(unload_tel)', function(data){
  174. var index = top.layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  175. var formData = new FormData($('#cityForm')[0]);
  176. $.ajax({
  177. cache : true,
  178. type : "post",
  179. url : "/othertel/addcityascription",
  180. data : formData, // 你的formid
  181. async : false,
  182. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  183. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  184. error : function(request) {
  185. top.layer.close(index); //关闭数据提交信息
  186. layer.alert("网络超时");
  187. },
  188. success : function(data) {
  189. top.layer.close(index); //关闭数据提交信息
  190. if (data.code == 200) {
  191. layer.msg(data.msg);
  192. parent.layui.table.reload('menulist');
  193. // TableClose();
  194. } else if(data.code == 300){
  195. layer.msg(data.msg);
  196. if(data.data.length > 0){
  197. layer.msg(ReturnInfo(data.data),{icon:5});
  198. }
  199. }
  200. }
  201. });
  202. return false;
  203. });
  204. });