mall-list.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. <u-checkbox-group v-model="checkboxList" placement="column" :activeColor="$settingStore.themeColor.color" @change="checkboxChange">
  6. <view
  7. v-for="item in currentData"
  8. class="box-list-item"
  9. :class="[item.children && item.children.length >= 0 ? 'box-list-item-department-icon' : 'box-list-item-user']"
  10. :key="item.id"
  11. @click="handelClickItem(item)"
  12. >
  13. <view class="box-list-item-department-pic" v-if="item.children && item.children.length >= 0"><image src="http://192.168.123.165:9300/statics/department-icon.png"></image></view>
  14. <view class="box-list-item-user-pic flex" v-else>
  15. <u-checkbox class="box-list-item-user-pic-checkbox mr9" :name="item.id"> </u-checkbox>
  16. <u-avatar
  17. class="box-list-item-user-pic-avatar mr10"
  18. :src="item.avatar"
  19. shape="square"
  20. size="40"
  21. fontSize="12"
  22. color="#ffffff"
  23. :bgColor="$settingStore.themeColor.color"
  24. v-if="item.avatar"
  25. ></u-avatar>
  26. <u-avatar
  27. class="box-list-item-user-pic-avatar mr10"
  28. :text="item.label.length > 2 ? item.label.slice(1, 3) : item.label"
  29. shape="square"
  30. size="40"
  31. fontSize="12"
  32. color="#ffffff"
  33. :bgColor="$settingStore.themeColor.color"
  34. v-else
  35. ></u-avatar>
  36. </view>
  37. <view class="box-list-item-right">
  38. <view class="box-list-item-text">{{ item.label }} {{ item.children && item.children.length > 0 ? `(${item.children.length})` : "" }}</view>
  39. <view class="box-list-item-user-tag" v-if="!item.children && item.post">
  40. <text>{{ item.post }}</text>
  41. </view>
  42. </view>
  43. </view>
  44. </u-checkbox-group>
  45. </view>
  46. <view class="box-foot">
  47. <view class="box-foot-left" style="justify-self: center">
  48. <view class="box-foot-left-count" :style="{ color: $settingStore.themeColor.color }">已选择:{{ checkboxUserList.length }}人</view>
  49. <view class="box-foot-left-people"> {{ checkboxUserList.toString() || `最多选择${activeUserNumber}人` }}</view>
  50. </view>
  51. <view class="box-foot-right">
  52. <u-button class="app-buttom" type="primary" @click="handleSubmit()" shape="square" :color="$settingStore.themeColor.color">
  53. 确定({{ checkboxUserList.length + "/" + activeUserNumber }})
  54. </u-button>
  55. </view>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. import uniMallHead from "./mall-head.vue";
  61. import common from "@/plugins/common.plugins.js";
  62. export default {
  63. props: {
  64. userList: {
  65. type: Array,
  66. default: () => [],
  67. }, //人员列表汇总
  68. activeUserList: {
  69. type: Array,
  70. default: () => [],
  71. }, //选中人员列表
  72. defaultHeadList: {
  73. type: Object,
  74. default: () => {},
  75. },
  76. activeUserNumber: {
  77. type: Number,
  78. default: 200,
  79. }, //选中人员数量
  80. },
  81. components: {
  82. uniMallHead,
  83. },
  84. data() {
  85. return {
  86. currentData: [],
  87. checkboxList: [], //选中人员id数组
  88. checkboxUserData: [], //选中人员数组集合
  89. checkboxUserList: [], //选中人员label数组
  90. };
  91. },
  92. mounted() {
  93. this.init();
  94. if (this.activeUserList) {
  95. this.activeUserList.forEach((e) => {
  96. this.checkboxList.push(e.id);
  97. this.checkboxUserData.push(e);
  98. this.checkboxUserList.push(e.label);
  99. });
  100. }
  101. },
  102. methods: {
  103. init() {
  104. if (Object.keys(this.defaultHeadList).length > 0) {
  105. this.$refs.refUniMallHead.addTab(this.defaultHeadList);
  106. }
  107. this.currentData = this.userList;
  108. },
  109. tabChange(obj) {
  110. this.getCurrentData(obj.id, this.userList);
  111. },
  112. handelClickItem(item) {
  113. if (item.children && item.children.length > 0) {
  114. this.$refs.refUniMallHead.addTab({ label: item.label, id: item.id });
  115. this.currentData = item.children;
  116. this.currentData.forEach((e) => {
  117. this.checkboxUserData.forEach((f) => {
  118. if (e.id === f.id) {
  119. this.checkboxList.push(f.id);
  120. }
  121. });
  122. });
  123. } else if ("deptId" in item) {
  124. this.checkboxList = common.uniq(this.checkboxList);
  125. if (this.checkboxList.includes(item.userId)) {
  126. this.checkboxList.splice(this.checkboxList.indexOf(item.userId), 1);
  127. } else {
  128. this.checkboxList.push(item.userId);
  129. }
  130. this.checkboxChange(this.checkboxList);
  131. } else {
  132. this.$modal.msg("该部门下暂无可选择人员!");
  133. }
  134. // this.$emit("change", item);
  135. },
  136. getCurrentData(id, data) {
  137. if (id === this.defaultHeadList.id) {
  138. this.currentData = this.userList;
  139. } else {
  140. if (data.length > 0) {
  141. data.map((item) => {
  142. if (item.id === id) {
  143. this.currentData = item.children;
  144. }
  145. if (item.children && item.children.length > 0) {
  146. this.getCurrentData(id, item.children);
  147. }
  148. });
  149. }
  150. }
  151. },
  152. handleSubmit() {
  153. if (this.checkboxList.length > this.activeUserNumber) {
  154. this.$modal.msg(`最多选择${this.activeUserNumber}人!`);
  155. return;
  156. }
  157. this.$emit("submit", this.checkboxUserData);
  158. },
  159. checkboxChange(event) {
  160. this.currentData.forEach((f) => {
  161. if (event.includes(f.id)) {
  162. this.checkboxUserData.push(f);
  163. } else {
  164. this.checkboxUserData.forEach((e, index) => {
  165. if (e.id === f.id) {
  166. delete this.checkboxUserData[index];
  167. }
  168. });
  169. }
  170. });
  171. this.checkboxUserList = [];
  172. this.checkboxUserData = common.uniq(this.checkboxUserData, "id");
  173. this.checkboxUserData.forEach((e) => {
  174. this.checkboxUserList.push(e.label);
  175. });
  176. },
  177. },
  178. };
  179. </script>
  180. <style lang="scss" scoped>
  181. .box-head {
  182. position: fixed;
  183. left: 0px;
  184. width: 100%;
  185. height: 48px;
  186. background: #ffffff;
  187. padding-left: 17px;
  188. box-sizing: border-box;
  189. overflow-y: hidden;
  190. z-index: 999;
  191. }
  192. .box-list {
  193. padding-top: 52px;
  194. //#ifdef APP-PLUS || MP-WEIXIN
  195. padding-bottom: 60px;
  196. //#endif
  197. .box-list-item {
  198. position: relative;
  199. height: 60px;
  200. display: flex;
  201. align-items: center;
  202. padding: 0 15px;
  203. box-sizing: border-box;
  204. background: #ffffff;
  205. margin-bottom: 1px;
  206. &:active {
  207. background: #f2f3f4;
  208. }
  209. &:last-child {
  210. margin-bottom: 0px;
  211. }
  212. .box-list-item-department-pic {
  213. width: 40px;
  214. height: 40px;
  215. background: rgba(55, 127, 255, 0.1);
  216. border-radius: 4px;
  217. display: flex;
  218. align-items: center;
  219. justify-content: center;
  220. margin-right: 15px;
  221. overflow: hidden;
  222. image {
  223. width: 20px;
  224. height: 20px;
  225. }
  226. }
  227. .box-list-item-right {
  228. display: flex;
  229. align-items: center;
  230. justify-content: space-between;
  231. flex: 1;
  232. }
  233. .box-list-item-text {
  234. color: #333333;
  235. font-size: 14px;
  236. }
  237. .box-list-item-user-tag {
  238. text {
  239. box-sizing: border-box;
  240. border-radius: 8px;
  241. padding: 4px 8px;
  242. font-size: 10px;
  243. margin-left: 5px;
  244. &:first-child {
  245. margin-left: 0px;
  246. }
  247. &:nth-child(1) {
  248. background: rgba(49, 210, 144, 0.05);
  249. border: 1px solid #31d290;
  250. color: #31d290;
  251. }
  252. &:nth-child(2) {
  253. background: rgba(55, 127, 255, 0.05);
  254. border: 1px solid #377fff;
  255. color: #377fff;
  256. }
  257. }
  258. }
  259. &.box-list-item-department-icon {
  260. &::before {
  261. content: " ";
  262. height: 10px;
  263. width: 10px;
  264. border-width: 2px 2px 0 0;
  265. border-color: #c0c0c0;
  266. border-style: solid;
  267. transform: matrix(0.5, 0.5, -0.5, 0.5, 0, 0);
  268. position: absolute;
  269. top: 50%;
  270. margin-top: -6px;
  271. right: 14px;
  272. }
  273. }
  274. }
  275. .box-list-item-department + .box-list-item-user {
  276. margin-top: 10px;
  277. }
  278. }
  279. .box-foot {
  280. position: fixed;
  281. bottom: 0px;
  282. width: 100%;
  283. height: 60px;
  284. background: #ffffff;
  285. z-index: 999;
  286. box-shadow: 1px 1px 4px rgb(26 26 26 / 10%);
  287. display: flex;
  288. padding: 0 15px;
  289. &-left {
  290. margin: auto auto auto 0;
  291. &-count {
  292. color: #377fff;
  293. font-size: 14px;
  294. margin-bottom: 5px;
  295. }
  296. &-people {
  297. color: #999;
  298. font-size: 12px;
  299. }
  300. }
  301. &-right {
  302. margin: auto 0 auto 15px;
  303. }
  304. }
  305. </style>