voteInfoDetails.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <div class="vote" id="app" style="width: 1200px;margin: auto;color: #333;overflow:hidden">
  3. <!-- 投票按钮 -->
  4. <div
  5. style="position: fixed;top: 0;left: auto;background: #fff;z-index: 9;width: 100%;border-bottom: 1px solid #ccc;">
  6. <!-- 十秒后投票按钮显示 -->
  7. <div :class="loadflag?'voteButton':'notvoteButton'" @click="voteSend" v-if="flag">
  8. <div style="font-size: 20px;">
  9. 投票
  10. </div>
  11. <div>请阅读完最后一页投票</div>
  12. </div>
  13. <!-- 投票倒计时 -->
  14. <div :class="loadflag?'voteButton':'notvoteButton'" v-if="!flag">
  15. <div style="font-size: 20px;line-height:80px" v-if="flagplus">阅读{{mytime}}秒后可投票</div>
  16. <div style="font-size: 16px;line-height:80px" v-if="!flagplus">阅读完最后一页方可投票</div>
  17. </div>
  18. <!-- 页数及投票信息 -->
  19. <div>
  20. <div>
  21. <span style="width: 908px;display: inline-block; ">{{ Items.itemName }}</span>
  22. <span style="margin-left: 150px;">当前投票数:<span class="color">{{ Items.numOfVote }}</span></span>
  23. </div>
  24. <div></div>
  25. <div @click=" getCurren">当前页:{{currentNum}}</div>
  26. </div>
  27. <!-- 返回按钮 -->
  28. <div class="backButton" @click="voteback">返回上一页</div>
  29. </div>
  30. <div id="demo" style="margin-top: 80px;"></div>
  31. </div>
  32. </template>
  33. <script>
  34. import Pdfh5 from "pdfh5";
  35. import Base from "@/views/base/Base";
  36. import { saveOrUpdateVote, getVoteParams } from "@/api/vote/vote";
  37. import "pdfh5/css/pdfh5.css";
  38. import { parse } from 'qs';
  39. export default {
  40. extends: Base,
  41. name: 'pdf',
  42. data () {
  43. return {
  44. pdfh5: null,
  45. pdfUrl: '', //地址最好用http: 的访问
  46. flag: false,//按钮是否显示flag
  47. flagplus: true,
  48. loadflag: true,//决定按钮是否可以禁用的flag
  49. mytime: 10,//计时时间
  50. itemVoteDetail: {
  51. id: null,
  52. activityId: '', //活动id
  53. itemId: '', //参投id
  54. },
  55. ActivityInfos: '',//从投票列表页传过来的数据
  56. Items: '', //从投票列表页传过来的数据
  57. userPhone: '',//账号手机号
  58. userEmail: '',//账号邮箱
  59. //--投票规则--
  60. //是否启用白名单(Yes,No): this.$route.query.activityInfos.isWhiteList
  61. //白名单内容: this.$route.query.activityInfos.whiteList
  62. //投票期间投票总数: this.$route.query.activityInfos.maxNumTotal
  63. //账号每天最多投票数: this.$route.query.activityInfos.maxNumOneday
  64. //账号对同一个参投条目每天最多投票数: this.$route.query.activityInfos.maxNumOneitemOneday
  65. //一个参投条目是否允许重复投票(Yes,No): this.$route.query.activityInfos.isRevoteOneitem
  66. //--当前账号投票情况--
  67. totalVotes: '', //账号在投票期间投票总数
  68. nowDayTotalVotes: '',//账号当天投票总数
  69. nowDayTotalVotesForOneItem: '',//账号对单个参投项当天投票总数
  70. isVoteForOneItem: '',//账号在投票期间对单个参投项是否投过票
  71. //----------------------------------------------------------
  72. currentNum: '',
  73. totalNum: '',
  74. };
  75. },
  76. watch: {
  77. "pdfh5.currentNum" () {
  78. this.currentNum = this.pdfh5.currentNum;
  79. if (this.pdfh5.currentNum == this.pdfh5.totalNum) { this.flag = true };
  80. },
  81. },
  82. beforeCreate: function () {
  83. document.getElementsByTagName("body")[0].className = "add_bg";
  84. },
  85. mounted () {
  86. this.timekeep();//读秒计时
  87. this.ActivityInfos = JSON.parse(this.$route.query.activityInfos);
  88. this.Items = JSON.parse(this.$route.query.items);
  89. // console.log('23232323232323',this.ActivityInfos)
  90. // console.log('23232323232323',this.Items)
  91. var nowtime = Date.parse(new Date());
  92. this.ActivityInfos.voteStartDate = Date.parse(this.ActivityInfos.voteStartDate);
  93. this.ActivityInfos.voteEndDate = Date.parse(this.ActivityInfos.voteEndDate);
  94. if (this.ActivityInfos.voteStartDate > nowtime || this.ActivityInfos.voteEndDate < nowtime) { this.flag = true };
  95. //取出用户手机号和邮箱
  96. this.loginAccount = JSON.parse(localStorage.getItem("user")).umsUser.userPreferredMobile ? JSON.parse(localStorage.getItem("user")).umsUser.userPreferredMobile : JSON.parse(localStorage.getItem("user")).umsUser.userEmail;
  97. this.getVoteParam();
  98. //实例化
  99. this.pdfUrl = this.Items.fileUrl;
  100. this.pdfh5 = new Pdfh5("#demo", {
  101. URIenable: false,
  102. pdfurl: './api/file/pub/' + this.pdfUrl
  103. });
  104. //监听完成事件
  105. this.pdfh5.on("complete", function (status, msg, time) {
  106. console.log("状态:" + status + ",信息:" + msg + ",耗时:" + time + "毫秒,总页数:" + this.totalNum, this.currentNum)
  107. });
  108. this.pdfh5.on("error", function (msg, time) {
  109. console.log(",信息:" + msg + ",耗时:" + time + "毫秒,总页数:" + this.totalNum)
  110. });
  111. //计时器
  112. setTimeout(() => {
  113. this.flagplus = false;
  114. if (this.pdfh5.currentNum == this.pdfh5.totalNum) { this.flag = true };
  115. }, 10000);
  116. },
  117. // destroyed(){
  118. // console.log('当天页数' + this.pdfh5.currentNum ,'总页数' + this.pdfh5.totalNum )
  119. // },
  120. methods: {
  121. getCurren () {
  122. // alert(this.pdfh5.currentNum==this.pdfh5.totalNum)
  123. },
  124. voteSend () {
  125. this.$confirm('是否确定投票', '提示', {
  126. confirmButtonText: '确定',
  127. cancelButtonText: '取消',
  128. type: 'warning'
  129. }).then(() => {
  130. var nowTime = Date.parse(new Date());//现在的时间戳
  131. if (this.loginAccount.slice(0, 4) == '0086') { this.loginAccount = this.loginAccount.slice(4) };//截取用户手机号
  132. if (this.ActivityInfos.voteStartDate <= nowTime && this.ActivityInfos.voteEndDate >= nowTime) {//判断一下投票时间
  133. if (this.ActivityInfos.maxNumTotal && (parseInt(this.totalVotes) >= parseInt(this.ActivityInfos.maxNumTotal))) {
  134. this.$message({
  135. type: 'warning',
  136. message: '活动期间投票数已达上限!'
  137. });
  138. return
  139. } else if (parseInt(this.nowDayTotalVotes) >= parseInt(this.ActivityInfos.maxNumOneday)) {
  140. this.$message({
  141. type: 'warning',
  142. message: '当天投票数已达上限!'
  143. });
  144. return
  145. } else if (parseInt(this.nowDayTotalVotesForOneItem) >= parseInt(this.ActivityInfos.maxNumOneitemOneday)) {
  146. this.$message({
  147. type: 'warning',
  148. message: '该论文投票数已达上限!'
  149. });
  150. return
  151. } else if (this.ActivityInfos.isRevoteOneitem == 'No' && this.isVoteForOneItem == 'Yes') {
  152. this.$message({
  153. type: 'warning',
  154. message: '请勿对一个论文重复投票!'
  155. });
  156. return
  157. } else {
  158. this.saveVote()
  159. }
  160. } else {
  161. this.$message({
  162. type: 'warning',
  163. message: '未到投票时间!'
  164. });
  165. }
  166. }).catch(() => {
  167. this.$message({
  168. type: 'info',
  169. message: '投票取消'
  170. });
  171. });
  172. },
  173. saveVote: function () {
  174. this.submitHandler((token) => {
  175. saveOrUpdateVote(JSON.stringify(this.itemVoteDetail), token).then(res => {
  176. //投票成功提示信息, 页面跳转
  177. this.$router.back()
  178. }).catch((error) => {
  179. this.resetToken();
  180. });
  181. });
  182. this.$message({
  183. type: 'success',
  184. message: '投票成功!'
  185. });
  186. },
  187. getVoteParam () {
  188. //活动id赋值
  189. this.itemVoteDetail.activityId = this.ActivityInfos.id;
  190. //参投id赋值
  191. this.itemVoteDetail.itemId = this.Items.id;
  192. // console.log('/////////',this.itemVoteDetail.activityId)
  193. getVoteParams({ itemId: this.itemVoteDetail.itemId }).then(res => {
  194. this.totalVotes = res.data.voteParams.totalVotes;
  195. this.nowDayTotalVotes = res.data.voteParams.nowDayTotalVotes;
  196. this.nowDayTotalVotesForOneItem = res.data.voteParams.nowDayTotalVotesForOneItem;
  197. this.isVoteForOneItem = res.data.voteParams.isVoteForOneItem;
  198. this.buttonChang()
  199. })
  200. },
  201. //读秒
  202. timekeep () {
  203. var that = this
  204. var myVar = setInterval(function () {
  205. if (that.mytime == 1) {
  206. clearTimeout(myVar)
  207. };
  208. return that.mytime--;
  209. }, 1000);
  210. },
  211. //返回按钮
  212. voteback () {
  213. this.$router.go(-1)
  214. },
  215. //按钮是否禁用
  216. buttonChang () {
  217. // this.getVoteParam()
  218. var nowTime = Date.parse(new Date());//现在的时间戳
  219. console.log('9090909090', this.totalVotes)
  220. if (this.ActivityInfos.voteStartDate <= nowTime && this.ActivityInfos.voteEndDate >= nowTime) {//判断一下投票时间
  221. if (this.ActivityInfos.maxNumTotal && (parseInt(this.totalVotes) >= parseInt(this.ActivityInfos.maxNumTotal))) {
  222. this.loadflag = false;
  223. return
  224. } else if (parseInt(this.nowDayTotalVotes) >= parseInt(this.ActivityInfos.maxNumOneday)) {
  225. this.loadflag = false;
  226. return
  227. } else if (parseInt(this.nowDayTotalVotesForOneItem) >= parseInt(this.ActivityInfos.maxNumOneitemOneday)) {
  228. this.loadflag = false;
  229. return
  230. } else if (this.ActivityInfos.isRevoteOneitem == 'No' && this.isVoteForOneItem == 'Yes') {
  231. this.loadflag = false;
  232. return
  233. }
  234. // debugger
  235. } else {
  236. this.loadflag = false;
  237. }
  238. }
  239. }
  240. }
  241. </script>
  242. <style scoped>
  243. * {
  244. padding: 0;
  245. margin: 0;
  246. }
  247. html,
  248. body,
  249. #app {
  250. width: 100%;
  251. height: 100%;
  252. }
  253. body {
  254. overflow: hidden
  255. }
  256. ;
  257. .vote>>>.pageContainer img {
  258. width: 100%;
  259. }
  260. /* .pdfjs .pdfViewer .pageContainer ::-webkit-scrollbar{
  261. display:none;
  262. } */
  263. /deep/.viewerContainer {
  264. height: calc(100vh);
  265. }
  266. .color {
  267. color: #e12c2c;
  268. }
  269. .voteButton {
  270. width: 200px;
  271. height: 80px;
  272. background: linear-gradient(90deg, #62bf00 0%, #47ab16 100%);
  273. color: #fff;
  274. vertical-align: center;
  275. line-height: 35px;
  276. position: fixed;
  277. top: 50%;
  278. left: 50%;
  279. transform: translateX(200%);
  280. cursor: pointer;
  281. }
  282. .notvoteButton {
  283. width: 200px;
  284. height: 80px;
  285. background: linear-gradient(90deg, #727472 0%, #555a53 100%);
  286. color: #fff;
  287. text-align: center;
  288. line-height: 35px;
  289. position: fixed;
  290. top: 50%;
  291. left: 50%;
  292. transform: translateX(200%);
  293. cursor: pointer;
  294. pointer-events: none;
  295. }
  296. .voteButton:active {
  297. background: linear-gradient(90deg, #B4D5FF 0%, #4F81BF 100%);
  298. }
  299. .voteButton div {
  300. width: 100%;
  301. text-align: center;
  302. }
  303. .backButton {
  304. width: 100px;
  305. height: 30px;
  306. background-color: #B4D5FF;
  307. position: absolute;
  308. top: 6px;
  309. right: 25%;
  310. border-radius: 8px;
  311. text-align: center;
  312. line-height: 30px;
  313. cursor: pointer;
  314. }
  315. </style>