You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

99 lines
1.9 KiB

  1. <template>
  2. <view class="page">
  3. <!-- 顶部搜索栏 -->
  4. <l-banner v-model="searchText" placeholder="搜索项目名/项目值" type="search" noSearchButton fill fixed />
  5. <!-- 选单列表 -->
  6. <view class="layer-list">
  7. <view v-for="(item, index) of list" @click="itemClick(item)" :key="index" class="layer-item">
  8. <view v-for="fieldItem of fieldList" :key="fieldItem.name">
  9. <text class="text-black label">{{ fieldItem.label || '(未命名标题)' }}:</text>
  10. <text>{{ item[fieldItem.name] }}</text>
  11. </view>
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. data() {
  19. return {
  20. searchText: '',
  21. sourceList: [],
  22. fieldList: []
  23. }
  24. },
  25. // 按下返回键,移除监听
  26. onBackPress() {
  27. this.OFF('select-layer')
  28. },
  29. // 页面卸载,移除监听
  30. onUnload() {
  31. this.OFF('select-layer')
  32. },
  33. async onLoad() {
  34. await this.init()
  35. },
  36. methods: {
  37. // 页面初始化
  38. async init() {
  39. this.LOADING('加载数据中…')
  40. const { source, layerData } = this.GET_PARAM()
  41. this.sourceList = source
  42. this.fieldList = layerData
  43. this.$nextTick(() => {
  44. this.HIDE_LOADING()
  45. })
  46. },
  47. // 点击选择某一项
  48. itemClick(item) {
  49. this.EMIT('select-layer', item)
  50. this.NAV_BACK()
  51. }
  52. },
  53. computed: {
  54. // 根据搜索值按需渲染
  55. list() {
  56. if (!this.searchText) {
  57. return this.sourceList
  58. }
  59. return this.sourceList.filter(item => this.fieldList.some(t => (item[t.name] || '').includes(this.searchText)))
  60. }
  61. }
  62. }
  63. </script>
  64. <style lang="less" scoped>
  65. .layer-item {
  66. padding: 20rpx 25rpx;
  67. border-bottom: 1rpx solid #ddd;
  68. background: #ffffff;
  69. color: #8f8f94;
  70. .label {
  71. white-space: nowrap;
  72. }
  73. &:first-child {
  74. border-top: 1rpx solid #ddd;
  75. }
  76. }
  77. </style>
  78. <style>
  79. page {
  80. padding-top: 100rpx;
  81. }
  82. </style>