tel.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. var openid = null;
  10. //第一个实例
  11. table.render({
  12. elem: '#menulist'
  13. ,url: '/othertel/homeform' //数据接口
  14. ,where:{token:csrfToken}
  15. ,method:'post'
  16. ,page: true //开启分页
  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. ,{fixed: 'right',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. where:wheres,
  41. id:'tablerReload',
  42. cols: [[
  43. {type:'numbers'}
  44. // {field: 'id', title: 'ID', width:80, sort: true,align:'center'}
  45. ,{field: 'city_name', title: '区域名称',align:'center'}
  46. ,{field: 'name', title: '方案名称',align:'center'}
  47. ,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'}
  48. ]],
  49. done: function () {
  50. layer.closeAll('loading');
  51. $('.treeTable-icon').on('click',function(){
  52. var tid = $(this).attr('lay-tid');
  53. var ttype = $(this).attr('lay-ttype');
  54. if(ttype == 'dir' && openid != tid){
  55. openid = tid;
  56. }else{
  57. openid = null;
  58. }
  59. })
  60. if(openid){
  61. $('span[lay-tid='+openid+']').addClass('open');
  62. $('span[lay-tpid='+openid+']').each(function(){
  63. $(this).parents().parents().parents().attr('style','');
  64. });
  65. var ppid = $($('span[lay-tid='+openid+']')[0]).attr('lay-tpid');
  66. optable(ppid);
  67. }
  68. }
  69. });
  70. };
  71. renderTable();
  72. }
  73. //列表操作
  74. table.on('tool(menulist)', function(obj){
  75. var layEvent = obj.event,
  76. data = obj.data;
  77. if(layEvent === 'edit'){
  78. layer.open({
  79. type: 2,
  80. title: '修改方案',
  81. closeBtn: 1, //不显示关闭按钮
  82. shade: [0],
  83. area: ['600px', '500px'],
  84. anim: 2,
  85. content:'/othertel/edit?id='+data.id,
  86. end:function () {
  87. table.reload('tablerReload');
  88. }
  89. });
  90. } else if(layEvent === 'del') {
  91. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  92. $.post('/othertel/del',{'id':data.id},function (data) {
  93. layer.msg(data.msg);
  94. table.reload('tablerReload');
  95. })
  96. })
  97. }else if(layEvent === 'tel_city'){
  98. layer.open({
  99. type: 2,
  100. title: '添加区域',
  101. closeBtn: 1, //不显示关闭按钮
  102. shade: [0],
  103. area: ['600px', '500px'],
  104. anim: 2,
  105. content:'/othertel/cityascription?id='+data.id, //iframe的url,no代表不显示滚动条
  106. });
  107. }
  108. });
  109. table.on('tool(citytellist)', function(obj){
  110. var layEvent = obj.event,
  111. data = obj.data;
  112. if(layEvent === 'tel_city'){
  113. layer.open({
  114. type: 2,
  115. title: '加载方案',
  116. closeBtn: 1, //不显示关闭按钮
  117. shade: [0],
  118. area: ['600px', '500px'],
  119. anim: 2,
  120. content:'/othertel/cityascription?id='+data.id,
  121. end:function () {
  122. renderTable();
  123. }
  124. });
  125. }
  126. });
  127. var $ = layui.$, active = {
  128. addData: function(){ //获取选中数据
  129. layer.open({
  130. type: 2,
  131. title: '添加电话',
  132. closeBtn: 1, //不显示关闭按钮
  133. shade: [0],
  134. area: ['600px', '500px'],
  135. anim: 2,
  136. content: '/othertel/add', //iframe的url,no代表不显示滚动条
  137. end: function(){ //此处用于演示
  138. table.reload('tablerReload');
  139. }
  140. });
  141. },
  142. reloadb:function () {
  143. var form = pfgs_serialize($('form'));
  144. var city = '';
  145. var name = '';
  146. if(form.province != ''){
  147. city = form.province;
  148. }
  149. if(form.name != ''){
  150. name = form.name;
  151. }
  152. // if(form.city != ''){
  153. // city = form.city;
  154. // }
  155. renderTable({id:city,name:name});
  156. }
  157. };
  158. $('.demoTable .layui-btn').on('click', function(){
  159. var type = $(this).data('type');
  160. active[type] ? active[type].call(this) : '';
  161. });
  162. form.on('submit(edittel)', function(data){
  163. $.post('/othertel/editform',{'data':data.field},function (data) {
  164. if(data.code == 200)
  165. {
  166. layer.msg(data.msg);
  167. parent.layui.table.reload('menulist');
  168. } else if(data.code == 300 ) {
  169. layer.msg(data.msg);
  170. layer.msg(ReturnInfo(data.data),{icon:5});
  171. }
  172. })
  173. return false;
  174. });
  175. form.on('submit(tijiao)', function(data){
  176. $.post('/othertel/addform',{'data':data.field},function (data) {
  177. if(data.code == 200)
  178. {
  179. layer.msg(data.msg);
  180. parent.layui.table.reload('menulist');
  181. // TableClose();
  182. } else if(data.code == 300 ) {
  183. layer.msg(data.msg);
  184. layer.msg(ReturnInfo(data.data),{icon:5});
  185. }
  186. })
  187. return false;
  188. });
  189. form.on('submit(unload_tel)', function(data){
  190. var index = top.layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  191. var formData = new FormData($('#cityForm')[0]);
  192. $.ajax({
  193. cache : true,
  194. type : "post",
  195. url : "/othertel/addcityascription",
  196. data : formData, // 你的formid
  197. async : false,
  198. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  199. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  200. error : function(request) {
  201. top.layer.close(index); //关闭数据提交信息
  202. layer.alert("网络超时");
  203. },
  204. success : function(data) {
  205. top.layer.close(index); //关闭数据提交信息
  206. if (data.code == 200) {
  207. layer.msg(data.msg);
  208. parent.layui.table.reload('menulist');
  209. // TableClose();
  210. } else if(data.code == 300){
  211. layer.msg(data.msg);
  212. if(data.data.length > 0){
  213. layer.msg(ReturnInfo(data.data),{icon:5});
  214. }
  215. }
  216. }
  217. });
  218. return false;
  219. });
  220. form.on('select(province)',function (data) {
  221. var type= data.value;
  222. table.reload('tablerReload',{
  223. where:{token:csrfToken,city:type}
  224. ,method:'post'
  225. });
  226. });
  227. function optable(ppid){
  228. if(ppid != 0){
  229. $('span[lay-tid='+ppid+']').addClass('open');
  230. $('span[lay-tpid='+ppid+']').each(function(){
  231. $(this).parents().parents().parents().attr('style','');
  232. });
  233. var ppid = $($('span[lay-tid='+ppid+']')[0]).attr('lay-tpid');
  234. optable(ppid);
  235. }
  236. }
  237. });