/** * Created by zhang on 2018/9/3. */ $(document).ready(function () { const locked = lockUtil.getLocked(); lockUtil.lockTools($(document.body), locked); try { let tem = sortJson(JSON.parse($("#originalInfo").val()), compareInfo); $("#template").val(JSON.stringify(tem, null, 4)); } catch (err) { console.log(err); } $("#format").click(function () { try { let jsonText = $("#template").val(); $("#template").val(JSON.stringify(JSON.parse(jsonText), null, 4)); } catch (err) { console.log(err); alert("输入的JSON格式有误,请重新输入!"); } }); $("#save").click(async function () { try { $.bootstrapLoading.start(); let libID = $("#libID").val(); let jsonText = $("#template").val(); if (jsonText.indexOf("'") != -1) { alert( "输入的格式不能包含 ' 位于:" + jsonText.substr(jsonText.indexOf("'") - 15, 18) ); return; } await ajaxPost("/itemSetting/saveLib", { query: { ID: libID }, data: { template: JSON.parse(jsonText) }, }); $.bootstrapLoading.end(); } catch (err) { $.bootstrapLoading.end(); console.log(err); alert("保存失败,请查看输入数据"); } }); $("#createNormal").click(async function () { let basicTemplate = [ { ID: "1", name: "在生产车间边生产边施工", base: "人工费", coe: 10, isCalc: false, reductionRate: 100, measureRate: 70, position: "010001", }, { ID: "2", name: "在有害身体健康的场所内施工", base: "人工费", coe: 10, isCalc: false, reductionRate: 100, measureRate: 70, position: "010001", }, { ID: "3", name: "在洞内、地下室内、库内或暗室内进行施工", base: "人工费", coe: 40, isCalc: false, reductionRate: 100, measureRate: 70, position: "010001", }, { ID: "4", name: "在洞内、地下室内、库内或暗室内进行施工(模板拆除)", base: "人工费", coe: 10, isCalc: false, reductionRate: 100, measureRate: 70, position: "010001", }, ]; try { let jsonText = JSON.stringify(basicTemplate); $("#template").val(JSON.stringify(JSON.parse(jsonText), null, 4)); } catch (err) { console.log(err); } }); }); function compareInfo(a, b) { let mapping = { ID: 1, name: 2, }; let aV = mapping[a] ? mapping[a] : 0, bV = mapping[b] ? mapping[b] : 0; return aV - bV; }