h5-cli
Version:
hello
284 lines (245 loc) • 11.2 kB
JavaScript
"use strict";
define(function (require, exports, module) {
var PageModule = require("component/PageModule");
//\u652f\u4ed8\u6a21\u5757\u9875\u9762UI
var payPageModule = require("mods/pay/index");
//\u652f\u4ed8\u6a21\u5757\u7f51\u8def\u8bf7\u6c42
var payModule = require("mods/pay/pay");
//\u5fae\u4fe1\u5185\u83b7\u53d6openid
var weixin = require("mods/wxOpenId/index");
var page = PageModule.render({
init: function init() {
this.corpId = this.query.corpId;
this.unionId = this.query.unionId;
this.patientId = this.query.patientId || null;
this.cardNo = '';
this.cardId = this.query.cardId || '';
//\u5b58\u653eurl\u4e2d\u7684patientId\u548ccardId\uff0c\u4e0d\u53ef\u53d8
this.urlPatientId = this.query.patientId || '';
this.urlCardId = this.query.cardId || '';
//\u5982\u679c\u5728\u5fae\u4fe1\u4e2d\uff0c\u9996\u5148\u8981\u83b7\u53d6openId
if (this.util.isInMicroMessenger()) {
this.openId = weixin.getOpenId(this.corpId, 1);
}
//\u521d\u59cb\u5316\u7f34\u8d39\u65b9\u5f0f
payPageModule.onReady = function (isSupport) {
if (isSupport) {
$('#J_Submit').removeClass("hide");
}
};
payPageModule.init(this.corpId, 4);
this.regEvent();
},
isDefaultSelect: function isDefaultSelect(patientId, currentPatientId, isDefault) {
if (patientId) {
return patientId == currentPatientId ? "selected" : "";
} else {
return isDefault ? "selected" : "";
}
},
regEvent: function regEvent() {
var self = this;
/*$('#J_PatientSelect').change(function(){
self.cache.set("patientId", $(this).val());
self.queryAccout($(this).val())
})*/
// var patientId = patient ? patient.value : null;
var patientId = this.cache.get("patientId") || null;
// console.log(patient)
PageModule.render({
init: function init() {
this.get("/user-web/restapi/patient/getList", { corpId: this.query.corpId || this.corpId });
$('.close-container').click(function () {
$('.patient-list-container').hide();
});
//\u5f39\u7a97\u70b9\u51fb\u534a\u900f\u660e\u5904\u6d88\u5931
$('.patient-list-container').click(function () {
$('.patient-list-container').hide();
});
$('.patient-list-main').click(function (e) {
e.stopPropagation();
});
//\u70b9\u51fb\u5c31\u8bca\u4eba\u5f39\u51fa\u6846
$('#J_PatientSelect').click(function () {
$('#patientList').show();
});
//\u70b9\u51fb\u5c31\u8bca\u4eba\u9009\u62e9\uff0c\u5f39\u7a97\u6d88\u5931\u5e76\u8d4b\u503c\u7ed9this.patientId
$('#patientList .patient-list').on('click', '.patient-li', function () {
self.patientId = $(this).attr('data-pid');
$('#patientList').hide();
$('#J_PatientSelect').text($(this).attr('data-pname'));
$('#J_Balance').val(0 + '\u5143');
$('#J_CardSelect').text('\u8bf7\u9009\u62e9\u5145\u503c\u8d26\u6237');
self.cardId = '';
self.cardNo = '';
self.queryAccout(self.patientId);
});
},
onSuccess: function onSuccess(result) {
if (result.data) {
var patientList = result.data;
if (patientList.length > 0) {
$('#patientList .patient-list').html(patientList.map(function (item) {
var icon = item.idType == 1 ? 'https://front-images.oss-cn-hangzhou.aliyuncs.com/i4/7fee31b86360d5ee6b19c10b4dae22c2-68-68.png' : 'https://front-images.oss-cn-hangzhou.aliyuncs.com/i4/f67f01446d90cf0613feee5389c44b36-68-68.png';
return "<div class=\"patient-li\" data-pid=" + item.id + " data-pname=" + item.patientName + ">\n <img class=\"patient-list-avatar\" src=" + icon + " />\n <div class=\"patient-list-item\">\n <div class=\"patient-list-name\">\n " + item.patientName + "\n <span>" + (item.idType == 1 ? "\u6210\u4eba" : "\u513f\u7ae5") + "</span>\n </div>\n <div class=\"patient-list-brief\">" + (item.idNo || item.guarderIdNo) + "</div>\n </div>\n </div>";
}).join(""));
} else {
$('#patientList .patient-list').html("<div class=\"patient-notice\">\n <span></span>\n <p>\u5C1A\u672A\u6DFB\u52A0\u5C31\u8BCA\u4EBA</p>\n <p>\u8BF7\u5148\u6DFB\u52A0\u5C31\u8BCA\u4EBA</p>\n </div>");
}
//\u5982\u679c\u5c31\u8bca\u4eba\u5217\u8868\u957f\u5ea6>0\uff0c\u9ed8\u8ba4\u9009\u62e9\u9ed8\u8ba4\u5c31\u8bca\u4eba\uff0c\u5982\u679c\u65e0\u9ed8\u8ba4\u5c31\u8bca\u4eba\uff0c\u5219\u9009\u62e9\u7b2c\u4e00\u4e2a\u5c31\u8bca\u4eba
if (self.patientId) {
var defaultPatient = patientList.filter(function (z) {
return z.id == self.patientId;
})[0];
$('#J_PatientSelect').text(defaultPatient ? defaultPatient.patientName : patientList[0].patientName);
} else if (patientList.length > 0) {
var _defaultPatient = patientList.filter(function (z) {
return z.default;
})[0];
self.patientId = _defaultPatient ? _defaultPatient.id : patientList[0].id;
$('#J_PatientSelect').text(_defaultPatient ? _defaultPatient.patientName : patientList[0].patientName);
self.queryAccout(self.patientId);
}
}
},
onError: function onError(e) {
if (e.msg == '\u672a\u767b\u5f55') {
self.util.goLogin();
}
}
}).init();
$('#J_Submit').click(function () {
if (!$(this).attr("disabled")) {
self.submit();
}
});
// $('#J_AddPatient').attr("href","../patient-list.html?selectView=1&corpId="+self.query.corpId+"&target=_blank");
},
//\u67e5\u8be2\u5c31\u8bca\u4eba\u4f59\u989d
queryAccout: function queryAccout(patientId) {
this.util.waitAlert("\u6b63\u5728\u67e5\u8be2\u4f59\u989d...");
/*PageModule.render({
init: function() {
this.get("/user-web/restapi/patient/getallinfo", {
corpId: self.corpId,
unionId: self.unionId,
patientId: patientId,
queryBalance: true //\u662f\u5426\u67e5\u8be2\u4f59\u989d
});
},
onSuccess: function(result) {
//\u8868\u793a\u5c31\u8bca\u4eba\u80fd\u4e0d\u80fd\u5145\u503c
console.log(result);
if (result.data.account) {
$('#J_Tips').addClass("hide");
$('#J_Submit').removeAttr("disabled");
} else {
$('#J_Tips').text("\u8bf7\u5230\u81ea\u52a9\u7ec8\u7aef\u53d6\u5361\u540e\u518d\u5145\u503c").removeClass("hide");
$('#J_Submit').attr("disabled", "disabled");
}
},
onError: function () {
$('#J_Tips').text("\u5f53\u524d\u5c31\u8bca\u4eba\u72b6\u6001\u65e0\u6cd5\u5145\u503c").removeClass("hide");
$('#J_Submit').attr("disabled", "disabled");
},
}).init();*/
this.get("/user-web/restapi/inhos/patientinfo", {
unionId: this.unionId,
corpId: this.corpId,
patientId: patientId,
queryInHosPatient: true,
queryBalance: true //\u662f\u5426\u67e5\u8be2\u4f59\u989d
});
},
//\u67e5\u8be2\u4f59\u989d\u56de\u8c03
onComplate: function onComplate(result) {
this.util.waitHide();
if (result.success && result.data) {
this.onSuccess(result);
} else {
//\u5931\u8d25
$('#J_Balance').val(0 + "\u5143");
this.onError(result);
}
},
onSuccess: function onSuccess(result) {
this.util.waitHide();
var balance = 0;
if (result.success && result.data.balance) {
balance = result.data.balance;
}
$('#J_Balance').val(balance / 100 + " \u5143");
//\u8868\u793a\u5c31\u8bca\u4eba\u80fd\u4e0d\u80fd\u5145\u503c
if (result.data.accountNo) {
//\u5357\u9633\u533b\u9662\u5751\u7239 \u76f4\u63a5\u5224\u65ad\u4e2d\u6587
if (result.data.status != "\u5165\u9662") {
$('#J_Tips').text("\u8be5\u60a3\u8005\u72b6\u6001\u4e0d\u652f\u6301\u5145\u503c").removeClass("hide");
$('#J_Submit').attr("disabled", "disabled");
} else {
//\u5176\u4ed6\u72b6\u6001 \u53ef\u4ee5\u5145\u503c
$('#J_Tips').addClass("hide");
$('#J_Submit').removeAttr("disabled");
}
} else {
$('#J_Tips').text("\u8bf7\u5230\u81ea\u52a9\u7ec8\u7aef\u53d6\u5361\u540e\u518d\u5145\u503c").removeClass("hide");
$('#J_Submit').attr("disabled", "disabled");
}
},
onError: function onError() {
$('#J_Tips').text("\u4f4f\u9662\u75c5\u4eba\u4e0d\u5b58\u5728\uff0c\u4e0d\u80fd\u5145\u503c").removeClass("hide");
$('#J_Submit').attr("disabled", "disabled");
},
submit: function submit() {
var self = this;
var feeChannel = payPageModule.getPayType();
var patientId = this.patientId || '';
var fee = parseFloat($('#J_recharge_money').val());
var corpId = this.corpId;
var unionId = this.unionId;
var cardId = this.cardId || '';
var util = this.util;
if (!patientId) {
this.util.alert("\u8bf7\u9009\u62e9\u5c31\u8bca\u4eba");
return;
}
if (!(fee >= 0.01)) {
this.util.alert("\u8f93\u5165\u91d1\u989d\u5fc5\u987b\u5927\u4e8e\u7b49\u4e8e0.01");
return;
}
if (feeChannel == -1) {
this.uitl.alert("\u8bf7\u9009\u62e9\u652f\u4ed8\u65b9\u5f0f");
return;
}
this.feeChannel = feeChannel;
fee = (fee * 100).toFixed(0);
/**
feeChannel \u652f\u4ed8\u65b9\u5f0f //1\u3001\u652f\u4ed8\u5b9d 2\u3001\u5fae\u4fe1 3\u3001\u4f59\u989d
optType \u4e1a\u52a1\u7c7b\u578b //1\u3001\u5145\u503c 2\u3001\u7f34\u8d39 3\u3001\u6302\u53f7 4\u4f4f\u9662\u5145\u503c
optParam \u4e1a\u52a1\u53c2\u6570
*/
//\u652f\u4ed8\u5b8c\u6210
payModule.onPayComplate = function (isOkay, id, result) {
if (isOkay) {
self.util.alert("\u5145\u503c\u6210\u529f");
setTimeout(function () {
window.location.reload();
}, 1000);
} else {
setTimeout(function () {
window.location.href = util.h5URL("/pages/bill-detail.html?unionId=" + unionId + "&id=" + id + "&corpId=" + corpId); //"https://uat.yuantutech.com/yuantu/h5-cli/1.3.32/pages/bill-detail.html?id="+id;
}, 1500);
}
};
//optType \u4e1a\u52a1\u7c7b\u578b //1\u3001\u5145\u503c 2\u3001\u7f34\u8d39 3\u3001\u6302\u53f7 4\u4f4f\u9662\u5145\u503c
payModule.pay(feeChannel, 4, {
fee: fee,
patientId: patientId,
corpId: this.corpId,
openId: this.openId,
cardId: cardId
});
}
});
page.init();
module.exports = page;
});