remotePicker.js 1.0 KB

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