index.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. Component({
  2. /**
  3. * 组件的属性列表
  4. */
  5. externalClasses: ['l-deleted-class', 'l-unit-class', 'l-value-class', 'l-class'],
  6. properties: {
  7. unit: {
  8. type: String,
  9. value: '¥'
  10. },
  11. size: {
  12. type: String,
  13. value: '28'
  14. },
  15. color: {
  16. type: String,
  17. value: '#3963BC'
  18. },
  19. bold: {
  20. type: String,
  21. value: '500'
  22. },
  23. unitColor: String,
  24. unitSize: String,
  25. unitBold: String,
  26. value: {
  27. type: String,
  28. value: '0.00'
  29. },
  30. mode: {
  31. type: String,
  32. value: 'number'
  33. },
  34. valueColor: String,
  35. valueSize: String,
  36. valueBold: String,
  37. deleted: Boolean,
  38. delColor: String,
  39. reserveDigit: {
  40. type: Number,
  41. value: 2
  42. },
  43. autofix: Boolean
  44. },
  45. /**
  46. * 组件的初始数据
  47. */
  48. data: {
  49. },
  50. observers: {
  51. 'value': function () {
  52. this.reserveNumber();
  53. }
  54. },
  55. /**
  56. * 组件的方法列表
  57. */
  58. methods: {
  59. reserveNumber() {
  60. const countToNumber = Number(this.data.value);
  61. const isText = isNaN(Number(countToNumber)) || (this.data.mode === 'text');
  62. if (!isText && this.data.autofix) {
  63. const result = countToNumber.toFixed(this.data.reserveDigit);
  64. this.setData({
  65. result
  66. });
  67. } else {
  68. this.setData({
  69. result: this.data.value
  70. });
  71. }
  72. }
  73. }
  74. });