office-user-select.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. size: String,
  59. placeholder: String,
  60. title: String,
  61. types: {
  62. type: String,
  63. default: () => {
  64. return ""
  65. }
  66. },
  67. multiple: {
  68. type: Boolean,
  69. default: () => {
  70. return false
  71. }
  72. },
  73. myOffice: {
  74. type: Boolean,
  75. default: () => {
  76. return false
  77. }
  78. },
  79. props: {
  80. type: Object,
  81. default: () => {
  82. return {
  83. children: 'children',
  84. label: 'name'
  85. }
  86. }
  87. }
  88. },
  89. mounted() {
  90. officeService.treeData({
  91. parentId: "1770354728635834369"
  92. }).then((data) => {
  93. if (this.types.length > 0) {
  94. let types = this.types.split(",")
  95. let officeList = []
  96. types.forEach(item => {
  97. data.forEach(item1 => {
  98. if (item1.type == item) {
  99. officeList.push(item1)
  100. }
  101. })
  102. })
  103. data = officeList
  104. console.log("this.types.length", data);
  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.multiple) {
  157. this.selectList = []
  158. this.userList.forEach(item1 => {
  159. item1.check = false
  160. })
  161. }
  162. item.check = !item.check
  163. if (item.check) {
  164. this.selectList.push(item)
  165. } else {
  166. this.selectList = this.selectList.filter(e => item.id != e.id)
  167. }
  168. },
  169. getSelect(id) {
  170. let s = this.selectList.filter(item => item.officeDTO && item.officeDTO.id == id)
  171. return s.length
  172. }
  173. }
  174. }
  175. </script>
  176. <style>
  177. .allsrc {
  178. display: flex;
  179. height: 60vh;
  180. }
  181. .src1 {
  182. flex: 1;
  183. background: #f5f5f5;
  184. }
  185. .tab1 {
  186. height: 80rpx;
  187. color: black;
  188. text-align: center;
  189. justify-content: center;
  190. align-items: center;
  191. display: flex;
  192. position: relative;
  193. }
  194. .tab1_seltext {
  195. background: #fff;
  196. padding: 16rpx 40rpx;
  197. width: 100%;
  198. }
  199. .src2 {
  200. flex: 2;
  201. background: #fff;
  202. margin-left: 3rpx;
  203. margin-right: 3rpx;
  204. height: 100%;
  205. }
  206. .tab2 .u-button {
  207. width: 40% !important;
  208. float: left;
  209. margin: 20rpx;
  210. }
  211. .describle {
  212. text-align: center;
  213. font-size: 22rpx;
  214. color: #5ac775;
  215. height: 40px;
  216. line-height: 40px;
  217. }
  218. .tab2_text {
  219. height: 40px;
  220. font-size: 14px;
  221. line-height: 40px;
  222. }
  223. .tab2 .current {
  224. color: #36a7f3;
  225. }
  226. </style>