clientList.vue 18 KB

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