rate.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // components/rate/rate.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. num: {
  8. type: Number,
  9. value: 2
  10. },
  11. w: {
  12. type: Number,
  13. value: 24
  14. },
  15. h: {
  16. type: Number,
  17. value: 24
  18. },
  19. disabled: {
  20. type: Boolean,
  21. value: false
  22. }
  23. },
  24. /**
  25. * 组件的初始数据
  26. */
  27. data: {
  28. select: 2,
  29. open: 'https://yuesuo.yueguanjia.com/MiniProgram/images/lightstar.png',
  30. off: 'https://yuesuo.yueguanjia.com/MiniProgram/images/greystar.png'
  31. },
  32. attached: function() {
  33. // 在组件实例进入页面节点树时执行
  34. this.setData({
  35. select: this.data.num
  36. })
  37. },
  38. /**
  39. * 组件的方法列表
  40. */
  41. methods: {
  42. // 点击评分
  43. clickRate(event) {
  44. if (this.data.disabled) return
  45. let numb = event.currentTarget.dataset.num + 1
  46. this.setData({
  47. select: numb
  48. })
  49. let myEventDetail = { number: numb}
  50. let myEventOption = {}
  51. this.triggerEvent('isSel', myEventDetail, myEventOption)
  52. }
  53. }
  54. })