index.js 1.7 KB

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