123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522 |
- /**
- * 编办管理相关js
- *
- * @author CaiAoLin
- * @date 2017/7/28
- * @version
- */
- $(document).ready(function() {
- let isAdding = false;
- let model = '';
- let section = 'bill';
- let id = $("#compilation-id").val();
- // 计价规则页面初始化数据
- if ($("#save-lib").length > 0) {
- initCompilation();
- }
- // 计价类型选择
- $(".nav-tabs li > a").click(function() {
- section = $(this).attr("aria-controls");
- });
- // 新增编办
- $("#add-compilation").click(function() {
- try {
- let data = getAndValidData(model);
- let url = '/compilation/add'
- if (model === 'all') {
- // 新增编办操作
- $.ajax({
- url: url,
- type: 'post',
- data: {name: data.name},
- error: function() {
- isAdding = false;
- },
- beforeSend: function() {
- isAdding = true;
- },
- success: function(response) {
- isAdding = false;
- if (response.err === 0) {
- window.location.reload();
- } else {
- let msg = response.msg === undefined ? '未知错误' : response.msg;
- alert(msg);
- }
- }
- });
- } else {
- // 新增标准清单/定额库
- let addLib = {
- name: data[model].name,
- id: data[model].id
- };
- // 判断是否有重复的数据
- if ($("input:hidden[name='"+ model +"_lib'][data-id='"+ addLib.id +"']").length > 0) {
- alert('重复添加数据!');
- return false;
- }
- let removeHtml = '<a class="pull-right text-danger remove-lib" data-model="bill" ' +
- 'title="移除"><span class="glyphicon glyphicon-remove"></span></a>';
- let tmpHtml = '<p class="form-control-static">' + removeHtml + addLib.name +
- '<input type="hidden" data-id="'+ addLib.id +'" name=\'' + model + '_lib\' value=\'' + JSON.stringify(addLib) + '\'>' + '</p>';
- $("." + model + "-list").append(tmpHtml);
- $('#addcompilation').modal('hide');
- }
- } catch (error) {
- alert(error);
- }
- });
- // 新增计价规则
- $("#add-valuation").click(function() {
- try {
- if (id === '') {
- throw '页面数据有误';
- }
- let name = $("input[name='valuation_name']").val();
- if (name === '') {
- throw '请填写计价规则名称';
- }
- $.ajax({
- url: '/compilation/add-valuation',
- type: 'post',
- data: {name: name, id: id, section: section},
- error: function() {
- isAdding = false;
- },
- beforeSend: function() {
- isAdding = true;
- },
- success: function(response) {
- isAdding = false;
- if (response.err === 0) {
- window.location.reload();
- } else {
- let msg = response.msg === undefined ? '未知错误' : response.msg;
- alert(msg);
- }
- }
- });
- } catch (error) {
- alert(error);
- return false;
- }
- });
- // 添加
- $(".add-compilation").click(function() {
- model = $(this).data('model');
- $("#addcompilation .modal-body > div").hide();
- switch (model) {
- case 'all':
- $("#name-area").show();
- $("#add-compilation-title").text('添加新编办');
- break;
- case 'bill':
- $("#bill-area").show();
- $("#add-compilation-title").text('添加标准清单');
- break;
- case 'ration':
- $("#ration-area").show();
- $("#add-compilation-title").text('添加定额库');
- break;
- case 'glj':
- $("#glj-area").show();
- $("#add-compilation-title").text('添加定额库');
- break;
- case 'billsGuidance':
- $("#billsGuidance-area").show();
- $("#add-compilation-title").text('添加清单指引库');
- break;
- case 'fee':
- $("#fee-area").show();
- $("#add-compilation-title").text('添加费率标准');
- break;
- case 'artificial':
- $("#artificial-area").show();
- $("#add-compilation-title").text('添加人工系数');
- break;
- case 'program':
- $("#program-area").show();
- $("#add-compilation-title").text('添加计算程序');
- break;
- }
- $("#addcompilation").modal('show');
- });
- // 保存专业工程标准库
- $("#save-lib").click(function() {
- if (validLib()) {
- $("form").submit();
- }
- });
- // 保存计价规则
- $("#save-valuation").click(function() {
- $("form").submit();
- });
- // 移除操作
- $(".bill-list, .ration-list, .glj-list, .fee-list, .artificial-list, .program-list, .billsGuidance-list").on("click", ".remove-lib", function() {
- $(this).parent().remove();
- });
- //更改描述
- $('#description').change(function () {
- let description = $(this).val();
- $.ajax({
- url: '/compilation/setDescription',
- type: 'post',
- dataType: "json",
- data: {id: id, description: description},
- success: function(response) {
- if (response.err !== 0) {
- alert('更改失败');
- }
- }
- });
- });
- // 计价规则启用/禁止
- $(".enable").click(function() {
- let goingChangeStatus = switchChange($(this));
- let id = $(this).data('id');
- if (id === undefined || id === '' || isAdding) {
- return false;
- }
- $.ajax({
- url: '/compilation/valuation/' + section + '/enable',
- type: 'post',
- dataType: "json",
- data: {id: id, enable: goingChangeStatus},
- error: function() {
- isAdding = false;
- switchChange($(this));
- },
- beforeSend: function() {
- isAdding = true;
- },
- success: function(response) {
- isAdding = false;
- if (response.err !== 0) {
- switchChange($(this));
- alert('更改失败');
- }
- }
- });
- });
- //计价规则删除
- $('#delete-confirm').click(function () {
- let id = $('#del').attr('selectedId');
- if (id === undefined || id === '') {
- return false;
- }
- window.location.href = `/compilation/valuation/bill/delete/${id}`;
- });
- // 发布编办
- $("#release").click(function() {
- let id = $(this).data("id");
- let status = $(this).data("status");
- status = parseInt(status);
- if (isAdding || id === '' || isNaN(status)) {
- return false;
- }
- $.ajax({
- url: '/compilation/release',
- type: 'post',
- data: {id: id, status: status},
- dataType: "json",
- error: function() {
- isAdding = false;
- },
- beforeSend: function() {
- isAdding = true;
- },
- success: function(response) {
- isAdding = false;
- if (response.err === 0) {
- window.location.reload();
- } else {
- let msg = response.msg === undefined ? "未知错误" : response.msg;
- alert(msg);
- }
- }
- });
- });
- });
- /**
- * 初始化
- *
- * @return {void|boolean}
- */
- function initCompilation() {
- let billListData = billList === undefined ? [] : JSON.parse(billList);
- let rationLibData = rationList === undefined ? [] : JSON.parse(rationList);
- let gljLibData = gljList === undefined ? [] : JSON.parse(gljList);
- let feeLibData = feeRateList === undefined ? [] : JSON.parse(feeRateList);
- let artificialCoefficientData = artificialCoefficientList === undefined ? [] : JSON.parse(artificialCoefficientList);
- let programData = programList === undefined ? [] : JSON.parse(programList);
- let billsGuidanceData = billsGuidanceList === undefined ? [] : JSON.parse(billsGuidanceList);
- mainTreeCol = mainTreeCol !== '' ? mainTreeCol.replace(/\n/g, '\\n') : mainTreeCol;
- billsTemplateData = billsTemplateData.replace(/\n/g, '\\n');
- let mainTreeColObj = mainTreeCol === '' ? {} : JSON.parse(mainTreeCol);
- // 初始化 造价书列设置
- colSpread = TREE_SHEET_HELPER.createNewSpread($('#main-tree-col')[0]);
- let billsTemplateTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1});
- billsTemplateTree.loadDatas(JSON.parse(billsTemplateData));
- if (mainTreeCol !== '') {
- TREE_SHEET_HELPER.loadSheetHeader(mainTreeColObj, colSpread.getActiveSheet());
- TREE_SHEET_HELPER.showTreeData(mainTreeColObj, colSpread.getActiveSheet(), billsTemplateTree);
- }
- if (billListData.length <= 0 || rationLibData.length <= 0 || gljLibData.length <= 0) {
- return false;
- }
- // 标准清单
- let html = '';
- for(let tmp of billListData) {
- let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
- html += tmpHtml;
- }
- $("select[name='standard_bill']").children("option").first().after(html);
- // 定额库
- html = '';
- for(let tmp of rationLibData) {
- let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
- html += tmpHtml;
- }
- $("select[name='ration_lib']").children("option").first().after(html);
- // 工料机库
- html = '';
- for(let tmp of gljLibData) {
- let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
- html += tmpHtml;
- }
- $("select[name='glj_lib']").children("option").first().after(html);
- // 清单指引库
- html = '';
- for(let tmp of billsGuidanceData) {
- let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
- html += tmpHtml;
- }
- $("select[name='billsGuidance_lib']").children("option").first().after(html);
- // 费率标准库
- html = '';
- for(let tmp of feeLibData) {
- let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
- html += tmpHtml;
- }
- $("select[name='fee_lib']").children("option").first().after(html);
- // 人工系数标准库
- html = '';
- for(let tmp of artificialCoefficientData) {
- let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
- html += tmpHtml;
- }
- $("select[name='artificial_lib']").children("option").first().after(html);
- // 计算程序标准库
- html = '';
- for(let tmp of programData) {
- let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
- html += tmpHtml;
- }
- $("select[name='program_lib']").children("option").first().after(html);
- }
- /**
- * 校验数据
- *
- * @param {String} model
- * @return {Object}
- */
- function getAndValidData(model) {
- let name = $("input[name='compilation_name']").val();
- let standardBill = $("select[name='standard_bill']").children("option:selected").val();
- let rationLib = $("select[name='ration_lib']").children("option:selected").val();
- let gljLib = $("select[name='glj_lib']").children("option:selected").val();
- let feeLib = $("select[name='fee_lib']").children("option:selected").val();
- let artificialLib = $("select[name='artificial_lib']").children("option:selected").val();
- let programLib = $("select[name='program_lib']").children("option:selected").val();
- let billsGuidanceLib = $("select[name='billsGuidance_lib']").children("option:selected").val();
- if (name === '' && model === 'all') {
- throw '编办名字不能为空';
- }
- if ( model === 'bill' && (standardBill === '' || standardBill === undefined)) {
- throw '请选择标准清单库';
- }
- if (model === 'ration' && (rationLib === '' || rationLib === undefined)) {
- throw '请选择定额库';
- }
- if (model === 'glj' && (gljLib === '' || gljLib === undefined)) {
- throw '请选择人材机库';
- }
- if (model === 'fee' && (feeLib === '' || feeLib === undefined)) {
- throw '请选择费率标准';
- }
- if (model === 'artificial' && (artificialLib === '' || artificialLib === undefined)) {
- throw '请选择费率库';
- }
- if (model === 'program' && (programLib === '' || programLib === undefined)) {
- throw '请选择计算程序';
- }
- if (model === 'billsGuidance' && (billsGuidanceLib === '' || billsGuidanceLib === undefined)) {
- throw '请选择清单指引库';
- }
- let standardBillString = $("select[name='standard_bill']").children("option:selected").text();
- let rationLibString = $("select[name='ration_lib']").children("option:selected").text();
- let gljLibString = $("select[name='glj_lib']").children("option:selected").text();
- let feeLibString = $("select[name='fee_lib']").children("option:selected").text();
- let artificialString = $("select[name='artificial_lib']").children("option:selected").text();
- let programString = $("select[name='program_lib']").children("option:selected").text();
- let billsGuidanceString = $("select[name='billsGuidance_lib']").children("option:selected").text();
- let result = {
- name: name,
- bill: {
- id: standardBill,
- name: standardBillString
- },
- ration: {
- id: rationLib,
- name: rationLibString
- },
- glj: {
- id: gljLib,
- name: gljLibString
- },
- fee: {
- id: feeLib,
- name: feeLibString
- },
- artificial: {
- id: artificialLib,
- name: artificialString
- },
- program: {
- id: programLib,
- name: programString
- },
- billsGuidance: {
- id: billsGuidanceLib,
- name: billsGuidanceString
- }
- };
- return result;
- }
- /**
- * 验证标准库数据
- *
- * @return {boolean}
- */
- function validLib() {
- let result = false;
- try {
- let valuationName = $("input[name='name']").val();
- if (valuationName === '') {
- throw '请填写计价规则名称';
- }
- let engineering = $("select[name='engineering']").val();
- if (engineering === '' || engineering <= 0) {
- throw '请选择工程专业';
- }
- if ($("input:hidden[name='bill_lib']").length <= 0) {
- throw '请添加标准清单';
- }
- if ($("input:hidden[name='ration_lib']").length <= 0) {
- throw '请添加定额库';
- }
- if ($("input:hidden[name='glj_lib']").length <= 0) {
- throw '请添加人材机库';
- }
- if ($("input:hidden[name='fee_lib']").length <= 0) {
- throw '请添加费率标准';
- }
- if ($("input:hidden[name='artificial_lib']").length <= 0) {
- throw '请添加人工系数';
- }
- if ($("input:hidden[name='program_lib']").length <= 0) {
- throw '请添加计算程序';
- }
- if ($("input:hidden[name='billsGuidance_lib']").length <= 0) {
- throw '请添加清单指引库';
- }
- result = true;
- } catch (error) {
- alert(error);
- result = false;
- }
- return result;
- }
- /**
- * 切换switch效果
- *
- * @param {Object} element
- * @return {boolean}
- */
- function switchChange(element) {
- // 第一个元素判断当前的状态
- let firstButton = element.children("button").first();
- let secondButton = element.children("button").eq(1);
- let currentStatus = firstButton.is(":disabled");
- if (currentStatus) {
- // 当前为true切换到false
- firstButton.removeClass('btn-success').removeClass('disabled').addClass('btn-default').removeAttr("disabled");
- firstButton.text('开启');
- secondButton.removeClass("btn-default").addClass("btn-danger").addClass("disabled").attr("disabled", "disabled");
- secondButton.text('已禁用');
- } else {
- // 当前false切换到true
- firstButton.removeClass("btn-default").addClass("btn-success").addClass("disabled").attr("disabled", "disabled");
- firstButton.text('已开启');
- secondButton.removeClass('btn-danger').removeClass('disabled').addClass('btn-default').removeAttr("disabled");
- secondButton.text('禁用');
- }
- return !currentStatus;
- }
|