price.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. , height: 600
  17. , text: '数据加载中'
  18. , id: 'tablerReload'
  19. , limit: 15
  20. , cols: [[ //表头
  21. {type: "checkbox", width: 50},
  22. {field: 'city_id', title: '区域ID', align: 'center', width: 50}
  23. , {field: 'city_name', title: '区域名称', align: 'center'}
  24. , {fixed: 'right', title: '操作', width: 165, align: 'center', toolbar: '#operate'}
  25. ]],
  26. done: function (res, curr, count) {
  27. var _btn = '<div class="layui-inline " style="float:left;position:absolute;left:10px;bottom:6px">'
  28. + '<a class="layui-btn layui-btn-danger search_btn layui_w_btn" style="height:30px;line-height:30px;font-size:14px;" lay-submit="" lay-filter="del_alls_Pricetrends">批量删除</a>'
  29. + '</div>'
  30. $('.layui-border-box').append(_btn)
  31. }
  32. });
  33. //列表操作
  34. table.on('tool(' + tableId + ')', function (obj) {
  35. var layEvent = obj.event,
  36. data = obj.data;
  37. if (layEvent === 'edit') {
  38. indexOpen = layui.layer.open({
  39. type: 2,
  40. title: '[<span style="color:red">' + data.city_name + '</span>]区域历史价格',
  41. area: ['', '100%'],
  42. content: '/pricetrend/recordprice?cid=' + data.city_id,
  43. success: function (layero, index) {
  44. }
  45. });
  46. layui.layer.full(indexOpen);
  47. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  48. $(window).on("resize", function () {
  49. layui.layer.full(indexOpen);
  50. })
  51. }
  52. // else if (layEvent === 'del') {
  53. // layer.confirm('您确定要删除吗?', {btn: ['确定', '取消']}, function () {
  54. // $.post('/categorycity/delform', {'id': data.id}, function (data) {
  55. //
  56. // if (data.code == 200) {
  57. // layer.msg(data.msg);
  58. // table.reload('tablerReload');
  59. //
  60. // } else if (data.code == 300) {
  61. // layer.msg(data.msg);
  62. // }
  63. // });
  64. // });
  65. // }
  66. else if (layEvent === 'add') {
  67. layer.open({
  68. type: 2,
  69. title: '添加价格',
  70. closeBtn: 1, //不显示关闭按钮
  71. shade: [0],
  72. area: ['780px', '550px'],
  73. anim: 2,
  74. content: '/pricetrend/lineadd?cid=' + data.city_id + '&city_name=' + data.city_name,
  75. });
  76. }
  77. });
  78. var $ = layui.$, active = {
  79. addData: function () { //获取选中数据
  80. layer.open({
  81. type: 2,
  82. title: '添加价格',
  83. closeBtn: 1, //不显示关闭按钮
  84. shade: [0],
  85. area: ['780px', '550px'],
  86. anim: 2,
  87. content: '/pricetrend/priceadd.html',
  88. });
  89. },
  90. reload: function () {//搜索
  91. var form = pfgs_serialize($('form'));
  92. var name = '';
  93. var house_name = '';
  94. if (form.input_house == 'name') {
  95. name = form.input_house_text;
  96. } else if (form.input_house == 'house_name') {
  97. house_name = form.input_house_text;
  98. }
  99. table.reload('tablerReload', {
  100. where: {
  101. title: name,
  102. house_name: form.input_house_text,
  103. city: form.province,
  104. type_name: form.type_name
  105. }
  106. })
  107. }
  108. };
  109. //日期
  110. laydate.render({
  111. elem: '#date1'
  112. });
  113. $('.demoTable .layui-btn').on('click', function () {
  114. var type = $(this).data('type');
  115. active[type] ? active[type].call(this) : '';
  116. });
  117. $('.The_house').focus(function () {
  118. indexOpen = parent.layui.layer.open({
  119. type: 2,
  120. title: '选择需要添加的区域',
  121. area: ['', '100%'],
  122. content: '/publicuse/cncity?type=1',
  123. success: function (layero, index) {
  124. },
  125. end: function () {
  126. }
  127. });
  128. parent.layui.layer.full(indexOpen);
  129. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  130. $(window).on("resize", function () {
  131. parent.layui.layer.full(indexOpen);
  132. })
  133. })
  134. form.on('submit(editcity)', function (data) {
  135. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  136. var formData = new FormData($('form')[0]);
  137. $.ajax({
  138. cache: true,
  139. type: "post",
  140. url: '/categorycity/edithomeform',
  141. data: formData, // 你的formid
  142. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  143. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  144. error: function (request) {
  145. layer.close(index); //关闭数据提交信息
  146. layer.alert("网络超时");
  147. },
  148. success: function (data) {
  149. if (data.data != null) {
  150. layer.msg(ReturnInfo(data.data), {icon: 5});
  151. return;
  152. }
  153. layer.msg(data.msg);
  154. parent.layui.table.reload('tablerReload');
  155. }
  156. });
  157. return false;
  158. });
  159. //添加
  160. form.on('submit(addcity)', function (data) {
  161. layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  162. var formData = new FormData($('form')[0]);
  163. $.ajax({
  164. cache: true,
  165. type: "post",
  166. url: '/pricetrend/priceaddform',
  167. data: formData, // 你的formid
  168. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  169. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  170. error: function (request) {
  171. layer.alert("网络超时");
  172. },
  173. success: function (data) {
  174. if (data.data != null) {
  175. layer.msg(ReturnInfo(data.data), {icon: 5});
  176. return;
  177. }
  178. layer.msg(data.msg);
  179. parent.layui.table.reload('tablerReload');
  180. }
  181. });
  182. return false;
  183. });
  184. form.on('submit(del_alls_Pricetrends)', function (data) {
  185. var checkStatus = table.checkStatus('tablerReload');
  186. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  187. if (typeof checkStatus.data[0] == 'object') {
  188. layer.confirm('您确定要删除吗?', {btn: ['确认', '取消']}, function () {
  189. var formdat = new FormData();
  190. $.each(checkStatus.data, function (key, val) {
  191. formdat.append('hid[]', val.city_id);
  192. })
  193. $.ajax({
  194. cache: true,
  195. type: "post",
  196. url: "/pricetrend/pricecityalldell",
  197. data: formdat, // 你的formid
  198. // async : false, //async 默认为true异步,修改为false为同步
  199. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  200. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  201. error: function (request) {
  202. layer.close(index); //关闭数据提交信息
  203. layer.alert("网络超时");
  204. },
  205. success: function (data) {
  206. if (data.code == 200) {
  207. layer.msg(data.msg);
  208. // reloadTable(reloadId);
  209. table.reload('tablerReload');
  210. } else {
  211. layer.msg(data.msg);
  212. }
  213. }
  214. });
  215. })
  216. return false;
  217. }
  218. layer.msg('请选择需要删除的楼盘', {icon: 5});
  219. return false;
  220. })
  221. //加载省数据
  222. function loadProvince() {
  223. $.ajax({
  224. url: '/categorycity/citypid',
  225. type: 'post',
  226. async: false,//使用同步的方式,true为异步方式
  227. data: {'pid': 0},//这里使用json对象
  228. success: function (data) {
  229. // console.log(data);
  230. var areaData = data.data;
  231. var proHtml = '';
  232. for (var i = 0; i < areaData.length; i++) {
  233. proHtml += '<option value="' + areaData[i].id + '">' + areaData[i].city_name + '</option>';
  234. }
  235. //初始化省数据
  236. $('select[name=province]').append(proHtml);
  237. form.render();
  238. },
  239. fail: function () {
  240. }
  241. });
  242. }
  243. loadProvince();
  244. });