clientList.vue 19 KB

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