const platform = uni.getSystemInfoSync().platform; // 主颜色 const $mainColor = "FF5C03"; // 弹窗图标url const $iconUrl = "./static/images/ic_ar.png"; let popupViewData; // 文件下载的弹窗 function healthButlerPopup(data,callBack) { // 弹窗遮罩层 let maskLayer = new plus.nativeObj.View("maskLayer", { //先创建遮罩层 top: '0px', left: '0px', height: '100%', width: '100%', backgroundColor: 'rgba(0,0,0,0.5)' }); popupViewData = healthButlerPopupDrawing(data); popupViewData.isShow=true; // 弹窗内容 let popupView = new plus.nativeObj.View("popupView", { //创建底部图标菜单 tag: "rect", top: (popupViewData.screenHeight - popupViewData.popupViewHeight - 70) / 2.0 + "px", left: '10%', height: popupViewData.popupViewHeight + "px", width: "80%", }); let closeBtnData = closeBtnDrawing(); // 弹窗内容 let closeWid=40; let closeBtn = new plus.nativeObj.View("closeBtn", { tag: "rect", top: (popupViewData.screenHeight - (popupViewData.popupViewHeight+closeWid+30))*0.5 +(popupViewData.popupViewHeight+30) + "px", left: ((closeBtnData.screenWidth - closeWid) / 2) +"px", height: closeWid+"px", width: closeWid+"px", }); popupView.draw(popupViewData.elementList); closeBtn.draw(closeBtnData.elementList); let callbackData = { change: function(res) { }, cancel: function() { maskLayer.hide(); popupView.hide(); } } popupView.addEventListener("click", function(e) { let maxTop = popupViewData.popupViewHeight - popupViewData.viewContentPadding; let maxLeft = popupViewData.popupViewWidth - popupViewData.viewContentPadding; if (e.clientY > maxTop - 60 && e.clientY < maxTop) { if(data.buttonNum == 1){ // 单按钮 if (e.clientX > popupViewData.viewContentPadding && e.clientX < maxLeft) { console.log("----qxj clientX isLogin:"+isLogin()); if(isLogin()){ let day=dateFormat("YYYY-mm-dd",new Date()); let healthButler=uni.getStorageSync("healthButler"); let userInfo=JSON.parse(uni.getStorageSync('userInfo')); if(!!healthButler){ healthButler=JSON.parse(healthButler); healthButler.dayNum++; healthButler.isAddQw=userInfo.isAddQw; }else{ healthButler={"day":day,"dayNum":0,"isAddQw":false}; } uni.setStorageSync("healthButler",JSON.stringify(healthButler)); maskLayer.hide(); popupView.hide(); closeBtn.hide(); popupViewData.isShow=false; callBack(1); if(userInfo.isAddQw){ uni.showToast({title:"您已添加健康管家",icon:"none",duration:2000}); }else{ gotoMiniProgram(); } //clearInterval(that.$qconfig.healthTimer); } else{ maskLayer.hide(); popupView.hide(); closeBtn.hide(); popupViewData.isShow=false; callBack(0); } } } } }); closeBtn.addEventListener("click", function(e) { let healthButler=uni.getStorageSync("healthButler"); if(!!healthButler){ healthButler=JSON.parse(healthButler); }else{ healthButler={"dayNum":0}; } let day=dateFormat("YYYY-mm-dd",new Date()); let jsonDate={"day":day,"dayNum":healthButler.dayNum++} uni.setStorageSync("healthButler",JSON.stringify(jsonDate)); maskLayer.hide(); popupView.hide(); closeBtn.hide(); popupViewData.isShow=false; }); // 显示弹窗 maskLayer.show(); popupView.show(); closeBtn.show(); // 改变进度条 return callbackData; } // 弹窗绘图 function healthButlerPopupDrawing(data){ // 以下为计算菜单的nview绘制布局,为固定算法,使用者无关关心 const screenWidth = plus.screen.resolutionWidth; const screenHeight = plus.screen.resolutionHeight; //弹窗容器宽度 const popupViewWidth = screenWidth * 0.8; // 弹窗容器的Padding const viewContentPadding = 20; // 弹窗容器的宽度 const viewContentWidth = popupViewWidth - (viewContentPadding * 2); // 弹窗容器高度 let popupViewHeight = viewContentPadding * 7 + 130; let iconWid=popupViewWidth/4.0; let icWidth=50; let elementList = [ { tag: 'rect', //背景色 color: '#FFFFFF', rectStyles:{ radius: "8px" } }, { tag: 'rect', //背景色 color: 'rgba(255,255,255,0)', rectStyles:{ radius: "8px", }, position:{ left:"0px", top:"0px", width:"100%", height:"80px", } }, { src:'./static/images/ad/service.png', id: "logo", tag: "img", position: { top: "10px", left: (popupViewWidth - 70) / 2 + "px", width: "70px", height: "70px", } }, { tag: 'font', id: 'title', text: "添加健康管家", textStyles: { size: '20px', color: "#222", weight: "bold", verticalAlign: "middle", whiteSpace: "normal", backgroundColor:"#ff0000" }, position: { top: viewContentPadding*4 + 'px', height: "50px", } }, { tag: 'font', id: 'content', text: "—解锁更多权益—", textStyles: { size: '14px', color: "#999", verticalAlign: "middle", whiteSpace: "normal" }, position: { top: viewContentPadding * 4 + 45 + 'px', height: "20px", } }, { tag: 'rect', //背景色 color: 'rgba(255,255,255,0)', // color:'#ff0000', rectStyles:{ radius: "8px", }, position:{ left:"0px", top:viewContentPadding * 4 + 50+ 35 + 'px', width:"100%", height:"90px", } }, { src:'./static/images/ad/zsfw_icon40.png', id: "icon1", tag: "img", position: { top: viewContentPadding * 4 + 50+ 35 + 'px', left: (iconWid - icWidth) / 2 + "px", width: icWidth+"px", height: icWidth+"px", } }, { src:'./static/images/ad/jskc_icon40.png', id: "icon2", tag: "img", position: { top: viewContentPadding * 4 + 50+ 35 + 'px', left: iconWid+(iconWid - icWidth) / 2 + "px", width: icWidth+"px", height: icWidth+"px", } }, { src:'./static/images/ad/mflp_icon40.png', id: "icon3", tag: "img", position: { top: viewContentPadding * 4 + 50+ 35 + 'px', left: iconWid*2+(iconWid - icWidth) / 2 + "px", width: icWidth+"px", height: icWidth+"px", } }, { src:'./static/images/ad/hdtz_icon40.png', id: "icon4", tag: "img", position: { top: viewContentPadding * 4 + 50+ 35 + 'px', left: iconWid*3+(iconWid - icWidth) / 2 + "px", width: icWidth+"px", height: icWidth+"px", } }, { tag: 'font', id: 'title1', text: "专属服务", textStyles: { size: '14px', color: "#DC760D", weight: "bold", verticalAlign: "middle", align:"center", whiteSpace: "normal", backgroundColor:"#ff0000" }, position: { top: viewContentPadding*4+135+'px', left: "0px", width:iconWid+"px", height: "30px", } }, { tag: 'font', id: 'title2', text: "解锁课程", textStyles: { size: '14px', color: "#DC760D", weight: "bold", verticalAlign: "middle", align:"center", whiteSpace: "normal", }, position: { top: viewContentPadding * 4 + 135 + 'px', left: iconWid*1+"px", width:iconWid+"px", height: "30px", } }, { tag: 'font', id: 'title3', text: "免费礼品", textStyles: { size: '14px', color: "#DC760D", weight: "bold", verticalAlign: "middle", align:"center", whiteSpace: "normal", }, position: { top: viewContentPadding * 4 + 135 + 'px', left: iconWid*2+"px", width:iconWid+"px", height: "30px", } }, { tag: 'font', id: 'title4', text: "活动通知", textStyles: { size: '14px', color: "#DC760D", weight: "bold", verticalAlign: "middle", align:"center", whiteSpace: "normal", }, position: { top: viewContentPadding * 4 + 135 + 'px', left: iconWid*3+"px", width:iconWid+"px", height: "30px", } } ]; if (data.buttonNum == 2) { popupViewHeight += viewContentPadding + 30; elementList = elementList.concat([ { tag: 'rect', //绘制底边按钮 rectStyles:{ radius: "3px", borderColor: "#f1f1f1", borderWidth: "1px", }, position:{ bottom: viewContentPadding + 'px', left: viewContentPadding + "px", width: (viewContentWidth - viewContentPadding) / 2 + "px", height: "30px" } }, { tag: 'rect', //绘制底边按钮 rectStyles:{ radius: "3px", color: $mainColor }, position:{ bottom: viewContentPadding + 'px', left: ((viewContentWidth - viewContentPadding) / 2 + viewContentPadding * 2) + "px", width: (viewContentWidth - viewContentPadding) / 2 + "px", height: "30px" } }, { tag: 'font', id: 'cancelText', text: "取消下载", textStyles: { size: '14px', color: "#666", lineSpacing: "0%", whiteSpace: "normal" }, position: { bottom: viewContentPadding + 'px', left: viewContentPadding + "px", width: (viewContentWidth - viewContentPadding) / 2 + "px", height: "30px", } }, { tag: 'font', id: 'confirmText', text: "后台下载", textStyles: { size: '14px', color: "#FFF", lineSpacing: "0%", whiteSpace: "normal" }, position: { bottom: viewContentPadding + 'px', left: ((viewContentWidth - viewContentPadding) / 2 + viewContentPadding * 2) + "px", width: (viewContentWidth - viewContentPadding) / 2 + "px", height: "30px", } } ]); } if (data.buttonNum == 1) { popupViewHeight += viewContentPadding + 40; elementList = elementList.concat([ { tag: 'rect', //绘制底边按钮 rectStyles:{ radius: "26px", color: $mainColor }, position:{ bottom: viewContentPadding + 'px', left: viewContentPadding + "px", width: viewContentWidth + "px", height: "52px" } }, { tag: 'font', id: 'confirmText', text: "立即添加", textStyles: { size: '18px', color: "#FFF", lineSpacing: "0%", radius:"26px", weight: "bold", }, position: { bottom: viewContentPadding + 'px', left: viewContentPadding + "px", width: viewContentWidth + "px", height: "52px" } } ]); } return { popupViewHeight:popupViewHeight, popupViewWidth:popupViewWidth, screenHeight:screenHeight, viewContentWidth:viewContentWidth, viewContentPadding:viewContentPadding, elementList: elementList }; } //关闭按钮绘图 function closeBtnDrawing(){ // 以下为计算菜单的nview绘制布局,为固定算法,使用者无关关心 const screenWidth = plus.screen.resolutionWidth; const screenHeight = plus.screen.resolutionHeight; //弹窗容器宽度 const popupViewWidth = screenWidth * 0.8; // 弹窗容器的Padding const viewContentPadding = 20; // 弹窗容器的宽度 const viewContentWidth = popupViewWidth - (viewContentPadding * 2); // 弹窗容器高度 let closeY = viewContentPadding * 7 + 60+32; let elementList = [ { tag: 'rect', //背景色 color: 'rgba(255,255,255,0)', rectStyles:{ radius: "0px" } }, { src:'./static/images/ad/close_icon.png', id: "close", tag: "img", position: { top: '0px', left: "0px", width: "32px", height: "32px", } } ]; return { popupViewHeight:32, popupViewWidth:popupViewWidth, screenWidth:screenWidth, screenHeight:screenHeight, elementList: elementList }; } export function healthButlerPop(callBack) { let popupData = {buttonNum:1}; if(popupViewData==null || (popupViewData!=null && !popupViewData.isShow)){ healthButlerPopup(popupData,callBack); } } export function gotoMiniProgram(){ plus.share.getServices(function(res){ var sweixin = null; for(var i=0;i