123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578 |
- 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<res.length;i++){
- var t = res[i];
- if(t.id == 'weixin'){
- sweixin = t;
- }
- }
- let userInfo=JSON.parse(uni.getStorageSync('userInfo'));
- if(sweixin){
- //唤起微信跳转小程序
- sweixin.launchMiniProgram({
- id:"gh_7a6a32e5ef61",
- path:'/pages_user/addHealthButler?userId='+userInfo.userId,
- type:0
- },function(){
- console.log("微信唤起成功");
- return true;
- },function(e){
- console.log("微信唤起失败",e);
- uni.showToast({
- title:'微信唤起失败,请检查是否有微信应用',
- icon:'none'
- })
- return false;
- })
-
- }
- else{
- uni.showToast({
- title:'微信唤起失败,请检查是否有微信应用',
- icon:'none',
- duration:3000
- })
- return false;
- }
-
- },function(res){
-
- });
- }
- function isLogin() {
- let obj=uni.getStorageSync("AppToken");
- return !!obj;
- }
- function dateFormat(fmt, date) {
- let ret;
- const opt = {
- "Y+": date.getFullYear().toString(), // 年
- "m+": (date.getMonth() + 1).toString(), // 月
- "d+": date.getDate().toString(), // 日
- "H+": date.getHours().toString(), // 时
- "M+": date.getMinutes().toString(), // 分
- "S+": date.getSeconds().toString() // 秒
- // 有其他格式化字符需求可以继续添加,必须转化成字符串
- };
- for (let k in opt) {
- ret = new RegExp("(" + k + ")").exec(fmt);
- if (ret) {
- fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
- };
- };
- return fmt;
- }
|