remotePicker.js 1023 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // components/remotePicker/remotePicker.js
  2. import {
  3. postApi
  4. } from "../../apis/api"
  5. Component({
  6. properties: {
  7. url: {
  8. type: String
  9. },
  10. params: {
  11. type: Object
  12. },
  13. inputStyle: {
  14. type: String
  15. }
  16. },
  17. data: {
  18. arr: [],
  19. value: '',
  20. label: '',
  21. },
  22. methods: {
  23. async _getList() {
  24. let res = await postApi(this.data.url, {
  25. ...this.data.params,
  26. term: this.data.label
  27. })
  28. this.setData({
  29. arr: res.data.result,
  30. label: ''
  31. })
  32. },
  33. _selectItem(e) {
  34. let {
  35. label,
  36. value
  37. } = e.currentTarget.dataset
  38. this.setData({
  39. label,
  40. value,
  41. arr: []
  42. })
  43. this.triggerEvent('selectItem', {
  44. label,
  45. value
  46. })
  47. },
  48. _handlerOne() {
  49. this.setData({
  50. arr: []
  51. })
  52. },
  53. _clear() {
  54. if (this.data.value) return
  55. this.setData({
  56. label: ''
  57. })
  58. }
  59. },
  60. options: {
  61. styleIsolation: 'isolated'
  62. }
  63. })