移动端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 ">实名</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"/>
  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" />
  98. </van-cell>
  99. <van-row>
  100. <van-col span="15" :offset="2" style="margin-top: 7px;">
  101. <van-progress v-if="result1!=item" :percentage="voteNum>0?((item.num/voteNum)*100).toFixed(2):0" :show-pivot="false"/>
  102. <van-progress v-if="result1==item" :percentage="voteNum>0?(((item.num+1)/(voteNum+1))*100).toFixed(2):0" :show-pivot="false"/>
  103. </van-col>
  104. <van-col span="5" :offset="2" v-if="result1!=item.id">
  105. {{item.num}}票 {{voteNum>0?((item.num/voteNum)*100).toFixed(2):0}}%
  106. </van-col>
  107. <van-col span="5" :offset="2" v-if="result1==item.id">
  108. {{item.num+1}}票 {{voteNum>0?(((item.num+1)/(voteNum+1))*100).toFixed(2):0}}%
  109. </van-col>
  110. </van-row>
  111. </van-cell-group>
  112. </van-radio-group>
  113. <van-row style="text-align: center;margin-top: 40px" v-if="isPoll">
  114. <van-button color="#1D6FE9" style="border-radius: 6px;width: 90%;margin: 0 auto" @click="submit">提交</van-button>
  115. </van-row>
  116. <onlineHomeIndex></onlineHomeIndex>
  117. </div>
  118. </template>
  119. <script>
  120. import onlineHomeIndex from "../onlineHomeIndex";
  121. import {getPoll, listPollVote, votePoll} from "../../api/onlineHome/poll";
  122. export default {
  123. components: {
  124. onlineHomeIndex
  125. },
  126. name: "homePollDetail",
  127. data() {
  128. return {
  129. loading: false,
  130. form:{},
  131. pollOptions:[],
  132. id:this.$route.query.id,
  133. voteNum:0,
  134. result:[],
  135. result1:"",
  136. isPoll:true,
  137. };
  138. },
  139. created() {
  140. this.getInfo(this.id);
  141. listPollVote().then(res => {
  142. if(res.rows.length>0){
  143. res.rows.map(r => {
  144. if(r.pollId==this.id){
  145. this.isPoll=false
  146. }
  147. })
  148. }
  149. })
  150. },
  151. methods:{
  152. reset(){
  153. this.pollOptions = []
  154. },
  155. getInfo(val){
  156. this.reset();
  157. this.loading = true
  158. getPoll(val).then(response => {
  159. response.data.options.map(res => {
  160. this.voteNum += res.num
  161. this.pollOptions.push(res)
  162. })
  163. this.form = response.data;
  164. this.loading = true
  165. });
  166. },
  167. submit(){
  168. let list = []
  169. let _this = this
  170. if (this.form.type == 1) {
  171. if (this.result1 != "") {
  172. list.push(this.pollRadioValue)
  173. } else {
  174. this.$toast({
  175. icon: 'error', // 找到自己需要的图标
  176. message: '请选择一个选项',
  177. duration:"1000",
  178. onClose:function(){
  179. return false;
  180. }
  181. })
  182. }
  183. } else {
  184. if (this.result.length > 0) {
  185. list = this.result
  186. } else {
  187. this.$toast({
  188. icon: 'error', // 找到自己需要的图标
  189. message: '请至少选择一个选项',
  190. duration:"1000",
  191. onClose:function(){
  192. return false;
  193. }
  194. })
  195. }
  196. }
  197. votePoll(this.id,list).then(response => {
  198. this.$toast({
  199. icon: 'success', // 找到自己需要的图标
  200. message: '保存成功',
  201. duration:"1000",
  202. onClose:function(){
  203. _this.getInfo(this.id);
  204. }
  205. })
  206. });
  207. },
  208. },
  209. }
  210. </script>
  211. <style scoped>
  212. >>>.van-cell::after {
  213. border-bottom: none;
  214. }
  215. </style>