topic.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <scroll-view class="scroll-wrapper" :style="{top: top + 'px'}" scroll-y refresher-enabled refresher-default-style="white"
  3. @refresherrefresh="pullRefresh" :refresher-triggered="refreshing" @scrolltolower="loadMore">
  4. <view style="padding: 0 14px">
  5. <view v-for="(item) in tableData" :key="item.id" class="cell marginB12">
  6. <view class="flex-align">
  7. <image :src="item.avatar" style="width: 88rpx;height: 88rpx;border-radius: 44rpx;" />
  8. <view class="font2 color-white flex1 marginL10">{{item.nickname}}</view>
  9. </view>
  10. <view class="paddingY12 color-white bold color-white font6">
  11. {{item.question}}
  12. </view>
  13. <view style="height: 20px; border-radius: 10px; overflow: hidden;" class="flex-align relative">
  14. <view v-for="(aItem, aIndex) in item.chooseList" :key="aItem.answer"
  15. :style="{background: aItem.color, width: aItem.width, height: '100%'}"
  16. :class="[aIndex != 0 && aItem.width != '0%' && 'marginL4']"></view>
  17. </view>
  18. <view class="paddingY12 flex-align-center">
  19. <view v-for="(aItem, aIndex) in item.chooseList" :key="aItem.answer" class="btn flex-align-center"
  20. @click="join(item, aItem.answer)">
  21. <image v-if="item.myAnswer === aItem.answer" :src="resource[`${aItem.btn}_active`]" class="image" />
  22. <image v-else :src="resource[aItem.btn]" class="image" />
  23. <div class="color-white font6 relative" :style="{opacity: item.myAnswer === aItem.answer ? 1 : 0.4}">{{aItem.answer}}</div>
  24. </view>
  25. </view>
  26. <view class="flex-align">
  27. <view class="font2 color-white" style="opacity: 0.5">{{item.publishTime}}</view>
  28. <view class="paddingL10 font2 color-white">{{item.participatedQuantity}}投票</view>
  29. </view>
  30. </view>
  31. </view>
  32. <empty v-if="isEmpty" :top="180" />
  33. <image :src="resource.weal_topic_publish" class="publish_btn" @click="showPublish" />
  34. </scroll-view>
  35. </template>
  36. <script>
  37. import pageMixin from './../../mixin/page'
  38. import resource from '@/utils/resource'
  39. import empty from '../../components/empty.vue'
  40. export default {
  41. components: { empty },
  42. mixins: [pageMixin],
  43. props: {
  44. statusBarHeight: Number
  45. },
  46. data() {
  47. return {
  48. resource,
  49. refreshing: false,
  50. requesting: false,
  51. isRefreshClear: false
  52. }
  53. },
  54. computed: {
  55. top() {
  56. return this.statusBarHeight + uni.upx2px(72) + 45
  57. },
  58. width() {
  59. return this.$store.state.systemInfo.screenWidth - 28 - 30
  60. }
  61. },
  62. mounted() {
  63. this.refresh(true)
  64. },
  65. methods: {
  66. search() {
  67. this.refresh(true)
  68. },
  69. pullRefresh() {
  70. this.refreshing = true
  71. this.refresh()
  72. },
  73. async loadData(loading = false) {
  74. this.requesting = true
  75. const res = await this.$service.weal.topics(this.pageNum, this.pageSize, loading)
  76. if (res && res.length > 0) {
  77. res.forEach((item) => {
  78. const colors = item.answerSet.split(',').length === 3 ? ['#6F62E3', '#E44E58', '#4CA1BB'] : ['#6F62E3', '#4CA1BB']
  79. const btns = item.answerSet.split(',').length === 3 ? ['weal_topic_btn_1', 'weal_topic_btn_2', 'weal_topic_btn_3'] : ['weal_topic_btn_1', 'weal_topic_btn_3']
  80. let defaulWidth = (100 / (item.answerSet.split(',').length)).toFixed(2) + '%'
  81. let map = {}
  82. let total = 0
  83. item.answerQuantityList.forEach((item, index) => {
  84. map[item.answer] = item
  85. total += item.quantity
  86. })
  87. for (var x in map) {
  88. map[x].width = total == 0 ? defaulWidth : ((map[x].quantity / total * 100).toFixed(2) + '%')
  89. }
  90. item.chooseList = item.answerSet.split(',').map((item, index) => {
  91. return {
  92. answer: item,
  93. color: colors[index],
  94. btn: btns[index],
  95. width: total == 0 ? defaulWidth : (!!map[item] ? map[item].width : '0%')
  96. }
  97. })
  98. })
  99. }
  100. setTimeout(() => {
  101. this.refreshing = false
  102. this.requesting = false
  103. }, 1000)
  104. return res
  105. },
  106. async join(item, answer) {
  107. if (!this.$common.checkLogin()) return;
  108. if (item.myAnswer) return
  109. const res = await this.$service.weal.topicJoin(item.id, answer)
  110. if (res) {
  111. this.refresh()
  112. }
  113. },
  114. showPublish() {
  115. this.$router.pushCheck('topic_create')
  116. }
  117. }
  118. }
  119. </script>
  120. <style lang="scss" scoped>
  121. .scroll-wrapper {
  122. position: fixed;
  123. left: 0;
  124. right: 0;
  125. bottom: 0;
  126. }
  127. .cell {
  128. padding: 15px;
  129. background: rgba(0, 0, 0, 0.6);
  130. box-shadow: 0px 0px 4px 2px rgba(147, 67, 255, 0.3);
  131. border-radius: 10px;
  132. border: 1px solid rgba(174, 231, 255, 0.5);
  133. .btn {
  134. width: 184rpx;
  135. height: 60rpx;
  136. position: relative;
  137. .image {
  138. position: absolute;
  139. left: 0;
  140. top: 0;
  141. width: 184rpx;
  142. height: 60rpx;
  143. }
  144. }
  145. .bar-mask {
  146. background: rgb(0, 0, 0);
  147. height: 100%;
  148. position: absolute;
  149. width: 16px;
  150. top: 0;
  151. }
  152. }
  153. .publish_btn {
  154. position: fixed;
  155. right: 20rpx;
  156. bottom: 100rpx;
  157. width: 94rpx;
  158. height: 100rpx;
  159. }
  160. </style>