index.js 1.5 KB

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