| | |
| | | import { SuperComponent, wxComponent } from '../common/src/index'; |
| | | import config from '../common/config'; |
| | | import props from './props'; |
| | | import { getCharacterLength } from '../common/utils'; |
| | | const { prefix } = config; |
| | | const name = `${prefix}-search`; |
| | | let Search = class Search extends SuperComponent { |
| | |
| | | }; |
| | | this.properties = props; |
| | | this.observers = { |
| | | focus(nextValue) { |
| | | this.setData({ 'localValue.focus': nextValue }); |
| | | resultList(val) { |
| | | const { isSelected } = this.data; |
| | | if (val.length) { |
| | | if (isSelected) { |
| | | this.setData({ |
| | | isShowResultList: false, |
| | | isSelected: false, |
| | | }); |
| | | } |
| | | else { |
| | | this.setData({ |
| | | isShowResultList: true, |
| | | }); |
| | | } |
| | | } |
| | | else { |
| | | this.setData({ |
| | | isShowResultList: false, |
| | | }); |
| | | } |
| | | }, |
| | | }; |
| | | this.data = { |
| | | classPrefix: name, |
| | | prefix, |
| | | localValue: { |
| | | focus: false, |
| | | }, |
| | | isShowResultList: false, |
| | | isSelected: false, |
| | | }; |
| | | } |
| | | onInput(e) { |
| | | const { value } = e.detail; |
| | | this.setData({ value }); |
| | | let { value } = e.detail; |
| | | const { maxcharacter } = this.properties; |
| | | if (maxcharacter && typeof maxcharacter === 'number' && maxcharacter > 0) { |
| | | const { characters } = getCharacterLength('maxcharacter', value, maxcharacter); |
| | | value = characters; |
| | | } |
| | | this.setData({ |
| | | value, |
| | | }); |
| | | this.triggerEvent('change', { value }); |
| | | } |
| | | onFocus(e) { |
| | | const { value } = e.detail; |
| | | this.setData({ 'localValue.focus': true }); |
| | | this.triggerEvent('focus', { value }); |
| | | } |
| | | onBlur(e) { |
| | | const { value } = e.detail; |
| | | this.setData({ 'localValue.focus': false }); |
| | | this.triggerEvent('blur', { value }); |
| | | } |
| | | handleClear() { |
| | | this.setData({ value: '' }); |
| | | this.triggerEvent('clear', { value: '' }); |
| | | this.triggerEvent('change', { value: '' }); |
| | | } |
| | | onConfirm(e) { |
| | | const { value } = e.detail; |
| | |
| | | onActionClick() { |
| | | this.triggerEvent('action-click'); |
| | | } |
| | | onSelectResultItem(e) { |
| | | const { index } = e.currentTarget.dataset; |
| | | const item = this.properties.resultList[index]; |
| | | this.setData({ |
| | | value: item, |
| | | isSelected: true, |
| | | }); |
| | | this.triggerEvent('change', { value: item }); |
| | | this.triggerEvent('selectresult', { index, item }); |
| | | } |
| | | }; |
| | | Search = __decorate([ |
| | | wxComponent() |