dk-select-field.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // components/dkbase/dk-select-field/dk-select-field.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. label:{
  8. type: String,
  9. },
  10. placeholder:{
  11. type: String
  12. },
  13. inputClass:{
  14. type:String
  15. },
  16. readonly:{
  17. type: Boolean,
  18. value: false
  19. },
  20. errorMessage:{
  21. type: String
  22. },
  23. border:{
  24. type: Boolean,
  25. value: false
  26. },
  27. required: {
  28. type: Boolean,
  29. value: false
  30. },
  31. labelClass: {
  32. type: String
  33. },
  34. iconUrl: {
  35. type: String
  36. },
  37. fieldValue: {
  38. type: String
  39. },
  40. valueList: {
  41. type: Array
  42. }
  43. },
  44. /**
  45. * 组件的初始数据
  46. */
  47. data: {
  48. selectListShow: false,
  49. selectList: [],
  50. fieldAddress:{}
  51. },
  52. lifetimes:{
  53. attached(){
  54. const that = this
  55. const query = this.createSelectorQuery();
  56. query.select("#vanField").boundingClientRect();
  57. query.exec((res) => {
  58. that.setData({
  59. fieldAddress: res[0]
  60. })
  61. });
  62. }
  63. },
  64. /**
  65. * 组件的方法列表
  66. */
  67. methods: {
  68. /**
  69. * @desc : icon点击事件
  70. * @author : 刘尧
  71. * @date : 2024/7/2 11:34
  72. */
  73. open(e){
  74. this.triggerEvent('iconClick')
  75. },
  76. /**
  77. * @desc : 输入框失去焦点隐藏列表
  78. * @author : 刘尧
  79. * @date : 2024/7/2 11:34
  80. */
  81. blurField(e){
  82. const valueList = this.data.valueList
  83. const inputValue = e.detail.value
  84. const selectList = valueList.filter(res => res.supName === inputValue)
  85. this.setData({
  86. selectListShow: false
  87. })
  88. this.triggerEvent('selectCellValue', selectList[0])
  89. },
  90. /**
  91. * @desc : 输入监听事件
  92. * @author : 刘尧
  93. * @date : 2024/7/2 11:34
  94. */
  95. inputField(e){
  96. const valueList = this.data.valueList
  97. if(e.detail && e.detail !== ""){
  98. const selectList = valueList.filter((item) => item.supName.includes(e.detail))
  99. this.setData({
  100. selectListShow: true,
  101. selectList: selectList
  102. })
  103. }else {
  104. this.setData({
  105. selectListShow: false,
  106. selectList: []
  107. })
  108. }
  109. this.triggerEvent('inputValue', e.detail)
  110. },
  111. clickCell(e){
  112. this.triggerEvent('selectCellValue', e.currentTarget.dataset.item)
  113. }
  114. }
  115. })