price.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. layui.use([ 'laypage', 'layer', 'table', 'element','form','upload','laydate'], function(){
  2. var laypage = layui.laypage //分页
  3. ,$ = layui.jquery
  4. ,layer = layui.layer //弹层
  5. ,table = layui.table //表格
  6. ,form = layui.form
  7. ,laydate = layui.laydate;
  8. var tableId = 'citylist';
  9. //第一个实例
  10. table.render({
  11. elem: '#'+tableId
  12. ,url: '/pricetrend/homeform' //数据接口
  13. ,where:{token:csrfToken}
  14. ,method:'post'
  15. ,page: true //开启分页
  16. ,text:'数据加载中'
  17. ,id:'tablerReload'
  18. ,height : 600
  19. ,limit:15
  20. ,cols: [[ //表头
  21. {type:'numbers'}
  22. ,{field: 'city_name', title: '区域名称',align:'center'}
  23. ,{field: 'count', title: '价格数量',align:'center'}
  24. ,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'}
  25. ]]
  26. });
  27. //列表操作
  28. table.on('tool('+tableId+')', function(obj){
  29. var layEvent = obj.event,
  30. data = obj.data;
  31. if(layEvent === 'edit'){
  32. indexOpen = layui.layer.open({
  33. type: 2,
  34. title: '[<span style="color:red">'+data.city_name+'</span>]区域历史价格',
  35. area: ['','100%'],
  36. content: '/pricetrend/recordprice?cid='+data.city_id,
  37. success:function (layero, index) {
  38. }
  39. });
  40. layui.layer.full(indexOpen);
  41. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  42. $(window).on("resize",function(){
  43. layui.layer.full(indexOpen);
  44. })
  45. } else if(layEvent === 'del') {
  46. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  47. $.post('/categorycity/delform',{'id':data.id},function (data) {
  48. if(data.code == 200)
  49. {
  50. layer.msg(data.msg);
  51. table.reload('tablerReload');
  52. } else if(data.code == 300 ) {
  53. layer.msg(data.msg);
  54. }
  55. });
  56. });
  57. }else if(layEvent === 'add') {
  58. layer.open({
  59. type: 2,
  60. title: '添加价格',
  61. closeBtn: 1, //不显示关闭按钮
  62. shade: [0],
  63. area: ['780px', '550px'],
  64. anim: 2,
  65. content: '/pricetrend/lineadd?cid='+data.city_id+'&city_name='+data.city_name,
  66. });
  67. }
  68. });
  69. var $ = layui.$, active = {
  70. addData: function(){ //获取选中数据
  71. layer.open({
  72. type: 2,
  73. title: '添加价格',
  74. closeBtn: 1, //不显示关闭按钮
  75. shade: [0],
  76. area: ['780px', '550px'],
  77. anim: 2,
  78. content: '/pricetrend/priceadd.html',
  79. });
  80. },
  81. reload:function () {
  82. var formdara = pfgs_serialize($('form'));
  83. table.reload('tablerReload',{
  84. where:{
  85. city_id:formdara.input_city
  86. }
  87. })
  88. // console.log(formdara);
  89. }
  90. };
  91. //日期
  92. laydate.render({
  93. elem: '#date1'
  94. });
  95. $('.demoTable .layui-btn').on('click', function(){
  96. var type = $(this).data('type');
  97. active[type] ? active[type].call(this) : '';
  98. });
  99. $('.The_house').focus(function(){
  100. indexOpen = parent.layui.layer.open({
  101. type: 2,
  102. title: '选择需要添加的区域',
  103. area: ['','100%'],
  104. content: '/publicuse/city?type=1',
  105. success:function (layero, index) {
  106. },
  107. end:function(){
  108. }
  109. });
  110. parent.layui.layer.full(indexOpen);
  111. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  112. $(window).on("resize",function(){
  113. parent.layui.layer.full(indexOpen);
  114. })
  115. })
  116. form.on('submit(editcity)', function(data){
  117. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  118. var formData = new FormData($('form')[0]);
  119. $.ajax({
  120. cache : true,
  121. type : "post",
  122. url : '/categorycity/edithomeform',
  123. data : formData, // 你的formid
  124. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  125. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  126. error : function(request) {
  127. layer.close(index); //关闭数据提交信息
  128. layer.alert("网络超时");
  129. },
  130. success : function(data) {
  131. if(data.data != null){
  132. layer.msg(ReturnInfo(data.data),{icon:5});
  133. return ;
  134. }
  135. layer.msg(data.msg);
  136. parent.layui.table.reload('tablerReload');
  137. }
  138. });
  139. return false;
  140. });
  141. //添加
  142. form.on('submit(addcity)', function(data){
  143. layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  144. var formData = new FormData($('form')[0]);
  145. $.ajax({
  146. cache : true,
  147. type : "post",
  148. url : '/pricetrend/priceaddform',
  149. data : formData, // 你的formid
  150. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  151. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  152. error : function(request) {
  153. layer.alert("网络超时");
  154. },
  155. success : function(data) {
  156. if(data.data != null){
  157. layer.msg(ReturnInfo(data.data),{icon:5});
  158. return ;
  159. }
  160. layer.msg(data.msg);
  161. parent.layui.table.reload('tablerReload');
  162. }
  163. });
  164. return false;
  165. });
  166. });