associated.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <div class="associated">
  3. <div style="display: flex;justify-content: flex-end;margin-bottom: 36rpx">
  4. <span style="font-size: 32rpx;color: #0A98D5" @tap="confirm">确认并返回</span>
  5. </div>
  6. <input v-model="searchName" class="ipt" placeholder="可输入搜索" @input="changeSearch">
  7. <van-checkbox-group :value="result" @change="onChange">
  8. <van-checkbox :name="item.qymc" v-for="item in list" :key="item.id">{{item.qymc}}</van-checkbox>
  9. </van-checkbox-group>
  10. </div>
  11. </template>
  12. <script>
  13. import { getAllBaseCompany } from "@/js_sdk/http";
  14. export default {
  15. name: "associated",
  16. data(){
  17. return{
  18. result:[],
  19. list:[],
  20. page: 1, // 当前页数
  21. pageSize: 20, // 每页数据量
  22. hasMore: true,
  23. searchName:'',
  24. timeout:null,
  25. selectedItems:[]
  26. }
  27. },
  28. onReachBottom(){
  29. if (this.hasMore) {
  30. this.loadMore();
  31. }
  32. },
  33. mounted(){
  34. // this.getCompanyList()
  35. this.loadMore()
  36. },
  37. methods:{
  38. confirm(){
  39. uni.$emit('selectInfo',JSON.stringify(this.selectedItems))
  40. uni.navigateBack()
  41. },
  42. changeSearch(e){
  43. if (this.timeout){
  44. this.timeout = null
  45. }
  46. console.log(e.detail.value)
  47. this.list = []
  48. this.page = 1
  49. this.pageSize = 20
  50. this.searchName = e.detail.value
  51. this.timeout = setTimeout(() => {
  52. this.loadMore()
  53. }, 500)
  54. },
  55. async loadMore() {
  56. try {
  57. const res = await this.fetchListData(this.page, this.pageSize);
  58. console.log('res',res)
  59. if (res.rows && res.rows.length) {
  60. this.list = this.list.concat(res.rows);
  61. this.page += 1;
  62. } else {
  63. this.hasMore = false;
  64. }
  65. } catch (error) {
  66. // 处理错误
  67. }
  68. },
  69. async fetchListData(page, pageSize) {
  70. return getAllBaseCompany({pageNum:page,pageSize,name:this.searchName})
  71. },
  72. getCompanyList(){
  73. },
  74. onChange(e){
  75. this.result = e.detail
  76. this.selectedItems = this.list.filter(item => e.detail.includes(item.qymc));
  77. // 现在你有了一个包含完整 item 对象的数组
  78. console.log(this.selectedItems);
  79. }
  80. }
  81. }
  82. </script>
  83. <style lang="scss">
  84. .associated{
  85. min-height: 100vh;
  86. padding: 36rpx;
  87. background: white;
  88. .van-checkbox{
  89. margin: 24rpx 0;
  90. }
  91. .ipt{
  92. background: rgba(96,96,96,0.1);
  93. margin-bottom: 24rpx;
  94. padding: 12rpx 24rpx;
  95. border-radius: 12rpx;
  96. }
  97. }
  98. </style>