"use strict";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)}var _luckymoney2=require("../../../../utils/luckymoney"),_times=require("../../../../utils/times"),_luckymoneyService=require("../../../../services/luckymoney-service");function _regeneratorRuntime(){_regeneratorRuntime=function(){return t};var t={},e=Object.prototype,n=e.hasOwnProperty,r=Object.defineProperty||function(t,e,n){t[e]=n.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function c(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,n){return t[e]=n}}function l(t,e,n,o){var i=e&&e.prototype instanceof f?e:f,a=Object.create(i.prototype),u=new E(o||[]);return r(a,"_invoke",{value:L(t,n,u)}),a}function s(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}t.wrap=l;var d={};function f(){}function h(){}function p(){}var v={};c(v,i,function(){return this});var y=Object.getPrototypeOf,m=y&&y(y(T([])));m&&m!==e&&n.call(m,i)&&(v=m);var g=p.prototype=f.prototype=Object.create(v);function w(t){["next","throw","return"].forEach(function(e){c(t,e,function(t){return this._invoke(e,t)})})}function k(t,e){function o(r,i,a,u){var c=s(t[r],t,i);if("throw"!==c.type){var l=c.arg,d=l.value;return d&&"object"==_typeof(d)&&n.call(d,"__await")?e.resolve(d.__await).then(function(t){o("next",t,a,u)},function(t){o("throw",t,a,u)}):e.resolve(d).then(function(t){l.value=t,a(l)},function(t){return o("throw",t,a,u)})}u(c.arg)}var i;r(this,"_invoke",{value:function(t,n){function r(){return new e(function(e,r){o(t,n,e,r)})}return i=i?i.then(r,r):r()}})}function L(t,e,n){var r="suspendedStart";return function(o,i){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw i;return{value:void 0,done:!0}}for(n.method=o,n.arg=i;;){var a=n.delegate;if(a){var u=b(a,n);if(u){if(u===d)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var c=s(t,e,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===d)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}function b(t,e){var n=e.method,r=t.iterator[n];if(void 0===r)return e.delegate=null,"throw"===n&&t.iterator.return&&(e.method="return",e.arg=void 0,b(t,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),d;var o=s(r,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 x(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 D(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function E(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(x,this),this.reset(!0)}function T(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 r=-1,o=function e(){for(;++r=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var u=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(u&&c){if(this.prev=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),D(n),d}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var o=r.arg;D(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:T(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},t}function asyncGeneratorStep(t,e,n,r,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void n(t)}u.done?e(c):Promise.resolve(c).then(r,o)}function _asyncToGenerator(t){return function(){var e=this,n=arguments;return new Promise(function(r,o){var i=t.apply(e,n);function a(t){asyncGeneratorStep(i,r,o,a,u,"next",t)}function u(t){asyncGeneratorStep(i,r,o,a,u,"throw",t)}a(void 0)})}}var ConditionTypeTipMap={Quiz:["提交全部答题","至少提交{Num}道答题"],Questionnaire:["提交全部问卷","至少提交{Num}个问卷"],CheckIn:["提交全部签到","至少提交{Num}个签到"],Vote:["提交全部投票","至少提交{Num}个投票"],RightQuiz:["答对全部答题","至少答对{Num}道答题"],Order:["下单商品","至少答对{Num}道答题"]},getBySplit=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";if(!t)return"";var e=t.split(/\|||/);return function(t){if(!t.length)return"";for(var e=0;e0)return t[e];return""}([e[0],e[-1],e[0],t])};Component({properties:{luckymoney:{type:Object,value:{}},sdkInstance:{type:Object,value:null}},data:{countDownStr:"00 : 00",isPoint:!1,isManual:!1,unitBlock:!1,useBigStyle:!1,isAttended:!1,attendBtnText:"立即参与",currentAmount:0,currentUnit:"元",hasConditions:!1,attendStr:[],attendFailFlag:!1,conditionDisplayFlag:!1,conditionList:[],load:!1,current:{},iconDot:"data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2216%22%20height%3D%2216%22%20viewBox%3D%220%200%2016%2016%22%20fill%3D%22none%22%3E%3Ccircle%20cx%3D%228%22%20cy%3D%228%22%20r%3D%222%22%20fill%3D%22white%22%20fill-opacity%3D%220.7%22/%3E%3C/svg%3E",iconCompleted:"data:image/svg+xml;utf8,%3Csvg%20width%3D%2216%22%20height%3D%2216%22%20viewBox%3D%220%200%2016%2016%22%20fill%3D%22none%22%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%3E%3Cpath%20opacity%3D%220.3%22%20fill-rule%3D%22evenodd%22%20clip-rule%3D%22evenodd%22%20d%3D%22M13.042%203.87876C12.7075%203.54524%2012.1594%203.56866%2011.8545%203.9295L6.83723%209.86788L4.41464%207.35201C4.1009%207.0262%203.58082%207.02141%203.26114%207.3414L2.69036%207.91272C2.37932%208.22406%202.37469%208.72708%202.67995%209.04409L6.28186%2012.7847C6.52707%2013.0393%206.89831%2013.0979%207.20141%2012.9586C7.3538%2012.9173%207.49599%2012.8309%207.60632%2012.7003L8.02311%2012.207L8.56618%2011.6634L8.52155%2011.6171L13.657%205.53882C13.9284%205.21767%2013.908%204.7421%2013.6103%204.44527L13.042%203.87876Z%22%20fill%3D%22white%22/%3E%3C/svg%3E"},observers:{luckymoney:function(t){var e,n;if(t){var r=t.current;if(r){var o=(null===(e=t.userStatusMap)||void 0===e?void 0:e[r.RedPacketID])===_luckymoney2.LuckyMoneyResult.ATTENDED,i=r.RedPacketType===_luckymoney2.RedPacketType.POINT,a=r.OpenRedPacketType===_luckymoney2.OpenRedPacketType.MANUAL,u=this.getConditionList(r),c=u.findIndex(function(t){return"BarragePwd"===t.key});if(c>-1&&c2,p=u&&u.length>0,v="立即参与";o?v="您已参与,等待领红包":s&&(v="去完成参与任务");var y=0;r.TotalAmount&&(y=i?r.TotalAmount:r.TotalAmount/100);var m=i?r.RewardsPointsUnit:"元",g=u.length,w=u.filter(function(t){return t.completed}).length,k=[];g>0&&(o?k=[g,"/",g]:s&&(k=[w,"/",g])),this.setData({isPoint:i,isManual:a,unitBlock:h,useBigStyle:f,isAttended:o,attendBtnText:v,attendFailFlag:s,conditionDisplayFlag:d,currentAmount:y,currentUnit:m,hasConditions:p,attendStr:k,conditionList:u,current:r}),this.handleCountDown(r)}}}},lifetimes:{detached:function(){clearTimeout(this.countDownTimer)}},methods:{getSdkInstanceId:function(){var t,e,n;return(null===(t=this.properties)||void 0===t||null===(e=t.sdkInstance)||void 0===e?void 0:e.uuid)||(null===(n=this.properties)||void 0===n?void 0:n.sdkInstance)},onClose:function(){var t,e,n=this.getSdkInstanceId();null===(t=(0,_luckymoneyService.getLuckymoneyService)(n))||void 0===t||null===(e=t.closeAttendModal)||void 0===e||e.call(t)},onAttend:function(){var t=this;return _asyncToGenerator(_regeneratorRuntime().mark(function e(){var n,r,o,i,a;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.data,r=n.isAttended,o=n.current,i=n.load,a=t.properties.sdkInstance,!r){e.next=4;break}return e.abrupt("return");case 4:if(!o.UndoAwardCondition){e.next=7;break}return t.onClose(),e.abrupt("return");case 7:if(!i){e.next=9;break}return e.abrupt("return");case 9:if(t.isLogin(!0)){e.next=11;break}return e.abrupt("return");case 11:if(a){e.next=14;break}return console.warn("sdkInstance is required for attendLuckymoney"),e.abrupt("return");case 14:return t.setData({load:!0}),e.next=17,a.attendLuckymoney(o.RedPacketID);case 17:t.setData({load:!1});case 18:case"end":return e.stop()}},e)}))()},isLogin:function(){var t,e,n,r=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return 2===((null===(t=this.properties)||void 0===t||null===(e=t.sdkInstance)||void 0===e||null===(n=e.store)||void 0===n?void 0:n.get("mainInfo"))||{}).mode||(r&&this.triggerEvent("commentCheck"),!1)},handleCountDown:function(t){var e=this;clearTimeout(this.countDownTimer),null!=t&&t.SendTime&&null!=t&&t.DeadLine&&!this.data.isManual&&function n(){var r,o=(0,_times.getCountDownV2)(t.SendTime,t.DeadLine);r=o.length>2?o.join(":"):o.join(" : "),e.setData({countDownStr:r}),e.countDownTimer=setTimeout(n,1e3)}()},getConditionList:function(t){var e=[];if(!t)return e;var n=(null==t?void 0:t.AwardCondition)||{},r=(null==t?void 0:t.UndoAwardCondition)||{};return t.BarragePwd&&e.push({key:"BarragePwd",label:"BarragePwd",value:t.BarragePwd,completed:!1,tip:"发布弹幕口令: ".concat(getBySplit(t.BarragePwd))}),Object.keys(n).forEach(function(t){if(n[t]&&("Order"!==t||n[t].IsUse)){var o="all"===n[t]?0:1,i="";if(ConditionTypeTipMap[t]){var a=ConditionTypeTipMap[t][o],u=Number(n[t]);i=a.replace("{Num}",u).replace("Num",u)}else i="".concat(t,": ").concat(n[t]);var c=!(!r||1!==r[t]),l=r&&2===r[t];e.push({key:t,label:t,value:n[t],completed:c,unattended:l,tip:i})}}),e}}});