海鲜小程序

index.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 =
  42. typeof price === 'number' &&
  43. (price / 100).toFixed(decimalLength).split('.');
  44. this.setData({
  45. hasPrice: typeof price === 'number',
  46. integerStr: priceStrArr && priceStrArr[0],
  47. decimalStr: decimalLength && priceStrArr ? `.${priceStrArr[1]}` : '',
  48. });
  49. },
  50. updateTip() {
  51. this.setData({ hasTip: typeof this.data.tip === 'string' });
  52. },
  53. onSubmit(event) {
  54. this.$emit('submit', event.detail);
  55. },
  56. },
  57. });