chooseUserOrDept.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <view class="uni-app">
  3. <view class="status-bar" />
  4. <view class="main-container">
  5. <wk-nav-bar title="员工与部门" />
  6. <view ref="wkTabs" class="wk-tabs">
  7. <view
  8. v-for="(tab, index) in tabs"
  9. :key="index"
  10. :class="{active: activeTab === tab.value}"
  11. class="wk-tab-item"
  12. @click="handleToggleTabs(tab.value)">
  13. {{ tab.label }}
  14. </view>
  15. </view>
  16. <wk-search-box class="search-box" @search="handleSearch" />
  17. <view class="container">
  18. <wk-select-list
  19. v-if="activeTab === 1"
  20. v-model="selectedList"
  21. :max="1"
  22. :list="deptList"
  23. label-field="name"
  24. value-field="id"
  25. @change="handleChange" />
  26. <wk-select-list
  27. v-else-if="activeTab === 2"
  28. v-model="selectedList"
  29. :list="userList"
  30. :max="1"
  31. label-field="realname"
  32. value-field="userId"
  33. @change="handleChange">
  34. <template v-slot:default="{ scopeData }">
  35. <view>{{ scopeData.realname }}</view>
  36. <view class="dept-name">
  37. {{ scopeData.deptName }}
  38. </view>
  39. </template>
  40. </wk-select-list>
  41. </view>
  42. <view class="footer">
  43. <view class="left">
  44. 已选择:{{ selectedStr }}
  45. </view>
  46. <button class="confirm-btn" @click="handleConfirm">
  47. 确定
  48. </button>
  49. </view>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. import { AdminQueryDeptTree, AdminQueryUserList } from 'API/admin'
  55. export default {
  56. name: 'ChooseUserOrDept',
  57. data() {
  58. return {
  59. activeTab: null,
  60. tabs: [
  61. { label: '部门', value: 1 },
  62. { label: '员工', value: 2 }
  63. ],
  64. allUserList: [],
  65. allDeptList: [],
  66. userList: [],
  67. deptList: [],
  68. bridge: {},
  69. selectedType: null,
  70. selectedList: []
  71. }
  72. },
  73. computed: {
  74. selectedStr() {
  75. if (this.selectedList.length === 0) return ''
  76. if (this.selectedType === 1) {
  77. return this.selectedList[0].name
  78. } else if (this.selectedType === 2) {
  79. return this.selectedList[0].realname
  80. } else {
  81. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  82. this.selectedList = []
  83. return ''
  84. }
  85. }
  86. },
  87. mounted() {
  88. this.bridge = getApp().globalData.selectedValBridge.userOrDept || {}
  89. if (this.bridge.data) {
  90. this.activeTab = this.bridge.data.type || 1
  91. this.selectedType = this.activeTab
  92. this.selectedList = this.bridge.data.data || []
  93. }
  94. this.getData()
  95. },
  96. onUnload() {
  97. getApp().globalData.selectedValBridge = {}
  98. },
  99. methods: {
  100. /**
  101. * 获取列表数据
  102. */
  103. getData() {
  104. AdminQueryUserList({
  105. pageType: 0
  106. }).then(res => {
  107. console.log('userList', res)
  108. this.allUserList = res.list
  109. this.userList = [...res.list]
  110. }).catch()
  111. AdminQueryDeptTree({
  112. search: ''
  113. }).then(res => {
  114. console.log('deptList', res)
  115. this.allDeptList = res
  116. this.deptList = [...res]
  117. }).catch()
  118. },
  119. /**
  120. * 切换tab
  121. * @param {Number} val
  122. */
  123. handleToggleTabs(val) {
  124. this.activeTab = null
  125. this.$nextTick(() => {
  126. this.activeTab = val
  127. this.removeSearch()
  128. })
  129. },
  130. handleChange(data) {
  131. if (data.length > 0) {
  132. this.selectedType = this.activeTab
  133. }
  134. },
  135. handleSearch(keyword) {
  136. if (!keyword) {
  137. this.removeSearch()
  138. } else {
  139. if (this.activeTab === 1) {
  140. this.deptList = this.allDeptList.filter(o => o.name.indexOf(keyword) !== -1)
  141. } else if (this.activeTab === 2) {
  142. this.userList = this.allUserList.filter(o => o.realname.indexOf(keyword) !== -1)
  143. }
  144. }
  145. },
  146. removeSearch() {
  147. if (this.activeTab === 1) {
  148. this.deptList = [...this.allDeptList]
  149. } else if (this.activeTab === 2) {
  150. this.userList = [...this.allUserList]
  151. }
  152. },
  153. /**
  154. * 确认选择
  155. */
  156. handleConfirm() {
  157. const data = {
  158. guid: this.bridge.guid,
  159. bridge: this.bridge,
  160. data: {
  161. data: this.selectedList,
  162. type: this.selectedType
  163. }
  164. }
  165. uni.$emit('selected-user-dept', data)
  166. this.$Router.navigateBack()
  167. }
  168. }
  169. }
  170. </script>
  171. <style scoped lang="scss">
  172. .main-container {
  173. .wk-tabs {
  174. width: 100%;
  175. background-color: white;
  176. // margin-bottom: 15rpx;
  177. }
  178. .container {
  179. flex: 1;
  180. background-color: white;
  181. overflow: auto;
  182. .dept-name {
  183. font-size: 22rpx;
  184. color: #666666;
  185. }
  186. }
  187. .footer {
  188. width: 100%;
  189. height: 100rpx;
  190. background-color: white;
  191. padding: 0 32rpx;
  192. margin-top: 15rpx;
  193. @include left;
  194. .left {
  195. flex: 1;
  196. color: $theme-color;
  197. font-size: $wk-font-base;
  198. }
  199. .confirm-btn {
  200. width: 120rpx;
  201. height: 60rpx;
  202. color: white;
  203. font-size: $wk-font-base;
  204. line-height: 60rpx;
  205. border-radius: 6rpx;
  206. background-color: $theme-color;
  207. }
  208. }
  209. }
  210. </style>