index.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { VantComponent } from '../common/component';
  2. VantComponent({
  3. classes: ['bar-class', 'price-class', 'button-class'],
  4. props: {
  5. tip: {
  6. type: null,
  7. observer: 'updateTip',
  8. },
  9. tipIcon: String,
  10. type: Number,
  11. price: {
  12. type: null,
  13. observer: 'updatePrice',
  14. },
  15. label: String,
  16. loading: Boolean,
  17. disabled: Boolean,
  18. buttonText: String,
  19. currency: {
  20. type: String,
  21. value: '¥',
  22. },
  23. buttonType: {
  24. type: String,
  25. value: 'danger',
  26. },
  27. decimalLength: {
  28. type: Number,
  29. value: 2,
  30. observer: 'updatePrice',
  31. },
  32. suffixLabel: String,
  33. safeAreaInsetBottom: {
  34. type: Boolean,
  35. value: true,
  36. },
  37. },
  38. methods: {
  39. updatePrice() {
  40. const { price, decimalLength } = this.data;
  41. const priceStrArr = typeof price === 'number' &&
  42. (price / 100).toFixed(decimalLength).split('.');
  43. this.setData({
  44. hasPrice: typeof price === 'number',
  45. integerStr: priceStrArr && priceStrArr[0],
  46. decimalStr: decimalLength && priceStrArr ? `.${priceStrArr[1]}` : '',
  47. });
  48. },
  49. updateTip() {
  50. this.setData({ hasTip: typeof this.data.tip === 'string' });
  51. },
  52. onSubmit(event) {
  53. this.$emit('submit', event.detail);
  54. },
  55. },
  56. });