UNPKG

h5-cli

Version:

hello

442 lines (416 loc) 17 kB
"use strict"; define("pages/add-patient", function (require, exports, module) { var PageModule = require("component/PageModule"); var PatientCardModule = require("pages/patient-card"); //\u8868\u5355\u9a8c\u8bc1\u903b\u8f91 var formModule = PageModule.render({ init: function init() { this.regEvent(); }, regEvent: function regEvent() { var self = this; var idType = $('#idType').val(); self.render({ idType: idType }); $('#idType').change(function () { self.render({ idType: $(this).val() }); }); $('#J_Default').click(function () { var checked = this.checked; // console.log(checked) if (checked) { self.util.dialog("\u662f\u5426\u5c06\u6b64\u4eba\u8bbe\u4e3a\u9ed8\u8ba4\u5c31\u8bca\u4eba\uff1f", function (okay) { if (okay) { if (formModule.checkData()) { var data = formModule.getData(); if (data.id) { self.util.waitAlert("\u8bf7\u7a0d\u7b49..."); self.get("/user-web/restapi/patient/update", data); } } } else { $('#J_Default')[0].checked = !checked; } }); } else { self.util.dialog("\u4e0d\u518d\u5c06\u6b64\u4eba\u8bbe\u4e3a\u9ed8\u8ba4\u5c31\u8bca\u4eba\uff1f", function (okay) { if (okay) { if (formModule.checkData()) { var data = formModule.getData(); // self.submitData = data; if (data.id) { self.util.waitAlert("\u8bf7\u7a0d\u7b49..."); self.get("/user-web/restapi/patient/update", data); } } } else { $('#J_Default')[0].checked = !checked; } }); } }); // $('#J_Children').change(function () { // self.render({hasId:$(this)[0].checked}) // }); }, onError: function onError(result) { $('#J_Default')[0].checked = !$('#J_Default')[0].checked; $('#J_Page').removeClass("wait"); this.errorHandle(result); }, onSuccess: function onSuccess(result) { if (result) { this.cache.set("needDefault", true); this.util.alert("\u64cd\u4f5c\u6210\u529f"); } }, setData: function setData(data) { //... // $('#patientId').val( data.patientId ); this.id = data.id; if (data.guarderIdNo) { data.idType = 2; } else { data.idType = 1; } this.render(data); $('#patientName').val(data.patientName); // $('#sex').val(data.sex); $('#idType').val(data.idType); $('#idNo').val(data.idNo); $('#J_Default')[0].checked = data.default; if (data.id) { //\u4fee\u6539\u6a21\u5f0f // $('#idNo').attr("disabled", "disabled"); } else { //\u6dfb\u52a0\u5c31\u8bca\u4eba\u7684\u65f6\u5019 \u9ed8\u8ba4\u586b\u5165 } $('#J_Phone').val(data.phoneNum); $('#guarderIdNo').val(data.guarderIdNo); if (data.birthday) { var year = this.util.dateFormat(data.birthday, "yyyy"), month = this.util.dateFormat(data.birthday, "MM"), day = this.util.dateFormat(data.birthday, "dd"); document.getElementById("J_Year").value = year; document.getElementById("J_Month").value = month; document.getElementById("J_Day").value = day; } if (data.sex) { document.getElementById("J_Sex").value = data.sex; } // if(data.idNo){ // $('#J_Children')[0].checked = true; // }else { // $('#J_Children')[0].checked = false; // } this.render(data); }, getData: function getData() { var idType = $('#idType').val(); var birthday = $('#J_Year').val() + "-" + $('#J_Month').val() + "-" + $('#J_Day').val(); // var registerData = this.cache.getCacheModule(); // var corpId = registerData.get("corpId").value; // console.log("111=====>",this.query.corpId,corpId) return { corpId: this.query.corpId == "undefined" ? null : this.query.corpId, unionId: this.query.unionId == "undefined" ? null : this.query.unionId, id: this.id, //$('#patientId').val(), patientName: $('#patientName').val(), idType: idType, //, idNo: $('#idNo').val(), guarderIdNo: idType == 2 ? $('#guarderIdNo').val() : null, phoneNum: $.trim($('#J_Phone').val()), isDefault: $("#J_Default")[0].checked, sex: idType == 2 ? $('#J_Sex').val() : null, birthday: idType == 2 ? birthday : null }; }, render: function render(data) { // console.log(data.idType, data.guarderIdNo) // alert(data.idType); if (data.idType) { if (data.idType == 1) { $('#J_GuarderIdNoInput').hide(); $('#children').hide(); $('#sex,#J_Date').hide(); $('#J_idNo').show(); $('#J_BindCardTip').find('ul').remove(); $('#J_BindCardTip').append('<ul><li>1. \u5c31\u8bca\u4eba\u59d3\u540d\u3001\u8eab\u4efd\u8bc1\u53f7\u5c06\u7528\u4e8e\u533b\u9662\u5efa\u6863\u4fe1\u606f\u5339\u914d\uff0c\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u5c31\u8bca\u4eba\u59d3\u540d\u548c\u8eab\u4efd\u8bc1\u53f7\uff1b</li>' + '<li>2.\u6dfb\u52a0\u5c31\u8bca\u4eba\u540e\u9884\u7ea6\uff0c\u53d6\u53f7\u65f6\u9700\u4f7f\u7528\u4e0e\u6b64\u5904\u586b\u5199\u7684\u5c31\u8bca\u4eba\u8eab\u4efd\u8bc1\u53f7\u548c\u59d3\u540d\u76f8\u5339\u914d\u7684\u5c31\u8bca\u5361\uff0c\u5426\u5219\u65e0\u6cd5\u53d6\u53f7\uff1b</li>' + '<li>3.\u65e0\u8eab\u4efd\u8bc1\u513f\u7ae5\u8bf7\u9009\u62e9\u201c\u513f\u7ae5\u201d\u7c7b\u578b\u6dfb\u52a0\u5c31\u8bca\u4eba\u3002</li></ul>'); } if (data.idType == 2) { $('#J_GuarderIdNoInput').show(); $('#children').show(); // if (!$('#J_Children')[0].checked){ $('#sex,#J_Date').show(); $('#J_idNo').show(); // } $('#J_BindCardTip').find('ul').remove(); $('#J_BindCardTip').append('<ul><li>1. \u5982\u679c\u513f\u7ae5\u5df2\u529e\u7406\u8eab\u4efd\u8bc1\uff0c\u8bf7\u9009\u62e9\u201c\u6210\u4eba\u201d\u7c7b\u578b\u6dfb\u52a0\u5c31\u8bca\u4eba\uff0c\u5e76\u5728\u7ebf\u4e0b\u529e\u5361\u65f6\uff0c\u51ed\u501f\u513f\u7ae5\u672c\u4eba\u8eab\u4efd\u8bc1\u529e\u7406\u5c31\u8bca\u5361\uff1b</li>' + '<li>2.\u6dfb\u52a0\u201c\u513f\u7ae5\u201d\u7c7b\u578b\u5c31\u8bca\u4eba\u9700\u53e6\u5916\u63d0\u4f9b\u76d1\u62a4\u4eba\u8eab\u4efd\u4fe1\u606f\u3002</li>' + '<li>3.\u6dfb\u52a0\u513f\u7ae5\u5c31\u8bca\u4eba\u540e\u9884\u7ea6\uff0c\u53d6\u53f7\u65f6\u9700\u4f7f\u7528\u6b64\u5904\u586b\u5199\u7684\u76d1\u62a4\u4eba\u8eab\u4efd\u8bc1\u53f7\u548c\u513f\u7ae5\u59d3\u540d\u76f8\u5339\u914d\u7684\u5c31\u8bca\u5361\u53d6\u53f7\uff0c\u5426\u5219\u65e0\u6cd5\u53d6\u53f7\uff1b</li></ul>'); } } else { if (data.hasId) { $('#sex,#J_Date').hide(); $('#J_idNo').show(); } else { $('#sex,#J_Date').show(); $('#J_idNo').hide(); } } }, checkData: function checkData() { var data = this.getData(); // var type = $('#J_Children')[0].checked; // console.log( data ) //\u00b7 \u59d3\u540d\u4e2d\u95f4\u7684 \u00b7 //|| (!/^[a-zA-Z\u4e00-\u9fa5]+$/.test(data.patientName)) // \u4e2d\u6587\u59d3\u540d\u4e2d\u652f\u6301\u4e24\u79cd \u70b9 \u82f1\u6587\u7684\u70b9\uff08\u00b7\uff09 \u4e2d\u6587\u7684\u70b9\uff08\u2022\uff09\u4e0b\u70b9(\u002e) // alert(data.patientName) // var patientName = data.patientName.replace("\u2022", "").replace("\u00b7",""); // alert(patientName) if (!(data.patientName.length > 1) || !/^[a-zA-Z\u4e00-\u9fa5\u2022\u00b7.]+$/.test(data.patientName)) { this.util.alert("\u8bf7\u6b63\u786e\u586b\u5199\u60a3\u8005\u59d3\u540d"); return false; } if (!data.phoneNum || !/^\d{11}$/.test(data.phoneNum)) { this.util.alert("\u8bf7\u6b63\u786e\u586b\u5199\u624b\u673a\u53f7\u7801"); return false; } if (!/^\d{17}[\d\x]?/.test(data.idNo) && data.idType == "1") { this.util.alert("\u8bf7\u6b63\u786e\u586b\u5199\u8eab\u4efd\u8bc1\u53f7\u7801"); return false; } if (data.idType == 2 && !/^\d{4}-\d{2}-\d{2}$/.test(data.birthday)) { this.util.alert("\u8bf7\u6b63\u786e\u586b\u5199\u513f\u7ae5\u51fa\u751f\u65e5\u671f"); return false; } // console.log(/^\d{17}[\d\x]?/.test(data.guarderIdNo)) if (data.idType == "2") { //&& data.guarderIdNo != "" if (!/^\d{17}[\d\x]?/.test(data.guarderIdNo)) { this.util.alert("\u8bf7\u6b63\u786e\u586b\u5199\u76d1\u62a4\u4eba\u8eab\u4efd\u8bc1\u53f7\u7801"); return false; } } return true; } }); //\u6839\u636eunionid\u6216\u8005corpId\u5224\u65ad\u662f\u5426\u8981\u7ed1\u5361 var isNeedCard = PageModule.render({ init: function init() { this.unionId = this.query.unionId; this.corpId = this.query.corpId; if (this.unionId != "undefined") { this.util.waitAlert("\u52a0\u8f7d\u4e2d..."); this.get("/user-web/restapi/card/isNeedCardByUnionId", { unionId: this.unionId }); } else if (this.corpId != "undefined") { this.util.waitAlert("\u52a0\u8f7d\u4e2d..."); this.get("/user-web/restapi/card/isNeedCardByCorpId", { corpId: this.corpId }); } }, onSuccess: function onSuccess(result) { this.status = result.data; }, getData: function getData() { return this.status; } }); //\u6839\u636eunionid\u6216\u8005corpId,\u548cpatientId\u662f\u5426\u6709\u5361 var cardList = PageModule.render({ init: function init() { this.unionId = this.query.unionId; this.corpId = this.query.corpId; this.id = this.query.id; this.status = false; if (this.id) { this.util.waitAlert("\u52a0\u8f7d\u4e2d..."); this.get("/user-web/restapi/card/list", { unionId: this.unionId, corpId: this.corpId, patientId: this.id }); } }, onSuccess: function onSuccess(result) { if (result.data && result.data.cardNo) { this.status = true; } }, onError: function onError() { return false; }, getStatus: function getStatus() { return this.status; } }); //editModule var editModule = PageModule.render({ init: function init() { this.id = this.query.id; this.util.waitAlert("\u6b63\u5728\u83b7\u53d6\u60a3\u8005\u4fe1\u606f..."); this.get("/user-web/restapi/patient/getbaseinfo", { corpId: this.query.corpId || this.corpId, //\u53ef\u4e0d\u4f20 patientId: this.id }); }, regEvent: function regEvent() { document.getElementById("idNo").setAttribute("readOnly", true); document.getElementById("patientName").setAttribute("readOnly", true); document.getElementById("idType").setAttribute("disabled", true); document.getElementById("guarderIdNo").setAttribute("readOnly", true); }, onSuccess: function onSuccess(result) { if (result.success == true) { formModule.setData(result.data); this.regEvent(); // \u6ca1\u6709\u7ecf\u8fc7\u8ba4\u8bc1\u7684\u5c31\u8bca\u4eba\u53ef\u4ee5\u5220\u9664 if (result.data && result.data.auth == false) { deleteModule.init(this.query.id); } } } }); //submitModule var pageModule = PageModule.render({ init: function init() { //\u67e5\u770b\u8be5\u533b\u9662\u662f\u5426\u8981\u7ed1\u5361 isNeedCard.init(); cardList.init(); //\u4fee\u6539 if (this.query.id) { //\u4fee\u6539\u5c31\u8bca\u4eba editModule.init(); //\u67e5\u770b\u5c31\u8bca\u4eba\u662f\u5426\u5df2\u7ecf\u7ed1\u5b9a\u5c31\u8bca\u5361 PatientCardModule.init(this.query.unionId, this.query.id); } else { //\u6dfb\u52a0\u5c31\u8bca\u4eba \u9ed8\u8ba4\u586b\u5165\u5f53\u524d\u767b\u5f55\u7528\u6237\u7684\u624b\u673a\u53f7\u7801 this.io.get("/user-web/restapi/ytUsers/getUserInfo", {}, function (result) { if (result && result.data && result.data.phoneNum) { $('#J_Phone').val(result.data.phoneNum); } }); $('#J_BindCardTip').removeClass("hide"); } this.regEvent(); formModule.init(); }, regEvent: function regEvent() { var self = this; $('#J_SubmintBtn').click(function () { // result.data && result.data.cardType && result.data.isTiedCard if (formModule.checkData()) { var data = formModule.getData(); // self.submitData = data; self.util.waitAlert("\u8bf7\u7a0d\u7b49..."); if (data.id) { self.get("/user-web/restapi/patient/update", data); } else { self.get("/user-web/restapi/patient/add", data); } } }); var now = new Date(); var year = ""; for (var i = 0; i < 18; i++) { year += "<option value='" + (parseInt(now.getFullYear()) - i) + "'>" + (parseInt(now.getFullYear()) - i) + "</option>"; } $('#J_Year').append(year); var month = ""; for (var i = 1; i < 13; i++) { if (i < 10) { i = "0" + i; } month += "<option value='" + i + "'>" + i + "</option>"; } $('#J_Month').append(month); var day = ""; for (var i = 1; i < 32; i++) { if (i < 10) { i = "0" + i; } day += "<option value='" + i + "'>" + i + "</option>"; } $('#J_Day').append(day); $('#J_Month').change(function () { $('#J_Day').empty(); var d = new Date($('#J_Year').val(), $(this).val(), 0); var day = ""; for (var i = 1; i <= d.getDate(); i++) { if (i < 10) { i = "0" + i; } day += "<option value='" + i + "'>" + i + "</option>"; } $('#J_Day').append(day); }); }, onSuccess: function onSuccess(result) { // console.log( this.query.unionId ) // alert(2) var tip = this.query.id ? '\u4fee\u6539' : '\u6dfb\u52a0'; var tips = tip + '\u5c31\u8bca\u4eba\u6210\u529f'; var context = tip + '<span>\u5c31\u8bca\u4eba\u6210\u529f\uff0c\u662f\u5426\u7acb\u5373\u7ed1\u5b9a\u5c31\u8bca\u5361</span>' + '</br>' + "<span style='font-size: 12px;color: rgba(31, 29, 29, 0.95);'>\u7ed1\u5b9a\u5c31\u8bca\u5361\u53ef\u4ee5\u65b9\u4fbf\u5404\u9879\u533b\u9662\u5185\u670d\u52a1</span>"; var self = this; if (result.data && !isNeedCard.getData().need) { this.util.alert(tips, function () { self.util.goBack(true); }); } else if (result.data && !cardList.getStatus()) { var href = "bind-card.html?cardType=" + isNeedCard.getData().cardType + "&description=" + isNeedCard.getData().description + "&target=_blank" + "&patientId=" + result.data; if (self.query.unionId != "undefined") { href = href + "&unionId=" + self.query.unionId; } if (self.query.corpId != "undefined") { href = href + "&corpId=" + self.query.corpId; } self.util.dialog(context, function (okay) { if (okay) { self.util.goBack(true); } else { location.href = href; } }, { cancel: true, cancelText: "\u7ed1\u5b9a\u5c31\u8bca\u5361", ok: true, okText: "\u6682\u4e0d\u7ed1\u5361" }); // PatientCardModule.init(this.query.unionId, result.data,true,context); } } }); //\u5220\u9664\u5c31\u8bca\u4eba var deleteModule = PageModule.render({ init: function init(id) { var self = this; //this.id = id; $('#J_DeleteBtn').removeClass("hide").click(function () { self.util.dialog("\u5220\u9664\u5c31\u8bca\u4eba\u540e\uff0c\u6240\u6709\u533b\u7597\u670d\u52a1\u6570\u636e\u4e5f\u4e00\u5e76\u5220\u9664\uff0c\u786e\u8ba4\u8981\u5220\u9664\u5417\uff1f", function (okay) { if (okay) { self.deletePatient(id); } }); }); }, deletePatient: function deletePatient(id) { this.util.waitAlert("\u8bf7\u6c42\u4e2d..."); this.get("/user-web/restapi/patient/del", { patientId: id }); //\u4ece\u672c\u5730\u7f13\u5b58\u4e2d\u5220\u9664\u5c31\u8bca\u4eba var cache = this.cache.getCacheModule(); var patient = cache.get("patient"); if (patient && patient.value == id) { cache.remove("patient"); } }, onSuccess: function onSuccess() { var self = this; this.util.alert("\u5220\u9664\u6210\u529f", function () { self.util.goBack(true); }); } }); pageModule.init(); module.exports = pageModule; });