Detail.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import { use, isAndroid } from '../utils';
  3. import Cell from '../cell';
  4. import Field from '../field';
  5. var _use = use('address-edit-detail'),
  6. sfc = _use[0],
  7. bem = _use[1],
  8. t = _use[2];
  9. var android = isAndroid();
  10. export default sfc({
  11. props: {
  12. value: String,
  13. error: Boolean,
  14. focused: Boolean,
  15. detailRows: Number,
  16. searchResult: Array,
  17. showSearchResult: Boolean
  18. },
  19. methods: {
  20. onSelect: function onSelect(express) {
  21. this.$emit('select-search', express);
  22. this.$emit('input', ((express.address || '') + " " + (express.name || '')).trim());
  23. },
  24. onFinish: function onFinish() {
  25. this.$refs.field.blur();
  26. },
  27. renderFinish: function renderFinish() {
  28. var h = this.$createElement;
  29. var show = this.value && this.focused && android;
  30. if (show) {
  31. return h("div", {
  32. "class": bem('finish'),
  33. "on": {
  34. "click": this.onFinish
  35. }
  36. }, [t('complete')]);
  37. }
  38. },
  39. renderSearchResult: function renderSearchResult() {
  40. var _this = this;
  41. var h = this.$createElement;
  42. var searchResult = this.searchResult;
  43. var show = this.focused && searchResult && this.showSearchResult;
  44. if (show) {
  45. return searchResult.map(function (express) {
  46. return h(Cell, {
  47. "key": express.name + express.address,
  48. "attrs": {
  49. "title": express.name,
  50. "label": express.address,
  51. "icon": "location-o",
  52. "clickable": true
  53. },
  54. "on": {
  55. "click": function click() {
  56. _this.onSelect(express);
  57. }
  58. }
  59. });
  60. });
  61. }
  62. }
  63. },
  64. render: function render(h) {
  65. return h(Cell, {
  66. "class": bem()
  67. }, [h(Field, {
  68. "attrs": {
  69. "autosize": true,
  70. "rows": this.detailRows,
  71. "clearable": !android,
  72. "type": "textarea",
  73. "maxlength": "200",
  74. "value": this.value,
  75. "error": this.error,
  76. "label": t('label'),
  77. "placeholder": t('placeholder')
  78. },
  79. "ref": "field",
  80. "scopedSlots": {
  81. icon: this.renderFinish
  82. },
  83. "on": _extends({}, this.$listeners)
  84. }), this.renderSearchResult()]);
  85. }
  86. });