移动端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

236 行
8.5 KiB

  1. <template>
  2. <div class="app-container">
  3. <van-nav-bar
  4. title="投票"
  5. left-arrow
  6. @click-left="$router.back(-1)"
  7. >
  8. <!--<template #right>
  9. <van-image src=""></van-image>
  10. </template>-->
  11. </van-nav-bar>
  12. <van-row style="margin-top: 20px">
  13. <van-col span="20" offset="2">
  14. <H3 style="line-height: 20px;">{{form.subjectName}}</H3>
  15. </van-col>
  16. </van-row>
  17. <van-row style="margin-top: 10px">
  18. <van-col span="20" offset="2">
  19. <h4 style="color: #878787;line-height: 20px;">{{form.description}}</h4>
  20. </van-col>
  21. </van-row>
  22. <van-row style="margin-top: 10px">
  23. <van-col span="9" offset="2">
  24. <van-image
  25. v-if="form.anonymous!=1"
  26. width="12"
  27. height="12"
  28. style="display: inline-block;"
  29. src="../../../static/images/onlineHome/vote1.png"
  30. />
  31. <p style="display: inline-block;color:#1D6FE9" v-if="form.anonymous!=1">实名</p>
  32. <van-image
  33. v-if="form.type==1"
  34. width="12"
  35. height="12"
  36. style="display: inline-block;"
  37. src="../../../static/images/onlineHome/vote1.png"
  38. />
  39. <p v-if="form.type==1" style="display: inline-block;color:#1D6FE9 ">单选</p>
  40. <van-image
  41. v-if="form.type==2"
  42. width="12"
  43. height="12"
  44. style="display: inline-block;"
  45. src="../../../static/images/onlineHome/vote1.png"
  46. />
  47. <p v-if="form.type==2" style="display: inline-block;color:#1D6FE9 ">多选</p>
  48. </van-col>
  49. <van-col span="8" offset="5">
  50. <van-image
  51. width="12"
  52. height="12"
  53. style="display: inline-block;"
  54. src="../../../static/images/onlineHome/vote.png"
  55. />
  56. <p style="display: inline-block">{{this.form.nums}}人已参与</p>
  57. </van-col>
  58. </van-row>
  59. <van-checkbox-group v-if="form.type==2" v-model="result" style="margin-top: 20px">
  60. <van-cell-group v-for="(item,index) in pollOptions" :key="index" style="width: 96%;margin:2%;border-radius: 6px;overflow: hidden;padding-top: 10px;padding-bottom: 10px;box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);">
  61. <van-cell :title="item.name">
  62. <template #icon>
  63. <van-image
  64. fit="contain"
  65. height="18"
  66. style="margin-right: 10px"
  67. src="../../../static/images/onlineHome/home3.png"
  68. />
  69. </template>
  70. <van-checkbox :name="item.id" style="float: right" :disabled="!isPoll"/>
  71. </van-cell>
  72. <van-row>
  73. <van-col span="15" :offset="2" style="margin-top: 7px;">
  74. <van-progress v-if="result.indexOf(item.id)==-1" :percentage="voteNum>0?((item.num/voteNum)*100).toFixed(2):0" :show-pivot="false"/>
  75. <van-progress v-if="result.indexOf(item.id)!=-1" :percentage="(voteNum+result.length)>0?(((item.num+1)/(voteNum+result.length))*100).toFixed(2):0" :show-pivot="false"/>
  76. </van-col>
  77. <van-col span="5" :offset="2" v-if="result.indexOf(item.id)==-1">
  78. {{item.num}}票 {{voteNum>0?((item.num/voteNum)*100).toFixed(2):0}}%
  79. </van-col>
  80. <van-col span="5" :offset="2" v-if="result.indexOf(item.id)!=-1">
  81. {{item.num+1}}票 {{(voteNum+result.length)>0?(((item.num+1)/(voteNum+result.length))*100).toFixed(2):0}}%
  82. </van-col>
  83. </van-row>
  84. </van-cell-group>
  85. </van-checkbox-group>
  86. <van-radio-group v-if="form.type==1" v-model="result1" style="margin-top: 20px">
  87. <van-cell-group v-for="(item,index) in pollOptions" :key="index" style="width: 96%;margin:2%;border-radius: 6px;overflow: hidden;padding-top: 10px;padding-bottom: 10px;box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);">
  88. <van-cell :title="item.name">
  89. <template #icon>
  90. <van-image
  91. fit="contain"
  92. height="18"
  93. style="margin-right: 10px"
  94. src="../../../static/images/onlineHome/home3.png"
  95. />
  96. </template>
  97. <van-radio :name="item.id" style="float: right" :disabled="!isPoll"/>
  98. </van-cell>
  99. <van-row>
  100. <van-col span="15" :offset="2" style="margin-top: 7px;">
  101. <van-progress v-if="result1!=item.id" :percentage="voteNum>0?((item.num/voteNum)*100).toFixed(2):0" :show-pivot="false"/>
  102. <van-progress v-if="result1==item.id&&voteNum>0" :percentage="voteNum>0?(((item.num+1)/(voteNum+1))*100).toFixed(2):0" :show-pivot="false"/>
  103. <van-progress v-if="result1==item.id&&voteNum==0" :percentage="voteNum==0?(((item.num+1)/(voteNum+1))*100).toFixed(2):0" :show-pivot="false"/>
  104. </van-col>
  105. <van-col span="5" :offset="2" v-if="result1!=item.id">
  106. {{item.num}}票 {{voteNum>0?((item.num/voteNum)*100).toFixed(2):0}}%
  107. </van-col>
  108. <van-col span="5" :offset="2" v-if="result1==item.id&&voteNum>0">
  109. {{item.num+1}}票 {{voteNum>0?(((item.num+1)/(voteNum+1))*100).toFixed(2):0}}%
  110. </van-col>
  111. <van-col span="5" :offset="2" v-if="result1==item.id&&voteNum==0">
  112. {{item.num+1}}票 {{voteNum==0?(((item.num+1)/(voteNum+1))*100).toFixed(2):0}}%
  113. </van-col>
  114. </van-row>
  115. </van-cell-group>
  116. </van-radio-group>
  117. <van-row style="text-align: center;margin-top: 40px" v-if="isPoll">
  118. <van-button color="#1D6FE9" style="border-radius: 6px;width: 90%;margin: 0 auto" @click="submit">提交</van-button>
  119. </van-row>
  120. <van-row style="text-align: center;margin-top: 40px" v-if="!isPoll">
  121. <van-button color="#1D6FE9" style="border-radius: 6px;width: 90%;margin: 0 auto" @click="submit" :disabled="true">已投票</van-button>
  122. </van-row>
  123. </div>
  124. </template>
  125. <script>
  126. import onlineHomeIndex from "../onlineHomeIndex";
  127. import {getPoll, listPollVote, votePoll} from "../../api/onlineHome/poll";
  128. import {getInfo} from "../../api/login";
  129. export default {
  130. components: {
  131. onlineHomeIndex
  132. },
  133. name: "homePollDetail",
  134. data() {
  135. return {
  136. loading: false,
  137. form:{},
  138. pollOptions:[],
  139. id:this.$route.query.id,
  140. voteNum:0,
  141. result:[],
  142. result1:"",
  143. isPoll:true,
  144. };
  145. },
  146. created() {
  147. this.form={}
  148. this.getInfo(this.id);
  149. listPollVote().then(res => {
  150. console.log(this.$store)
  151. getInfo().then(response => {
  152. console.log(response)
  153. if(res.rows.length>0){
  154. res.rows.map(r => {
  155. if(r.pollId==this.id){
  156. if(r.userId == response.user.userId){
  157. this.isPoll = false
  158. }
  159. }
  160. })
  161. }
  162. });
  163. })
  164. },
  165. methods:{
  166. reset(){
  167. this.pollOptions = []
  168. },
  169. getInfo(val){
  170. this.reset();
  171. this.loading = true
  172. getPoll(val).then(response => {
  173. response.data.options.map(res => {
  174. this.voteNum += res.num
  175. this.pollOptions.push(res)
  176. })
  177. this.form = response.data;
  178. this.loading = true
  179. });
  180. },
  181. submit(){
  182. let list = []
  183. let _this = this
  184. if (this.form.type == 1) {
  185. if (this.result1 != "") {
  186. list.push(this.result1)
  187. } else {
  188. this.$toast({
  189. icon: 'error', // 找到自己需要的图标
  190. message: '请选择一个选项',
  191. duration:"1000",
  192. onClose:function(){
  193. return false;
  194. }
  195. })
  196. }
  197. } else {
  198. if (this.result.length > 0) {
  199. list.push(this.result)
  200. } else {
  201. this.$toast({
  202. icon: 'error', // 找到自己需要的图标
  203. message: '请至少选择一个选项',
  204. duration:"1000",
  205. onClose:function(){
  206. return false;
  207. }
  208. })
  209. }
  210. }
  211. votePoll(this.id,list).then(response => {
  212. this.$toast({
  213. icon: 'success', // 找到自己需要的图标
  214. message: '保存成功',
  215. duration:"1000",
  216. onClose:function(){
  217. _this.$router.go(-1)
  218. }
  219. })
  220. });
  221. },
  222. },
  223. }
  224. </script>
  225. <style scoped>
  226. >>>.van-cell::after {
  227. border-bottom: none;
  228. }
  229. </style>