uni-rate.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <view class="rate-media">
  3. <view class="rate-media-body">
  4. <view class="rate-media-cell"
  5. v-for="(item,index) in max"
  6. :key="index"
  7. @click="clickStars(index)">
  8. <img :style="{'width': size + 'rpx','height':size+'rpx','margin':margin+'rpx'}" :src="valueSync>index?star_fill:star_empty"/>
  9. </view>
  10. </view>
  11. <view class="rate-media-info" v-if="is_score||is_attitude">
  12. <view v-if="is_score">{{is_infos_text()}}</view>
  13. <view v-if="is_attitude">{{rateScoreText}}</view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default{
  19. name:'rate',
  20. props:{
  21. star_fill: {
  22. //亮星星
  23. type: [String],
  24. default: 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/app/tmp/star.png'
  25. },
  26. star_empty: {
  27. //暗星星
  28. type: [String],
  29. default: 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/app/tmp/star1.png'
  30. },
  31. score:{
  32. type:Array,
  33. default:function(){
  34. return ['极差','差','一般','较好','非常好']
  35. }
  36. },
  37. is_score:{
  38. type: [Boolean, String],
  39. default: false
  40. },
  41. attitude:{
  42. type: Array,
  43. default:function(){
  44. return ['非常不满意,各方面都很差', '不满意,比较差', '一般,还需改善', '比较满意,仍可改善', '非常满意,无可挑剔']
  45. }
  46. },
  47. is_attitude:{
  48. type: [Boolean, String],
  49. default: false
  50. },
  51. size: {
  52. // 星星的大小
  53. type: [Number, String],
  54. default: 48
  55. },
  56. value: {
  57. // 当前评分
  58. type: [Number, String],
  59. default: 0
  60. },
  61. max: {
  62. // 最大评分
  63. type: [Number, String],
  64. default: 5
  65. },
  66. disabled: {
  67. // 是否可点击
  68. type: [Boolean, String],
  69. default: false
  70. },
  71. margin: {
  72. // 星星的间距
  73. type: [Number, String],
  74. default: '0 5'
  75. },
  76. },
  77. data() {
  78. return {
  79. valueSync: 0,
  80. rateScoreText:"",
  81. };
  82. },
  83. created() {
  84. console.log(this.is_score)
  85. this.valueSync = Number(this.value);
  86. },
  87. methods: {
  88. clickStars(i){
  89. if (this.disabled) {
  90. return;
  91. }
  92. this.rateScoreText = this.attitude[i]||''
  93. this.valueSync = i+1
  94. this.$emit("change", {
  95. value: this.valueSync,
  96. attitude: this.attitude[i]||'',
  97. score: this.score[i]||''
  98. });
  99. },
  100. is_infos_text(){
  101. return this.score[this.valueSync-1||0]||''
  102. },
  103. // is_score_text(index){
  104. // return this.score[index]
  105. // }
  106. }
  107. }
  108. </script>
  109. <style lang="scss">
  110. .rate-media{
  111. display: flex;
  112. line-height: 1;
  113. justify-content: space-between;
  114. .rate-media-body{
  115. display: flex;
  116. }
  117. .rate-media-info{
  118. display: flex;
  119. align-items: center;
  120. color: #999;
  121. font-size: 30rpx;
  122. view:nth-child(1){
  123. margin:0 20rpx;
  124. }
  125. }
  126. }
  127. </style>