移动端
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

homePollDetail.vue 7.5 KiB

3 anni fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. </div>
  117. </template>
  118. <script>
  119. import onlineHomeIndex from "../onlineHomeIndex";
  120. import {getPoll, listPollVote, votePoll} from "../../api/onlineHome/poll";
  121. export default {
  122. components: {
  123. onlineHomeIndex
  124. },
  125. name: "homePollDetail",
  126. data() {
  127. return {
  128. loading: false,
  129. form:{},
  130. pollOptions:[],
  131. id:this.$route.query.id,
  132. voteNum:0,
  133. result:[],
  134. result1:"",
  135. isPoll:true,
  136. };
  137. },
  138. created() {
  139. this.getInfo(this.id);
  140. listPollVote().then(res => {
  141. if(res.rows.length>0){
  142. res.rows.map(r => {
  143. if(r.pollId==this.id){
  144. this.isPoll=false
  145. }
  146. })
  147. }
  148. })
  149. },
  150. methods:{
  151. reset(){
  152. this.pollOptions = []
  153. },
  154. getInfo(val){
  155. this.reset();
  156. this.loading = true
  157. getPoll(val).then(response => {
  158. response.data.options.map(res => {
  159. this.voteNum += res.num
  160. this.pollOptions.push(res)
  161. })
  162. this.form = response.data;
  163. this.loading = true
  164. });
  165. },
  166. submit(){
  167. let list = []
  168. let _this = this
  169. if (this.form.type == 1) {
  170. if (this.result1 != "") {
  171. list.push(this.pollRadioValue)
  172. } else {
  173. this.$toast({
  174. icon: 'error', // 找到自己需要的图标
  175. message: '请选择一个选项',
  176. duration:"1000",
  177. onClose:function(){
  178. return false;
  179. }
  180. })
  181. }
  182. } else {
  183. if (this.result.length > 0) {
  184. list = this.result
  185. } else {
  186. this.$toast({
  187. icon: 'error', // 找到自己需要的图标
  188. message: '请至少选择一个选项',
  189. duration:"1000",
  190. onClose:function(){
  191. return false;
  192. }
  193. })
  194. }
  195. }
  196. votePoll(this.id,list).then(response => {
  197. this.$toast({
  198. icon: 'success', // 找到自己需要的图标
  199. message: '保存成功',
  200. duration:"1000",
  201. onClose:function(){
  202. _this.getInfo(this.id);
  203. }
  204. })
  205. });
  206. },
  207. },
  208. }
  209. </script>
  210. <style scoped>
  211. >>>.van-cell::after {
  212. border-bottom: none;
  213. }
  214. </style>