index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <template>
  2. <u-popup class="jnpf-tree-select-popup" :maskCloseAble="maskCloseAble" mode="right" v-model="showPopup"
  3. :safeAreaInsetBottom="safeAreaInsetBottom" @close="close" :z-index="uZIndex" width="100%">
  4. <view class="jnpf-tree-select-body">
  5. <view class="jnpf-tree-select-title">
  6. <text class="icon-ym icon-ym-report-icon-preview-pagePre u-font-40 backIcon" @tap="close"></text>
  7. <view class="title">选择用户</view>
  8. </view>
  9. <view class="jnpf-tree-select-search">
  10. <u-search :placeholder="$t('app.apply.pleaseKeyword')" v-model="keyword" height="72"
  11. :show-action="false" @change="search()" bg-color="#f0f2f6" shape="square">
  12. </u-search>
  13. </view>
  14. <view class="jnpf-tree-selected">
  15. <view class="jnpf-tree-selected-head">
  16. <view>{{$t('component.jnpf.common.selected')}}</view>
  17. <view v-if="multiple" class="clear-btn" @click="cleanAll">
  18. {{$t('component.jnpf.common.clearAll')}}
  19. </view>
  20. </view>
  21. <view class="jnpf-tree-selected-box">
  22. <scroll-view scroll-y="true" style="max-height: 240rpx;">
  23. <view class="jnpf-tree-selected-list">
  24. <view class="u-selectTag" v-for="(list,index) in selectList" :key="index">
  25. <u-avatar class="avatar" :src="baseURL+list.headIcon" mode="circle"
  26. size="mini"></u-avatar>
  27. <view class="jnpf-tree-selected-content">
  28. <view class="name-box">
  29. <view class="name">{{list.fullName}}</view>
  30. <u-icon name="close" class="close" @click='delSelect(index)'></u-icon>
  31. </view>
  32. <view class="organize">{{list.organize}}</view>
  33. </view>
  34. </view>
  35. </view>
  36. </scroll-view>
  37. </view>
  38. </view>
  39. <view class="listTitle" v-if="selectType !== 'all'">全部数据</view>
  40. <view class="jnpf-tree-select-tree">
  41. <scroll-view class="scroll-view" :refresher-enabled="false" :refresher-threshold="100"
  42. :scroll-with-animation='true' :refresher-triggered="triggered" @scrolltolower="handleScrollToLower"
  43. :scroll-y="true">
  44. <view class="lists_box">
  45. <view class="list-cell-txt u-border-bottom" v-for="(list,index) in list" :key="index"
  46. @click="onSelect(list)">
  47. <u-avatar class="avatar" :src="baseURL+list.headIcon" mode="circle"
  48. size="default"></u-avatar>
  49. <view class="u-font-30 content">
  50. <view>{{list.fullName}}</view>
  51. <view class="organize">{{list.organize}}</view>
  52. </view>
  53. </view>
  54. <JnpfEmpty v-if="list.length<1"></JnpfEmpty>
  55. </view>
  56. </scroll-view>
  57. </view>
  58. <!-- 底部按钮 -->
  59. <view class="jnpf-tree-select-actions">
  60. <u-button class="buttom-btn" @click="close()">{{$t('common.cancelText')}}</u-button>
  61. <u-button class="buttom-btn" type="primary"
  62. @click.stop="handleConfirm">{{$t('common.okText')}}</u-button>
  63. </view>
  64. </view>
  65. </u-popup>
  66. </template>
  67. <script>
  68. /**
  69. * tree-select 树形选择器
  70. * @property {Boolean} v-model 布尔值变量,用于控制选择器的弹出与收起
  71. * @property {Boolean} safe-area-inset-bottom 是否开启底部安全区适配(默认false)
  72. * @property {String} cancel-color 取消按钮的颜色(默认#606266)
  73. * @property {String} confirm-color 确认按钮的颜色(默认#2979ff)
  74. * @property {String} confirm-text 确认按钮的文字
  75. * @property {String} cancel-text 取消按钮的文字
  76. * @property {Boolean} mask-close-able 是否允许通过点击遮罩关闭Picker(默认true)
  77. * @property {String Number} z-index 弹出时的z-index值(默认10075)
  78. * @event {Function} confirm 点击确定按钮,返回当前选择的值
  79. */
  80. const defaultProps = {
  81. label: 'fullName',
  82. value: 'id',
  83. icon: 'icon',
  84. children: 'children'
  85. }
  86. import {
  87. getTaskUserList
  88. } from '@/api/workFlow/flowBefore'
  89. export default {
  90. name: "comment-tree-select",
  91. props: {
  92. taskId: {
  93. type: String,
  94. default: ''
  95. },
  96. selectType: {
  97. type: String,
  98. default: 'all'
  99. },
  100. clearable: {
  101. type: Boolean,
  102. default: false
  103. },
  104. query: {
  105. type: Object,
  106. default: () => ({})
  107. },
  108. selectedData: {
  109. type: Array,
  110. default () {
  111. return [];
  112. }
  113. },
  114. // 是否显示边框
  115. border: {
  116. type: Boolean,
  117. default: true
  118. },
  119. // 通过双向绑定控制组件的弹出与收起
  120. modelValue: {
  121. type: Boolean,
  122. default: false
  123. },
  124. // "取消"按钮的颜色
  125. cancelColor: {
  126. type: String,
  127. default: '#606266'
  128. },
  129. // "确定"按钮的颜色
  130. confirmColor: {
  131. type: String,
  132. default: '#2979ff'
  133. },
  134. // 弹出的z-index值
  135. zIndex: {
  136. type: [String, Number],
  137. default: 999
  138. },
  139. safeAreaInsetBottom: {
  140. type: Boolean,
  141. default: false
  142. },
  143. // 是否允许通过点击遮罩关闭Picker
  144. maskCloseAble: {
  145. type: Boolean,
  146. default: true
  147. },
  148. props: {
  149. type: Object,
  150. default: () => ({
  151. label: 'fullName',
  152. value: 'id',
  153. icon: 'icon',
  154. children: 'children',
  155. isLeaf: 'isLeaf'
  156. })
  157. },
  158. //多选
  159. multiple: {
  160. type: Boolean,
  161. default: false
  162. },
  163. // 顶部标题
  164. title: {
  165. type: String,
  166. default: ''
  167. },
  168. // 取消按钮的文字
  169. cancelText: {
  170. type: String,
  171. default: '取消'
  172. },
  173. // 确认按钮的文字
  174. confirmText: {
  175. type: String,
  176. default: '确认'
  177. }
  178. },
  179. data() {
  180. return {
  181. triggered: false,
  182. selectList: [],
  183. keyword: '',
  184. current: 0,
  185. list: [],
  186. pagination: {
  187. currentPage: 1,
  188. pageSize: 20
  189. },
  190. total: 0,
  191. height: 0,
  192. showPopup: false
  193. };
  194. },
  195. watch: {
  196. // 在select弹起的时候,重新初始化所有数据
  197. modelValue: {
  198. immediate: true,
  199. handler(val) {
  200. this.showPopup = val
  201. if (val) setTimeout(() => this.getInfoList(), 10);
  202. }
  203. },
  204. },
  205. computed: {
  206. baseURL() {
  207. return this.define.baseURL
  208. },
  209. uZIndex() {
  210. // 如果用户有传递z-index值,优先使用
  211. return this.zIndex ? this.zIndex : this.$u.zIndex.popup;
  212. },
  213. realProps() {
  214. return {
  215. ...defaultProps,
  216. ...this.props
  217. }
  218. }
  219. },
  220. created() {
  221. setTimeout(() => {
  222. this.triggered = true;
  223. }, 1000)
  224. },
  225. methods: {
  226. handleScrollToLower() {
  227. this.getInfoList()
  228. },
  229. getInfoList() {
  230. this.pagination.keyword = this.keyword
  231. getTaskUserList(this.taskId, this.pagination).then(res => {
  232. const list = res.data.list;
  233. if (!list.length && this.pagination.currentPage != 1) return uni.showToast({
  234. title: '没有更多信息啦!',
  235. icon: 'none'
  236. });
  237. this.list = this.list.concat(list);
  238. this.pagination.currentPage++
  239. })
  240. },
  241. onSelect(list) {
  242. if (!this.multiple) this.selectList = []
  243. let flag = false;
  244. for (let i = 0; i < this.selectList.length; i++) {
  245. if (this.selectList[i].id === list.id) {
  246. flag = true;
  247. return
  248. }
  249. };
  250. !flag && this.selectList.push(list)
  251. },
  252. search() {
  253. this.searchTimer && clearTimeout(this.searchTimer)
  254. this.searchTimer = setTimeout(() => {
  255. this.pagination = {
  256. currentPage: 1,
  257. pageSize: 20
  258. }
  259. this.pagination.keyword = this.keyword
  260. getTaskUserList(this.taskId, this.pagination).then(res => {
  261. const list = res.data.list;
  262. this.list = list
  263. this.pagination = res.data.pagination
  264. this.total = this.pagination.total
  265. })
  266. }, 300)
  267. },
  268. delSelect(index) {
  269. this.selectList.splice(index, 1);
  270. },
  271. cleanAll() {
  272. this.selectList = [];
  273. },
  274. handleConfirm() {
  275. this.keyword = '';
  276. this.$emit('confirm', this.selectList);
  277. this.close();
  278. },
  279. close() {
  280. this.$emit('close');
  281. }
  282. }
  283. };
  284. </script>
  285. <style scoped lang="scss">
  286. .jnpf-user-content {
  287. flex: 1;
  288. display: flex;
  289. flex-direction: column;
  290. .swiper-box {
  291. flex: 1;
  292. }
  293. }
  294. .listTitle {
  295. padding: 10rpx 30rpx;
  296. font-size: 32rpx;
  297. }
  298. .scroll-view {
  299. height: 100%;
  300. }
  301. .lists_box {
  302. height: 100%;
  303. .nodata {
  304. height: 100%;
  305. margin: auto;
  306. align-items: center;
  307. justify-content: center;
  308. color: #909399;
  309. }
  310. .list-cell-txt {
  311. display: flex;
  312. box-sizing: border-box;
  313. width: 100%;
  314. padding: 20rpx 32rpx;
  315. overflow: hidden;
  316. color: $u-content-color;
  317. font-size: 28rpx;
  318. line-height: 24px;
  319. background-color: #fff;
  320. .content {
  321. width: 85%;
  322. margin-left: 15rpx;
  323. .organize {
  324. white-space: nowrap;
  325. overflow: hidden; //超出的文本隐藏
  326. text-overflow: ellipsis
  327. }
  328. }
  329. }
  330. }
  331. </style>