activityDetail.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. <template>
  2. <view :style="vuex_skin">
  3. <!-- #ifdef MP-WEIXIN -->
  4. <u-navbar :custom-back="customBack" :is-back="true" title="作品详情"></u-navbar>
  5. <!-- #endif -->
  6. <view class="" v-show="!loading">
  7. <video v-if="activity.activeType == 'VIDEO_TEXT'" class="works-video" @error="videoError"
  8. :poster="activity.imgUrl" :src="activity.videoUrl"></video>
  9. <image v-else class="works-video" :src="activity.imgUrl" mode=""></image>
  10. <view style="padding: 20rpx 30rpx 50rpx 30rpx;background: white;">
  11. <view class="title" style="border-bottom: 1rpx solid #EEEEEE ;">
  12. <span class="bg-red work-no"> {{activity.productNo}}号</span>
  13. <span class="work-title">{{activity.title}}</span>
  14. <view class="work-info-box">
  15. <image class="remen-icon" src="../../static/icon/remen.png"></image>
  16. <span class="vote-count">{{activity.voteCount}}</span>
  17. <span class="work-rank">排行榜第{{activity.rank}}名</span>
  18. </view>
  19. </view>
  20. <view style="font-size: 24rpx;color: #888888;padding: 30rpx 10rpx 20rpx 10rpx;">
  21. <u-parse :html="content"></u-parse>
  22. </view>
  23. </view>
  24. <view @click="showShare" class="bg-white padding-30 margin-top-30 flex">
  25. <view class="basis-xs">
  26. <image style="width: 84rpx;height: 84rpx;" src="../../static/icon/ic_zhuanfa.png"></image>
  27. </view>
  28. <view class="basis-lg flex flex-direction" style="margin-left: -20rpx;">
  29. <view style="font-size: 28rpx;color: #353535;">为TA拉票</view>
  30. <view style="font-size: 22rpx;color: #AEACAF;padding-top: 10rpx;">
  31. <!-- <text>成功邀请一位好友投票,获得{{vuex_active_setting.voteAndHeatRate}}热力值</text> -->
  32. <text>转发邀请好友为该作品助力</text>
  33. </view>
  34. </view>
  35. <view class="flex justify-center align-center"
  36. style="color: #666666;flex-basis: 20%;font-size: 26rpx;font-family: PingFang-SC-Medium;">去邀请 >
  37. </view>
  38. </view>
  39. <view class="footer-bar" style="z-index: 1;">
  40. <u-button @click="goVote" shape="circle" :custom-style="btnText=='给ta投票'?customStyle:disabledStyle">
  41. {{btnText}}
  42. </u-button>
  43. </view>
  44. </view>
  45. <login ref="login" @signIn="signIn" @phoneSuccess="showVote"></login>
  46. <toast ref="toast"></toast>
  47. <!-- #ifdef MP-WEIXIN -->
  48. <loading ref="loading" type="3" theme="2" />
  49. <!-- #endif -->
  50. <vote-popup ref="votePopup" @toVote="toVote"></vote-popup>
  51. <!-- 海报 -->
  52. <poster ref="poster" :avatar="posetrParams.avatar" :title="posetrParams.title"
  53. :subTitle="posetrParams.subTitle"></poster>
  54. <share-popup ref="sharePopup" @confirm="shareConfirm"></share-popup>
  55. <timeline-popup ref="timelinePopup"></timeline-popup>
  56. <sms-alert ref="smsAlert" @exchange="cmccVote"></sms-alert>
  57. <vote-success ref="voteSuccess" @support="showShare"></vote-success>
  58. </view>
  59. </template>
  60. <script>
  61. import voteSuccess from "@/components/alert/voteSuccess.vue"
  62. import sharePopup from "@/components/alert/sharePopup.vue"
  63. import timelinePopup from "@/components/alert/timelinePopup.vue"
  64. import votePopup from '@/components/alert/votePopup.vue'
  65. import poster from "@/components/poster/poster.vue"
  66. import smsAlert from "@/components/alert/smsAlert.vue"
  67. export default {
  68. components: {
  69. voteSuccess,
  70. smsAlert,
  71. sharePopup,
  72. timelinePopup,
  73. votePopup,
  74. poster,
  75. },
  76. async onLoad(props) {
  77. // #ifdef MP-WEIXIN
  78. uni.showShareMenu({
  79. menus: ['shareAppMessage', 'shareTimeline']
  80. })
  81. // #endif
  82. this.isCustomBack = props.isCustomBack || true
  83. this.showLoading()
  84. //作品id
  85. this.id = props.id;
  86. //获取详情
  87. await this.fetchData()
  88. //处理授权结果
  89. this.handelAuthResult(props)
  90. // #ifdef MP-WEIXIN
  91. //处理创建订单结果
  92. this.handelOrderResult(props)
  93. // #endif
  94. // #ifdef H5
  95. this.h5CreateOrder()
  96. // #endif
  97. //处理海报参数
  98. this.handelShareParams()
  99. //隐藏loading
  100. setTimeout(() => {
  101. this.hideLoading()
  102. }, 20)
  103. },
  104. computed: {
  105. content() {
  106. return decodeURIComponent(this.activity.content)
  107. },
  108. btnText: {
  109. get() {
  110. let now = new Date().getTime()
  111. let startTime = this.$dateTime.getTime(this.activity.activeStartTime)
  112. let endTime = this.$dateTime.getTime(this.activity.activeEndTime)
  113. if (now < startTime) {
  114. return "活动未开始"
  115. }
  116. if (now > endTime) {
  117. return "活动已结束"
  118. }
  119. return "给ta投票"
  120. }
  121. }
  122. },
  123. data() {
  124. return {
  125. count: 0,
  126. //是否自定义返回,防止授权时返回到webview页面
  127. isCustomBack: true,
  128. defaultAvatar: 'https://vote.guosen-fumao.cn/obsfile/446d9e043f3748e4a47ea4d0de81b140-3b748fea4150c469b8eb66f98cd29e2.png',
  129. loading: false,
  130. //作品id
  131. id: '',
  132. //订单结果
  133. orderResult: {},
  134. //授权结果
  135. authResult: {},
  136. //分享
  137. qrCodeImg: '',
  138. //选中的道具
  139. selectGoods: {},
  140. mpShare: {},
  141. posetrParams: {
  142. avatar: '',
  143. title: '我是普法帮帮代言人',
  144. subTitle: '邀请您为888号作品投票!'
  145. },
  146. activity: {},
  147. customStyle: {
  148. color: 'white',
  149. background: "#E72226",
  150. fontSize: '32rpx',
  151. width: '500rpx',
  152. margin: '25rpx auto'
  153. },
  154. disabledStyle: {
  155. background: "#f1f1f1",
  156. fontSize: '32rpx',
  157. width: '500rpx',
  158. margin: '25rpx auto'
  159. },
  160. }
  161. },
  162. onShareAppMessage(res) {
  163. return {
  164. title: this.mpShare.title,
  165. path: this.mpShare.path,
  166. imageUrl: this.mpShare.imageUrl
  167. }
  168. },
  169. onShareTimeline(res) {
  170. return {
  171. title: this.mpShare.title,
  172. path: this.mpShare.path,
  173. imageUrl: this.mpShare.imageUrl
  174. }
  175. },
  176. methods: {
  177. goVote() {
  178. if (this.btnText == '给ta投票') {
  179. this.login()
  180. return
  181. }
  182. this.$refs.toast.error(this.btnText)
  183. },
  184. showLoading() {
  185. // #ifdef MP-WEIXIN
  186. this.$refs.loading.showLoading()
  187. // #endif
  188. // #ifndef MP-WEIXIN
  189. this.$dialog.showLoading()
  190. // #endif
  191. },
  192. videoError(e) {
  193. console.log(e, "error");
  194. },
  195. hideLoading() {
  196. // #ifdef MP-WEIXIN
  197. this.$refs.loading.hide()
  198. // #endif
  199. // #ifndef MP-WEIXIN
  200. uni.hideLoading()
  201. // #endif
  202. this.loading = false
  203. },
  204. async fetchData() {
  205. this.activity = (await this.$api.activity.getWorksDetail(this.id)).data.data
  206. },
  207. async handelShareParams() {
  208. let title = await this.getPosetrParamsTitle()
  209. this.posetrParams = {
  210. avatar: this.defaultAvatar,
  211. title: title,
  212. subTitle: '邀请您为' + this.activity.productNo + '号作品投票!'
  213. }
  214. let userId = this.vuex_userId || '000000' //游客
  215. let sharePath = '/pages/activity/activityDetail?id=' + this.activity.id + '&userId=' + userId
  216. let encodePath = encodeURIComponent(sharePath)
  217. this.mpShare = {
  218. title: title + ',' + this.posetrParams.subTitle,
  219. path: '/pages/index/home?path=' + encodePath,
  220. imageUrl: this.activity.imgUrl
  221. }
  222. },
  223. async getPosetrParamsTitle() {
  224. let title = "我是普法帮帮代言人"
  225. if (this.$isEmpty(this.vuex_phone)) {
  226. return title
  227. }
  228. let params = {
  229. activeId: this.activity.activeId,
  230. phone: this.vuex_phone
  231. }
  232. let res = await this.$api.activity.getPromoteNum(params)
  233. if (this.$isNotEmpty(res.data) && this.$isNotEmpty(res.data.data.index)) {
  234. let index = res.data.data.index
  235. title = `我是第${index}位大赛代言人!`
  236. }
  237. return title
  238. },
  239. handelAuthResult(options) {
  240. if (options.authResult == undefined) {
  241. return
  242. }
  243. this.authResult = JSON.parse(options.authResult)
  244. if (this.authResult.resultCode == '0000') {
  245. //授权成功,直接弹出礼物框
  246. this.hideLoading()
  247. this.showVote()
  248. return
  249. }
  250. // #ifdef MP-WEIXIN
  251. if (this.authResult.resultCode == '9999') {
  252. //授权失败
  253. this.$refs.toast.error(this.authResult.message)
  254. return
  255. }
  256. // #endif
  257. },
  258. handelOrderResult(options) {
  259. if (options.orderPass && this.$cache.get('orderResult')) {
  260. this.orderResult = this.$cache.get('orderResult')
  261. this.createOrder()
  262. }
  263. },
  264. async showVote() {
  265. this.$refs.votePopup.showVote(this.vuex_phone, this.id, this.activity.activeId);
  266. },
  267. init() {
  268. if (this.vuex_phone) {
  269. this.showVote()
  270. }
  271. },
  272. //去投票
  273. toVote(item) {
  274. if (this.$cache.get('orderResult')) {
  275. this.orderResult = this.$cache.get('orderResult')
  276. this.orderResult.goodsId = item.id
  277. this.$cache.put('orderResult', this.orderResult, 1 * 60 * 60)
  278. }
  279. this.selectGoods = item
  280. if (item.point == 0) {
  281. //免费投票
  282. this.freeVote()
  283. return
  284. }
  285. this.$refs.votePopup.hideVote()
  286. //移动积分投票,创建订单
  287. if (this.$cache.get('orderResult')) {
  288. this.createOrder()
  289. return
  290. }
  291. // #ifdef MP-WEIXIN
  292. let params = {
  293. url: 'https://vote.guosen-fumao.cn/order.html',
  294. goodsId: this.selectGoods.id
  295. }
  296. this.$jump('/pages/webview/createOrder' + this.$u.queryParams(params))
  297. // #endif
  298. },
  299. //移动积分创建订单
  300. async createOrder() {
  301. if (this.$isEmpty(this.orderResult.fingerprint) ||
  302. this.$isEmpty(this.orderResult.sessionId) ||
  303. this.$isEmpty(this.orderResult.goodsId)) {
  304. this.$refs.toast.error('创建订单失败')
  305. return
  306. }
  307. let params = {
  308. fingerprint: this.orderResult.fingerprint,
  309. helpGoodsId: this.orderResult.goodsId,
  310. sessionId: this.orderResult.sessionId,
  311. num: 1,
  312. phone: this.vuex_phone,
  313. userId: this.vuex_userId
  314. }
  315. let res = await this.$api.order.create(params)
  316. if (res.data.success) {
  317. console.log("orderResult", this.orderResult);
  318. this.orderResult.outOrderId = res.data.data
  319. this.orderResult.mobile = this.vuex_phone
  320. this.$refs.smsAlert.showSmsAndSend(this.orderResult)
  321. } else {
  322. this.$refs.toast.error(res.data.msg)
  323. }
  324. },
  325. async cmccVote(item) {
  326. this.$refs.smsAlert.hideSms()
  327. let params = {
  328. ...item,
  329. machinetype: 'phone',
  330. productId: this.id,
  331. helpGoodsId: this.orderResult.goodsId,
  332. userId: this.vuex_userId,
  333. num: 1,
  334. }
  335. let res = await this.$api.order.exchange(params)
  336. if (res.data.success) {
  337. this.voteSuccess()
  338. this.$refs.smsAlert.hideSms()
  339. } else {
  340. this.$refs.toast.error(res.data.msg)
  341. }
  342. },
  343. voteSuccess() {
  344. try {
  345. let avatar = this.$cache.get('userInfo').avatar || this.defaultAvatar
  346. let activeVote = this.selectGoods.activeVote
  347. this.$refs.voteSuccess.showSuccess(avatar, activeVote)
  348. } catch (e) {
  349. this.$refs.toast.info('助力成功')
  350. }
  351. },
  352. async freeVote() {
  353. let params = {
  354. helpGoodsId: this.selectGoods.id,
  355. userId: this.vuex_userId,
  356. num: 1,
  357. productId: this.activity.id,
  358. }
  359. let res = await this.$api.order.exchange(params)
  360. if (res.data.success) {
  361. this.$refs.votePopup.hideVote()
  362. this.fetchData()
  363. let avatar = this.$cache.get('userInfo').avatar
  364. let voteCount = this.selectGoods.votePointRate
  365. let pointNum = this.vuex_active_setting.voteAndPointRate
  366. setTimeout(() => {
  367. this.voteSuccess()
  368. }, 200)
  369. } else {
  370. this.$refs.votePopup.hideVote()
  371. setTimeout(() => {
  372. this.$refs.toast.error(res.data.msg)
  373. }, 200)
  374. }
  375. },
  376. customBack() {
  377. if (this.isCustomBack == true) {
  378. uni.switchTab({
  379. url: '/pages/index/home'
  380. })
  381. } else {
  382. uni.navigateBack({
  383. delta: 1
  384. })
  385. }
  386. },
  387. //分享
  388. showPoster() {
  389. this.$refs.poster.showCanvas()
  390. },
  391. async shareConfirm(item) {
  392. if (item.name == '海报') {
  393. this.showPoster()
  394. return
  395. }
  396. if (item.name == '好友') {
  397. return
  398. }
  399. if (item.name == '朋友圈') {
  400. this.$refs.timelinePopup.show()
  401. }
  402. },
  403. async showShare() {
  404. await this.handelShareParams()
  405. // #ifdef MP-WEIXIN
  406. this.$refs.sharePopup.show()
  407. // #endif
  408. // #ifndef MP-WEIXIN
  409. this.showPoster()
  410. // #endif
  411. },
  412. // h5 创建订单 begin
  413. h5CreateOrder() {
  414. if (this.$cache.get('orderResult')) {
  415. this.orderResult = this.$cache.get('orderResult')
  416. return
  417. }
  418. //初始化js脚本
  419. this.initScript()
  420. //获取Fmopt
  421. this.fetchFmopt()
  422. //获取sessionId
  423. this.loadScriptFunc("", this.fetchSessionId())
  424. //打印数据
  425. this.cacheOrderData()
  426. },
  427. cacheOrderData() {
  428. let _this = this
  429. setTimeout(() => {
  430. _this.$nextTick(function() {
  431. try {
  432. _this.count++
  433. console.log("sessionId:" + window.sessionId);
  434. console.log("fingerprint:" + _fmOpt.getinfo());
  435. console.log("获取成功啦");
  436. _this.pushInCache(_fmOpt.getinfo(), window.sessionId)
  437. } catch (e) {
  438. console.log(_this.count);
  439. if (_this.count < 10) {
  440. _this.cacheOrderData()
  441. }
  442. }
  443. })
  444. }, 20)
  445. },
  446. pushInCache(fingerprint, sessionId) {
  447. this.orderResult = {
  448. fingerprint: encodeURIComponent(fingerprint),
  449. sessionId,
  450. goodsId: this.selectGoods.id
  451. }
  452. this.$cache.put('orderResult', this.orderResult)
  453. },
  454. initScript() {
  455. let monitorURL = "https://static.tongdun.net/monitor/monitor.js"
  456. this.loadScript(monitorURL)
  457. let tfdURL = "https://j.changyoyo.com/static/js/common/tfd.js"
  458. this.loadScript(tfdURL)
  459. let jqueryURL = "https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"
  460. this.loadScript(jqueryURL)
  461. },
  462. fetchFmopt() {
  463. window._fmOpt = {
  464. partner: 'changyou',
  465. appName: 'changyou_web',
  466. token: 'changyou' + "-" + new Date().getTime() + "-" +
  467. Math.random().toString(16).substr(2),
  468. fmb: true,
  469. success: function(data) {
  470. console.log('blackbox: ', data)
  471. },
  472. fpHost: "https://fp.tongdun.net"
  473. };
  474. var cimg = new Image(1, 1);
  475. cimg.onload = function() {
  476. _fmOpt.imgLoaded = true;
  477. };
  478. cimg.src =
  479. "https://fp.tongdun.net/fp/clear.png?partnerCode=changyou&appName=changyou_web&tokenId=" +
  480. _fmOpt.token;
  481. var fm = document.createElement('script');
  482. fm.type = 'text/javascript';
  483. fm.async = true;
  484. fm.src = ('https:' == document.location.protocol ? 'https://' : 'http://') +
  485. 'static.tongdun.net/v3/fm.js?ver=0.1&t=' + (new Date().getTime() / 3600000).toFixed(0);
  486. var s = document.getElementsByTagName('script')[0];
  487. s.parentNode.insertBefore(fm,
  488. s);
  489. },
  490. loadScript(src) {
  491. var script = document.createElement('script');
  492. script.src = src;
  493. document.body.appendChild(script);
  494. },
  495. loadScriptFunc(url, callback) {
  496. callback = typeof callback === 'function' ? callback : function() {};
  497. var head = document.getElementsByTagName('head')[0];
  498. var script = document.createElement('script');
  499. script.type = 'text/javascript';
  500. script.src = url;
  501. script.onreadystatechange = function() {
  502. if (this.readyState == "loaded" || this.readyState == "complete") {
  503. callback();
  504. }
  505. }
  506. script.onload = callback;
  507. head.appendChild(script);
  508. },
  509. fetchSessionId() {
  510. var url, ts, sessionId, appId, appkey;
  511. if (document.domain === 'm.changyoyo.com') {
  512. url = "tfd.changyoyo.com";
  513. } else {
  514. url = "101.132.237.10";
  515. }
  516. appId = "5308e20b";
  517. appkey = "3daf27ea2fe840ada6af8e1ec0d7b760";
  518. ts = new Date().getTime();
  519. sessionId = "changyo-pc-" + ts + "-" + Math.random().toString(16).substr(2);
  520. window.sessionId = sessionId;
  521. [document.getElementsByTagName('script')[0].parentNode.appendChild(document.createElement('script')).src =
  522. "http://" +
  523. url + "/did/js/dp.js?appId=" + appId + "&appkey=" + appkey + "&sessionId=" + sessionId +
  524. "&ts=" +
  525. ts
  526. ][0];
  527. },
  528. //h5 创建订单end
  529. },
  530. }
  531. </script>
  532. <style lang="scss" scoped>
  533. .works-video {
  534. width: 100%;
  535. height: 422rpx;
  536. }
  537. .title {
  538. padding: 20rpx;
  539. .work-no {
  540. padding: 5rpx 10rpx 5rpx 10rpx;
  541. border-radius: 7rpx;
  542. }
  543. .work-title {
  544. padding: 0 0 0 20rpx;
  545. color: #353535;
  546. font-size: 32rpx;
  547. font-weight: 800;
  548. }
  549. }
  550. .work-info-box {
  551. padding: 30rpx 0 15rpx 10rpx;
  552. .remen-icon {
  553. width: 30rpx;
  554. height: 30rpx;
  555. }
  556. .vote-count {
  557. padding: 0 40rpx 0 10rpx;
  558. font-size: 40rpx;
  559. color: #353535;
  560. font-weight: 800;
  561. }
  562. .work-rank {
  563. margin-left: -10rpx;
  564. color: #353535;
  565. background: #FDEBEC;
  566. border-radius: 21px 21px 21px 21px;
  567. font-size: 22rpx;
  568. padding: 8rpx 15rpx 8rpx 15rpx;
  569. }
  570. }
  571. .footer-bar {
  572. position: absolute;
  573. bottom: 0;
  574. left: 0;
  575. width: 100%;
  576. height: 170rpx;
  577. background-color: white;
  578. }
  579. .canvas-hide {
  580. position: fixed;
  581. right: 100vw;
  582. bottom: 100vh;
  583. z-index: -9999;
  584. opacity: 0;
  585. }
  586. </style>