var table, form, laypage, formSelects, element, util; // 地市公司id var cityId; let pageNum = 1, limitSize = 30; layui.config({ base: '../../js/layui/' //此处路径请自行处理, 可以使用绝对路径 }).extend({ formSelects: 'formSelects-v4' }).use(['form', 'formSelects', 'laypage', 'table', 'util'], function () { form = layui.form; //只有执行了这一步,部分表单元素才会自动修饰成功 table = layui.table; laypage = layui.laypage; formSelects = layui.formSelects; element = layui.element; util = layui.util; util.event('lay-active', { isShow: function () { let item = $(this).parent().parent().children("div.content-box-search-item-div"); let span = $(this).children('span'); let icon = $(this).children("i"); if (icon.hasClass('layui-icon-up')) { item.slideUp(500, function () { icon.removeClass('layui-icon-up'); icon.addClass('layui-icon-down'); span.text('展开'); }); } else { item.slideDown(500, function () { icon.addClass('layui-icon-up'); icon.removeClass('layui-icon-down'); span.text('收起'); }); } } }) getRiskDropRate(); form.render(); loadOrgName(); loadriskLevel(); // 加载风险等级 // 加载地市公司 getProByCity(''); pages(1, 10, 1); // select 监听 formSelects.on('cityName', function (id, val, vals) { let cityName = formSelects.value('cityName', 'val'); getProByCity(cityName); }, true); }); $(function () { $('#myModal_edit').on('show.bs.modal', centerModals); }); // 查询 function query(type) { if (type === 2) { resetForm(); } getRiskDropRate(); pages(1, limitSize, 1); } // 风险压降率 function getRiskDropRate() { let params = getDataParams(); $.ajax({ headers: { "encrypt": sm3(JSON.stringify(params)) }, url: dataUrl + 'proteam/pot/TRiskPressDropRate/getRiskDropRate' + '?token=' + token, type: 'POST', dataType: 'JSON', data: params, async: false, success: function (data) { let obj = data.data; setRiskDropRateData(obj); }, error: function () { console.error('风险压降率数据获取失败'); } }) } // 压降率赋值 function setRiskDropRateData(data) { $('.content-box-calculateInfo-center-item').each(function (index) { if (index !== 2) { $(this).empty(); } }); if (data == null || data.length === 0) { let item = $('.content-box-calculateInfo-center-item').eq(0); item.append('

全省总体基塔数:0

全省总体压降率:0%

'); let item2 = $('.content-box-calculateInfo-center-item').eq(1); item2.append( '

当前查询压降率计算结果

查询基塔数:0

' + '

总体压降率:0%

基础压降率:0%

' + '

组塔压降率:0%

架线压降率:0%

' ); } else { let item = $('.content-box-calculateInfo-center-item').eq(0); item.append('

全省总体基塔数:' + data[0].totalNum / 3 + '

全省总体压降率:' + data[0].calculate + '

'); let item2 = $('.content-box-calculateInfo-center-item').eq(1); item2.append( '

当前查询压降率计算结果

' + '

查询基塔数:' + data[1].currentTotalNum + '

' + '

总体压降率:' + data[1].currentTotalRate + '

基础压降率:' + data[1].currentBasicRate + '

' + '

组塔压降率:' + data[1].currentTowerRate + '

架线压降率:' + data[1].currentWireRate + '

' ); currentQueryComplex(data[2]); } } // 当前查询压降率综合计算结果 function currentQueryComplex(data) { console.error(data) if (data.workType !== "") { $('#center-item-third').css("visibility", "visible"); $('#center-item-second').css("visibility", "visible"); $('#center-item-third').css("visibility", "visible"); $('.center-item-first-box').eq(0).css("border-bottom", "1px solid #000"); if (data.workType === "基础") { // 基础 $('.center-item-first-box').eq(0).empty().append('

' + data.currentBasic + '

'); $('.center-item-first-box').eq(1).empty().append('

