uni-mall-list.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <view>
  3. <view class="box-head"><uni-mall-head ref="refUniMallHead" @change="tabChange"></uni-mall-head></view>
  4. <view class="box-list">
  5. <mescroll-empty :option="{tip:'暂无部门或成员'}" v-if="currentData.length === 0 && userData.length === 0">
  6. </mescroll-empty>
  7. <view>
  8. <view class="box-list-item"
  9. :class="[item.children && item.children.length ? 'box-list-item-department-icon' : '','box-list-item-department']"
  10. :key="item.id" @click="handelClickItem('depart',item)" v-for="item in currentData">
  11. <view class="box-list-item-department-pic">
  12. <uni-icons type="staff-filled" color="#08979c" size="24"></uni-icons>
  13. </view>
  14. <view class="box-list-item-right">
  15. <view class="box-list-item-text">{{ item.name }}</view>
  16. <uni-icons class="inherit-icons" type="right" color="#8c8c8c"></uni-icons>
  17. </view>
  18. </view>
  19. <view class="box-list-item box-list-item-user" :key="item.id" @click="handelClickItem('user',item)"
  20. v-for="item in userData">
  21. <view class="box-list-item-user-pic">
  22. <image v-if="item.pic" :src="item.portrait"></image>
  23. <text v-else>{{getUserName(item.name)}}</text>
  24. </view>
  25. <view class="box-list-item-right">
  26. <view class="box-list-item-text">{{ item.name }}</view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import uniMallHead from '@/components/uni-mall-head/uni-mall-head.vue';
  35. export default {
  36. props: {
  37. dataList: {
  38. type: Array,
  39. default: () => []
  40. },
  41. defaultHeadList: {
  42. type: Object,
  43. default: () => {}
  44. }
  45. },
  46. components: {
  47. uniMallHead
  48. },
  49. data() {
  50. return {
  51. currentData: [],
  52. userData: []
  53. };
  54. },
  55. mounted() {
  56. this.init();
  57. },
  58. watch: {
  59. dataList() {
  60. this.currentData = this.dataList;
  61. }
  62. },
  63. methods: {
  64. init() {
  65. if (Object.keys(this.defaultHeadList).length > 0) {
  66. this.$refs.refUniMallHead.addTab(this.defaultHeadList);
  67. }
  68. this.currentData = this.dataList;
  69. this.userData = [];
  70. },
  71. tabChange(obj) {
  72. this.getCurrentData(obj.id, this.dataList);
  73. },
  74. handelClickItem(type, item) {
  75. if (type === 'depart') {
  76. if (item.children) {
  77. this.$refs.refUniMallHead.addTab({
  78. name: item.name,
  79. id: item.id
  80. });
  81. this.currentData = item.children;
  82. this.userData = item.users || [];
  83. }
  84. }
  85. this.$emit('change', type, item);
  86. },
  87. getUserName(name) {
  88. if (name.length === 0) {
  89. return '';
  90. } else if (name.length <= 2) {
  91. return name;
  92. } else if (name.length >= 3) {
  93. return name.substring(name.length - 2);
  94. }
  95. },
  96. getCurrentData(id, data) {
  97. if (id === this.defaultHeadList.id) {
  98. this.currentData = this.dataList;
  99. this.userData = [];
  100. } else {
  101. if (data.length > 0) {
  102. data.map(item => {
  103. if (item.id === id) {
  104. this.currentData = item.children || [];
  105. this.userData = item.users || [];
  106. }
  107. if (item.children && item.children.length > 0) {
  108. this.getCurrentData(id, item.children);
  109. }
  110. });
  111. }
  112. }
  113. }
  114. }
  115. };
  116. </script>
  117. <style lang="scss" scoped>
  118. .box-head {
  119. position: fixed;
  120. left: 0px;
  121. width: 100%;
  122. height: 96rpx;
  123. background: #ffffff;
  124. padding-left: 34rpx;
  125. box-sizing: border-box;
  126. overflow-y: hidden;
  127. z-index: 999;
  128. border-top: 1px solid $uni-border-1;
  129. }
  130. .box-list {
  131. padding-top: 52px;
  132. .box-list-item {
  133. position: relative;
  134. height: 60px;
  135. display: flex;
  136. align-items: center;
  137. padding: 0 14px;
  138. box-sizing: border-box;
  139. background: #ffffff;
  140. margin-bottom: 1px;
  141. &:active {
  142. background: #f2f3f4;
  143. }
  144. &:last-child {
  145. margin-bottom: 0px;
  146. }
  147. .box-list-item-department-pic {
  148. width: 40px;
  149. height: 40px;
  150. background: rgba(8, 151, 156, 0.1);
  151. border-radius: 10px;
  152. display: flex;
  153. align-items: center;
  154. justify-content: center;
  155. margin-right: 14px;
  156. overflow: hidden;
  157. image {
  158. width: 20px;
  159. height: 20px;
  160. }
  161. }
  162. .user-icon {
  163. margin-right: 20rpx;
  164. }
  165. .box-list-item-user-pic {
  166. width: 40px;
  167. height: 40px;
  168. background: $uni-primary;
  169. border-radius: 10px;
  170. display: flex;
  171. align-items: center;
  172. justify-content: center;
  173. margin-right: 14px;
  174. overflow: hidden;
  175. image {
  176. width: 40px;
  177. height: 40px;
  178. }
  179. text {
  180. color: #ffffff;
  181. font-size: 12px;
  182. }
  183. }
  184. .box-list-item-right {
  185. display: flex;
  186. align-items: center;
  187. justify-content: space-between;
  188. flex: 1;
  189. }
  190. .box-list-item-user-tag {
  191. text {
  192. box-sizing: border-box;
  193. border-radius: 8px;
  194. padding: 4px 8px;
  195. font-size: 10px;
  196. margin-left: 5px;
  197. &:first-child {
  198. margin-left: 0px;
  199. }
  200. &:nth-child(1) {
  201. background: rgba(49, 210, 144, 0.05);
  202. border: 1px solid #31d290;
  203. color: #31d290;
  204. }
  205. &:nth-child(2) {
  206. background: rgba(55, 127, 255, 0.05);
  207. border: 1px solid #377fff;
  208. color: #377fff;
  209. }
  210. }
  211. }
  212. }
  213. .box-list-item-department+.box-list-item-user {
  214. margin-top: 10px;
  215. }
  216. }
  217. </style>