123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- layui.use(['laypage', 'layer', 'table', 'element', 'form', 'upload', 'laydate'], function () {
- var laypage = layui.laypage //分页
- , $ = layui.jquery
- , layer = layui.layer //弹层
- , table = layui.table //表格
- , form = layui.form
- , laydate = layui.laydate;
- var tableId = 'citylist';
- //第一个实例
- table.render({
- elem: '#' + tableId
- , url: '/pricetrend/homeform' //数据接口
- , where: {token: csrfToken}
- , method: 'post'
- , page: true //开启分页
- , height: 600
- , text: '数据加载中'
- , id: 'tablerReload'
- , limit: 15
- , cols: [[ //表头
- {type: "checkbox", width: 50},
- {field: 'city_id', title: '区域ID', align: 'center', width: 50}
- , {field: 'city_name', title: '区域名称', align: 'center'}
- , {fixed: 'right', title: '操作', width: 165, align: 'center', toolbar: '#operate'}
- ]],
- done: function (res, curr, count) {
- var _btn = '<div class="layui-inline " style="float:left;position:absolute;left:10px;bottom:6px">'
- + '<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>'
- + '</div>'
- $('.layui-border-box').append(_btn)
- }
- });
- //列表操作
- table.on('tool(' + tableId + ')', function (obj) {
- var layEvent = obj.event,
- data = obj.data;
- if (layEvent === 'edit') {
- indexOpen = layui.layer.open({
- type: 2,
- title: '[<span style="color:red">' + data.city_name + '</span>]区域历史价格',
- area: ['', '100%'],
- content: '/pricetrend/recordprice?cid=' + data.city_id,
- success: function (layero, index) {
- }
- });
- layui.layer.full(indexOpen);
- //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
- $(window).on("resize", function () {
- layui.layer.full(indexOpen);
- })
- }
- // else if (layEvent === 'del') {
- // layer.confirm('您确定要删除吗?', {btn: ['确定', '取消']}, function () {
- // $.post('/categorycity/delform', {'id': data.id}, function (data) {
- //
- // if (data.code == 200) {
- // layer.msg(data.msg);
- // table.reload('tablerReload');
- //
- // } else if (data.code == 300) {
- // layer.msg(data.msg);
- // }
- // });
- // });
- // }
- else if (layEvent === 'add') {
- layer.open({
- type: 2,
- title: '添加价格',
- closeBtn: 1, //不显示关闭按钮
- shade: [0],
- area: ['780px', '550px'],
- anim: 2,
- content: '/pricetrend/lineadd?cid=' + data.city_id + '&city_name=' + data.city_name,
- });
- }
- });
- var $ = layui.$, active = {
- addData: function () { //获取选中数据
- layer.open({
- type: 2,
- title: '添加价格',
- closeBtn: 1, //不显示关闭按钮
- shade: [0],
- area: ['780px', '550px'],
- anim: 2,
- content: '/pricetrend/priceadd.html',
- });
- },
- reload: function () {//搜索
- var form = pfgs_serialize($('form'));
- var name = '';
- var house_name = '';
- if (form.input_house == 'name') {
- name = form.input_house_text;
- } else if (form.input_house == 'house_name') {
- house_name = form.input_house_text;
- }
- table.reload('tablerReload', {
- where: {
- title: name,
- house_name: form.input_house_text,
- city: form.province,
- type_name: form.type_name
- }
- })
- }
- };
- //日期
- laydate.render({
- elem: '#date1'
- });
- $('.demoTable .layui-btn').on('click', function () {
- var type = $(this).data('type');
- active[type] ? active[type].call(this) : '';
- });
- $('.The_house').focus(function () {
- indexOpen = parent.layui.layer.open({
- type: 2,
- title: '选择需要添加的区域',
- area: ['', '100%'],
- content: '/publicuse/cncity?type=1',
- success: function (layero, index) {
- },
- end: function () {
- }
- });
- parent.layui.layer.full(indexOpen);
- //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
- $(window).on("resize", function () {
- parent.layui.layer.full(indexOpen);
- })
- })
- form.on('submit(editcity)', function (data) {
- var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
- var formData = new FormData($('form')[0]);
- $.ajax({
- cache: true,
- type: "post",
- url: '/categorycity/edithomeform',
- data: formData, // 你的formid
- contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
- processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
- error: function (request) {
- layer.close(index); //关闭数据提交信息
- layer.alert("网络超时");
- },
- success: function (data) {
- if (data.data != null) {
- layer.msg(ReturnInfo(data.data), {icon: 5});
- return;
- }
- layer.msg(data.msg);
- parent.layui.table.reload('tablerReload');
- }
- });
- return false;
- });
- //添加
- form.on('submit(addcity)', function (data) {
- layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
- var formData = new FormData($('form')[0]);
- $.ajax({
- cache: true,
- type: "post",
- url: '/pricetrend/priceaddform',
- data: formData, // 你的formid
- contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
- processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
- error: function (request) {
- layer.alert("网络超时");
- },
- success: function (data) {
- if (data.data != null) {
- layer.msg(ReturnInfo(data.data), {icon: 5});
- return;
- }
- layer.msg(data.msg);
- parent.layui.table.reload('tablerReload');
- }
- });
- return false;
- });
- form.on('submit(del_alls_Pricetrends)', function (data) {
- var checkStatus = table.checkStatus('tablerReload');
- var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
- if (typeof checkStatus.data[0] == 'object') {
- layer.confirm('您确定要删除吗?', {btn: ['确认', '取消']}, function () {
- var formdat = new FormData();
- $.each(checkStatus.data, function (key, val) {
- formdat.append('hid[]', val.city_id);
- })
- $.ajax({
- cache: true,
- type: "post",
- url: "/pricetrend/pricecityalldell",
- data: formdat, // 你的formid
- // async : false, //async 默认为true异步,修改为false为同步
- contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
- processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
- error: function (request) {
- layer.close(index); //关闭数据提交信息
- layer.alert("网络超时");
- },
- success: function (data) {
- if (data.code == 200) {
- layer.msg(data.msg);
- // reloadTable(reloadId);
- table.reload('tablerReload');
- } else {
- layer.msg(data.msg);
- }
- }
- });
- })
- return false;
- }
- layer.msg('请选择需要删除的楼盘', {icon: 5});
- return false;
- })
- //加载省数据
- function loadProvince() {
- $.ajax({
- url: '/categorycity/citypid',
- type: 'post',
- async: false,//使用同步的方式,true为异步方式
- data: {'pid': 0},//这里使用json对象
- success: function (data) {
- // console.log(data);
- var areaData = data.data;
- var proHtml = '';
- for (var i = 0; i < areaData.length; i++) {
- proHtml += '<option value="' + areaData[i].id + '">' + areaData[i].city_name + '</option>';
- }
- //初始化省数据
- $('select[name=province]').append(proHtml);
- form.render();
- },
- fail: function () {
- }
- });
- }
- loadProvince();
- });
|