vote.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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>{{ Items.itemName }}</span>
  22. <span style="margin-left: 200px;">当前投票数:<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. // if(this.ActivityInfos.isWhiteList == 'Yes'&&this.ActivityInfos.whiteList){
  173. // if(!this.ActivityInfos.whiteList.includes(this.loginAccount)){
  174. // alert('你没有投票权限')
  175. // return
  176. // }
  177. // }
  178. },
  179. saveVote: function () {
  180. this.submitHandler((token) => {
  181. saveOrUpdateVote(JSON.stringify(this.itemVoteDetail), token).then(res => {
  182. //投票成功提示信息, 页面跳转
  183. this.$router.back()
  184. }).catch((error) => {
  185. this.resetToken();
  186. });
  187. });
  188. this.$message({
  189. type: 'success',
  190. message: '投票成功!'
  191. });
  192. },
  193. getVoteParam () {
  194. //活动id赋值
  195. this.itemVoteDetail.activityId = this.ActivityInfos.id;
  196. //参投id赋值
  197. this.itemVoteDetail.itemId = this.Items.id;
  198. // console.log('/////////',this.itemVoteDetail.activityId)
  199. getVoteParams({ itemId: this.itemVoteDetail.itemId }).then(res => {
  200. this.totalVotes = res.data.voteParams.totalVotes;
  201. this.nowDayTotalVotes = res.data.voteParams.nowDayTotalVotes;
  202. this.nowDayTotalVotesForOneItem = res.data.voteParams.nowDayTotalVotesForOneItem;
  203. this.isVoteForOneItem = res.data.voteParams.isVoteForOneItem;
  204. this.buttonChang()
  205. })
  206. },
  207. //读秒
  208. timekeep () {
  209. var that = this
  210. var myVar = setInterval(function () {
  211. if (that.mytime == 1) {
  212. clearTimeout(myVar)
  213. };
  214. return that.mytime--;
  215. }, 1000);
  216. },
  217. //返回按钮
  218. voteback () {
  219. this.$router.go(-1)
  220. },
  221. //按钮是否禁用
  222. buttonChang () {
  223. // this.getVoteParam()
  224. var nowTime = Date.parse(new Date());//现在的时间戳
  225. console.log('9090909090', this.totalVotes)
  226. if (this.ActivityInfos.voteStartDate <= nowTime && this.ActivityInfos.voteEndDate >= nowTime) {//判断一下投票时间
  227. if (this.ActivityInfos.maxNumTotal && (parseInt(this.totalVotes) >= parseInt(this.ActivityInfos.maxNumTotal))) {
  228. this.loadflag = false;
  229. return
  230. } else if (parseInt(this.nowDayTotalVotes) >= parseInt(this.ActivityInfos.maxNumOneday)) {
  231. this.loadflag = false;
  232. return
  233. } else if (parseInt(this.nowDayTotalVotesForOneItem) >= parseInt(this.ActivityInfos.maxNumOneitemOneday)) {
  234. this.loadflag = false;
  235. return
  236. } else if (this.ActivityInfos.isRevoteOneitem == 'No' && this.isVoteForOneItem == 'Yes') {
  237. this.loadflag = false;
  238. return
  239. }
  240. // debugger
  241. } else {
  242. this.loadflag = false;
  243. }
  244. }
  245. }
  246. }
  247. </script>
  248. <style scoped>
  249. * {
  250. padding: 0;
  251. margin: 0;
  252. }
  253. html,
  254. body,
  255. #app {
  256. width: 100%;
  257. height: 100%;
  258. }
  259. body {
  260. overflow: hidden
  261. }
  262. ;
  263. .vote>>>.pageContainer img {
  264. width: 100%;
  265. }
  266. /* .pdfjs .pdfViewer .pageContainer ::-webkit-scrollbar{
  267. display:none;
  268. } */
  269. /deep/.viewerContainer {
  270. height: calc(100vh);
  271. }
  272. .color {
  273. color: #e12c2c;
  274. }
  275. .voteButton {
  276. width: 200px;
  277. height: 80px;
  278. background: linear-gradient(90deg, #62bf00 0%, #47ab16 100%);
  279. color: #fff;
  280. vertical-align: center;
  281. line-height: 35px;
  282. position: fixed;
  283. top: 50%;
  284. left: 50%;
  285. transform: translateX(200%);
  286. cursor: pointer;
  287. }
  288. .notvoteButton {
  289. width: 200px;
  290. height: 80px;
  291. background: linear-gradient(90deg, #727472 0%, #555a53 100%);
  292. color: #fff;
  293. text-align: center;
  294. line-height: 35px;
  295. position: fixed;
  296. top: 50%;
  297. left: 50%;
  298. transform: translateX(200%);
  299. cursor: pointer;
  300. pointer-events: none;
  301. }
  302. .voteButton:active {
  303. background: linear-gradient(90deg, #B4D5FF 0%, #4F81BF 100%);
  304. }
  305. .voteButton div {
  306. width: 100%;
  307. text-align: center;
  308. }
  309. .backButton {
  310. width: 100px;
  311. height: 30px;
  312. background-color: #B4D5FF;
  313. position: absolute;
  314. top: 6px;
  315. right: 25%;
  316. border-radius: 8px;
  317. text-align: center;
  318. line-height: 30px;
  319. cursor: pointer;
  320. }
  321. </style>