currency.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. layui.use([ 'laypage', 'layer', 'table', 'element','form','upload'], function(){
  2. var layer = layui.layer //弹层
  3. ,table = layui.table //表格
  4. ,element = layui.element //元素操作
  5. ,form = layui.form
  6. ,upload = layui.upload;
  7. //第一个实例
  8. var indexTtable =table.render({
  9. elem: '#citylist'
  10. ,url: '/categorycity/currencyform' //数据接口
  11. ,where:{token:csrfToken}
  12. ,method:'post'
  13. ,page: true //开启分页
  14. ,height:600
  15. ,text:'数据加载中'
  16. ,id:'tablerReload'
  17. ,cols: [[ //表头
  18. // {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left',align:'center'},
  19. {type:'numbers'},
  20. {field: 'city_name', title: '区域',align:'center'}
  21. ,{field: 'currency', title: '货币标识',align:'center'}
  22. ,{field: 'nickname', title: '货币名称',align:'center'}
  23. ,{field: 'exchange', title: '汇率',align:'center'}
  24. ,{field: 'create_at', title: '添加时间', width:120,align:'center'}
  25. ,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'}
  26. ]]
  27. });
  28. indexTtable.reload('tablerReload'); //重新加载
  29. //列表操作
  30. table.on('tool(citylist)', function(obj){
  31. var layEvent = obj.event,
  32. data = obj.data;
  33. if(layEvent === 'edit'){
  34. layer.open({
  35. type: 2,
  36. title: '修改配套信息',
  37. closeBtn: 1, //不显示关闭按钮
  38. shade: [0],
  39. area: ['600px', '500px'],
  40. anim: 2,
  41. content: ['/categorycity/editcurrency?id='+data.id, 'yes'], //iframe的url,no代表不显示滚动条
  42. });
  43. } else if(layEvent === 'del') {
  44. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  45. $.post('/categorycity/delcurrency',{'id':data.id},function (data) {
  46. if(data.code == 200)
  47. {
  48. layer.msg(data.msg);
  49. table.reload('tablerReload');
  50. } else if(data.code == 300 ) {
  51. layer.msg(data.msg);
  52. }
  53. })
  54. })
  55. }
  56. });
  57. var $ = layui.$, active = {
  58. addData: function(){ //获取选中数据
  59. layer.open({
  60. type: 2,
  61. title: '添加',
  62. closeBtn: 1, //不显示关闭按钮
  63. shade: [0],
  64. area: ['600px', '500px'],
  65. anim: 2,
  66. content: '/categorycity/addcurrency', //iframe的url,no代表不显示滚动条
  67. });
  68. }
  69. };
  70. $('.demoTable .layui-btn').on('click', function(){
  71. var type = $(this).data('type');
  72. active[type] ? active[type].call(this) : '';
  73. });
  74. //修改
  75. form.on('submit(editcity)', function(data){
  76. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  77. var formData = new FormData($('form')[0]);
  78. $.ajax({
  79. cache : true,
  80. type : "post",
  81. url : '/categorycity/editcurrencyform',
  82. data : formData, // 你的formid
  83. // async : false, //async 默认为true异步,修改为false为同步
  84. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  85. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  86. error : function(request) {
  87. layer.close(index); //关闭数据提交信息
  88. layer.alert("网络超时");
  89. },
  90. success : function(data) {
  91. if (data.code == 200) {
  92. layer.msg(data.msg);
  93. parent.layui.table.reload('housefacilitieslist');
  94. TableClose();
  95. } else if(data.code == 300){
  96. layer.msg(data.msg);
  97. layer.msg(ReturnInfo(data.data));
  98. }
  99. }
  100. });
  101. return false;
  102. });
  103. //添加
  104. form.on('submit(addcity)', function(data){
  105. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  106. var formData = new FormData($('form')[0]);
  107. $.ajax({
  108. cache : true,
  109. type : "post",
  110. url : '/categorycity/addcurrencyform',
  111. data : formData, // 你的formid
  112. // async : false, //async 默认为true异步,修改为false为同步
  113. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  114. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  115. error : function(request) {
  116. layer.close(index); //关闭数据提交信息
  117. layer.alert("网络超时");
  118. },
  119. success : function(data) {
  120. if (data.code == 200) {
  121. layer.msg(data.msg);
  122. parent.layui.table.reload('tablerReload');
  123. // TableClose();
  124. } else if(data.code == 300){
  125. layer.msg(data.msg);
  126. layer.msg(ReturnInfo(data.data),{icon:5});
  127. }
  128. }
  129. });
  130. return false;
  131. });
  132. });