wk-field-attention.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <view class="wk-field wk-field-attention">
  3. <view v-if="_label" class="wk-field__label">
  4. <view v-if="field.isNull === 1" class="line" />
  5. {{ _label }}
  6. </view>
  7. <view class="wk-field__body" @click.stop>
  8. <view
  9. v-for="(item, index) in list"
  10. :key="index"
  11. :class="{active: item}"
  12. class="ft ft-focus-on star-icon"
  13. @click="handleToChoose(index)" />
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. import mixins from './mixins'
  19. export default {
  20. name: 'WkFieldAttention',
  21. mixins: [mixins],
  22. data() {
  23. return {
  24. list: []
  25. }
  26. },
  27. watch: {
  28. value: {
  29. handler() {
  30. // 主要是为了处理 v-for 循环数字报错问题
  31. this.list = Array(5).fill(false)
  32. const num = Number(this.value) || 0
  33. if (num > 0) {
  34. const checked = Array(num).fill(true)
  35. this.list.splice(0, num, ...checked)
  36. }
  37. },
  38. deep: true,
  39. immediate: true
  40. }
  41. },
  42. methods: {
  43. handleToChoose(index) {
  44. this.emitChangeEvt(index + 1)
  45. }
  46. }
  47. }
  48. </script>
  49. <style scoped lang="scss">
  50. @import './wkField.scss';
  51. .wk-field {
  52. .wk-field__body {
  53. min-height: unset;
  54. border: 0 none;
  55. padding: 0;
  56. .star-icon {
  57. font-size: 42rpx;
  58. color: #D9D9D9;
  59. margin: 0 10rpx;
  60. &.active {
  61. color: #FAC23D;
  62. }
  63. }
  64. }
  65. }
  66. </style>