clientList.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. <template>
  2. <div class="list-wrap">
  3. <div class="list-content">
  4. <el-collapse v-model="activeNames" expand-icon-position="left">
  5. <el-collapse-item
  6. title="Consistency"
  7. v-for="(group, groupIndex) in groupList"
  8. :key="groupIndex"
  9. :name="groupIndex"
  10. >
  11. <template #title="{ isActive }">
  12. <div :class="['title-wrapper', { 'is-active': isActive }]">
  13. <div class="title-l">
  14. <el-icon class="arrow-icon"><CaretTop /></el-icon>
  15. {{ group.name }}
  16. <span class="group-length">({{ group.list.length }})</span>
  17. </div>
  18. <div class="title-r" @click.stop="handleRightClick">
  19. <span class="title-manage">管理</span>
  20. <el-checkbox
  21. v-show="toSelectClient"
  22. v-model="groupCheckStates[groupIndex].checkAll"
  23. :indeterminate="groupCheckStates[groupIndex].isIndeterminate"
  24. @change="(val) => handleCheckAllChange(val, groupIndex)"
  25. >
  26. 全选
  27. </el-checkbox>
  28. </div>
  29. </div>
  30. </template>
  31. <template #icon> </template>
  32. <!-- 遍历当前分组中的每一项 -->
  33. <div v-show="!group.list.length" class="no-data">暂无数据</div>
  34. <div v-show="group.list.length">
  35. <el-checkbox-group v-model="checkedCities" @change="handleCheckedCitiesChange">
  36. <div v-for="(ele, index) in group.list" :key="index" class="list-item">
  37. <el-checkbox v-show="toSelectClient" label="" :value="ele.tel"> </el-checkbox>
  38. <div class="item-flex">
  39. <img
  40. class="photo"
  41. :src="
  42. ele.icon || 'https://birdseye-img.sysuimars.com/dinggou-mini/defalut-icon.png'
  43. "
  44. alt=""
  45. />
  46. <div class="item-text">
  47. <div class="name">
  48. <span>{{ ele.name }}</span>
  49. <el-icon
  50. class="icon"
  51. @click.stop="handlePerson('edit', ele)"
  52. color="#2199F8"
  53. size="16"
  54. ><Edit
  55. /></el-icon>
  56. </div>
  57. <div><span class="item-title">电话:</span>{{ ele.tel }}</div>
  58. <div><span class="item-title">地址:</span>{{ ele.address || "--" }}</div>
  59. </div>
  60. <!-- <div class="blue-btn" @click="toCustomOneTree(ele)">去分配</div> -->
  61. </div>
  62. </div>
  63. </el-checkbox-group>
  64. </div>
  65. </el-collapse-item>
  66. </el-collapse>
  67. <div class="no-data" v-show="!groupList.length">暂无数据</div>
  68. </div>
  69. <!-- 渐变主色按钮 -->
  70. <div class="center-btn" v-show="!toSelectClient" @click="toCustomPage">一键分配</div>
  71. <div class="global-wrap" v-show="toSelectClient">
  72. <div class="global-btn" @click="handleGlobalCheckAllChange">全选</div>
  73. </div>
  74. </div>
  75. <!-- 新增客户、编辑客户 -->
  76. <edit-client-popup ref="editClientRef" @updateGroupList="getUserList"></edit-client-popup>
  77. </template>
  78. <script setup>
  79. import { ref, reactive, onMounted, watch } from "vue";
  80. import { Collapse, CollapseItem, Checkbox, Popup } from "vant";
  81. import EditClientPopup from "@/components/editClientPopup.vue";
  82. import { useRouter } from "vue-router";
  83. const router = useRouter();
  84. const props = defineProps({
  85. // 是否显示选择客户
  86. checkDistributeShow: {
  87. type: Boolean,
  88. default: false,
  89. },
  90. // 是否开始重新加载列表
  91. startReloadList: {
  92. type: Boolean,
  93. default: false,
  94. },
  95. });
  96. // const curIndex = ref(0)
  97. const handlePerson = (type, data) => {
  98. editClientRef.value.openClientPopup(type, data);
  99. };
  100. const editClientRef = ref(null);
  101. const activeNames = ref([0]);
  102. const groupList = ref([]);
  103. const toSelectClient = ref(false);
  104. function toCustomPage() {
  105. toSelectClient.value = true;
  106. // toSelectClient.value = !toSelectClient.value;
  107. // eventBus.emit("startBoxSelect", toSelectClient.value);
  108. emit("update:checkDistributeShow", toSelectClient.value);
  109. // router.push("/layout/customTree");
  110. }
  111. const handleGlobalCheckAllChange = (val) => {
  112. if (val) {
  113. // 全选所有项目
  114. checkedCities.value = groupList.value.flatMap((group) => group.list.map((item) => item.tel));
  115. } else {
  116. // 清空所有选择
  117. checkedCities.value = [];
  118. }
  119. // 更新所有分组的状态
  120. groupList.value.forEach((_, index) => {
  121. updateGroupCheckStatus(index);
  122. });
  123. };
  124. function toCustomOneTree(data) {
  125. router.push("/layout/customTree?type=single&data=" + JSON.stringify(data));
  126. }
  127. onMounted(() => {
  128. getUserList();
  129. });
  130. function getUserList() {
  131. VE_API.manage_interface.fetchGroupList({ farmId: 766, isAllot: 0 }).then(({ data }) => {
  132. // defalutList.value = data
  133. groupList.value = Object.keys(data)
  134. .filter(key => data[key] && data[key].length > 0) // 先过滤掉空的 key
  135. .map(key => ({
  136. name: key,
  137. list: data[key]
  138. }));
  139. initGroupCheckStates(); // 初始化分组选择状态
  140. });
  141. }
  142. const checkedCities = ref([]);
  143. // 使用一个对象来存储每个分组的全选状态
  144. const groupCheckStates = ref({});
  145. // 初始化分组选择状态
  146. const initGroupCheckStates = () => {
  147. groupList.value.forEach((group, index) => {
  148. groupCheckStates.value[index] = {
  149. checkAll: false,
  150. isIndeterminate: false,
  151. };
  152. });
  153. };
  154. // 修改后的全选处理方法
  155. const handleCheckAllChange = (val, groupIndex) => {
  156. const currentGroup = groupList.value[groupIndex];
  157. if (val) {
  158. // 添加当前分组的所有项到选中列表
  159. currentGroup.list.forEach((item) => {
  160. if (!checkedCities.value.includes(item.tel)) {
  161. checkedCities.value.push(item.tel);
  162. }
  163. });
  164. } else {
  165. // 移除当前分组的所有项
  166. checkedCities.value = checkedCities.value.filter(
  167. (name) => !currentGroup.list.some((item) => item.tel === name)
  168. );
  169. }
  170. updateGroupCheckStatus(groupIndex);
  171. };
  172. // 更新分组的选择状态
  173. const updateGroupCheckStatus = (groupIndex) => {
  174. const currentGroup = groupList.value[groupIndex];
  175. const checkedCount = currentGroup.list.filter((item) => checkedCities.value.includes(item.tel)).length;
  176. groupCheckStates.value[groupIndex].checkAll = checkedCount === currentGroup.list.length;
  177. groupCheckStates.value[groupIndex].isIndeterminate = checkedCount > 0 && checkedCount < currentGroup.list.length;
  178. emit("update:checkData", checkedCities.value);
  179. };
  180. // 修改 handleCheckedCitiesChange 方法
  181. const handleCheckedCitiesChange = (value) => {
  182. // 遍历所有分组,更新每个分组的选中状态
  183. groupList.value.forEach((group, groupIndex) => {
  184. updateGroupCheckStatus(groupIndex);
  185. });
  186. };
  187. function handleRightClick() {
  188. // 点击事件处理
  189. }
  190. watch(
  191. () => props.checkDistributeShow,
  192. (newVal) => {
  193. if (newVal === false) {
  194. toSelectClient.value = false; // 如果显示选择客户,则切换到选择客户模式
  195. // 清空所有选择
  196. checkedCities.value = [];
  197. initGroupCheckStates(); // 初始化分组选择状态
  198. }
  199. }
  200. );
  201. watch(
  202. () => props.startReloadList,
  203. (newVal) => {
  204. if (newVal) {
  205. getUserList(); // 重新加载用户列表
  206. }
  207. }
  208. );
  209. const emit = defineEmits(["update:checkDistributeShow", "update:checkData"]);
  210. </script>
  211. <style lang="scss" scoped>
  212. .list-wrap {
  213. width: 100%;
  214. height: 100%;
  215. position: relative;
  216. .list-header {
  217. display: flex;
  218. align-items: center;
  219. justify-content: space-between;
  220. .search {
  221. width: 90px;
  222. margin-right: 10px;
  223. --el-input-placeholder-color: rgba(255, 212, 137, 0.6);
  224. ::v-deep {
  225. .el-input__wrapper {
  226. box-shadow: none;
  227. border: 1px solid rgba(255, 212, 137, 0.6);
  228. background: transparent;
  229. }
  230. .el-input__prefix,
  231. .el-input__inner {
  232. color: rgba(255, 212, 137, 0.6);
  233. }
  234. }
  235. }
  236. .button {
  237. width: calc(100% - 100px);
  238. color: #ffd489;
  239. background: rgba(255, 212, 137, 0.06);
  240. border: 1px solid rgba(255, 212, 137, 0.3);
  241. display: flex;
  242. align-items: center;
  243. justify-content: center;
  244. padding: 8px;
  245. border-radius: 5px;
  246. cursor: pointer;
  247. img {
  248. width: 20px;
  249. height: 17px;
  250. margin-right: 6px;
  251. }
  252. }
  253. }
  254. .list-content {
  255. width: 100%;
  256. height: calc(100% - 56px);
  257. overflow: auto;
  258. padding: 0 8px;
  259. box-sizing: border-box;
  260. &.max-height {
  261. height: calc(100% - 50px - 55px);
  262. }
  263. .text {
  264. color: #ffd489;
  265. cursor: pointer;
  266. }
  267. .no-data {
  268. text-align: center;
  269. color: rgba(0, 0, 0, 0.6);
  270. }
  271. ::v-deep {
  272. .el-collapse-item__arrow {
  273. display: none;
  274. }
  275. .el-collapse-item__header {
  276. &.is-active {
  277. .arrow-icon {
  278. transform: rotate(180deg);
  279. }
  280. }
  281. }
  282. .el-collapse {
  283. border-color: transparent;
  284. }
  285. .van-cell:after,
  286. .van-collapse-item--border:after,
  287. .van-hairline--top-bottom:after {
  288. border: none !important;
  289. }
  290. .van-cell {
  291. border-radius: 5px 5px 0 0;
  292. justify-content: space-between;
  293. background: rgba(255, 255, 255, 0.08);
  294. color: #fff;
  295. .van-cell__value {
  296. flex: none;
  297. }
  298. .van-cell__title {
  299. display: flex;
  300. align-items: center;
  301. .icon {
  302. margin-right: 3px;
  303. color: #bfbfbf;
  304. font-size: 16px;
  305. }
  306. .span {
  307. color: rgba(255, 255, 255, 0.4);
  308. margin-left: 10px;
  309. }
  310. }
  311. }
  312. .van-collapse-item__content {
  313. background: transparent;
  314. padding: 10px 0 0 0;
  315. }
  316. .van-collapse-item__title--expanded {
  317. .van-cell__title {
  318. .icon {
  319. transform: rotate(90deg);
  320. }
  321. }
  322. }
  323. .van-collapse-item + .van-collapse-item {
  324. margin-top: 12px;
  325. }
  326. .van-checkbox__icon--checked .van-icon {
  327. background-color: #f7be5a;
  328. border-color: #f7be5a;
  329. color: #000;
  330. }
  331. }
  332. .title-wrapper {
  333. width: 100%;
  334. display: flex;
  335. align-items: center;
  336. justify-content: space-between;
  337. .arrow-icon {
  338. transition: transform 0.3s ease;
  339. }
  340. &.is-active {
  341. .arrow-icon {
  342. transform: rotate(90deg);
  343. }
  344. }
  345. .title-r {
  346. color: #2199f8;
  347. font-size: 14px;
  348. display: flex;
  349. align-items: center;
  350. .title-manage {
  351. margin-right: 10px;
  352. }
  353. ::v-deep {
  354. .el-checkbox {
  355. color: #2199f8;
  356. }
  357. }
  358. }
  359. }
  360. .group-length {
  361. color: rgba(0, 0, 0, 0.4);
  362. font-size: 12px;
  363. }
  364. .list-item {
  365. border-radius: 6px;
  366. position: relative;
  367. display: flex;
  368. align-items: center;
  369. background: rgba(120, 120, 120, 0.05);
  370. border: 1px solid transparent;
  371. padding: 8px 10px;
  372. &.active {
  373. background: rgba(243, 193, 29, 0.1);
  374. border-color: #ffd489;
  375. }
  376. .checkbox {
  377. margin-right: 12px;
  378. }
  379. .item-flex {
  380. display: flex;
  381. align-items: center;
  382. justify-content: space-between;
  383. width: 100%;
  384. .blue-btn {
  385. cursor: pointer;
  386. color: #ffffff;
  387. font-size: 12px;
  388. padding: 5px 15px;
  389. border-radius: 20px;
  390. background: #2199f8;
  391. }
  392. }
  393. .photo {
  394. width: 63px;
  395. height: 63px;
  396. border-radius: 8px;
  397. margin-right: 12px;
  398. }
  399. .item-text {
  400. color: #999999;
  401. font-size: 12px;
  402. line-height: 1.6;
  403. flex: 1;
  404. .name {
  405. display: flex;
  406. align-items: center;
  407. span {
  408. font-size: 14px;
  409. color: #000000;
  410. font-weight: 500;
  411. margin-right: 5px;
  412. }
  413. .icon {
  414. cursor: pointer;
  415. }
  416. }
  417. .item-title {
  418. color: #666666;
  419. }
  420. }
  421. }
  422. .list-item + .list-item {
  423. margin-top: 12px;
  424. }
  425. }
  426. .center-btn {
  427. position: absolute;
  428. bottom: 9px;
  429. left: 50%;
  430. transform: translateX(-50%);
  431. color: #ffffff;
  432. border-radius: 20px;
  433. font-size: 14px;
  434. padding: 7px 10px;
  435. cursor: pointer;
  436. border: 1px solid #fff;
  437. background: linear-gradient(180deg, #84c9ff, #2199f8);
  438. width: 194px;
  439. box-sizing: border-box;
  440. text-align: center;
  441. }
  442. .global-wrap {
  443. width: 100%;
  444. padding-top: 17px;
  445. box-shadow: 4px 0 4px rgba(0, 0, 0, 0.2);
  446. padding-top: 12px;
  447. box-shadow: 4px 0 4px rgba(0, 0, 0, 0.2);
  448. text-align: center;
  449. margin: 0 auto;
  450. padding-bottom: 11px;
  451. display: flex;
  452. align-items: center;
  453. justify-content: center;
  454. .global-btn {
  455. height: 38px;
  456. width: 168px;
  457. display: flex;
  458. align-items: center;
  459. justify-content: center;
  460. background: #2199f8;
  461. color: #fff;
  462. border-radius: 4px;
  463. }
  464. }
  465. .list-footer {
  466. position: absolute;
  467. bottom: 0;
  468. left: 0;
  469. width: 100%;
  470. background: rgba(255, 255, 255, 0.08);
  471. display: flex;
  472. justify-content: center;
  473. box-sizing: border-box;
  474. padding: 11px;
  475. .settings {
  476. background: rgba(255, 255, 255, 0.1);
  477. border-radius: 4px;
  478. padding: 8px 36px;
  479. color: #fff;
  480. cursor: pointer;
  481. }
  482. .flex {
  483. display: flex;
  484. align-items: center;
  485. }
  486. .delete {
  487. border: 1px solid #ffd489;
  488. border-radius: 4px;
  489. padding: 8px 19px;
  490. color: #ffd489;
  491. cursor: pointer;
  492. }
  493. .operation {
  494. width: 100%;
  495. justify-content: space-between;
  496. .btn-group {
  497. div {
  498. background: rgba(255, 255, 255, 0.1);
  499. padding: 8px 19px;
  500. border-radius: 4px;
  501. cursor: pointer;
  502. }
  503. .add {
  504. margin-right: 10px;
  505. }
  506. }
  507. }
  508. .controls {
  509. width: 100%;
  510. justify-content: space-between;
  511. .personnel {
  512. width: calc(100% - 100px);
  513. .circle {
  514. width: 16px;
  515. height: 16px;
  516. background: #ffd489;
  517. border-radius: 50%;
  518. justify-content: center;
  519. margin-right: 8px;
  520. }
  521. .text {
  522. width: 90%;
  523. }
  524. }
  525. .delete {
  526. background: #ffd489;
  527. color: #000;
  528. width: 85px;
  529. box-sizing: border-box;
  530. text-align: center;
  531. padding: 8px;
  532. }
  533. }
  534. }
  535. }
  536. </style>