remotePicker.js 1.1 KB

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