index.vue 8.3 KB

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