remotePicker.js 1021 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. disabled: {
  17. type: Boolean
  18. },
  19. value: {
  20. type: String || Number
  21. },
  22. label: {
  23. type: String
  24. }
  25. },
  26. data: {
  27. arr: [],
  28. },
  29. methods: {
  30. async _getList() {
  31. let res = await postApi(this.data.url, {
  32. ...this.data.params,
  33. term: this.data.label
  34. })
  35. this.setData({
  36. arr: res.data.result,
  37. label: ''
  38. })
  39. },
  40. _selectItem(e) {
  41. let {
  42. label,
  43. value
  44. } = e.currentTarget.dataset
  45. this.setData({
  46. label,
  47. value,
  48. arr: []
  49. })
  50. this.triggerEvent('selectItem', {
  51. label,
  52. value
  53. })
  54. },
  55. _handlerOne() {
  56. this.setData({
  57. arr: []
  58. })
  59. },
  60. },
  61. options: {
  62. styleIsolation: 'isolated'
  63. }
  64. })