newPicker.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // components/newPicker/newPicker.js
  2. import {
  3. postApi
  4. } from "../../apis/api"
  5. import {
  6. debounce
  7. } from "../../utils/utils"
  8. Component({
  9. properties: {
  10. url: {
  11. type: String
  12. },
  13. params: {
  14. type: Object
  15. },
  16. inputStyle: {
  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. visable: false,
  35. isLoading: false,
  36. isInit: true,
  37. index: -1
  38. },
  39. methods: {
  40. _getList: debounce(async function (e) {
  41. this.setData({
  42. isInit: false
  43. })
  44. let res = await postApi(this.data.url, {
  45. ...this.data.params,
  46. term: e.detail.value
  47. })
  48. this.setData({
  49. arr: res.data.result
  50. })
  51. }, 600),
  52. _selectItem(e) {
  53. let {
  54. label,
  55. value
  56. } = e.currentTarget.dataset
  57. this.triggerEvent('selectItem', {
  58. label,
  59. value,
  60. })
  61. this.setData({
  62. label: '',
  63. })
  64. this.cancel()
  65. },
  66. showModal() {
  67. this.setData({
  68. visable: true,
  69. })
  70. },
  71. cancel() {
  72. this.setData({
  73. visable: false,
  74. isInit: true,
  75. arr: [],
  76. index: -1
  77. })
  78. }
  79. },
  80. options: {
  81. styleIsolation: 'isolated'
  82. }
  83. })