合伙人运营小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

search.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  2. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  3. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  4. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  5. return c > 3 && r && Object.defineProperty(target, key, r), r;
  6. };
  7. import { SuperComponent, wxComponent } from '../common/src/index';
  8. import config from '../common/config';
  9. import props from './props';
  10. import { getCharacterLength } from '../common/utils';
  11. const { prefix } = config;
  12. const name = `${prefix}-search`;
  13. let Search = class Search extends SuperComponent {
  14. constructor() {
  15. super(...arguments);
  16. this.externalClasses = [
  17. `${prefix}-class`,
  18. `${prefix}-class-input-container`,
  19. `${prefix}-class-input`,
  20. `${prefix}-class-action`,
  21. `${prefix}-class-left`,
  22. `${prefix}-class-clear`,
  23. ];
  24. this.options = {
  25. multipleSlots: true,
  26. };
  27. this.properties = props;
  28. this.observers = {
  29. resultList(val) {
  30. const { isSelected } = this.data;
  31. if (val.length) {
  32. if (isSelected) {
  33. this.setData({
  34. isShowResultList: false,
  35. isSelected: false,
  36. });
  37. }
  38. else {
  39. this.setData({
  40. isShowResultList: true,
  41. });
  42. }
  43. }
  44. else {
  45. this.setData({
  46. isShowResultList: false,
  47. });
  48. }
  49. },
  50. };
  51. this.data = {
  52. classPrefix: name,
  53. prefix,
  54. isShowResultList: false,
  55. isSelected: false,
  56. };
  57. }
  58. onInput(e) {
  59. let { value } = e.detail;
  60. const { maxcharacter } = this.properties;
  61. if (maxcharacter && typeof maxcharacter === 'number' && maxcharacter > 0) {
  62. const { characters } = getCharacterLength('maxcharacter', value, maxcharacter);
  63. value = characters;
  64. }
  65. this.setData({
  66. value,
  67. });
  68. this.triggerEvent('change', { value });
  69. }
  70. onFocus(e) {
  71. const { value } = e.detail;
  72. this.triggerEvent('focus', { value });
  73. }
  74. onBlur(e) {
  75. const { value } = e.detail;
  76. this.triggerEvent('blur', { value });
  77. }
  78. handleClear() {
  79. this.setData({ value: '' });
  80. this.triggerEvent('clear', { value: '' });
  81. this.triggerEvent('change', { value: '' });
  82. }
  83. onConfirm(e) {
  84. const { value } = e.detail;
  85. this.triggerEvent('submit', { value });
  86. }
  87. onActionClick() {
  88. this.triggerEvent('action-click');
  89. }
  90. onSelectResultItem(e) {
  91. const { index } = e.currentTarget.dataset;
  92. const item = this.properties.resultList[index];
  93. this.setData({
  94. value: item,
  95. isSelected: true,
  96. });
  97. this.triggerEvent('change', { value: item });
  98. this.triggerEvent('selectresult', { index, item });
  99. }
  100. };
  101. Search = __decorate([
  102. wxComponent()
  103. ], Search);
  104. export default Search;