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.

select-organize.vue 2.1 KiB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <view id="contact" class="page">
  3. <!-- 顶部搜索栏 -->
  4. <l-banner v-model="searchText" :placeholder="placeholder" type="search" noSearchButton fill fixed />
  5. <!-- 树形列表 -->
  6. <l-organize-tree v-if="type && !searchText" @buttonClick="itemClick" :level="type" :root="root" button />
  7. <!-- 如果用户输入了搜索关键字,只列出用户 -->
  8. <view v-else-if="type" class="user-item-list">
  9. <l-organize-single-item v-for="item of searchList" @buttonClick="itemClick" :key="item.id" :item="item" button />
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. data() {
  16. return {
  17. type: null,
  18. contactList: [],
  19. searchText: '',
  20. placeholder: '搜索公司名/部门名/职员姓名',
  21. root: { type: 'company', id: '0' }
  22. }
  23. },
  24. onBackPress() {
  25. this.OFF('select-organize')
  26. },
  27. onUnload() {
  28. this.OFF('select-organize')
  29. },
  30. async onLoad({ type, rootId, rootType }) {
  31. await this.init(type, rootId, rootType)
  32. },
  33. methods: {
  34. // 加载页面
  35. async init(type, rootId, rootType) {
  36. this.placeholder = {
  37. user: '搜索职员姓名',
  38. department: '搜索公司名/部门名',
  39. company: '搜索公司名/部门名/职员姓名'
  40. }[type]
  41. if (rootId && rootId !== 'undefined' && rootId !== 'null') {
  42. this.root = { id: rootId, type: rootType }
  43. }
  44. this.type = type || 'user'
  45. const selectType = { user: '职员', department: '部门', company: '公司' }[type]
  46. this.SET_TITLE(`请选择一个${selectType}`)
  47. },
  48. // 某一项被点击,触发事件
  49. itemClick(item) {
  50. this.EMIT('select-organize', item)
  51. this.NAV_BACK()
  52. }
  53. },
  54. computed: {
  55. // 用户输入关键字搜索时的列表
  56. searchList() {
  57. if (!this.searchText) {
  58. return []
  59. }
  60. return Object.entries(this.GET_GLOBAL(this.type))
  61. .filter(([id, item]) => item.name.includes(this.searchText))
  62. .map(([id, item]) => ({
  63. ...item,
  64. type: this.type,
  65. id
  66. }))
  67. }
  68. }
  69. }
  70. </script>
  71. <style>
  72. page {
  73. padding-top: 100rpx;
  74. }
  75. </style>