String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith);
} else {
return this.replace(reallyDo, replaceWith);
}
}
$(function() {
// 初始化
medicalDocument.addEvents();
medical_document.init();
});
var medical_document = {
init : function() {
this.addEvents();
this.addValidate();
},
/**
* 事件注册
*/
addEvents : function() {
},
/**
* 保存数据
*
* @param callback
*/
save : function(callback) {
var selectTemplate = $("#select_template").val();
if(isEmpty(selectTemplate)){
showWarn("请选择医疗文书模板!");
return false;
}
if ($("#medialDocumentForm").valid()) {
$("#content").val(medicalDocument.ke.html());
$.ajax({
url : ctx + "/medicalDocument/save.shtml",
data : $("#medialDocumentForm").serialize(),
type : "post",
dateType : "json",
success : function(result) {
if (result.status == 1) {
showTips("保存成功");
if (!isEmpty(callback)) {
callback();
}
} else {
showWarn(result.error);
}
}
});
}
},
/**
* 校验数据是否有效
*
* @param num
* @param min
* @param max
*/
checkNum : function(num, min, max) {
var flag = true;
if (isNaN(num)) {
return false;
}
if (!isEmpty(min)) {
flag = Number(num) >= min;
}
if (flag && !isEmpty(max)) {
flag = Number(max) <= max;
}
return flag;
},
addValidate : function() {
$('#medialDocumentForm').validate({
// 校验字段
rules : {
recordDateShow : {
required : [ "测量日期" ]
},
weight : {
number : [ "体重" ],
customRange : [ 0.01, 999, "体重" ]
}
},
errorPlacement : function(error, element) {
var obj = getValidateErrorDisplayEl($(element));
$(error).css("display", "block");
obj.find("[data-error]").append(error);
}
});
}
};
//初始化编辑插件
var medicalDocument = {
dataResult : "",// 初始化模板值
ke : "", // 文本编辑器新增病程记录时用到
dke : "",// 文本编辑器与上面一个不是同一个。修改模板和新增模板时用到
/** 获取病程记录模板信息 */
getTemp : function() {
var selectTemplate = $("#select_template").val();
if(!isEmpty(selectTemplate)){
$.ajax({
url : ctx + "/medicalDocument/template/getTemplate.shtml",
type : "post",
data : {
id : selectTemplate
},
dataType : "json",
success : function(data) {
if (data.status == 1) {
medicalDocument.ke.html(data.context.content);
}
}
});
}
},
/** 根据模板归属获取对应的模板值 */
changeTemplate : function(obj) {
medicalDocument.getTemp();
},
/** 初始化 */
addEvents : function() {
var editorContentInput = $('#editorContentText', window.parent.document).val();
// 初始化一些元素的高度
$("#wardRoundDZBL").hide();
// 初始化文本编辑器
KindEditor.ready(function(K) {
medicalDocument.ke = K.create('#editorContent', {
items : [ 'source', '|', 'undo', 'redo', '|', 'wordpaste', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull',
'insertorderedlist', 'insertunorderedlist', '|', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor',
'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'fullscreen', 'preview', 'print' ],
afterCreate : function () {
// ios 下编辑器无法滑动需要在外层追加一个div
this.sync();
var u = navigator.userAgent;
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
if(isiOS){
$('.ke-edit').css('-webkit-overflow-scrolling','touch');
$('.ke-edit').css('overflow-y','scroll');
}
}
});
if (!isEmpty(editorContentInput)) {
medicalDocument.ke.html(editorContentInput);
}
medicalDocument.ke.toolbar.disableAll(0);
medicalDocument.ke.edit.design(1);
medicalDocument.ke.toolbar.unselect("source");
medicalDocument.dke = K.create('#tContent', {
minHeight : 300,
items : [ 'source', '|', 'undo', 'redo', '|', 'wordpaste', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull',
'insertorderedlist', 'insertunorderedlist', '|', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor',
'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'fullscreen', 'preview', 'print' ]
});
medicalDocument.dke.toolbar.disableAll(0);
medicalDocument.dke.edit.design(1);
medicalDocument.dke.toolbar.unselect("source");
});
},
/** 返回 */
cancel : function() {
if (existsFunction("parent.removeActiveTab")) {// 如果父节点存在removeActiveTab方法
// 删除tab
parent.removeActiveTab();
} else {
goBack();
}
}
}
Js通用写法
于 2019-09-28 10:43:54 首次发布