123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- layui.use(['laypage', 'layer', 'table', 'element', 'form', 'treetable'], function () {
- var laypage = layui.laypage //分页
- , $ = layui.jquery
- , layer = layui.layer //弹层
- , table = layui.table //表格
- , form = layui.form
- , treetable = layui.treetable;
- var tableId = 'citylist';
- if ($('#citylist').attr('lay-filter') == 'citylist') {
- var renderTable = function (wheres = {}) {
- layer.load(2);
- treetable.render({
- treeColIndex: 1,
- treeSpid: 0,
- treeIdName: 'id',
- treePidName: 'pid',
- treeDefaultClose: true,
- treeLinkage: false,
- elem: '#citylist',
- url: '/pricetrend/housingpriceform',
- page: false,
- where: wheres,
- id: 'tablerReload',
- cols: [[
- {type: 'numbers'}
- , {field: 'city_name', title: '区域名称', align: 'center', width:1200}
- // , {field: 'update_at', title: '更新时间', width: 300, align: 'center'}
- , {fixed: 'right', title: '操作', width: 300, align: 'center', toolbar: '#operate'}
- ]],
- done: function () {
- layer.closeAll('loading');
- var sz = false;
- $('.treeTable-icon').on('click', function () {
- if ($(this).attr('lay-tpid') == 0) {
- sessionStorage.setItem("key", $(this).attr('lay-tid'));
- if (sz) {
- sessionStorage.removeItem("erzi");
- }
- } else {
- sz = true;
- if ($(this).attr('lay-tid') == sessionStorage.getItem("erzi")) {
- sessionStorage.removeItem("erzi");
- } else {
- sessionStorage.setItem("erzi", $(this).attr('lay-tid'));
- }
- }
- });
- if (sessionStorage.getItem("key") != null) {
- var laytid = sessionStorage.getItem("key");
- $('span[lay-tid=' + laytid + ']').addClass('open');
- if (sessionStorage.getItem("erzi") != null) {
- var elaytid = sessionStorage.getItem("erzi");
- sz = true;
- }
- $('span[lay-tpid=' + laytid + ']').each(function () {
- $(this).parents().parents().parents().attr('style', '');
- if (sz) {
- $('span[lay-tid=' + elaytid + ']').addClass('open');
- $('span[lay-tpid=' + elaytid + ']').each(function () {
- $(this).parents().parents().parents().attr('style', '');
- });
- }
- });
- }
- }
- });
- };
- renderTable();
- }
- //列表操作
- table.on('tool(' + tableId + ')', function (obj) {
- var layEvent = obj.event,
- data = obj.data;
- switch (layEvent) {
- case 'add':
- layer.open({
- type: 2,
- title: '新增区域价格走势',
- closeBtn: 1, //不显示关闭按钮
- shade: [0],
- area: ['800px', '600px'],
- anim: 2,
- content: ['/pricetrend/housingpriceadd?cid=' + data.id + '&city_name=' + data.city_name, 'yes'],
- end: function () {
- renderTable();
- }
- });
- break;
- case 'see':
- layer.open({
- type: 2,
- title: '[<span style="color:red">'+data.city_name+'</span>]区域价格走势',
- area: ['100%','100%'],
- content: '/pricetrend/recordprice?cid='+data.id,
- success:function (layero, index) {
- }
- });
- break;
- }
- });
- var $ = layui.$, active = {
- addData: function () { //获取选中数据
- layer.open({
- type: 2,
- title: '添加区域',
- closeBtn: 1, //不显示关闭按钮
- shade: [0],
- area: ['780px', '550px'],
- anim: 2,
- content: '/categorycity/addhome?son=1',
- });
- },
- reload: function () {
- var form = pfgs_serialize($('form'));
- var city = '';
- if (form.province != '') {
- city = form.province;
- }
- if (form.city != '') {
- city = form.city;
- }
- renderTable({id: city});
- }
- };
- $('.demoTable .layui-btn').on('click', function () {
- var type = $(this).data('type');
- active[type] ? active[type].call(this) : '';
- });
- //显示或隐藏
- form.on('switch(switchTest)', function (data) {
- var state = '';
- if (data.elem.name == 1) {
- state = 2;
- } else if (data.elem.name == 2) {
- state = 1;
- }
- layer.confirm('确定要修改此操作吗?', {btn: ['确定', '取消']}, function () {
- $.post('/categorycity/editall', {id: data.value, state: state}, function (data) {
- if (data.data != null) {
- layer.msg(ReturnInfo(data.data), {icon: 5});
- return false;
- }
- layer.msg(data.msg);
- renderTable();
- })
- }, function (aa) {
- renderTable();
- })
- });
- //修改排序
- table.on('edit(' + tableId + ')', function (obj) {
- var data = obj.data;
- $.post('/categorycity/editall', {id: data.id, sort: data.sort}, function (data) {
- if (data.data != null) {
- layer.msg(ReturnInfo(data.data), {icon: 5});
- return false;
- }
- layer.msg(data.msg);
- })
- })
- 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);
- renderTable();
- }
- });
- return false;
- });
- //添加
- form.on('submit(addcity)', function (data) {
- var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
- $.post('/categorycity/addcityform', {'data': data.field}, function (data) {
- if (data.data != null) {
- layer.msg(ReturnInfo(data.data), {icon: 5});
- return;
- }
- layer.msg(data.msg);
- renderTable();
- })
- 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();
- form.on('select(province)', function (data) {
- $.post('/categorycity/citypid', {'pid': data.value}, function (data) {
- var areaData = data.data;
- var proHtml = '';
- $('select[name=city]').html('');
- proHtml = '<option value="">请选择市/区/县</option>';
- for (var i = 0; i < areaData.length; i++) {
- proHtml += '<option value="' + areaData[i].id + '">' + areaData[i].city_name + '</option>';
- }
- //初始化省数据
- $('select[name=city]').append(proHtml);
- form.render();
- })
- })
- // 转换拼音
- $('.layui_w_name').on('keyup ', function () {
- var _txt = $(this).val();
- var _convert = pinyinUtil.getPinyin(_txt, ' ', false).replace(/\s/g, "");
- $('.layui_w_spell').val(_convert)
- })
- });
|