newPicker.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. arrow: {
  39. type: Boolean,
  40. value: true
  41. }
  42. },
  43. data: {
  44. arr: [],
  45. visable: false,
  46. isLoading: false,
  47. isInit: true,
  48. index: -1
  49. },
  50. methods: {
  51. _getList: debounce(async function (e) {
  52. this.setData({
  53. isInit: false
  54. })
  55. let res = await postApi(this.data.url, {
  56. ...this.data.params,
  57. term: e.detail.value
  58. })
  59. this.setData({
  60. arr: res.data.result
  61. })
  62. }, 600),
  63. _selectItem(e) {
  64. let {
  65. label,
  66. value
  67. } = e.currentTarget.dataset
  68. this.triggerEvent('selectItem', {
  69. label,
  70. value,
  71. })
  72. this.setData({
  73. label: '',
  74. })
  75. this.cancel()
  76. },
  77. showModal() {
  78. this.setData({
  79. visable: true,
  80. })
  81. },
  82. cancel() {
  83. this.setData({
  84. visable: false,
  85. isInit: true,
  86. arr: [],
  87. index: -1
  88. })
  89. }
  90. },
  91. options: {
  92. styleIsolation: 'isolated'
  93. }
  94. })