clientList.vue 21 KB

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