index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. <template>
  2. <div class="user-index" :style="{ height: `calc(100vh - ${tabBarHeight}px)` }">
  3. <div class="user-header">
  4. <!-- <el-input class="search" v-model="input" placeholder="搜索">
  5. <template #prefix>
  6. <el-icon><search /></el-icon>
  7. </template>
  8. </el-input> -->
  9. <div class="button" @click="handleAddClient">
  10. <img src="@/assets/img/mine/firend-icon.png" alt="" />
  11. 新增客户
  12. </div>
  13. </div>
  14. <div class="list">
  15. <div class="map-container" ref="mapContainer"></div>
  16. <collapse v-model="activeNames" class="collapse-list">
  17. <collapse-item :name="index" v-for="(item, index) in dataList" :key="index" :is-link="false">
  18. <template #title>
  19. <el-icon class="icon"><CaretRight /></el-icon>
  20. {{ item.name }}
  21. <span class="span">{{ item.children?.length || 0 }}</span>
  22. </template>
  23. <!-- <template #value>
  24. <div @click.stop="hadnleManage(item)" class="text">管理</div>
  25. </template> -->
  26. <farm-info-card
  27. v-for="ele in item.children"
  28. :key="ele.agriculturalStoreId"
  29. class="list-item"
  30. :data="{
  31. ...ele,
  32. farmName: ele.name,
  33. userType: ele.userType || '--',
  34. variety: ele.speciesName,
  35. address: ele.address,
  36. noAction: true,
  37. maxWidth: '100%',
  38. customRight: 'tag-right',
  39. }"
  40. @click="handleItemClick(ele)"
  41. >
  42. <!-- <template #right>
  43. <el-popover title="" :popper-style="'min-width: 110px;'" :width="110" placement="left-start" trigger="click">
  44. <div class="tag-list">
  45. <div class="tag-item">全托管</div>
  46. <div class="tag-item">飞防托管</div>
  47. <div class="tag-item">营养托管</div>
  48. <div class="tag-item active">优质客户</div>
  49. </div>
  50. <template #reference>
  51. <div class="title-tag add-tag">标记为</div>
  52. </template>
  53. </el-popover>
  54. </template> -->
  55. <template #footerData>
  56. <div class="footer-data">
  57. <div class="footer-l">
  58. <div class="farm-info-footer-item">
  59. <div class="farm-info-footer-item-label">农事服务</div>
  60. <div class="farm-info-footer-item-value">{{ ele.serviceCost?.serviceCount || 0 }}<span class="unit">次</span></div>
  61. </div>
  62. <div class="farm-info-footer-item">
  63. <div class="farm-info-footer-item-label">总收益</div>
  64. <div class="farm-info-footer-item-value">{{ ele.serviceCost?.totalCost || 0 }}<span class="unit">元</span></div>
  65. </div>
  66. </div>
  67. <div class="footer-action" @click.stop="handleDetail('plan', ele.id, ele.agriculturalStoreId, ele.schemeId)">农事规划</div>
  68. </div>
  69. </template>
  70. </farm-info-card>
  71. </collapse-item>
  72. </collapse>
  73. </div>
  74. <!-- <div class="footer">
  75. <div class="btn" @click="showPopup">新建分组</div>
  76. </div> -->
  77. </div>
  78. <!-- 添加分组弹窗 -->
  79. <add-popup :show="showGroupPopup"></add-popup>
  80. <fn-share-sheet class="share-sheet" v-model:show="showShare" @select="onSelect" :options="[{ name: '微信', icon: 'wechat' }]" />
  81. </template>
  82. <script setup>
  83. import { Collapse, CollapseItem } from "vant";
  84. import { ref, onMounted, computed, nextTick, onActivated } from "vue";
  85. import wx from "weixin-js-sdk";
  86. import { useRouter } from "vue-router";
  87. import addPopup from "./components/addPopup.vue";
  88. import FarmInfoCard from "@/components/pageComponents/FarmInfoCard.vue";
  89. import { useStore } from "vuex";
  90. import FnShareSheet from "@/components/pageComponents/FnShareSheet.vue";
  91. import IndexMap from "../farm_manage/map/index";
  92. const router = useRouter();
  93. const store = useStore();
  94. const tabBarHeight = computed(() => store.state.home.tabBarHeight);
  95. const indexMap = new IndexMap();
  96. const mapContainer = ref(null);
  97. onMounted(() => {
  98. const point = store.state.home.miniUserLocationPoint;
  99. nextTick(() => {
  100. indexMap.initMap(point, mapContainer.value, true);
  101. });
  102. });
  103. onActivated(() => {
  104. // 确保地图已初始化,使用 nextTick 等待 DOM 更新
  105. nextTick(() => {
  106. // 检查地图实例是否已初始化,并且绑定到正确的容器
  107. const isMapValid = indexMap.kmap &&
  108. indexMap.kmap.map &&
  109. mapContainer.value &&
  110. indexMap.kmap.map.getTargetElement() === mapContainer.value;
  111. if (!isMapValid) {
  112. // 如果地图未初始化或绑定到错误的容器,重新初始化
  113. if (mapContainer.value) {
  114. const point = store.state.home.miniUserLocationPoint;
  115. indexMap.initMap(point, mapContainer.value, true);
  116. // 等待地图初始化完成后再加载数据
  117. setTimeout(() => {
  118. getUserList();
  119. }, 200);
  120. } else {
  121. getUserList();
  122. }
  123. } else {
  124. // 如果地图已初始化且绑定正确,更新地图尺寸(解决页面切换后地图不显示的问题)
  125. setTimeout(() => {
  126. indexMap.kmap.map.updateSize();
  127. }, 100);
  128. // 地图已存在,直接加载数据(数据加载完成后会自动调用 initData 更新缩放)
  129. getUserList();
  130. }
  131. });
  132. });
  133. const activeNames = ref([1]);
  134. const dataList = ref([
  135. {
  136. name: "Vip客户",
  137. isGroup: 0,
  138. children: [],
  139. },
  140. {
  141. name: "农场客户",
  142. isGroup: 1,
  143. children: [],
  144. },
  145. ]);
  146. const getUserList = async () => {
  147. const { data } = await VE_API.farm.userFarmSelectOption({ agriculturalQuery: true });
  148. if (data.length) {
  149. indexMap.initData(data, 'name','point');
  150. // 清空现有的子项
  151. dataList.value[0].children = [];
  152. dataList.value[1].children = data || [];
  153. // 为每个数据项的ID请求getFarmPastServiceCost,并将返回的数据添加到每一项中
  154. const promises = data.map(async (item) => {
  155. const farmId = item.id || item.farmId;
  156. if (farmId) {
  157. try {
  158. const { data: serviceCostData } = await VE_API.user.getFarmPastServiceCost({ farmId });
  159. // 将返回的数据添加到当前项中
  160. return {
  161. ...item,
  162. serviceCost: serviceCostData || {},
  163. };
  164. } catch (error) {
  165. console.error(`获取农场 ${farmId} 的服务成本失败:`, error);
  166. // 如果请求失败,返回原数据
  167. return {
  168. ...item,
  169. serviceCost: {},
  170. };
  171. }
  172. }
  173. return item;
  174. });
  175. // 等待所有请求完成
  176. const updatedData = await Promise.all(promises);
  177. // 更新数据列表
  178. dataList.value[1].children = updatedData;
  179. }
  180. };
  181. const getLatestBroadcast = () => {
  182. VE_API.user.getLatestBroadcast({sourceTypes:[0,1]}).then(({ data }) => {
  183. if (data && typeof data === 'object') {
  184. // 遍历广播数据,key 是 farmId(字符串格式)
  185. Object.keys(data).forEach(farmIdStr => {
  186. const farmId = Number(farmIdStr);
  187. const broadcasts = data[farmIdStr] || [];
  188. // 在农场列表中找到对应的农场
  189. const farmItem = dataList.value[1].children.find(item => item.id === farmId || item.farmId === farmId);
  190. if (farmItem && broadcasts.length > 0) {
  191. // 将广播数据合并到农场项中
  192. farmItem.broadcasts = broadcasts;
  193. }
  194. });
  195. }
  196. });
  197. };
  198. const input = ref("");
  199. //新建分组
  200. const showGroupPopup = ref(false);
  201. const showPopup = () => {
  202. showGroupPopup.value = !showGroupPopup.value;
  203. };
  204. // 新增客户
  205. const handleAddClient = () => {
  206. router.push("/create_farm?type=client&from=user");
  207. };
  208. // 管理
  209. const hadnleManage = (value) => {
  210. router.push(`/user_manage?name=${value.name}&total=${value.children.length}&isGroup=${value.isGroup}`);
  211. };
  212. const showShare = ref(false);
  213. const onSelect = () => {
  214. const query = {
  215. agriculturalStoreId: shareData.value.agriculturalStoreId,
  216. farmId: shareData.value.id,
  217. speciesName: shareData.value.speciesName,
  218. containerId: shareData.value.containerId,
  219. };
  220. wx.miniProgram.navigateTo({
  221. url: `/pages/subPages/share_page/index?pageParams=${JSON.stringify(query)}&type=shareFarm`,
  222. });
  223. };
  224. const shareData = ref({});
  225. // 在线沟通
  226. const handleChat = (data) => {
  227. if(data.receiveUserId){
  228. router.push(`/chat_frame?userId=${data.receiveUserId}&farmId=${data.id}`);
  229. }else{
  230. showShare.value = true;
  231. shareData.value = data;
  232. }
  233. };
  234. // 处理列表项点击
  235. const handleItemClick = (data) => {
  236. router.push(`/farm_details?farmId=${data.id}&agriculturalStoreId=${data.agriculturalStoreId}&receiveUserId=${data.receiveUserId}`);
  237. };
  238. const handleDetail = (path, farmId, agriculturalStoreId, schemeId) => {
  239. router.push(`/${path}?farmId=${farmId}&agriculturalStoreId=${agriculturalStoreId}&schemeId=${schemeId}`);
  240. };
  241. </script>
  242. <style lang="scss" scoped>
  243. .user-index {
  244. width: 100%;
  245. height: 100vh;
  246. box-sizing: border-box;
  247. padding: 10px 12px;
  248. background: #f5f7fb;
  249. .user-header {
  250. display: flex;
  251. align-items: center;
  252. justify-content: space-between;
  253. .search {
  254. width: 90px;
  255. margin-right: 10px;
  256. --el-input-placeholder-color: rgba(0, 0, 0, 0.5);
  257. ::v-deep {
  258. .el-input__wrapper {
  259. box-shadow: none;
  260. border: 1px solid rgba(0, 0, 0, 0.5);
  261. background: transparent;
  262. border-radius: 20px;
  263. }
  264. .el-input__prefix,
  265. .el-input__inner {
  266. color: #000;
  267. }
  268. }
  269. }
  270. .button {
  271. width: 100%;
  272. background: #fff;
  273. display: flex;
  274. align-items: center;
  275. justify-content: center;
  276. padding: 8px;
  277. border-radius: 20px;
  278. img {
  279. width: 20px;
  280. height: 17px;
  281. margin-right: 6px;
  282. }
  283. }
  284. }
  285. .list {
  286. width: 100%;
  287. margin-top: 12px;
  288. height: calc(100% - 36px);
  289. overflow: auto;
  290. padding-bottom: 12px;
  291. box-sizing: border-box;
  292. .map-container {
  293. width: 100%;
  294. height: 162px;
  295. clip-path: inset(0px round 8px);
  296. margin-bottom: 10px;
  297. }
  298. .collapse-list {
  299. // height: 100%;
  300. }
  301. .text {
  302. color: #7c7c7c;
  303. }
  304. ::v-deep {
  305. .van-collapse-item__content {
  306. padding: 0;
  307. background: #F5F7FB;
  308. }
  309. .van-cell {
  310. border-radius: 5px 5px 0 0;
  311. justify-content: space-between;
  312. .van-cell__value {
  313. flex: none;
  314. }
  315. .van-cell__title {
  316. display: flex;
  317. align-items: center;
  318. .icon {
  319. margin-right: 3px;
  320. color: #bfbfbf;
  321. font-size: 16px;
  322. }
  323. .span {
  324. color: rgba(0, 0, 0, 0.4);
  325. margin-left: 10px;
  326. }
  327. }
  328. }
  329. .van-collapse-item__title--expanded {
  330. .van-cell__title {
  331. .icon {
  332. transform: rotate(90deg);
  333. }
  334. }
  335. }
  336. .van-collapse-item + .van-collapse-item {
  337. margin-top: 12px;
  338. }
  339. }
  340. .list-item {
  341. margin-top: 10px;
  342. }
  343. .add-tag {
  344. font-size: 12px;
  345. color: #2199f8;
  346. line-height: 24px;
  347. }
  348. .footer-data {
  349. display: flex;
  350. align-items: center;
  351. justify-content: space-between;
  352. gap: 12px;
  353. margin-top: 12px;
  354. .footer-l {
  355. display: flex;
  356. gap: 8px;
  357. flex: 1;
  358. .farm-info-footer-item {
  359. display: flex;
  360. align-items: baseline;
  361. border: 0.4px solid rgba(215, 215, 215, 0.5);
  362. padding: 8px 5px 5px;
  363. box-sizing: border-box;
  364. .farm-info-footer-item-label {
  365. font-size: 12px;
  366. color: rgba(32, 32, 32, 0.4);
  367. margin-bottom: 4px;
  368. }
  369. .farm-info-footer-item-value {
  370. font-size: 16px;
  371. color: #202020;
  372. padding-left: 2px;
  373. .unit {
  374. font-size: 12px;
  375. padding-left: 2px;
  376. color: rgba(32, 32, 32, 0.4);
  377. }
  378. }
  379. }
  380. }
  381. .footer-action {
  382. border: 0.5px solid #888B8D;
  383. border-radius: 20px;
  384. padding: 5px 12px;
  385. font-size: 12px;
  386. color: #888B8D;
  387. white-space: nowrap;
  388. cursor: pointer;
  389. flex-shrink: 0;
  390. }
  391. }
  392. }
  393. .footer {
  394. display: flex;
  395. flex-direction: column;
  396. align-items: center;
  397. margin-top: 12px;
  398. .btn {
  399. font-size: 12px;
  400. color: #7f7f7f;
  401. padding: 5px 45px;
  402. background: rgba(201, 201, 201, 0.27);
  403. border-radius: 20px;
  404. }
  405. }
  406. }
  407. .tag-list {
  408. font-size: 14px;
  409. .tag-item + .tag-item {
  410. margin-top: 6px;
  411. }
  412. .tag-item {
  413. padding: 2px 8px;
  414. text-align: center;
  415. &.active {
  416. color: #2199f8;
  417. background: rgba(33, 153, 248, 0.16);
  418. border-radius: 4px;
  419. }
  420. }
  421. }
  422. </style>