UNPKG

h5-cli

Version:

hello

225 lines (185 loc) 7.05 kB
"use strict"; define(function (require, exports, module) { var md5 = require("libs/md5"); var PageModule = require("component/PageModule"); alert(1); try { var fromModule = PageModule.render({ init: function init() { this.patientId = this.query.patientId; this.patientName = this.query.patientName; //\u7ed1\u5b9a\u65b0\u5361\u7247\u9700\u8981\u8df3\u8f6c\u5230\u539f\u6765\u5c31\u8bca\u4eba\u9875\u9762 this.newCard = this.query.newCard; //\u672c\u9875\u9762 unionId corpId \u4e8c\u90091 this.unionId = this.query.unionId; this.corpId = this.query.corpId; $('#J_CardDescription').html(this.query.cardName); this.regEvent(); }, regEvent: function regEvent() { var self = this; $('#J_SubmintBtn').click(function () { self.submit(); }); }, submit: function submit() { var fromData = this.getData(); var cardNumber = fromData.cardNumber; //$.trim( $('#cardNumber').val() ); var phone = fromData.phone; // $.trim( $('#J_Phone').val() ); var cardType = fromData.cardType; // $.trim( $('#J_CardTypesList').val() ); var validCode = fromData.validCode; // if (!cardType) { this.util.alert("\u65e0\u53ef\u7528\u7684\u5c31\u8bca\u5361\u7c7b\u578b"); return; } if (!(cardNumber.length > 5 && cardNumber.length < 30)) { this.util.alert("\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u5361\u53f7"); return; } if (!/^\d{11}$/.test(phone)) { this.util.alert("\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u624b\u673a\u53f7\u7801"); return; } if (validCode.length == 0) { this.util.alert("\u8bf7\u8f93\u5165\u9a8c\u8bc1\u7801"); return; } //\u7ed1\u5b9a\u5361\u7247 this.get("/user-web/restapi/card/add", { unionId: this.unionId, corpId: this.corpId, cardNo: cardNumber, cardType: cardType, mobile: phone, patientId: this.patientId, validCode: validCode }); }, getData: function getData() { return { cardNumber: $.trim($('#cardNumber').val()), phone: $.trim($('#J_Phone').val()), cardType: $.trim($('#J_CardTypesList').val()), validCode: $.trim($('#J_Code').val()) }; }, onSuccess: function onSuccess(result) { var self = this; if (result.success) { this.util.alert("\u5361\u7247\u7ed1\u5b9a\u6210\u529f", function () { self.util.goBack(true); }); } else { this.util.alert(result.msg); } }, onError: function onError(result) { this.util.alert(result.msg); } }); //\u521d\u59cb\u5316\u53ef\u4ee5\u9009\u62e9\u7684\u5361\u7247\u7c7b\u578b var CardTypes = PageModule.render({ init: function init() { this.unionId = this.query.unionId; this.corpId = this.query.corpId; console.log(this.unionId, this.corpId); this.get("/user-web/restapi/card/types", { unionId: this.unionId, corpId: this.corpId }); }, onError: function onError() { $('#J_CardTypesList').html('<option>\u65e0\u5c31\u8bca\u5361\u7c7b\u578b</option>').attr("disabled", true); }, onSuccess: function onSuccess(result) { console.log(result); var list = result.data && result.data.cardType ? [result.data] : null; if (list && list.length) { var tmpl = '{@each list as item}' + '<option value="${item.cardType}">${item.cardName}</option>' + '{@/each}'; $('#J_CardTypesList').html(this.juicer(tmpl, { list: list })); } else { $('#J_CardTypesList').html('<option>\u5f53\u524d\u533a\u57df\u65e0\u5c31\u8bca\u5361</option>').attr("disabled", true); } } }); //\u53d1\u9001\u9a8c\u8bc1\u7801\u6a21\u5757 var sendCodeModule = PageModule.render({ isLoading: false, init: function init() { this.countTime = 0; var self = this; this.unionId = this.query.unionId; this.corpId = this.query.corpId; this.patientId = this.query.patientId; $('#J_SendCode').click(function () { if (self.isLoading) { return; } var data = fromModule.getData(); cardType = data.cardType; cardNumber = data.cardNumber; phone = data.phone; if (!cardType) { self.util.alert("\u65e0\u53ef\u7528\u7684\u5c31\u8bca\u5361\u7c7b\u578b"); return; } if (!(cardNumber.length > 5 && cardNumber.length < 30)) { self.util.alert("\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u5361\u53f7"); return; } if (!/^\d{11}$/.test(phone)) { self.util.alert("\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u624b\u673a\u53f7\u7801"); return; } self.isLoading = true; self.sendCode(phone, cardType, cardNumber, self.unionId, self.patientId, self.corpId); }); }, //\u5012\u8ba1\u65f6 countdown: function countdown() { var self = this; this.countTime = 60; var a = setInterval(function () { $('#J_SendCode').text(--self.countTime + "s"); if (self.countTime <= 0) { self.isLoading = false; $('#J_SendCode').text("\u91cd\u65b0\u9a8c\u8bc1"); clearInterval(a); } }, 1000); }, sendCode: function sendCode(phone, cardType, cardNumber, unionId, patientId, corpId) { //\u5148\u9a8c\u8bc1\u624b\u673a\u53f7\u7801\u662f\u5426\u5df2\u7ecf\u6ce8\u518c\uff0c\u6ca1\u6709\u6ce8\u518c\u7684\u7528\u6237\u63d0\u793a\u4ed6\u53bb\u6ce8\u518c //\u53d1\u9001\u9a8c\u8bc1\u7801 this.util.waitAlert("\u6b63\u5728\u9a8c\u8bc1\u4fe1\u606f\u662f\u5426\u5339\u914d..."); this.get("/user-web/restapi/card/validate", { mobile: phone, cardType: cardType, cardNo: cardNumber, unionId: unionId, patientId: patientId, corpId: corpId }); }, onSuccess: function onSuccess() { $('#J_SendCode').text("60s"); this.util.alert("\u9a8c\u8bc1\u7801\u5df2\u53d1\u9001"); this.countdown(); }, onError: function onError(result) { this.isLoading = false; this.util.alert(result.msg || "\u7f51\u7edc\u9519\u8bef\uff0c\u8bf7\u7a0d\u540e\u518d\u8bd5"); } }); //\u521d\u59cb\u5316\u53ef\u4ee5\u9009\u62e9\u7684\u5361\u7247\u7c7b\u578b CardTypes.init(); //\u521d\u59cb\u5316\u9a8c\u8bc1\u7801\u53d1\u9001\u6a21\u5757 sendCodeModule.init(); //\u521d\u59cb\u5316\u8868\u5355\u9a8c\u8bc1 fromModule.init(); module.exports = fromModule; } catch (e) { alert(JSON.stringify(e)); } alert(2); });