housingprice.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. , form = layui.form
  7. , treetable = layui.treetable;
  8. var tableId = 'citylist';
  9. if ($('#citylist').attr('lay-filter') == 'citylist') {
  10. var renderTable = function (wheres = {}) {
  11. layer.load(2);
  12. treetable.render({
  13. treeColIndex: 1,
  14. treeSpid: 0,
  15. treeIdName: 'id',
  16. treePidName: 'pid',
  17. treeDefaultClose: true,
  18. treeLinkage: false,
  19. elem: '#citylist',
  20. url: '/pricetrend/housingpriceform',
  21. page: false,
  22. where: wheres,
  23. id: 'tablerReload',
  24. cols: [[
  25. {type: 'numbers'}
  26. , {field: 'city_name', title: '区域名称', align: 'center', width:1200}
  27. // , {field: 'update_at', title: '更新时间', width: 300, align: 'center'}
  28. , {fixed: 'right', title: '操作', width: 300, align: 'center', toolbar: '#operate'}
  29. ]],
  30. done: function () {
  31. layer.closeAll('loading');
  32. var sz = false;
  33. $('.treeTable-icon').on('click', function () {
  34. if ($(this).attr('lay-tpid') == 0) {
  35. sessionStorage.setItem("key", $(this).attr('lay-tid'));
  36. if (sz) {
  37. sessionStorage.removeItem("erzi");
  38. }
  39. } else {
  40. sz = true;
  41. if ($(this).attr('lay-tid') == sessionStorage.getItem("erzi")) {
  42. sessionStorage.removeItem("erzi");
  43. } else {
  44. sessionStorage.setItem("erzi", $(this).attr('lay-tid'));
  45. }
  46. }
  47. });
  48. if (sessionStorage.getItem("key") != null) {
  49. var laytid = sessionStorage.getItem("key");
  50. $('span[lay-tid=' + laytid + ']').addClass('open');
  51. if (sessionStorage.getItem("erzi") != null) {
  52. var elaytid = sessionStorage.getItem("erzi");
  53. sz = true;
  54. }
  55. $('span[lay-tpid=' + laytid + ']').each(function () {
  56. $(this).parents().parents().parents().attr('style', '');
  57. if (sz) {
  58. $('span[lay-tid=' + elaytid + ']').addClass('open');
  59. $('span[lay-tpid=' + elaytid + ']').each(function () {
  60. $(this).parents().parents().parents().attr('style', '');
  61. });
  62. }
  63. });
  64. }
  65. }
  66. });
  67. };
  68. renderTable();
  69. }
  70. //列表操作
  71. table.on('tool(' + tableId + ')', function (obj) {
  72. var layEvent = obj.event,
  73. data = obj.data;
  74. switch (layEvent) {
  75. case 'add':
  76. layer.open({
  77. type: 2,
  78. title: '新增区域价格走势',
  79. closeBtn: 1, //不显示关闭按钮
  80. shade: [0],
  81. area: ['800px', '600px'],
  82. anim: 2,
  83. content: ['/pricetrend/housingpriceadd?cid=' + data.id + '&city_name=' + data.city_name, 'yes'],
  84. end: function () {
  85. renderTable();
  86. }
  87. });
  88. break;
  89. case 'see':
  90. layer.open({
  91. type: 2,
  92. title: '[<span style="color:red">'+data.city_name+'</span>]区域价格走势',
  93. area: ['100%','100%'],
  94. content: '/pricetrend/recordprice?cid='+data.id,
  95. success:function (layero, index) {
  96. }
  97. });
  98. break;
  99. }
  100. });
  101. var $ = layui.$, active = {
  102. addData: function () { //获取选中数据
  103. layer.open({
  104. type: 2,
  105. title: '添加区域',
  106. closeBtn: 1, //不显示关闭按钮
  107. shade: [0],
  108. area: ['780px', '550px'],
  109. anim: 2,
  110. content: '/categorycity/addhome?son=1',
  111. });
  112. },
  113. reload: function () {
  114. var form = pfgs_serialize($('form'));
  115. var city = '';
  116. if (form.province != '') {
  117. city = form.province;
  118. }
  119. if (form.city != '') {
  120. city = form.city;
  121. }
  122. renderTable({id: city});
  123. }
  124. };
  125. $('.demoTable .layui-btn').on('click', function () {
  126. var type = $(this).data('type');
  127. active[type] ? active[type].call(this) : '';
  128. });
  129. //显示或隐藏
  130. form.on('switch(switchTest)', function (data) {
  131. var state = '';
  132. if (data.elem.name == 1) {
  133. state = 2;
  134. } else if (data.elem.name == 2) {
  135. state = 1;
  136. }
  137. layer.confirm('确定要修改此操作吗?', {btn: ['确定', '取消']}, function () {
  138. $.post('/categorycity/editall', {id: data.value, state: state}, function (data) {
  139. if (data.data != null) {
  140. layer.msg(ReturnInfo(data.data), {icon: 5});
  141. return false;
  142. }
  143. layer.msg(data.msg);
  144. renderTable();
  145. })
  146. }, function (aa) {
  147. renderTable();
  148. })
  149. });
  150. //修改排序
  151. table.on('edit(' + tableId + ')', function (obj) {
  152. var data = obj.data;
  153. $.post('/categorycity/editall', {id: data.id, sort: data.sort}, function (data) {
  154. if (data.data != null) {
  155. layer.msg(ReturnInfo(data.data), {icon: 5});
  156. return false;
  157. }
  158. layer.msg(data.msg);
  159. })
  160. })
  161. form.on('submit(editcity)', function (data) {
  162. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  163. var formData = new FormData($('form')[0]);
  164. $.ajax({
  165. cache: true,
  166. type: "post",
  167. url: '/categorycity/edithomeform',
  168. data: formData, // 你的formid
  169. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  170. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  171. error: function (request) {
  172. layer.close(index); //关闭数据提交信息
  173. layer.alert("网络超时");
  174. },
  175. success: function (data) {
  176. if (data.data != null) {
  177. layer.msg(ReturnInfo(data.data), {icon: 5});
  178. return;
  179. }
  180. layer.msg(data.msg);
  181. renderTable();
  182. }
  183. });
  184. return false;
  185. });
  186. //添加
  187. form.on('submit(addcity)', function (data) {
  188. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  189. $.post('/categorycity/addcityform', {'data': data.field}, function (data) {
  190. if (data.data != null) {
  191. layer.msg(ReturnInfo(data.data), {icon: 5});
  192. return;
  193. }
  194. layer.msg(data.msg);
  195. renderTable();
  196. })
  197. return false;
  198. });
  199. //加载省数据
  200. function loadProvince() {
  201. $.ajax({
  202. url: '/categorycity/citypid',
  203. type: 'post',
  204. async: false,//使用同步的方式,true为异步方式
  205. data: {'pid': 0},//这里使用json对象
  206. success: function (data) {
  207. // console.log(data);
  208. var areaData = data.data;
  209. var proHtml = '';
  210. for (var i = 0; i < areaData.length; i++) {
  211. proHtml += '<option value="' + areaData[i].id + '">' + areaData[i].city_name + '</option>';
  212. }
  213. //初始化省数据
  214. $('select[name=province]').append(proHtml);
  215. form.render();
  216. },
  217. fail: function () {
  218. }
  219. });
  220. }
  221. loadProvince();
  222. form.on('select(province)', function (data) {
  223. $.post('/categorycity/citypid', {'pid': data.value}, function (data) {
  224. var areaData = data.data;
  225. var proHtml = '';
  226. $('select[name=city]').html('');
  227. proHtml = '<option value="">请选择市/区/县</option>';
  228. for (var i = 0; i < areaData.length; i++) {
  229. proHtml += '<option value="' + areaData[i].id + '">' + areaData[i].city_name + '</option>';
  230. }
  231. //初始化省数据
  232. $('select[name=city]').append(proHtml);
  233. form.render();
  234. })
  235. })
  236. // 转换拼音
  237. $('.layui_w_name').on('keyup ', function () {
  238. var _txt = $(this).val();
  239. var _convert = pinyinUtil.getPinyin(_txt, ' ', false).replace(/\s/g, "");
  240. $('.layui_w_spell').val(_convert)
  241. })
  242. });