uni-mall-list.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <view>
  3. <view class="box-head"><uni-mall-head ref="refUniMallHead" @change="tabChange"></uni-mall-head></view>
  4. <pinapp-empty-page title="暂无部门或成员" v-if="currentData.length === 0 && userData.length === 0"></pinapp-empty-page>
  5. <view class="box-list">
  6. <view class="box-list-item"
  7. :class="[item.children && item.children.length ? 'box-list-item-department-icon' : '','box-list-item-department']"
  8. :key="item.id" @click="handelClickItem('depart',item)" v-for="item in currentData">
  9. <view class="box-list-item-department-pic">
  10. <uni-icons type="staff-filled" color="#08979c" size="24"></uni-icons>
  11. </view>
  12. <view class="box-list-item-right">
  13. <view class="box-list-item-text">{{ item.name }}</view>
  14. <uni-icons class="inherit-icons" type="right" color="#8c8c8c"></uni-icons>
  15. </view>
  16. </view>
  17. <view class="box-list-item box-list-item-user" :key="item.id" @click="handelClickItem('user',item)"
  18. v-for="item in userData">
  19. <view class="box-list-item-user-pic">
  20. <image v-if="item.pic" :src="item.portrait"></image>
  21. <text v-else>{{getUserName(item.name)}}</text>
  22. </view>
  23. <view class="box-list-item-right">
  24. <view class="box-list-item-text">{{ item.name }}</view>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. import uniMallHead from '@/components/uni-mall-head/uni-mall-head.vue';
  32. import pinappEmptyPage from "@/components/pinapp-empty-page/pinapp-empty-page.vue"
  33. export default {
  34. props: {
  35. dataList: {
  36. type: Array,
  37. default: () => []
  38. },
  39. defaultHeadList: {
  40. type: Object,
  41. default: () => {}
  42. }
  43. },
  44. components: {
  45. uniMallHead,
  46. pinappEmptyPage
  47. },
  48. data() {
  49. return {
  50. currentData: [],
  51. userData: []
  52. };
  53. },
  54. mounted() {
  55. this.init();
  56. },
  57. watch: {
  58. dataList() {
  59. this.currentData = this.dataList;
  60. }
  61. },
  62. methods: {
  63. init() {
  64. if (Object.keys(this.defaultHeadList).length > 0) {
  65. this.$refs.refUniMallHead.addTab(this.defaultHeadList);
  66. }
  67. this.currentData = this.dataList;
  68. this.userData = [];
  69. },
  70. tabChange(obj) {
  71. this.getCurrentData(obj.id, this.dataList);
  72. },
  73. handelClickItem(type, item) {
  74. console.log(type);
  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', 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. .box-list-item-user-pic {
  163. width: 40px;
  164. height: 40px;
  165. background: $uni-primary;
  166. border-radius: 10px;
  167. display: flex;
  168. align-items: center;
  169. justify-content: center;
  170. margin-right: 14px;
  171. overflow: hidden;
  172. image {
  173. width: 40px;
  174. height: 40px;
  175. }
  176. text {
  177. color: #ffffff;
  178. font-size: 12px;
  179. }
  180. }
  181. .box-list-item-right {
  182. display: flex;
  183. align-items: center;
  184. justify-content: space-between;
  185. flex: 1;
  186. }
  187. .box-list-item-user-tag {
  188. text {
  189. box-sizing: border-box;
  190. border-radius: 8px;
  191. padding: 4px 8px;
  192. font-size: 10px;
  193. margin-left: 5px;
  194. &:first-child {
  195. margin-left: 0px;
  196. }
  197. &:nth-child(1) {
  198. background: rgba(49, 210, 144, 0.05);
  199. border: 1px solid #31d290;
  200. color: #31d290;
  201. }
  202. &:nth-child(2) {
  203. background: rgba(55, 127, 255, 0.05);
  204. border: 1px solid #377fff;
  205. color: #377fff;
  206. }
  207. }
  208. }
  209. }
  210. .box-list-item-department+.box-list-item-user {
  211. margin-top: 10px;
  212. }
  213. }
  214. </style>