localPicker.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // components/localPicker/localPicker.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. index: ''
  32. },
  33. lifetimes: {
  34. ready() {
  35. this._getList()
  36. }
  37. },
  38. methods: {
  39. async _getList() {
  40. let res = await postApi(this.data.url, {
  41. ...this.data.params,
  42. term: this.data.label
  43. })
  44. this.setData({
  45. arr: res.data.result,
  46. label: ''
  47. })
  48. },
  49. _selectItem(e) {
  50. let index = e.detail.value
  51. let {
  52. value: label,
  53. key: value
  54. } = this.data.arr[index]
  55. this.setData({
  56. label,
  57. value,
  58. index,
  59. })
  60. this.triggerEvent('selectItem', {
  61. label,
  62. value
  63. })
  64. },
  65. _handlerOne() {
  66. this.setData({
  67. arr: [],
  68. visable: true
  69. })
  70. },
  71. },
  72. options: {
  73. styleIsolation: 'isolated'
  74. }
  75. })