index.js 2.1 KB

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