office-user-select.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <view style="width: 100%;" @tap="open">
  3. <u--input v-model="labels" suffixIcon="arrow-right" suffixIconStyle="color: #17a2f8" disabled
  4. disabledColor="#ffffff" :placeholder="placeholder" border="none"></u--input>
  5. <u-action-sheet :show="show" @close="show = false">
  6. <view class="cu-bar bg-white">
  7. <view class="action text-blue" @tap="show=false">取消</view>
  8. <view>{{title}}</view>
  9. <view class="action text-green" @tap="selectUser">确定</view>
  10. </view>
  11. <view class="allsrc">
  12. <scroll-view scroll-y class="src1">
  13. <view v-for="item in tab1" class="tab1" @click="tab1click(item)">
  14. <text :class="item.id==index1?'tab1_seltext':'tab1_text '"
  15. class="tab1_text">{{ item.name }}</text>
  16. <u-badge :absolute="true" :offset="[0,0]" type="primary" :value="getSelect(item.id)"></u-badge>
  17. </view>
  18. </scroll-view>
  19. <scroll-view scroll-y class="src2">
  20. <view class="tab2" v-if="tab2.length>0">
  21. <view class="tab2_text" v-for="item in tab2" @click="tab1click2(item)"
  22. :class="item.check?'current':''">
  23. {{item.name}}
  24. </view>
  25. </view>
  26. <view class="tab2" v-else>
  27. <view class="tab2_text">
  28. 暂无人员
  29. </view>
  30. </view>
  31. </scroll-view>
  32. </view>
  33. </u-action-sheet>
  34. </view>
  35. </template>
  36. <script>
  37. import {
  38. stubFalse
  39. } from "lodash"
  40. import officeService from "@/api/sys/officeService"
  41. import userService from "@/api/sys/userService"
  42. import * as $auth from "@/common/auth.js"
  43. export default {
  44. data() {
  45. return {
  46. index1: "",
  47. tab1: [],
  48. tab2: [],
  49. labels: '',
  50. show: false,
  51. data: [],
  52. selectList: [],
  53. userList: [],
  54. }
  55. },
  56. props: {
  57. value: String,
  58. limit:Number,
  59. size: String,
  60. placeholder: String,
  61. title: String,
  62. types: {
  63. type: String,
  64. default: () => {
  65. return ""
  66. }
  67. },
  68. multiple: {
  69. type: Boolean,
  70. default: () => {
  71. return false
  72. }
  73. },
  74. myOffice: {
  75. type: Boolean,
  76. default: () => {
  77. return false
  78. }
  79. },
  80. props: {
  81. type: Object,
  82. default: () => {
  83. return {
  84. children: 'children',
  85. label: 'name'
  86. }
  87. }
  88. }
  89. },
  90. mounted() {
  91. officeService.treeData({
  92. parentId: "1770354728635834369"
  93. }).then((data) => {
  94. if (this.types.length > 0) {
  95. let types = this.types.split(",")
  96. let officeList = []
  97. types.forEach(item => {
  98. data.forEach(item1 => {
  99. if (item1.type == item) {
  100. officeList.push(item1)
  101. }
  102. })
  103. })
  104. data = officeList
  105. }
  106. this.tab1 = data
  107. this.index1 = this.tab1[0].id
  108. userService.list({
  109. current: 1,
  110. size: 10000
  111. }).then(res => {
  112. this.userList = res.records
  113. this.userList = this.userList.filter(item => item.loginName !='jld')
  114. this.userList = this.userList.map(item => ({
  115. ...item,
  116. check: false
  117. }));
  118. if (this.myOffice) {
  119. this.userList = this.userList.filter(item => item.id != $auth.getUserInfo().id)
  120. }
  121. this.tab1click(this.tab1[0])
  122. })
  123. })
  124. },
  125. methods: {
  126. open() {
  127. this.show = true;
  128. if (this.value) {
  129. let u = this.value.split(",")
  130. this.$nextTick(() => {
  131. for (let i = 0; i < this.userList.length; i++) {
  132. let b = u.filter(t => t == this.userList[i].id)
  133. if (b.length > 0) {
  134. this.$set(this.userList[i], "check", true);
  135. this.selectList.push(this.userList[i])
  136. }
  137. }
  138. })
  139. }
  140. },
  141. selectUser() {
  142. let ids = this.selectList.map((item) => {
  143. return item.loginName
  144. }).join(",");
  145. let names = this.selectList.map((item) => {
  146. return item.name
  147. }).join(",");
  148. this.labels = names
  149. this.$emit('input', ids)
  150. this.show = false
  151. },
  152. tab1click(e) {
  153. this.index1 = e.id;
  154. this.tab2 = this.userList.filter(item => item.officeDTO && item.officeDTO.id == e.id)
  155. },
  156. tab1click2(item) {
  157. if(this.selectList.length>=this.limit) {
  158. uni.showToast({
  159. title:`只能选择${this.limit}人`,
  160. icon:'none'
  161. })
  162. }else {
  163. if (!this.multiple) {
  164. this.selectList = []
  165. this.userList.forEach(item1 => {
  166. item1.check = false
  167. })
  168. }
  169. item.check = !item.check
  170. if (item.check) {
  171. this.selectList.push(item)
  172. } else {
  173. this.selectList = this.selectList.filter(e => item.id != e.id)
  174. }
  175. }
  176. },
  177. getSelect(id) {
  178. let s = this.selectList.filter(item => item.officeDTO && item.officeDTO.id == id)
  179. return s.length
  180. }
  181. }
  182. }
  183. </script>
  184. <style>
  185. .allsrc {
  186. display: flex;
  187. height: 60vh;
  188. }
  189. .src1 {
  190. flex: 1;
  191. background: #f5f5f5;
  192. }
  193. .tab1 {
  194. height: 80rpx;
  195. color: black;
  196. text-align: center;
  197. justify-content: center;
  198. align-items: center;
  199. display: flex;
  200. position: relative;
  201. }
  202. .tab1_seltext {
  203. background: #fff;
  204. padding: 16rpx 40rpx;
  205. width: 100%;
  206. }
  207. .src2 {
  208. flex: 2;
  209. background: #fff;
  210. margin-left: 3rpx;
  211. margin-right: 3rpx;
  212. height: 100%;
  213. }
  214. .tab2 .u-button {
  215. width: 40% !important;
  216. float: left;
  217. margin: 20rpx;
  218. }
  219. .describle {
  220. text-align: center;
  221. font-size: 22rpx;
  222. color: #5ac775;
  223. height: 40px;
  224. line-height: 40px;
  225. }
  226. .tab2_text {
  227. height: 40px;
  228. font-size: 14px;
  229. line-height: 40px;
  230. }
  231. .tab2 .current {
  232. color: #36a7f3;
  233. }
  234. </style>