index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. "use strict";
  2. var _component = require("../common/component");
  3. var _version = require("../common/version");
  4. var _my = require("../../__antmove/api/index.js")(my);
  5. var wx = _my;
  6. (0, _component.VantComponent)({
  7. field: true,
  8. classes: ["icon-class"],
  9. props: {
  10. value: {
  11. type: Number,
  12. observer: function observer(value) {
  13. if (value !== this.data.innerValue) {
  14. this.setData({
  15. innerValue: value
  16. });
  17. }
  18. }
  19. },
  20. readonly: Boolean,
  21. disabled: Boolean,
  22. allowHalf: Boolean,
  23. size: null,
  24. icon: {
  25. type: String,
  26. value: "star"
  27. },
  28. voidIcon: {
  29. type: String,
  30. value: "star-o"
  31. },
  32. color: {
  33. type: String,
  34. value: "#ffd21e"
  35. },
  36. voidColor: {
  37. type: String,
  38. value: "#c7c7c7"
  39. },
  40. disabledColor: {
  41. type: String,
  42. value: "#bdbdbd"
  43. },
  44. count: {
  45. type: Number,
  46. value: 5,
  47. observer: function observer(value) {
  48. this.setData({
  49. innerCountArray: Array.from({
  50. length: value
  51. })
  52. });
  53. }
  54. },
  55. gutter: null,
  56. touchable: {
  57. type: Boolean,
  58. value: true
  59. }
  60. },
  61. data: {
  62. innerValue: 0,
  63. innerCountArray: Array.from({
  64. length: 5
  65. })
  66. },
  67. methods: {
  68. onSelect: function onSelect(event) {
  69. var _this = this;
  70. var data = this.data;
  71. var score = event.detail.target.dataset.score;
  72. if (!data.disabled && !data.readonly) {
  73. this.setData({
  74. innerValue: score + 1
  75. }); // if (canIUseModel()) {
  76. // this.setData({ value: score + 1 });
  77. // }
  78. wx.nextTick(function () {
  79. _this.$emit("input", score + 1);
  80. _this.$emit("change", score + 1);
  81. });
  82. }
  83. },
  84. onTouchMove: function onTouchMove(event) {
  85. var _this2 = this;
  86. var touchable = this.data.touchable;
  87. if (!touchable) return;
  88. var clientX = event.touches[0].clientX;
  89. this.getRect(".van-rate__icon", true).then(function (list) {
  90. var target = list.sort(function (item) {
  91. return item.right - item.left;
  92. }).find(function (item) {
  93. return clientX >= item.left && clientX <= item.right;
  94. });
  95. if (target != null) {
  96. _this2.onSelect(Object.assign(Object.assign({}, event), {
  97. currentTarget: target
  98. }));
  99. }
  100. });
  101. }
  102. }
  103. });