index.vue 14 KB

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