couponPop.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. export function couponPop(options = {}, callBack) {
  2. // 以下为计算菜单的nview绘制布局,为固定算法,使用者无关关心
  3. const screenWidth = plus.screen.resolutionWidth;
  4. const screenHeight = plus.screen.resolutionHeight;
  5. //弹窗容器宽度
  6. const popupViewWidth = uni.upx2px(590);
  7. // 弹窗容器的Padding
  8. const viewContentPadding = 12;
  9. // 弹窗容器的宽度
  10. const viewContentWidth = popupViewWidth - (viewContentPadding * 2);
  11. let iconWid = popupViewWidth / 4.0;
  12. let icWidth = 35;
  13. let imgWidth = viewContentWidth
  14. let imgHeight = viewContentWidth / 1.78
  15. // 弹窗容器高度
  16. let popupViewHeight = uni.upx2px(748);
  17. let elementList = [{
  18. tag: 'rect', //背景色
  19. color: 'rgba(0,0,0,0)',
  20. rectStyles: {
  21. radius: "8px"
  22. }
  23. },
  24. {
  25. src: './static/images/ad/gift_img_head.png',
  26. id: "gift_img_head",
  27. tag: "img",
  28. position: {
  29. top: "0px",
  30. left: (popupViewWidth - uni.upx2px(312)) / 2 + "px",
  31. width: uni.upx2px(312) + "px",
  32. height: uni.upx2px(120) + "px",
  33. }
  34. },
  35. {
  36. tag: 'rect', //背景色
  37. id: "body",
  38. color: '#fff',
  39. rectStyles: {
  40. radius: uni.upx2px(28) + "px",
  41. },
  42. position: {
  43. top: uni.upx2px(120) + "px",
  44. left: "0px",
  45. width: "100%",
  46. height: popupViewHeight - uni.upx2px(120) + "px",
  47. }
  48. },
  49. // 背景
  50. {
  51. src: './static/images/ad/wzj_bg.png',
  52. id: "wzj_bg",
  53. tag: "img",
  54. position: {
  55. top: uni.upx2px(120) + "px",
  56. left: "0px",
  57. width: "100%",
  58. height: popupViewHeight - uni.upx2px(120) + "px",
  59. }
  60. },
  61. // 新客专享
  62. {
  63. src: './static/images/ad/new_customer_bg.png',
  64. id: "new_customer_bg",
  65. tag: "img",
  66. position: {
  67. top: uni.upx2px(120) + "px",
  68. left: (popupViewWidth - uni.upx2px(288)) / 2 + "px",
  69. width: uni.upx2px(288) + "px",
  70. height: uni.upx2px(72) + "px",
  71. }
  72. },
  73. {
  74. src: './static/images/ad/wz_txt.png',
  75. id: "wz_txt",
  76. tag: "img",
  77. position: {
  78. top: uni.upx2px(476) + "px",
  79. left: (popupViewWidth - uni.upx2px(354)) / 2 + "px",
  80. width: uni.upx2px(354) + "px",
  81. height: uni.upx2px(57) + "px",
  82. }
  83. },
  84. {
  85. src: './static/images/ad/consultation_voucher_img.png',
  86. id: "consultation_voucher_img",
  87. tag: "img",
  88. position: {
  89. top: uni.upx2px(216) + "px",
  90. left: (popupViewWidth - uni.upx2px(280)) / 2 + "px",
  91. width: uni.upx2px(313) + "px",
  92. height: uni.upx2px(261) + "px",
  93. }
  94. }
  95. ];
  96. let detailbtnEle = [{
  97. tag: 'rect', //背景色
  98. color: 'rgba(0,0,0,0)'
  99. },{
  100. src: './static/images/ad/consultation_button.png',
  101. id: "consultation_button",
  102. tag: "img",
  103. position: {
  104. top: "0px",
  105. left: "0px",
  106. width: '100%',
  107. height: '100%',
  108. }
  109. }]
  110. // 弹窗遮罩层
  111. let maskLayer = new plus.nativeObj.View("maskLayer", { //先创建遮罩层
  112. top: '0px',
  113. left: '0px',
  114. height: '100%',
  115. width: '100%',
  116. backgroundColor: 'rgba(0,0,0,0.5)',
  117. visible: false
  118. });
  119. // 弹窗内容
  120. let popupView = new plus.nativeObj.View("popupView", { //创建底部图标菜单
  121. tag: "rect",
  122. top: (screenHeight - popupViewHeight - 70) / 2.0 + "px",
  123. left: '10%',
  124. height: popupViewHeight,
  125. width: "80%",
  126. });
  127. // 去问诊按钮
  128. let detailBtn = new plus.nativeObj.View("detailBtn", {
  129. tag: "rect",
  130. top: (screenHeight - popupViewHeight - 70) / 2.0 + uni.upx2px(595) + "px",
  131. left: (screenWidth - uni.upx2px(415)) / 2 + "px",
  132. width: uni.upx2px(415) + "px",
  133. height: uni.upx2px(119) + "px",
  134. });
  135. // 弹窗关闭按钮
  136. let closeBtnData = closeBtnDrawing();
  137. let closeWid = 40;
  138. let closeBtn = new plus.nativeObj.View("closeBtn", {
  139. tag: "rect",
  140. top: (screenHeight - (popupViewHeight + closeWid + 30)) * 0.5 + (popupViewHeight + 30) + "px",
  141. left: ((closeBtnData.screenWidth - closeWid) / 2) + "px",
  142. height: closeWid + "px",
  143. width: closeWid + "px",
  144. });
  145. popupView.draw(elementList);
  146. detailBtn.draw(detailbtnEle)
  147. closeBtn.draw(closeBtnData.elementList);
  148. maskLayer.show();
  149. popupView.show();
  150. detailBtn.show();
  151. detailBtn.addEventListener('click', (e) => {
  152. maskLayer.hide();
  153. popupView.hide();
  154. detailBtn.hide();
  155. closeBtn.hide();
  156. callBack(1);
  157. });
  158. closeBtn.show();
  159. closeBtn.addEventListener("click", function(e) {
  160. maskLayer.hide();
  161. popupView.hide();
  162. detailBtn.hide();
  163. closeBtn.hide();
  164. });
  165. setTimeout(function(){
  166. maskLayer.hide();
  167. popupView.hide();
  168. detailBtn.hide();
  169. closeBtn.hide();
  170. },3000)
  171. }
  172. //关闭按钮绘图
  173. function closeBtnDrawing() {
  174. // 以下为计算菜单的nview绘制布局,为固定算法,使用者无关关心
  175. const screenWidth = plus.screen.resolutionWidth;
  176. const screenHeight = plus.screen.resolutionHeight;
  177. //弹窗容器宽度
  178. const popupViewWidth = screenWidth * 0.8;
  179. // 弹窗容器的Padding
  180. const viewContentPadding = 12;
  181. // 弹窗容器的宽度
  182. const viewContentWidth = popupViewWidth - (viewContentPadding * 2);
  183. // 弹窗容器高度
  184. let closeY = viewContentPadding * 7 + 60 + 32;
  185. let elementList = [{
  186. tag: 'rect', //背景色
  187. color: 'rgba(255,255,255,0)',
  188. rectStyles: {
  189. radius: "0px"
  190. }
  191. },
  192. {
  193. src: './static/images/ad/close_icon.png',
  194. id: "close",
  195. tag: "img",
  196. position: {
  197. top: '0px',
  198. left: "0px",
  199. width: "32px",
  200. height: "32px",
  201. }
  202. }
  203. ];
  204. return {
  205. popupViewHeight: 32,
  206. popupViewWidth: popupViewWidth,
  207. screenWidth: screenWidth,
  208. screenHeight: screenHeight,
  209. elementList: elementList
  210. };
  211. }