index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <view>
  3. <view class="bg">
  4. <image src="/static/icon/ad/bg.png" mode="widthFix"></image>
  5. </view>
  6. <view class="contents">
  7. <image class="contents-text" src="/static/icon/ad/wcrw.png" mode="widthFix"></image>
  8. <view class="daynum">
  9. <image class="contents-bg" src="/static/icon/ad/cjcs.png" mode="aspectFill"></image>
  10. <view style="flex: 1;"></view>
  11. <text class="daynumtitle">今日奖励</text>
  12. <text class="daydraw">抽奖次数1次</text>
  13. <text class="todraw todraw1" v-if="taskStatus1" @click="toChoujiang">去抽奖</text>
  14. <text class="todraw" v-else>去抽奖</text>
  15. </view>
  16. <view class="daytask">
  17. <view class="daytask-title">今日任务</view>
  18. <view class="daytask-line">
  19. <image src="/static/icon/ad/ad-video.png" mode="widthFix"></image>
  20. <view class="line-title">
  21. <view class="title1">观看视频任务</view>
  22. <view class="title2">已观看{{ taskObj.watchCount }}/{{ taskObj.total }}</view>
  23. </view>
  24. <view style="flex: 1;"></view>
  25. <!-- v-if="taskStatus == false" -->
  26. <ad-rewarded-video ref="adRewardedVideo" :adpid="adpid" :preload="false"
  27. v-slot:default="{loading, error}" @load="onadload" @close="onadclose" @error="onaderror"
  28. :url-callback="callbackData">
  29. <!-- <view v-if="error">{{error}}</view> -->
  30. <!-- <u-button type="primary" style="width:100px;" size="mini" :disabled="loading" :loading="loading">去完成</u-button> -->
  31. <!-- <button :disabled="loading" :loading="loading" class="video-button">去完成</button> -->
  32. </ad-rewarded-video>
  33. <button v-if="taskStatus == false" :disabled="isLoading" :loading="isLoading" class="video-button" @click="showAd">去完成</button>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import {
  41. mapState
  42. } from "vuex"
  43. export default {
  44. data() {
  45. return {
  46. adpid: '1372912966',
  47. appid: '',
  48. activityId: '1824703218157920256',
  49. taskObj: {},
  50. progress: 0,
  51. callbackData: {
  52. userId: "",
  53. extra: ''
  54. },
  55. error: "",
  56. taskStatus: false,
  57. taskStatus1: false,
  58. isLoading: false,
  59. adId: '',
  60. }
  61. },
  62. computed: {
  63. ...mapState(['userInfo', 'userCheckInfo']),
  64. },
  65. async onLoad() {
  66. // this.refreshData();
  67. // this.callbackData.userId = this.userInfo.sysUser.id
  68. },
  69. onShow() {
  70. this.refreshData();
  71. this.callbackData.userId = this.userInfo.sysUser.id
  72. },
  73. onReady() {
  74. // this.isLoading = true;
  75. // this.$refs.adRewardedVideo.load();
  76. },
  77. methods: {
  78. onadload(e) {
  79. // this.isLoading = false;
  80. console.log(e, 'onadload')
  81. },
  82. // 去看广告
  83. async showAd() {
  84. if (this.isLoading) {
  85. return
  86. }
  87. // 获取广告id /callback/advertisingLog
  88. let res = await this.$http.post('https://marketing.baoxianzhanggui.com/api/callback/advertisingLog', {
  89. // let res = await this.$http.post('/callback/advertisingLog', {
  90. userId: this.userInfo.sysUser.id
  91. })
  92. console.log(res)
  93. if (res.code == 200) {
  94. this.adId = res.data
  95. this.isLoading = true
  96. // this.callbackData.extra = "{id: " + res.data + "}"
  97. this.callbackData.extra = this.adId
  98. this.$refs.adRewardedVideo.show();
  99. }
  100. },
  101. async onadclose(e) {
  102. const detail = e.detail
  103. // 用户点击了【关闭广告】按钮
  104. let that = this
  105. if (detail && detail.isEnded) {
  106. //重新拉取数据
  107. let times = 0
  108. this.timer = setInterval(async () => {
  109. times ++
  110. let res = await that.$http.get('https://marketing.baoxianzhanggui.com/api/callback/verifyWatch', {
  111. id: that.adId
  112. })
  113. if (times >= 30 || res.data) {
  114. clearInterval(that.timer)
  115. that.refreshData()
  116. that.isLoading = false
  117. times = 0
  118. }
  119. }, 1000)
  120. // setTimeout(this.refreshData(), 3000);
  121. } else {
  122. // 播放中途退出
  123. console.log("onadclose " + detail.isEnded);
  124. }
  125. },
  126. // 广告加载失败
  127. onaderror(e) {
  128. uni.showToast({
  129. icon: 'none',
  130. title: e.detail.errMsg
  131. })
  132. this.isLoading = false;
  133. console.log("onaderror: ", e.detail);
  134. },
  135. // 刷新数据
  136. refreshData() {
  137. console.log(this.userInfo)
  138. this.$http.post('https://marketing.baoxianzhanggui.com/api/advertising/getUserWatchCount', {
  139. // this.$http.post('/advertising/getUserWatchCount', {
  140. userId: this.userInfo.sysUser.id
  141. }).then(res => {
  142. console.log(res)
  143. this.taskObj = res.data;
  144. this.progress = this.taskObj.watchCount / this.taskObj.total * 100
  145. this.taskStatus = res.data.total <= res.data.watchCount
  146. if (this.taskObj.drawCount > 0) {
  147. this.taskStatus1 = true
  148. }
  149. })
  150. },
  151. getErrorInfo() {
  152. console.log(this.error)
  153. },
  154. toChoujiang() {
  155. console.log('抽奖')
  156. plus.share.getServices(res => {
  157. let sweixin = null;
  158. sweixin = res.find(i => i.id === 'weixin')
  159. if (sweixin) {
  160. // 分享跳转到微信小程序
  161. sweixin.launchMiniProgram({
  162. id: "gh_71ff3b2409d8", //微信小程序原生id
  163. path: "pages/index/bigWheel/bigWheel?userId=" + this.userInfo.sysUser.id +
  164. "&activityId=" + this.activityId, // 打开小程序的页面路径,不传默认跳转首页
  165. type: 0 // 微信小程序版本类型,可取值: 0-正式版; 1-测试版; 2-体验版。 默认值为0。
  166. })
  167. } else {
  168. uni.showToast({
  169. title: '请安装微信',
  170. icon: 'none'
  171. })
  172. }
  173. }, err => {
  174. console.log("分享失败"); // 获取分享服务列表失败
  175. });
  176. uni.navigateToMiniProgram({
  177. appId: 'wx4014825e79c10552',
  178. path: 'pages/index/index?userId=' + this.userInfo.sysUser.id,
  179. extraData: {
  180. },
  181. success(res) {
  182. // 打开成功
  183. console.log(res)
  184. },
  185. error(error) {
  186. console.log(error)
  187. }
  188. })
  189. }
  190. }
  191. }
  192. </script>
  193. <style>
  194. page {
  195. background: #ffe9c6;
  196. padding: 30rpx;
  197. }
  198. </style>
  199. <style lang="scss" scoped>
  200. .page {
  201. // background-color: #fff;
  202. margin: 30rpx;
  203. }
  204. // .video-button {
  205. // border: 1rpx solid var(--primary);
  206. // font-size: 30rpx;
  207. // line-height: 40rpx;
  208. // padding: 10rpx 14rpx;
  209. // color: var(--primary)
  210. // }
  211. .bg {
  212. position: fixed;
  213. top: 0;
  214. left: 0;
  215. z-index: 0;
  216. width: 100%;
  217. }
  218. .contents {
  219. position: relative;
  220. box-sizing: border-box;
  221. .contents-text {
  222. width: 394rpx;
  223. position: absolute;
  224. top: 60rpx;
  225. left: 20rpx;
  226. }
  227. .daynum {
  228. position: relative;
  229. height: 808rpx;
  230. width: 100%;
  231. display: flex;
  232. flex-direction: column;
  233. align-items: center;
  234. justify-content: end;
  235. text {
  236. position: relative;
  237. }
  238. .contents-bg {
  239. position: absolute;
  240. top: 0;
  241. left: 0;
  242. width: 100%;
  243. height: 808rpx;
  244. }
  245. .daynumtitle {
  246. margin-bottom: 28rpx;
  247. font-size: 32rpx;
  248. color: #333;
  249. }
  250. .daydraw {
  251. width: 398rpx;
  252. height: 74rpx;
  253. background: linear-gradient(266deg, rgba(255, 255, 255, 0) 0%, rgba(255, 94, 39, 0.1) 100%);
  254. border-radius: 38rpx;
  255. border: 1rpx solid #FFC5B0;
  256. margin-bottom: 150rpx;
  257. text-align: center;
  258. line-height: 70rpx;
  259. color: #8F3A21;
  260. font-weight: 800;
  261. }
  262. .todraw {
  263. width: 334rpx;
  264. height: 72rpx;
  265. background: #CCCCCC;
  266. border-radius: 38rpx;
  267. border: 5rpx solid #EFEFEF;
  268. text-align: center;
  269. line-height: 64rpx;
  270. color: #FFF;
  271. font-size: 36rpx;
  272. margin-bottom: 54rpx;
  273. }
  274. .todraw1 {
  275. background: linear-gradient(180deg, #fffbf4 0%, #ffe1a1 100%);
  276. color: #8F3A21;
  277. border: 5rpx solid #ffe8ad;
  278. }
  279. }
  280. .daytask {
  281. padding: 30rpx;
  282. background: #FFF;
  283. margin-top: 40rpx;
  284. border-radius: 22rpx;
  285. .daytask-title {
  286. font-size: 32rpx;
  287. color: 333;
  288. margin-bottom: 20rpx;
  289. }
  290. .daytask-line {
  291. display: flex;
  292. justify-content: space-between;
  293. align-items: center;
  294. .line-title {
  295. margin-left: 30rpx;
  296. .title1 {
  297. color: #333;
  298. font-size: 28rpx;
  299. }
  300. .title2 {
  301. color: #969696;
  302. font-size: 24rpx;
  303. }
  304. }
  305. .video-button {
  306. background: linear-gradient(359deg, #FF4A13 0%, #FF8851 100%), #D8D8D8;
  307. height: 60rpx;
  308. line-height: 60rpx;
  309. color: #FFF;
  310. font-size: 26rpx;
  311. border-radius: 30rpx;
  312. padding: 0 30rpx;
  313. }
  314. }
  315. image {
  316. width: 48rpx;
  317. }
  318. }
  319. }
  320. </style>