localPicker.js 1.3 KB

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