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.
 
 
 
 
 
 

158 lines
3.6 KiB

  1. <template>
  2. <view id="contact" class="page">
  3. <!-- 顶部搜索栏 -->
  4. <view class="topSearch">
  5. <!-- <view style="padding-top: 54px;"> -->
  6. <l-banner v-model="searchText" :placeholder="placeholder" type="search" noSearchButton fill />
  7. <!-- </view> -->
  8. <view>
  9. <view class="pearson">
  10. 已选择:{{names||'暂无'}}
  11. </view>
  12. <view style="display: flex;justify-content: center;">
  13. <view class="cu-btn sm line-red" @tap="itemClear" style="font-size: 16px;margin: 4px;">
  14. 清空选择
  15. </view>
  16. <view class="cu-btn sm line-green" @tap="itemConfirm" style="font-size: 16px;margin: 4px;">
  17. 确定选择
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. <!-- 树形列表 -->
  23. <l-organize-tree v-if="type && !searchText && refreshFlag" @buttonClick="itemClick" :level="type" :root="root" button :value="ids" />
  24. <!-- 如果用户输入了搜索关键字,只列出用户 -->
  25. <view v-else-if="type && refreshFlag" class="user-item-list">
  26. <l-organize-single-item v-for="item of searchList" @buttonClick="itemClick" :key="item.id" :item="item" button :value="ids" />
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. data() {
  33. return {
  34. type: null,
  35. contactList: [],
  36. searchText: '',
  37. placeholder: '搜索公司名/部门名/职员姓名',
  38. root: { type: 'company', id: '0' },
  39. items:[],
  40. ids:'',
  41. refreshFlag:true,
  42. }
  43. },
  44. onBackPress() {
  45. this.OFF('select-organize')
  46. },
  47. onUnload() {
  48. this.OFF('select-organize')
  49. },
  50. async onLoad({ type, rootId, rootType }) {
  51. await this.init(type, rootId, rootType)
  52. },
  53. methods: {
  54. // 加载页面
  55. async init(type, rootId, rootType) {
  56. this.ids = this.GET_PARAM()
  57. if(this.ids){
  58. let arr = this.ids.split(",")
  59. let items = []
  60. for (let s of arr) {
  61. if(this.GET_GLOBAL(type)[s]){
  62. items.push({...this.GET_GLOBAL(type)[s],id:s})
  63. }
  64. }
  65. this.items = items
  66. }
  67. this.placeholder = {
  68. user: '搜索职员姓名',
  69. department: '搜索公司名/部门名',
  70. company: '搜索公司名/部门名/职员姓名'
  71. }[type]
  72. if (rootId && rootId !== 'undefined' && rootId !== 'null') {
  73. this.root = { id: rootId, type: rootType }
  74. }
  75. this.type = type || 'user'
  76. const selectType = { user: '职员', department: '部门', company: '公司' }[type]
  77. this.SET_TITLE(`请选择${selectType}`)
  78. },
  79. findItem(arr,item){
  80. const result = arr.findIndex(t => t.id === item.id);
  81. if(result === -1){
  82. arr.push(item)
  83. }else{
  84. arr.splice(result,1)
  85. }
  86. return arr
  87. },
  88. itemClear(){
  89. this.items = []
  90. this.ids = ''
  91. this.refreshFlag = false
  92. this.$nextTick(()=>{
  93. this.refreshFlag = true
  94. })
  95. },
  96. // 某一项被点击,触发事件
  97. itemClick(item) {
  98. this.items = this.findItem(this.items,item)
  99. this.ids = this.items.map(t=>t.id).toString()
  100. // this.EMIT('select-organize', item)
  101. // this.NAV_BACK()
  102. },
  103. itemConfirm(){
  104. this.EMIT('select-organize', this.items)
  105. this.NAV_BACK()
  106. }
  107. },
  108. computed: {
  109. // 用户输入关键字搜索时的列表
  110. searchList() {
  111. if (!this.searchText) {
  112. return []
  113. }
  114. return Object.entries(this.GET_GLOBAL(this.type))
  115. .filter(([id, item]) => item.name.includes(this.searchText))
  116. .map(([id, item]) => ({
  117. ...item,
  118. type: this.type,
  119. id
  120. }))
  121. },
  122. names(){
  123. if(!this.items.length){
  124. return ''
  125. }
  126. return this.items.map(t=>t.name).toString()
  127. }
  128. }
  129. }
  130. </script>
  131. <style lang="scss">
  132. // page {
  133. // padding-top: 100rpx;
  134. // }
  135. .topSearch{
  136. .pearson{
  137. color: #606266;
  138. line-height: 32px;
  139. padding: 6px 8px;
  140. }
  141. }
  142. </style>