' + data.currentTotal + '

x

1

'); $('#center-item-third').empty().append('

=

' + data.currentTotalRate + '

'); } if (data.workType === "组塔") { // 组塔 $('.center-item-first-box').eq(0).empty().append('

' + data.currentTower + '

'); $('.center-item-first-box').eq(1).empty().append('

' + data.currentTotal + '

x

1

'); $('#center-item-third').empty().append('

=

' + data.currentTotalRate + '

'); } if (data.workType === "架线") { // 架线 $('.center-item-first-box').eq(0).empty().append(''); $('.center-item-first-box').eq(1).empty().append('

' + data.currentTotal + '

x

1

'); $('#center-item-third').empty().append('

=

' + data.currentTotalRate + '

'); } if (data.workType === "基础,组塔") { // 基础,组塔 $('.center-item-first-box').eq(0).empty().append('

' + data.currentBasic + '

+

' + data.currentTower + '

'); $('.center-item-first-box').eq(1).empty().append('

' + data.currentTotal + '

x

2

'); $('#center-item-third').empty().append('

=

' + data.currentTotalRate + '

'); } if (data.workType === "基础,架线") { // 基础,架线 $('.center-item-first-box').eq(0).empty().append('

' + data.currentBasic + '

+

'); $('.center-item-first-box').eq(1).empty().append('

' + data.currentTotal + '

x

2

'); $('#center-item-third').empty().append('

=

' + data.currentTotalRate + '

'); } if (data.workType === "组塔,架线") { // 组塔,架线 $('.center-item-first-box').eq(0).empty().append('

' + data.currentTower + '

+

'); $('.center-item-first-box').eq(1).empty().append('

' + data.currentTotal + '

x

2

'); $('#center-item-third').empty().append('

=

' + data.currentTotalRate + '

'); } if (data.workType === "基础,组塔,架线") { // 基础,组塔,架线 $('.center-item-first-box').eq(0).empty().append('

' + data.currentBasic + '

+

' + data.currentTower + '

+

'); $('.center-item-first-box').eq(1).empty().append('

' + data.currentTotal + '

x

3

'); $('#center-item-third').empty().append('

=

' + data.currentTotalRate + '

'); } } else { $('.center-item-first-box').eq(0).empty().css("border-bottom", "none"); $('.center-item-first-box').eq(1).empty(); $('#center-item-third').css("visibility", "hidden"); $('#center-item-second').css("visibility", "hidden"); $('#center-item-third').css("visibility", "hidden"); } } // 降压率计算结果 function calculate(value, currentTotal, workType, currentTotalRate) { if (parseInt(value) > parseInt(currentTotal) || parseInt(value) < 0 || value === '') { layer.msg("请输入0~" + currentTotal + "的正整数", {icon: 7, time: 2000}); $('.center-item-first-box').eq(0).find('input').val(currentTotal); $('#center-item-third').empty().append('

=

' + currentTotalRate + '

'); } else { if (workType === "架线") { let val = ''; if (parseInt(value) === parseInt(currentTotal)) { val = '100%' } else { val = (parseInt(value) / parseInt(currentTotal) * 100).toFixed(2) + "%"; } $('#center-item-third').empty().append('

=

' + val + '

'); } else if (workType === "基础,架线") { let val = ''; let basicNum = parseInt($('.center-item-first-box').eq(0).find('p').eq(0).html()); if (((basicNum + parseInt(value))) === (parseInt(currentTotal) * 2)) { val = '100%'; } else { val = (((basicNum + parseInt(value)) / (parseInt(currentTotal) * 2)) * 100).toFixed(2) + "%"; } $('#center-item-third').empty().append('

=

' + val + '

'); } else if (workType === "组塔,架线") { let val = ''; let towerNum = parseInt($('.center-item-first-box').eq(0).find('p').eq(0).html()); if ((towerNum + parseInt(value)) === (parseInt(currentTotal) * 2)) { val = '100%'; } else { val = (((towerNum + parseInt(value)) / (parseInt(currentTotal) * 2)) * 100).toFixed(2) + "%"; } $('#center-item-third').empty().append('

