office-user-select.vue 5.1 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.map(item => ({
  114. ...item,
  115. check: false
  116. }));
  117. if (this.myOffice) {
  118. this.userList = this.userList.filter(item => item.id != $auth.getUserInfo().id)
  119. }
  120. this.tab1click(this.tab1[0])
  121. })
  122. })
  123. },
  124. methods: {
  125. open() {
  126. this.show = true;
  127. if (this.value) {
  128. let u = this.value.split(",")
  129. this.$nextTick(() => {
  130. for (let i = 0; i < this.userList.length; i++) {
  131. let b = u.filter(t => t == this.userList[i].id)
  132. if (b.length > 0) {
  133. this.$set(this.userList[i], "check", true);
  134. this.selectList.push(this.userList[i])
  135. }
  136. }
  137. })
  138. }
  139. },
  140. selectUser() {
  141. let ids = this.selectList.map((item) => {
  142. return item.loginName
  143. }).join(",");
  144. let names = this.selectList.map((item) => {
  145. return item.name
  146. }).join(",");
  147. this.labels = names
  148. this.$emit('input', ids)
  149. this.show = false
  150. },
  151. tab1click(e) {
  152. this.index1 = e.id;
  153. this.tab2 = this.userList.filter(item => item.officeDTO && item.officeDTO.id == e.id)
  154. },
  155. tab1click2(item) {
  156. if(this.selectList.length>=this.limit) {
  157. uni.showToast({
  158. title:`只能选择${this.limit}人`,
  159. icon:'none'
  160. })
  161. }else {
  162. if (!this.multiple) {
  163. this.selectList = []
  164. this.userList.forEach(item1 => {
  165. item1.check = false
  166. })
  167. }
  168. item.check = !item.check
  169. if (item.check) {
  170. this.selectList.push(item)
  171. } else {
  172. this.selectList = this.selectList.filter(e => item.id != e.id)
  173. }
  174. }
  175. },
  176. getSelect(id) {
  177. let s = this.selectList.filter(item => item.officeDTO && item.officeDTO.id == id)
  178. return s.length
  179. }
  180. }
  181. }
  182. </script>
  183. <style>
  184. .allsrc {
  185. display: flex;
  186. height: 60vh;
  187. }
  188. .src1 {
  189. flex: 1;
  190. background: #f5f5f5;
  191. }
  192. .tab1 {
  193. height: 80rpx;
  194. color: black;
  195. text-align: center;
  196. justify-content: center;
  197. align-items: center;
  198. display: flex;
  199. position: relative;
  200. }
  201. .tab1_seltext {
  202. background: #fff;
  203. padding: 16rpx 40rpx;
  204. width: 100%;
  205. }
  206. .src2 {
  207. flex: 2;
  208. background: #fff;
  209. margin-left: 3rpx;
  210. margin-right: 3rpx;
  211. height: 100%;
  212. }
  213. .tab2 .u-button {
  214. width: 40% !important;
  215. float: left;
  216. margin: 20rpx;
  217. }
  218. .describle {
  219. text-align: center;
  220. font-size: 22rpx;
  221. color: #5ac775;
  222. height: 40px;
  223. line-height: 40px;
  224. }
  225. .tab2_text {
  226. height: 40px;
  227. font-size: 14px;
  228. line-height: 40px;
  229. }
  230. .tab2 .current {
  231. color: #36a7f3;
  232. }
  233. </style>