Detail.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. exports.__esModule = true;
  4. exports.default = void 0;
  5. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  6. var _utils = require("../utils");
  7. var _system = require("../utils/validate/system");
  8. var _cell = _interopRequireDefault(require("../cell"));
  9. var _field = _interopRequireDefault(require("../field"));
  10. // Utils
  11. // Components
  12. var _createNamespace = (0, _utils.createNamespace)('address-edit-detail'),
  13. createComponent = _createNamespace[0],
  14. bem = _createNamespace[1],
  15. t = _createNamespace[2];
  16. var android = (0, _system.isAndroid)();
  17. var _default = createComponent({
  18. props: {
  19. value: String,
  20. errorMessage: String,
  21. focused: Boolean,
  22. detailRows: [Number, String],
  23. searchResult: Array,
  24. detailMaxlength: [Number, String],
  25. showSearchResult: Boolean
  26. },
  27. computed: {
  28. shouldShowSearchResult: function shouldShowSearchResult() {
  29. return this.focused && this.searchResult && this.showSearchResult;
  30. }
  31. },
  32. methods: {
  33. onSelect: function onSelect(express) {
  34. this.$emit('select-search', express);
  35. this.$emit('input', ((express.address || '') + " " + (express.name || '')).trim());
  36. },
  37. onFinish: function onFinish() {
  38. this.$refs.field.blur();
  39. },
  40. genFinish: function genFinish() {
  41. var h = this.$createElement;
  42. var show = this.value && this.focused && android;
  43. if (show) {
  44. return h("div", {
  45. "class": bem('finish'),
  46. "on": {
  47. "click": this.onFinish
  48. }
  49. }, [t('complete')]);
  50. }
  51. },
  52. genSearchResult: function genSearchResult() {
  53. var _this = this;
  54. var h = this.$createElement;
  55. var value = this.value,
  56. shouldShowSearchResult = this.shouldShowSearchResult,
  57. searchResult = this.searchResult;
  58. if (shouldShowSearchResult) {
  59. return searchResult.map(function (express) {
  60. return h(_cell.default, {
  61. "key": express.name + express.address,
  62. "attrs": {
  63. "clickable": true,
  64. "border": false,
  65. "icon": "location-o",
  66. "label": express.address
  67. },
  68. "class": bem('search-item'),
  69. "on": {
  70. "click": function click() {
  71. _this.onSelect(express);
  72. }
  73. },
  74. "scopedSlots": {
  75. title: function title() {
  76. if (express.name) {
  77. var text = express.name.replace(value, "<span class=" + bem('keyword') + ">" + value + "</span>");
  78. return h("div", {
  79. "domProps": {
  80. "innerHTML": text
  81. }
  82. });
  83. }
  84. }
  85. }
  86. });
  87. });
  88. }
  89. }
  90. },
  91. render: function render() {
  92. var h = arguments[0];
  93. return h(_cell.default, {
  94. "class": bem()
  95. }, [h(_field.default, {
  96. "attrs": {
  97. "autosize": true,
  98. "rows": this.detailRows,
  99. "clearable": !android,
  100. "type": "textarea",
  101. "value": this.value,
  102. "errorMessage": this.errorMessage,
  103. "border": !this.shouldShowSearchResult,
  104. "label": t('label'),
  105. "maxlength": this.detailMaxlength,
  106. "placeholder": t('placeholder')
  107. },
  108. "ref": "field",
  109. "scopedSlots": {
  110. icon: this.genFinish
  111. },
  112. "on": (0, _extends2.default)({}, this.$listeners)
  113. }), this.genSearchResult()]);
  114. }
  115. });
  116. exports.default = _default;