=

' + val + '

'); } else if (workType === "基础,组塔,架线") { let val = ''; let basicNum = parseInt($('.center-item-first-box').eq(0).find('p').eq(0).html()); let towerNum = parseInt($('.center-item-first-box').eq(0).find('p').eq(2).html()); if ((basicNum + towerNum + parseInt(value)) === (parseInt(currentTotal) * 3)) { val = '100%'; } else { val = (((basicNum + towerNum + parseInt(value)) / (parseInt(currentTotal) * 3)) * 100).toFixed(2) + "%"; } $('#center-item-third').empty().append('

=

' + val + '

'); } } } function pages(pageNum, pageSize, typeNum) { let params = getDataParams(pageNum, pageSize); $.ajax({ headers: { "encrypt": sm3(JSON.stringify(params)) }, url: dataUrl + 'proteam/pot/TRiskPressDropRate/getRiskBloodList' + '?token=' + token, data: params, type: 'POST', async: false, success: function (result) { console.log(result); if (result.code === 200) { if (result.rows) { initTable(result.rows, limitSize, pageNum) laypages(result.total, pageNum, limitSize) } } else if (result.code === 500) { layer.alert(result.msg, {icon: 2}) } else if (result.code === 401) { logout(1); } }, error: function () { } }); } function laypages(total, page, limit) { layui.use(['laypage'], function () { let laypage = layui.laypage; laypage.render({ elem: 'voi-page', count: total, curr: page, limit: limit, limits: [30,50,100], layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'], groups: 5, jump: function (obj, first) { if (!first) { pageNum = obj.curr, limitSize = obj.limit; pages(obj.curr, obj.limit, null); } } }); }) } // 初始化表格 function initTable(dataList, limit, page) { table.render({ elem: '#testTable', height: "full-540", id: 'testTable', data: dataList, cols: [ [ { field: 'number', type: 'numbers', title: '序号', width: 80, rowspan: 2, fixed: 'left', align: 'center', style: "height:78px;line-height:78px;", unresize: true, }, { field: 'cityName', title: '地市', width: 120, fixed: 'left', rowspan: 2, align: 'center', style: "height:78px;line-height:78px;", unresize: true, }, { field: 'proName', title: '工程名称', width: 240, rowspan: 2, fixed: 'left', align: 'center', style: "height:78px;line-height:78px;", unresize: true, }, { field: 'tower', title: '塔号', width: 80, rowspan: 2, fixed: 'left', align: 'center', style: "height:78px;line-height:78px;", unresize: true, }, {field: 'lon', title: '经度', width: 120, rowspan: 2, align: 'center', unresize: true}, {field: 'lat', title: '纬度', width: 120, rowspan: 2, align: 'center', unresize: true}, {title: '基础施工风险', align: 'center', colspan: 5, unresize: true}, {title: '组塔施工风险', align: 'center', colspan: 5, unresize: true}, {title: '架线施工风险', align: 'center', colspan: 5, unresize: true}, {title: '“8+2”类风险', align: 'center', colspan: 2, sort: true,unresize: true}, {title: '塔位及周边环境', align: 'center', colspan: 2, sort: true, unresize: true}, ], [ //表头 {field: 'basicBaseType', title: '基础类型', width: 120, align: 'center', unresize: true}, {field: 'basicWorkStyle', title: '作业方式', width: 120, align: 'center', unresize: true}, {field: 'basicRiskLevel', title: '风险等级', width: 120, align: 'center', unresize: true}, {field: 'basicOperProcedure', title: '3级及以上风险作业工序', width: 280, align: 'center', unresize: true}, {field: 'basicAppMethod', title: '工法应用', width: 120, align: 'center', unresize: true}, {field: 'groupTowerFullHeight', title: '杆塔全高', width: 120, align: 'center', unresize: true}, {field: 'groupTowerStyle', title: '组塔方式', width: 120, align: 'center', unresize: true}, {field: 'groupTowerRiskLevel', title: '风险等级', width: 120, align: 'center', unresize: true}, {field: 'groupTowerOperProcedure', title: '3级及以上风险作业工序', width: 280, align: 'center', unresize: true}, {field: 'groupTowerAppMethod', title: '工法应用', width: 120, align: 'center', unresize: true}, {field: 'wireSpan', title: '跨越物(面向小号)', width: 250, align: 'center', unresize: true}, {field: 'wireStyle', title: '放线方式', width: 120, align: 'center', unresize: true}, {field: 'wireRiskLevel', title: '风险等级', width: 120, align: 'center', unresize: true}, {field: 'wireOperProcedure', title: '3级及以上风险作业工序', width: 280, align: 'center', unresize: true}, {field: 'wireAppMethod', title: '工法应用', width: 120, align: 'center', unresize: true}, {field: 'riskType', title: '风险类型', width: 150, align: 'center', unresize: true}, {field: 'riskDetails', title: '风险明细', width: 120, align: 'center', unresize: true}, { title: '杆位原始地貌', width: 180, align: 'center', style: "height:78px;", unresize: true, templet: function (d) { if (d.landFormPath !== null) { let path = photoUrl.substring(0,(photoUrl.length - 1)) + d.landFormPath + '?token=' + token return ''; } else { return ''; } } }, { title: 'A1-A2档内实景', width: 180, align: 'center', style: "height:78px;", unresize: true, templet: function (d) { if (d.surroundingsPath !== null) { let path = photoUrl.substring(0,(photoUrl.length - 1)) + d.surroundingsPath + '?token=' + token return ''; } else { return ''; } } }, ]], limit: limit, //默认十条数据一页 done: function (res, curr, count) { $(".layui-laypage-skip").css("display", "none"); // $(".layui-table-cell").css({'height': 'auto'}); table.resize('testTable'); count || this.elem.next('.layui-table-view').find('.layui-table-header').css('display', 'inline-block'); count || this.elem.next('.layui-table-view').find('.layui-table-box').css('overflow', 'auto'); } }); } // 获取参数 function getDataParams(page, limit) { let arr_box = []; // 复选框选中的值 $('input[type=checkbox]:checked').each(function () { arr_box.push($(this).val()); }); let obj = { pageNum: page + "", pageSize: limit + "", 'cityName': formSelects.value('cityName', 'val').toString(), 'proName': formSelects.value('proName', 'val').toString(), 'basicBaseType': $('#basicBaseType').val(), 'basicWorkStyle': $('#basicWorkStyle').val(), 'basicRiskLevel': $('#basicRiskLevel').val(), 'basicOperProcedure': $('#basicOperProcedure').val(), 'basicAppMethod': $('#basicAppMethod').val(), 'groupTowerFullHeight': $('#groupTowerFullHeight').val(), 'groupTowerStyle': $('#groupTowerStyle').val(), 'groupTowerRiskLevel': $('#groupTowerRiskLevel').val(), 'groupTowerOperProcedure': $('#groupTowerOperProcedure').val(), 'groupTowerAppMethod': $('#groupTowerAppMethod').val(), 'wireSpan': $('#wireSpan').val(), 'wireStyle': $('#wireStyle').val(), 'wireRiskLevel': $('#wireRiskLevel').val(), 'wireOperProcedure': $('#wireOperProcedure').val(), 'wireAppMethod': $('#wireAppMethod').val(), 'riskType': $('#riskType').val(), 'workType': arr_box.toString(), }; return obj; } // 重置查询条件 function resetForm() { getProByCity(''); formSelects.value('cityName', []); formSelects.value('proName', []); $('#basicBaseType').val(''); $('#basicWorkStyle').val(''); $('#basicRiskLevel').val(''); $('#basicOperProcedure').val(''); $('#basicAppMethod').val(''); $('#groupTowerFullHeight').val(''); $('#groupTowerStyle').val(''); $('#groupTowerRiskLevel').val(''); $('#groupTowerOperProcedure').val(''); $('#groupTowerAppMethod').val(''); $('#wireSpan').val(''); $('#wireStyle').val(''); $('#wireRiskLevel').val(''); $('#wireAppMethod').val(''); $('#riskType').val(''); // 清空复选框 $('input[type=checkbox]').each(function () { $(this).prop("checked", false); }); layui.form.render('checkbox'); layui.form.render('select'); //这里就是我们要渲染的地方了 } // 监听导入数据 $("#import-excel").change(function () { if ($(this).val() !== "") { excelUpload6(this, dataUrl + "proteam/pot/TRiskPressDropRate/importExcel" + '?token=' + token, cityId); } }); // 弹出模态框 function centerModals() { $('#myModal_edit').each(function (i) { var $clone = $(this).clone().css('display', 'block').appendTo('body'); var top = Math.round(($clone.height() - $clone.find('.modal-content').height()) / 3); top = top > 0 ? top : 0; $clone.remove(); $(this).find('.modal-content').css("margin-top", top); }); }; // 导入数据 function exportData() { cityId = ''; let height = '400px'; let width = '500px'; layer.open({ title: ['地市选择', 'color:#000'], type: 2, shade: 0.1, shadeClose: false, content: '../../html/riskDropRateCal/child/selCity.html', area: [width, height], maxmin: false, move: false, end: function () { // 地市id不为空执行数据导入 if (cityId != null && cityId !== '' && cityId !== undefined) { $("#import-excel").trigger('click'); } } }); } // 数据清理 function dataCleaning() { let height = '600px'; let width = '800px'; layer.open({ title: ['数据清理', 'color:#000'], type: 2, shade: 0.1, shadeClose: false, content: '../../html/riskDropRateCal/child/dataCleaning.html', area: [width, height], maxmin: false, move: false, end: function () { query(); } }); } // 加载地市公司 function loadOrgName() { let keys = []; $("#cityName").empty(); let data = [{'id': '合肥', 'name': '合肥'}, {'id': '马鞍山', 'name': '马鞍山'}, {'id': '芜湖', 'name': '芜湖'}, {'id': '安庆', 'name': '安庆'}, {'id': '淮南', 'name': '淮南'}, {'id': '宣城', 'name': '宣城'}, {'id': '阜阳', 'name': '阜阳'}, {'id': '铜陵', 'name': '铜陵'}, {'id': '蚌埠', 'name': '蚌埠'}, {'id': '滁州', 'name': '滁州'}, {'id': '六安', 'name': '六安'}, {'id': '淮北', 'name': '淮北'}, {'id': '宿州', 'name': '宿州'}, {'id': '池州', 'name': '池州'}, {'id': '黄山', 'name': '黄山'}, {'id': '亳州', 'name': '亳州'}, {'id': '建设分公司', 'name': '建设分公司'}]; for (let i = 0; i < data.length; i++) { let temp = { "name": data[i].id, "value": data[i].name }; keys.push(temp); } formSelects.data('cityName', 'local', { arr: keys }); } // 根据所选地市选择工程 function getProByCity(value) { let keys = []; $("#proName").empty(); $.ajax({ headers: { "encrypt": sm3(JSON.stringify({ cityName: value.toString(), })) }, url: dataUrl + 'proteam/pot/TRiskPressDropRate/getProNameList' + '?token=' + token, type: 'get', dataType: 'json', data: { cityName: value.toString(), }, success: function (result) { let data = result.data; if (data.length > 0 && data != null) { for (var i = 0; i < data.length; i++) { var temp = { "name": data[i].id, "value": data[i].name }; keys.push(temp); } formSelects.data('proName', 'local', { arr: keys }); } }, error: function () { console.error("获取工程数据失败"); } }) } //加载风险等级 function loadriskLevel() { $("#basicRiskLevel").empty(); $("#groupTowerRiskLevel").empty(); $("#wireRiskLevel").empty(); var data = [ {'id': '', 'name': '全部'}, {'id': '1', 'name': '一级'}, {'id': '2', 'name': '二级'}, {'id': '3', 'name': '三级'}, {'id': '4', 'name': '四级'}, {'id': '5', 'name': '五级'}]; let html = ''; for (let i = 0; i < data.length; i++) { html += ''; } $("#basicRiskLevel").append(html); $("#groupTowerRiskLevel").append(html); $("#wireRiskLevel").append(html); layui.form.render('select'); //这里就是我们要渲染的地方了 } //显示大图片 function enlargeImg(that) { var _this = $(that);//将当前的pimg元素作为_this传入函数 imgShow("#outerdiv", "#innerdiv", "#bigimg", _this); } // 图片点击预览 function imgShow(outerdiv, innerdiv, bigimg, _this) { var src = _this.attr("src");//获取当前点击的pimg元素中的src属性 $(bigimg).attr("src", src);//设置#bigimg元素的src属性 /*获取当前点击图片的真实大小,并显示弹出层及大图*/ $("").attr("src", src).on('load', function () { var windowW = $(window).width();//获取当前窗口宽度 var windowH = $(window).height();//获取当前窗口高度 var realWidth = this.width;//获取图片真实宽度 var realHeight = this.height;//获取图片真实高度 var imgWidth, imgHeight; var scale = 0.4;//缩放尺寸,当图片真实宽度和高度大于窗口宽度和高度时进行缩放 if (realHeight > windowH * scale) {//判断图片高度 imgHeight = windowH * scale;//如大于窗口高度,图片高度进行缩放 imgWidth = imgHeight / realHeight * realWidth;//等比例缩放宽度 if (imgWidth > windowW * scale) {//如宽度扔大于窗口宽度 imgWidth = windowW * scale;//再对宽度进行缩放 } } else if (realWidth > windowW * scale) {//如图片高度合适,判断图片宽度 imgWidth = windowW * scale;//如大于窗口宽度,图片宽度进行缩放 imgHeight = imgWidth / realWidth * realHeight;//等比例缩放高度 } else {//如果图片真实高度和宽度都符合要求,高宽不变 imgWidth = realWidth; imgHeight = realHeight; } $(bigimg).css("width", imgWidth);//以最终的宽度对图片缩放 var w = (windowW - imgWidth) / 2;//计算图片与窗口左边距 var h = (windowH - imgHeight) / 2;//计算图片与窗口上边距 $(innerdiv).css({"top": h, "left": w});//设置#innerdiv的top和left属性 $(outerdiv).fadeIn("fast");//淡入显示#outerdiv及.pimg }); $(outerdiv).click(function () {//再次点击淡出消失弹出层 $(this).fadeOut("fast"); }); } $('#downloadExcel').click(function () { downLoadExcelModel(); }); /*模板下载*/ function downLoadExcelModel() { let loadingMsg = layer.msg('模板下载中,请稍候...', {icon: 16, scrollbar: false, time: 0}); let url = dataUrl + 'proteam/pot/TRiskPressDropRate/downloadExcel?token=' + token; let xhr = new XMLHttpRequest(); xhr.open("get", url, true); xhr.responseType = "blob"; // 转换流 xhr.setRequestHeader("encrypt", sm3(JSON.stringify({}))); xhr.onload = function () { layer.close(loadingMsg); // 关闭提示层 if (this.status === 200) { let blob = this.response; var a = document.createElement("a"); var url = window.URL.createObjectURL(blob); a.href = url; a.download = "压降率模板.xlsx"; // 文件名 } else { layer.msg('服务异常,请稍后重试', {icon: 16, scrollbar: false, time: 2000}); } a.click() window.URL.revokeObjectURL(url) }; xhr.send(); }