"use strict";var _luckymoneyService=require("../../../../services/luckymoney-service"),_luckymoney2=require("../../../../utils/luckymoney"),_constant=require("../../../../utils/constant"),_jump=require("../../../../utils/jump");function _typeof(t){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_typeof(t)}function _regeneratorRuntime(){_regeneratorRuntime=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,n=Object.defineProperty||function(t,e,r){t[e]=r.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function l(t,e,r,o){var i=e&&e.prototype instanceof f?e:f,a=Object.create(i.prototype),c=new E(o||[]);return n(a,"_invoke",{value:k(t,r,c)}),a}function s(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=l;var d={};function f(){}function p(){}function h(){}var v={};u(v,i,function(){return this});var y=Object.getPrototypeOf,m=y&&y(y(x([])));m&&m!==e&&r.call(m,i)&&(v=m);var g=h.prototype=f.prototype=Object.create(v);function w(t){["next","throw","return"].forEach(function(e){u(t,e,function(t){return this._invoke(e,t)})})}function b(t,e){function o(n,i,a,c){var u=s(t[n],t,i);if("throw"!==u.type){var l=u.arg,d=l.value;return d&&"object"==_typeof(d)&&r.call(d,"__await")?e.resolve(d.__await).then(function(t){o("next",t,a,c)},function(t){o("throw",t,a,c)}):e.resolve(d).then(function(t){l.value=t,a(l)},function(t){return o("throw",t,a,c)})}c(u.arg)}var i;n(this,"_invoke",{value:function(t,r){function n(){return new e(function(e,n){o(t,r,e,n)})}return i=i?i.then(n,n):n()}})}function k(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=_(a,r);if(c){if(c===d)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=s(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===d)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}function _(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,_(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),d;var o=s(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,d;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,d):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,d)}function I(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function E(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(I,this),this.reset(!0)}function x(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),P(r),d}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;P(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:x(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),d}},t}function asyncGeneratorStep(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function _asyncToGenerator(t){return function(){var e=this,r=arguments;return new Promise(function(n,o){var i=t.apply(e,r);function a(t){asyncGeneratorStep(i,n,o,a,c,"next",t)}function c(t){asyncGeneratorStep(i,n,o,a,c,"throw",t)}a(void 0)})}}function ownKeys(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function _objectSpread(t){for(var e=1;e0)){e.next=2;break}return e.abrupt("return");case 2:if(r=t.data.phoneNumber,t.isValidPhoneNumber(r)){e.next=6;break}return t.setData({cellError:"请输入正确的手机号码"}),e.abrupt("return");case 6:return t.setData({cellCountdown:60}),t.countDown(),e.prev=8,o=(0,_luckymoneyService.getLuckymoneyService)(t.getSdkInstanceId()),e.next=12,null==o||null===(n=o.sendVerifyCode)||void 0===n?void 0:n.call(o,r);case 12:(i=e.sent)&&i.Status||t.setData({cellCountdown:0}),e.next=19;break;case 16:e.prev=16,e.t0=e.catch(8),t.setData({cellError:"notify too frequency"===e.t0.message?"发送验证码太频繁":"请求失败,请重试",cellCountdown:0});case 19:case"end":return e.stop()}},e,null,[[8,16]])}))()},countDown:function(){var t=this;this.data.cellCountdown<=0||setTimeout(function(){t.data.cellCountdown>0&&(t.setData({cellCountdown:t.data.cellCountdown-1}),t.countDown())},1e3)},onHandleWechatRedirect:function(){var t,e,r,n,o,i=this.data.mergedCurrent,a=this.properties.sdkInstance;if(a&&null!=i&&i.RedPacketID){var c=(null===(t=a.store)||void 0===t||null===(e=t.get)||void 0===e?void 0:e.call(t,"liveInfo.ActivityId"))||(null===(r=a.store)||void 0===r||null===(n=r.get)||void 0===n?void 0:n.call(r,"mainInfo.activityId"));a.emitEvent(_constant.EVENTS.PUBLIC.luckymoney.withdrawal,{activityId:c,redPacketId:i.RedPacketID,timestamp:Date.now(),detail:{redPacketId:i.RedPacketID}}),null==a||null===(o=a.reportTea)||void 0===o||o.call(a,"withdraw_wechat_auth_click",{terminal:"miniprogram",evModule:"luckymoney",params:{activityId:c,redPacketId:i.RedPacketID,timestamp:Date.now()}})}},isValidPhoneNumber:function(t){return _constant.TelRegx.test(t)},emitWithdrawEvent:function(){var t,e,r,n,o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=this.data.mergedCurrent,a=this.properties.sdkInstance;if(a&&null!=i&&i.RedPacketID){var c=(null===(t=a.store)||void 0===t||null===(e=t.get)||void 0===e?void 0:e.call(t,"liveInfo.ActivityId"))||(null===(r=a.store)||void 0===r||null===(n=r.get)||void 0===n?void 0:n.call(r,"mainInfo.activityId"));a.emitEvent(_constant.EVENTS.PUBLIC.luckymoney.withdrawal,_objectSpread({activityId:c,redPacketId:i.RedPacketID,timestamp:Date.now()},o||{}))}},onWithdrawClick:function(){var t=this;return _asyncToGenerator(_regeneratorRuntime().mark(function e(){var r,n,o,i,a,c,u,l,s,d,f,p,h,v;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.data,n=r.mergedCurrent,o=r.canWithdraw,i=r.withdrawRedirectInfo,a=t.properties.sdkInstance,o){e.next=4;break}return e.abrupt("return");case 4:if(a&&null!=n&&n.RedPacketID){e.next=6;break}return e.abrupt("return");case 6:if(u=(c=i||{}).EnableMiniApp,l=c.EnableCustomRedirect,s=c.MiniAppId,d=c.MiniAppRedirectUrl,f=c.CustomRedirectUrl,p=Boolean(u&&s&&d),h=Boolean(l&&f),v="",p?v="miniapp":h&&(v="custom"),v){e.next=13;break}return e.abrupt("return");case 13:if("miniapp"!==v){e.next=20;break}if(!s){e.next=18;break}return wx.navigateToMiniProgram({appId:s,path:d||"",fail:function(t){console.log("navigateToMiniProgram fail",t)}}),t.emitWithdrawEvent({type:"miniapp"}),e.abrupt("return");case 18:e.next=25;break;case 20:if("custom"!==v){e.next=25;break}if(!f){e.next=25;break}return t.emitWithdrawEvent({type:"custom",customRedirectUrl:f}),(0,_jump.navigateToConfiguredWebview)(a,_jump.JUMP_FEATURES.LUCKYMONEY_WITHDRAWAL,f),e.abrupt("return");case 25:case"end":return e.stop()}},e)}))()}}});