index.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import _mergeJSXProps from "@vue/babel-helper-vue-jsx-merge-props";
  2. import { use } from '../utils';
  3. import { inherit } from '../utils/functional';
  4. import Cell from '../cell'; // Types
  5. var _use = use('coupon-cell'),
  6. sfc = _use[0],
  7. bem = _use[1],
  8. t = _use[2];
  9. function formatValue(props) {
  10. var coupons = props.coupons,
  11. chosenCoupon = props.chosenCoupon,
  12. currency = props.currency;
  13. var coupon = coupons[chosenCoupon];
  14. if (coupon) {
  15. var value = coupon.denominations || coupon.value;
  16. return "-" + currency + (value / 100).toFixed(2);
  17. }
  18. return coupons.length === 0 ? t('tips') : t('count', coupons.length);
  19. }
  20. function CouponCell(h, props, slots, ctx) {
  21. var valueClass = props.coupons[props.chosenCoupon] ? 'van-coupon-cell--selected' : '';
  22. var value = formatValue(props);
  23. return h(Cell, _mergeJSXProps([{
  24. "class": bem(),
  25. "attrs": {
  26. "value": value,
  27. "title": props.title || t('title'),
  28. "border": props.border,
  29. "isLink": props.editable,
  30. "valueClass": valueClass
  31. }
  32. }, inherit(ctx, true)]));
  33. }
  34. CouponCell.model = {
  35. prop: 'chosenCoupon'
  36. };
  37. CouponCell.props = {
  38. title: String,
  39. coupons: Array,
  40. currency: {
  41. type: String,
  42. "default": '¥'
  43. },
  44. border: {
  45. type: Boolean,
  46. "default": true
  47. },
  48. editable: {
  49. type: Boolean,
  50. "default": true
  51. },
  52. chosenCoupon: {
  53. type: Number,
  54. "default": -1
  55. }
  56. };
  57. export default sfc(CouponCell);