vote-card.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <template>
  2. <view class="vote-card" @click="$emit('on-click',vote)">
  3. <view class="vote-card-head flex">
  4. <view class="left flex flex-center">
  5. <view class="flex-shrink">
  6. <tm-tags v-if="vote.spec.type==='single'" color="light-blue" :shadow="0" rounded size="s"
  7. model="fill">单选</tm-tags>
  8. <tm-tags v-else-if="vote.spec.type==='multiple'" color="light-blue" :shadow="0" rounded size="s"
  9. model="fill">多选</tm-tags>
  10. <tm-tags v-else-if="vote.spec.type==='pk'" color="light-blue" :shadow="0" rounded size="s"
  11. model="fill">双选PK</tm-tags>
  12. </view>
  13. <view class="title text-overflow">
  14. {{ vote.spec.title }}
  15. </view>
  16. </view>
  17. <view class="flex-shrink right flex flex-end">
  18. <tm-tags v-if="vote.spec.hasEnded" color="red" rounded :shadow="0" size="s" model="text">已结束</tm-tags>
  19. <tm-tags v-else color="green" rounded size="s" :shadow="0" model="text">进行中</tm-tags>
  20. </view>
  21. </view>
  22. <view class="vote-card-body">
  23. <view v-if="vote.spec.remark" class="remark text-overflow-2 text-size-s">
  24. {{vote.spec.remark}}
  25. </view>
  26. <template v-if="showOptions">
  27. <!-- 单选 -->
  28. <view v-if="vote.spec.type==='single'" class="single">
  29. <tm-groupradio @change="onOptionRadioChange">
  30. <tm-radio v-for="(option,optionIndex) in vote.spec.options" :key="optionIndex" dense
  31. :disabled="vote.spec.disabled" v-model="option.checked" :extendData="option">
  32. <template v-slot:default="{checkData}">
  33. <tm-button :shadow="0" :theme="checkData.checked?'light-blue':'grey-lighten-3'"
  34. :plan="false" :block="true" class="w-full" size="m" :height="72">
  35. <view class="flex flex-between w-full">
  36. <text class="text-align-left text-overflow"> {{ checkData.extendData.title }}
  37. </text>
  38. <text class="flex-shrink"> {{checkData.extendData.percent }}% </text>
  39. </view>
  40. </tm-button>
  41. </template>
  42. </tm-radio>
  43. </tm-groupradio>
  44. </view>
  45. <!-- 多选 -->
  46. <view v-else-if="vote.spec.type==='multiple'" class="multiple">
  47. <tm-groupcheckbox @change="onOptionCheckboxChange">
  48. <tm-checkbox v-for="(option,optionIndex) in vote.spec.options" :key="optionIndex" dense
  49. :disabled="vote.spec.disabled" v-model="option.checked" :extendData="option">
  50. <template v-slot:default="{checkData}">
  51. <tm-button :shadow="0" :theme="checkData.checked?'light-blue':'grey-lighten-3'"
  52. :plan="false" :block="true" class="w-full" size="m" :height="72">
  53. <view class="flex flex-between w-full">
  54. <text class="text-align-left text-overflow"> {{ checkData.extendData.title }}
  55. </text>
  56. <text class="flex-shrink"> {{checkData.extendData.percent }}% </text>
  57. </view>
  58. </tm-button>
  59. </template>
  60. </tm-checkbox>
  61. </tm-groupcheckbox>
  62. </view>
  63. <!-- PK -->
  64. <view v-else-if="vote.spec.type==='pk'" class="pk">
  65. <tm-groupradio @change="onOptionPkChange">
  66. <tm-radio v-for="(option,optionIndex) in vote.spec.options" :key="optionIndex" dense
  67. :disabled="vote.spec.disabled" v-model="option.checked" :extendData="option"
  68. class="radio-item" :class="[optionIndex==0?'radio-left':'radio-right']"
  69. :style="{width:option.percent + '%'}">
  70. <template v-slot:default="{checkData}">
  71. <view class="option-item"
  72. :class="[optionIndex==0?'option-item-left':'option-item-right']">
  73. {{checkData.extendData.percent }}%
  74. </view>
  75. </template>
  76. </tm-radio>
  77. </tm-groupradio>
  78. <view class="option-foot w-full flex flex-between">
  79. <view v-for="(option,optionIndex) in vote.spec.options" :key="optionIndex">
  80. <view v-if="optionIndex==0" class="left flex-1 flex-shrink text-overflow">
  81. {{option.title}}
  82. </view>
  83. <view v-else class="right flex-1 flex-shrink text-overflow text-align-right">
  84. {{option.title}}
  85. </view>
  86. </view>
  87. </view>
  88. </view>
  89. </template>
  90. </view>
  91. <view class="vote-card-foot flex flex-between">
  92. <view class="left flex">
  93. <tm-tags color="grey-darken-2" rounded size="s"
  94. model="text">{{ {d: vote.spec.endDate, f: 'yyyy-MM-dd HH:mm'} | formatTime }} 结束</tm-tags>
  95. </view>
  96. <view class="right flex flex-end">
  97. <tm-tags color="grey-darken-2" rounded size="s" model="text">{{ vote.stats.voteCount }} 人已参与</tm-tags>
  98. <tm-tags v-if="vote.spec.isVoted" color="blue" rounded size="s" model="text">已投票</tm-tags>
  99. </view>
  100. </view>
  101. </view>
  102. </template>
  103. <script>
  104. import tmGroupradio from '@/tm-vuetify/components/tm-groupradio/tm-groupradio.vue';
  105. import tmRadio from '@/tm-vuetify/components/tm-radio/tm-radio.vue';
  106. import tmGroupcheckbox from '@/tm-vuetify/components/tm-groupcheckbox/tm-groupcheckbox.vue';
  107. import tmCheckbox from '@/tm-vuetify/components/tm-checkbox/tm-checkbox.vue';
  108. import tmButton from '@/tm-vuetify/components/tm-button/tm-button.vue';
  109. import tmTags from '@/tm-vuetify/components/tm-tags/tm-tags.vue';
  110. export default {
  111. name: "VoteCard",
  112. options: {
  113. virtualHost: true,
  114. styleIsolation: 'shared'
  115. },
  116. components: {
  117. tmGroupradio,
  118. tmRadio,
  119. tmGroupcheckbox,
  120. tmCheckbox,
  121. tmButton,
  122. tmTags
  123. },
  124. props: {
  125. vote: {
  126. type: Object,
  127. default: () => ({})
  128. },
  129. index: {
  130. type: Number,
  131. default: 0
  132. },
  133. showOptions: {
  134. type: Boolean,
  135. default: false
  136. }
  137. },
  138. methods: {
  139. onOptionRadioChange(e) {
  140. console.log("onOptionRadioChange", e)
  141. },
  142. onOptionCheckboxChange(e) {
  143. console.log("onOptionCheckboxChange", e)
  144. },
  145. onOptionPkChange(e) {
  146. console.log("onOptionPkChange", e)
  147. },
  148. }
  149. }
  150. </script>
  151. <style lang="scss" scoped>
  152. .w-full {
  153. width: 100%;
  154. }
  155. .wp-50 {
  156. width: 50%;
  157. }
  158. .vote-card {
  159. display: flex;
  160. flex-direction: column;
  161. box-sizing: border-box;
  162. margin: 0 24rpx;
  163. padding: 24rpx;
  164. border-radius: 12rpx;
  165. background-color: #ffff;
  166. box-shadow: 0rpx 2rpx 24rpx rgba(0, 0, 0, 0.075);
  167. overflow: hidden;
  168. margin-bottom: 24rpx;
  169. // border: 1px solid #eee;
  170. }
  171. .vote-card-head {
  172. margin-bottom: 12rpx;
  173. display: flex;
  174. align-items: center;
  175. justify-content: space-between;
  176. .left {
  177. .title {
  178. font-size: 28rpx;
  179. font-weight: bold;
  180. }
  181. }
  182. }
  183. .vote-card-body {
  184. .remark {
  185. box-sizing: border-box;
  186. padding: 12rpx 6rpx;
  187. padding-top: 0;
  188. color: rgba(0, 0, 0, 0.75);
  189. }
  190. }
  191. .vote-card-foot {
  192. box-sizing: border-box;
  193. padding-top: 6px;
  194. margin-top: 6px;
  195. border-top: 2rpx solid #eee;
  196. .left{
  197. }
  198. }
  199. .single {
  200. ::v-deep {
  201. .tm-groupradio {
  202. width: 100%;
  203. box-sizing: border-box;
  204. display: flex;
  205. flex-wrap: wrap;
  206. gap: 12rpx 0;
  207. }
  208. .tm-checkbox {
  209. box-sizing: border-box;
  210. display: block;
  211. padding: 0 12rpx;
  212. width: 50%;
  213. }
  214. .tm-button-label {
  215. width: 100%;
  216. }
  217. }
  218. }
  219. .multiple {
  220. ::v-deep {
  221. .tm-groupcheckbox {
  222. width: 100%;
  223. box-sizing: border-box;
  224. display: flex;
  225. flex-wrap: wrap;
  226. gap: 12rpx 0;
  227. }
  228. .tm-checkbox {
  229. box-sizing: border-box;
  230. display: block;
  231. padding: 0 12rpx;
  232. width: 50%;
  233. }
  234. .tm-button-label {
  235. width: 100%;
  236. }
  237. }
  238. }
  239. .pk {
  240. box-sizing: border-box;
  241. width: 100%;
  242. padding: 0 12rpx;
  243. ::v-deep {
  244. .tm-groupradio {
  245. display: flex;
  246. width: 100%;
  247. }
  248. .tm-checkbox {
  249. flex-grow: 1;
  250. min-width: 30% !important;
  251. max-width: 70% !important;
  252. }
  253. .radio-item {
  254. position: relative;
  255. .selected {
  256. z-index: 10;
  257. }
  258. }
  259. .radio-left {}
  260. .radio-right {}
  261. .option-item {
  262. width: 100%;
  263. padding: 12rpx 24rpx;
  264. border-radius: 12rpx;
  265. }
  266. .option-item-left {
  267. background: linear-gradient(90deg, #3B82F6, #60A5FA);
  268. color: white;
  269. clip-path: polygon(0 0, calc(100% - 40rpx) 0, 100% 100%, 0 100%);
  270. }
  271. .option-item-right {
  272. background: linear-gradient(90deg, #F87171, #EF4444);
  273. color: white;
  274. clip-path: polygon(0 0, 100% 0, 100% 100%, 40rpx 100%);
  275. text-align: right;
  276. }
  277. .option-foot {
  278. width: 100%;
  279. margin-top: 6rpx;
  280. font-size: 24rpx;
  281. color: #666;
  282. .left {
  283. box-sizing: border-box;
  284. padding-right: 24rpx;
  285. }
  286. .right {
  287. box-sizing: border-box;
  288. padding-left: 24rpx;
  289. }
  290. }
  291. }
  292. }
  293. </style>