healthButlerPop.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. const platform = uni.getSystemInfoSync().platform;
  2. // 主颜色
  3. const $mainColor = "FF5C03";
  4. // 弹窗图标url
  5. const $iconUrl = "./static/images/ic_ar.png";
  6. let popupViewData;
  7. // 文件下载的弹窗
  8. function healthButlerPopup(data,callBack) {
  9. // 弹窗遮罩层
  10. let maskLayer = new plus.nativeObj.View("maskLayer", { //先创建遮罩层
  11. top: '0px',
  12. left: '0px',
  13. height: '100%',
  14. width: '100%',
  15. backgroundColor: 'rgba(0,0,0,0.5)'
  16. });
  17. popupViewData = healthButlerPopupDrawing(data);
  18. popupViewData.isShow=true;
  19. // 弹窗内容
  20. let popupView = new plus.nativeObj.View("popupView", { //创建底部图标菜单
  21. tag: "rect",
  22. top: (popupViewData.screenHeight - popupViewData.popupViewHeight - 70) / 2.0 + "px",
  23. left: '10%',
  24. height: popupViewData.popupViewHeight + "px",
  25. width: "80%",
  26. });
  27. let closeBtnData = closeBtnDrawing();
  28. // 弹窗内容
  29. let closeWid=40;
  30. let closeBtn = new plus.nativeObj.View("closeBtn", {
  31. tag: "rect",
  32. top: (popupViewData.screenHeight - (popupViewData.popupViewHeight+closeWid+30))*0.5 +(popupViewData.popupViewHeight+30) + "px",
  33. left: ((closeBtnData.screenWidth - closeWid) / 2) +"px",
  34. height: closeWid+"px",
  35. width: closeWid+"px",
  36. });
  37. popupView.draw(popupViewData.elementList);
  38. closeBtn.draw(closeBtnData.elementList);
  39. let callbackData = {
  40. change: function(res) {
  41. },
  42. cancel: function() {
  43. maskLayer.hide();
  44. popupView.hide();
  45. }
  46. }
  47. popupView.addEventListener("click", function(e) {
  48. let maxTop = popupViewData.popupViewHeight - popupViewData.viewContentPadding;
  49. let maxLeft = popupViewData.popupViewWidth - popupViewData.viewContentPadding;
  50. if (e.clientY > maxTop - 60 && e.clientY < maxTop) {
  51. if(data.buttonNum == 1){ // 单按钮
  52. if (e.clientX > popupViewData.viewContentPadding && e.clientX < maxLeft) {
  53. console.log("----qxj clientX isLogin:"+isLogin());
  54. if(isLogin()){
  55. let day=dateFormat("YYYY-mm-dd",new Date());
  56. let healthButler=uni.getStorageSync("healthButler");
  57. let userInfo=JSON.parse(uni.getStorageSync('userInfo'));
  58. if(!!healthButler){
  59. healthButler=JSON.parse(healthButler);
  60. healthButler.dayNum++;
  61. healthButler.isAddQw=userInfo.isAddQw;
  62. }else{
  63. healthButler={"day":day,"dayNum":0,"isAddQw":false};
  64. }
  65. uni.setStorageSync("healthButler",JSON.stringify(healthButler));
  66. maskLayer.hide();
  67. popupView.hide();
  68. closeBtn.hide();
  69. popupViewData.isShow=false;
  70. callBack(1);
  71. if(userInfo.isAddQw){
  72. uni.showToast({title:"您已添加健康管家",icon:"none",duration:2000});
  73. }else{
  74. gotoMiniProgram();
  75. }
  76. //clearInterval(that.$qconfig.healthTimer);
  77. }
  78. else{
  79. maskLayer.hide();
  80. popupView.hide();
  81. closeBtn.hide();
  82. popupViewData.isShow=false;
  83. callBack(0);
  84. }
  85. }
  86. }
  87. }
  88. });
  89. closeBtn.addEventListener("click", function(e) {
  90. let healthButler=uni.getStorageSync("healthButler");
  91. if(!!healthButler){
  92. healthButler=JSON.parse(healthButler);
  93. }else{
  94. healthButler={"dayNum":0};
  95. }
  96. let day=dateFormat("YYYY-mm-dd",new Date());
  97. let jsonDate={"day":day,"dayNum":healthButler.dayNum++}
  98. uni.setStorageSync("healthButler",JSON.stringify(jsonDate));
  99. maskLayer.hide();
  100. popupView.hide();
  101. closeBtn.hide();
  102. popupViewData.isShow=false;
  103. });
  104. // 显示弹窗
  105. maskLayer.show();
  106. popupView.show();
  107. closeBtn.show();
  108. // 改变进度条
  109. return callbackData;
  110. }
  111. // 弹窗绘图
  112. function healthButlerPopupDrawing(data){
  113. // 以下为计算菜单的nview绘制布局,为固定算法,使用者无关关心
  114. const screenWidth = plus.screen.resolutionWidth;
  115. const screenHeight = plus.screen.resolutionHeight;
  116. //弹窗容器宽度
  117. const popupViewWidth = screenWidth * 0.8;
  118. // 弹窗容器的Padding
  119. const viewContentPadding = 20;
  120. // 弹窗容器的宽度
  121. const viewContentWidth = popupViewWidth - (viewContentPadding * 2);
  122. // 弹窗容器高度
  123. let popupViewHeight = viewContentPadding * 7 + 130;
  124. let iconWid=popupViewWidth/4.0;
  125. let icWidth=50;
  126. let elementList = [
  127. {
  128. tag: 'rect', //背景色
  129. color: '#FFFFFF',
  130. rectStyles:{
  131. radius: "8px"
  132. }
  133. },
  134. {
  135. tag: 'rect', //背景色
  136. color: 'rgba(255,255,255,0)',
  137. rectStyles:{
  138. radius: "8px",
  139. },
  140. position:{
  141. left:"0px",
  142. top:"0px",
  143. width:"100%",
  144. height:"80px",
  145. }
  146. },
  147. {
  148. src:'./static/images/ad/service.png',
  149. id: "logo",
  150. tag: "img",
  151. position: {
  152. top: "10px",
  153. left: (popupViewWidth - 70) / 2 + "px",
  154. width: "70px",
  155. height: "70px",
  156. }
  157. },
  158. {
  159. tag: 'font',
  160. id: 'title',
  161. text: "添加健康管家",
  162. textStyles: {
  163. size: '20px',
  164. color: "#222",
  165. weight: "bold",
  166. verticalAlign: "middle",
  167. whiteSpace: "normal",
  168. backgroundColor:"#ff0000"
  169. },
  170. position: {
  171. top: viewContentPadding*4 + 'px',
  172. height: "50px",
  173. }
  174. },
  175. {
  176. tag: 'font',
  177. id: 'content',
  178. text: "—解锁更多权益—",
  179. textStyles: {
  180. size: '14px',
  181. color: "#999",
  182. verticalAlign: "middle",
  183. whiteSpace: "normal"
  184. },
  185. position: {
  186. top: viewContentPadding * 4 + 45 + 'px',
  187. height: "20px",
  188. }
  189. },
  190. {
  191. tag: 'rect', //背景色
  192. color: 'rgba(255,255,255,0)',
  193. // color:'#ff0000',
  194. rectStyles:{
  195. radius: "8px",
  196. },
  197. position:{
  198. left:"0px",
  199. top:viewContentPadding * 4 + 50+ 35 + 'px',
  200. width:"100%",
  201. height:"90px",
  202. }
  203. },
  204. {
  205. src:'./static/images/ad/zsfw_icon40.png',
  206. id: "icon1",
  207. tag: "img",
  208. position: {
  209. top: viewContentPadding * 4 + 50+ 35 + 'px',
  210. left: (iconWid - icWidth) / 2 + "px",
  211. width: icWidth+"px",
  212. height: icWidth+"px",
  213. }
  214. },
  215. {
  216. src:'./static/images/ad/jskc_icon40.png',
  217. id: "icon2",
  218. tag: "img",
  219. position: {
  220. top: viewContentPadding * 4 + 50+ 35 + 'px',
  221. left: iconWid+(iconWid - icWidth) / 2 + "px",
  222. width: icWidth+"px",
  223. height: icWidth+"px",
  224. }
  225. },
  226. {
  227. src:'./static/images/ad/mflp_icon40.png',
  228. id: "icon3",
  229. tag: "img",
  230. position: {
  231. top: viewContentPadding * 4 + 50+ 35 + 'px',
  232. left: iconWid*2+(iconWid - icWidth) / 2 + "px",
  233. width: icWidth+"px",
  234. height: icWidth+"px",
  235. }
  236. },
  237. {
  238. src:'./static/images/ad/hdtz_icon40.png',
  239. id: "icon4",
  240. tag: "img",
  241. position: {
  242. top: viewContentPadding * 4 + 50+ 35 + 'px',
  243. left: iconWid*3+(iconWid - icWidth) / 2 + "px",
  244. width: icWidth+"px",
  245. height: icWidth+"px",
  246. }
  247. },
  248. {
  249. tag: 'font',
  250. id: 'title1',
  251. text: "专属服务",
  252. textStyles: {
  253. size: '14px',
  254. color: "#DC760D",
  255. weight: "bold",
  256. verticalAlign: "middle",
  257. align:"center",
  258. whiteSpace: "normal",
  259. backgroundColor:"#ff0000"
  260. },
  261. position: {
  262. top: viewContentPadding*4+135+'px',
  263. left: "0px",
  264. width:iconWid+"px",
  265. height: "30px",
  266. }
  267. },
  268. {
  269. tag: 'font',
  270. id: 'title2',
  271. text: "解锁课程",
  272. textStyles: {
  273. size: '14px',
  274. color: "#DC760D",
  275. weight: "bold",
  276. verticalAlign: "middle",
  277. align:"center",
  278. whiteSpace: "normal",
  279. },
  280. position: {
  281. top: viewContentPadding * 4 + 135 + 'px',
  282. left: iconWid*1+"px",
  283. width:iconWid+"px",
  284. height: "30px",
  285. }
  286. },
  287. {
  288. tag: 'font',
  289. id: 'title3',
  290. text: "免费礼品",
  291. textStyles: {
  292. size: '14px',
  293. color: "#DC760D",
  294. weight: "bold",
  295. verticalAlign: "middle",
  296. align:"center",
  297. whiteSpace: "normal",
  298. },
  299. position: {
  300. top: viewContentPadding * 4 + 135 + 'px',
  301. left: iconWid*2+"px",
  302. width:iconWid+"px",
  303. height: "30px",
  304. }
  305. },
  306. {
  307. tag: 'font',
  308. id: 'title4',
  309. text: "活动通知",
  310. textStyles: {
  311. size: '14px',
  312. color: "#DC760D",
  313. weight: "bold",
  314. verticalAlign: "middle",
  315. align:"center",
  316. whiteSpace: "normal",
  317. },
  318. position: {
  319. top: viewContentPadding * 4 + 135 + 'px',
  320. left: iconWid*3+"px",
  321. width:iconWid+"px",
  322. height: "30px",
  323. }
  324. }
  325. ];
  326. if (data.buttonNum == 2) {
  327. popupViewHeight += viewContentPadding + 30;
  328. elementList = elementList.concat([
  329. {
  330. tag: 'rect', //绘制底边按钮
  331. rectStyles:{
  332. radius: "3px",
  333. borderColor: "#f1f1f1",
  334. borderWidth: "1px",
  335. },
  336. position:{
  337. bottom: viewContentPadding + 'px',
  338. left: viewContentPadding + "px",
  339. width: (viewContentWidth - viewContentPadding) / 2 + "px",
  340. height: "30px"
  341. }
  342. },
  343. {
  344. tag: 'rect', //绘制底边按钮
  345. rectStyles:{
  346. radius: "3px",
  347. color: $mainColor
  348. },
  349. position:{
  350. bottom: viewContentPadding + 'px',
  351. left: ((viewContentWidth - viewContentPadding) / 2 + viewContentPadding * 2) + "px",
  352. width: (viewContentWidth - viewContentPadding) / 2 + "px",
  353. height: "30px"
  354. }
  355. },
  356. {
  357. tag: 'font',
  358. id: 'cancelText',
  359. text: "取消下载",
  360. textStyles: {
  361. size: '14px',
  362. color: "#666",
  363. lineSpacing: "0%",
  364. whiteSpace: "normal"
  365. },
  366. position: {
  367. bottom: viewContentPadding + 'px',
  368. left: viewContentPadding + "px",
  369. width: (viewContentWidth - viewContentPadding) / 2 + "px",
  370. height: "30px",
  371. }
  372. },
  373. {
  374. tag: 'font',
  375. id: 'confirmText',
  376. text: "后台下载",
  377. textStyles: {
  378. size: '14px',
  379. color: "#FFF",
  380. lineSpacing: "0%",
  381. whiteSpace: "normal"
  382. },
  383. position: {
  384. bottom: viewContentPadding + 'px',
  385. left: ((viewContentWidth - viewContentPadding) / 2 + viewContentPadding * 2) + "px",
  386. width: (viewContentWidth - viewContentPadding) / 2 + "px",
  387. height: "30px",
  388. }
  389. }
  390. ]);
  391. }
  392. if (data.buttonNum == 1) {
  393. popupViewHeight += viewContentPadding + 40;
  394. elementList = elementList.concat([
  395. {
  396. tag: 'rect', //绘制底边按钮
  397. rectStyles:{
  398. radius: "26px",
  399. color: $mainColor
  400. },
  401. position:{
  402. bottom: viewContentPadding + 'px',
  403. left: viewContentPadding + "px",
  404. width: viewContentWidth + "px",
  405. height: "52px"
  406. }
  407. },
  408. {
  409. tag: 'font',
  410. id: 'confirmText',
  411. text: "立即添加",
  412. textStyles: {
  413. size: '18px',
  414. color: "#FFF",
  415. lineSpacing: "0%",
  416. radius:"26px",
  417. weight: "bold",
  418. },
  419. position: {
  420. bottom: viewContentPadding + 'px',
  421. left: viewContentPadding + "px",
  422. width: viewContentWidth + "px",
  423. height: "52px"
  424. }
  425. }
  426. ]);
  427. }
  428. return {
  429. popupViewHeight:popupViewHeight,
  430. popupViewWidth:popupViewWidth,
  431. screenHeight:screenHeight,
  432. viewContentWidth:viewContentWidth,
  433. viewContentPadding:viewContentPadding,
  434. elementList: elementList
  435. };
  436. }
  437. //关闭按钮绘图
  438. function closeBtnDrawing(){
  439. // 以下为计算菜单的nview绘制布局,为固定算法,使用者无关关心
  440. const screenWidth = plus.screen.resolutionWidth;
  441. const screenHeight = plus.screen.resolutionHeight;
  442. //弹窗容器宽度
  443. const popupViewWidth = screenWidth * 0.8;
  444. // 弹窗容器的Padding
  445. const viewContentPadding = 20;
  446. // 弹窗容器的宽度
  447. const viewContentWidth = popupViewWidth - (viewContentPadding * 2);
  448. // 弹窗容器高度
  449. let closeY = viewContentPadding * 7 + 60+32;
  450. let elementList = [
  451. {
  452. tag: 'rect', //背景色
  453. color: 'rgba(255,255,255,0)',
  454. rectStyles:{
  455. radius: "0px"
  456. }
  457. },
  458. {
  459. src:'./static/images/ad/close_icon.png',
  460. id: "close",
  461. tag: "img",
  462. position: {
  463. top: '0px',
  464. left: "0px",
  465. width: "32px",
  466. height: "32px",
  467. }
  468. }
  469. ];
  470. return {
  471. popupViewHeight:32,
  472. popupViewWidth:popupViewWidth,
  473. screenWidth:screenWidth,
  474. screenHeight:screenHeight,
  475. elementList: elementList
  476. };
  477. }
  478. export function healthButlerPop(callBack) {
  479. let popupData = {buttonNum:1};
  480. if(popupViewData==null || (popupViewData!=null && !popupViewData.isShow)){
  481. healthButlerPopup(popupData,callBack);
  482. }
  483. }
  484. export function gotoMiniProgram(){
  485. plus.share.getServices(function(res){
  486. var sweixin = null;
  487. for(var i=0;i<res.length;i++){
  488. var t = res[i];
  489. if(t.id == 'weixin'){
  490. sweixin = t;
  491. }
  492. }
  493. let userInfo=JSON.parse(uni.getStorageSync('userInfo'));
  494. if(sweixin){
  495. //唤起微信跳转小程序
  496. sweixin.launchMiniProgram({
  497. id:"gh_7a6a32e5ef61",
  498. path:'/pages_user/addHealthButler?userId='+userInfo.userId,
  499. type:0
  500. },function(){
  501. console.log("微信唤起成功");
  502. return true;
  503. },function(e){
  504. console.log("微信唤起失败",e);
  505. uni.showToast({
  506. title:'微信唤起失败,请检查是否有微信应用',
  507. icon:'none'
  508. })
  509. return false;
  510. })
  511. }
  512. else{
  513. uni.showToast({
  514. title:'微信唤起失败,请检查是否有微信应用',
  515. icon:'none',
  516. duration:3000
  517. })
  518. return false;
  519. }
  520. },function(res){
  521. });
  522. }
  523. function isLogin() {
  524. let obj=uni.getStorageSync("AppToken");
  525. return !!obj;
  526. }
  527. function dateFormat(fmt, date) {
  528. let ret;
  529. const opt = {
  530. "Y+": date.getFullYear().toString(), // 年
  531. "m+": (date.getMonth() + 1).toString(), // 月
  532. "d+": date.getDate().toString(), // 日
  533. "H+": date.getHours().toString(), // 时
  534. "M+": date.getMinutes().toString(), // 分
  535. "S+": date.getSeconds().toString() // 秒
  536. // 有其他格式化字符需求可以继续添加,必须转化成字符串
  537. };
  538. for (let k in opt) {
  539. ret = new RegExp("(" + k + ")").exec(fmt);
  540. if (ret) {
  541. fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
  542. };
  543. };
  544. return fmt;
  545. }