newPicker.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. spTop: {
  20. type: String
  21. },
  22. spHeight: {
  23. type: String,
  24. value: "0rpx"
  25. },
  26. disabled: {
  27. type: Boolean
  28. },
  29. value: {
  30. type: String || Number
  31. },
  32. label: {
  33. type: String
  34. },
  35. placeholder: {
  36. type: String
  37. },
  38. },
  39. data: {
  40. arr: [],
  41. visable: false,
  42. isLoading: false,
  43. isInit: true,
  44. index: -1
  45. },
  46. methods: {
  47. _getList: debounce(async function (e) {
  48. this.setData({
  49. isInit: false
  50. })
  51. let res = await postApi(this.data.url, {
  52. ...this.data.params,
  53. term: e.detail.value
  54. })
  55. this.setData({
  56. arr: res.data.result
  57. })
  58. }, 600),
  59. _selectItem(e) {
  60. let {
  61. label,
  62. value
  63. } = e.currentTarget.dataset
  64. this.triggerEvent('selectItem', {
  65. label,
  66. value,
  67. })
  68. this.setData({
  69. label: '',
  70. })
  71. this.cancel()
  72. },
  73. showModal() {
  74. this.setData({
  75. visable: true,
  76. })
  77. },
  78. cancel() {
  79. this.setData({
  80. visable: false,
  81. isInit: true,
  82. arr: [],
  83. index: -1
  84. })
  85. }
  86. },
  87. options: {
  88. styleIsolation: 'isolated'
  89. }
  90. })