index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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: '90px',
  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">10<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">1450<span class="unit">元</span></div>
  64. </div>
  65. </div>
  66. <div class="footer-action" @click.stop="handleDetail('plan', ele.id, ele.agriculturalStoreId)">农事规划</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. // 地图使用筛选后的数据
  122. const wktArr = ["POINT (113.10930176274309 22.574540836684672)", "POINT (113.407189 23.032344)"]
  123. data.map((item, index) => {
  124. item.point = wktArr[Math.floor(Math.random() * wktArr.length)]
  125. });
  126. indexMap.initData(data, 'name');
  127. // 清空现有的子项
  128. dataList.value[0].children = [];
  129. dataList.value[1].children = data || [];
  130. getLatestBroadcast();
  131. }
  132. };
  133. const getLatestBroadcast = () => {
  134. VE_API.user.getLatestBroadcast({sourceTypes:[0,1]}).then(({ data }) => {
  135. if (data && typeof data === 'object') {
  136. // 遍历广播数据,key 是 farmId(字符串格式)
  137. Object.keys(data).forEach(farmIdStr => {
  138. const farmId = Number(farmIdStr);
  139. const broadcasts = data[farmIdStr] || [];
  140. // 在农场列表中找到对应的农场
  141. const farmItem = dataList.value[1].children.find(item => item.id === farmId || item.farmId === farmId);
  142. if (farmItem && broadcasts.length > 0) {
  143. // 将广播数据合并到农场项中
  144. farmItem.broadcasts = broadcasts;
  145. }
  146. });
  147. }
  148. });
  149. };
  150. const input = ref("");
  151. //新建分组
  152. const showGroupPopup = ref(false);
  153. const showPopup = () => {
  154. showGroupPopup.value = !showGroupPopup.value;
  155. };
  156. // 新增客户
  157. const handleAddClient = () => {
  158. router.push("/create_farm?type=client&from=user");
  159. };
  160. // 管理
  161. const hadnleManage = (value) => {
  162. router.push(`/user_manage?name=${value.name}&total=${value.children.length}&isGroup=${value.isGroup}`);
  163. };
  164. const showShare = ref(false);
  165. const onSelect = () => {
  166. const query = {
  167. agriculturalStoreId: shareData.value.agriculturalStoreId,
  168. farmId: shareData.value.id,
  169. speciesName: shareData.value.speciesName,
  170. containerId: shareData.value.containerId,
  171. };
  172. wx.miniProgram.navigateTo({
  173. url: `/pages/subPages/share_page/index?pageParams=${JSON.stringify(query)}&type=shareFarm`,
  174. });
  175. };
  176. const shareData = ref({});
  177. // 在线沟通
  178. const handleChat = (data) => {
  179. if(data.receiveUserId){
  180. router.push(`/chat_frame?userId=${data.receiveUserId}&farmId=${data.id}`);
  181. }else{
  182. showShare.value = true;
  183. shareData.value = data;
  184. }
  185. };
  186. // 处理列表项点击
  187. const handleItemClick = (data) => {
  188. router.push(`/farm_details?farmId=${data.id}&agriculturalStoreId=${data.agriculturalStoreId}&receiveUserId=${data.receiveUserId}`);
  189. };
  190. const handleDetail = (path, farmId, agriculturalStoreId) => {
  191. router.push(`/${path}?farmId=${farmId}&agriculturalStoreId=${agriculturalStoreId}`);
  192. };
  193. </script>
  194. <style lang="scss" scoped>
  195. .user-index {
  196. width: 100%;
  197. height: 100vh;
  198. box-sizing: border-box;
  199. padding: 10px 12px;
  200. background: #f5f7fb;
  201. .user-header {
  202. display: flex;
  203. align-items: center;
  204. justify-content: space-between;
  205. .search {
  206. width: 90px;
  207. margin-right: 10px;
  208. --el-input-placeholder-color: rgba(0, 0, 0, 0.5);
  209. ::v-deep {
  210. .el-input__wrapper {
  211. box-shadow: none;
  212. border: 1px solid rgba(0, 0, 0, 0.5);
  213. background: transparent;
  214. border-radius: 20px;
  215. }
  216. .el-input__prefix,
  217. .el-input__inner {
  218. color: #000;
  219. }
  220. }
  221. }
  222. .button {
  223. width: calc(100% - 100px);
  224. background: #fff;
  225. display: flex;
  226. align-items: center;
  227. justify-content: center;
  228. padding: 8px;
  229. border-radius: 20px;
  230. img {
  231. width: 20px;
  232. height: 17px;
  233. margin-right: 6px;
  234. }
  235. }
  236. }
  237. .list {
  238. width: 100%;
  239. margin-top: 12px;
  240. height: calc(100% - 90px);
  241. overflow: auto;
  242. .map-container {
  243. width: 100%;
  244. height: 162px;
  245. clip-path: inset(0px round 8px);
  246. margin-bottom: 10px;
  247. }
  248. .collapse-list {
  249. // height: 100%;
  250. }
  251. .text {
  252. color: #7c7c7c;
  253. }
  254. ::v-deep {
  255. .van-collapse-item__content {
  256. padding: 0;
  257. background: #F5F7FB;
  258. }
  259. .van-cell {
  260. border-radius: 5px 5px 0 0;
  261. justify-content: space-between;
  262. .van-cell__value {
  263. flex: none;
  264. }
  265. .van-cell__title {
  266. display: flex;
  267. align-items: center;
  268. .icon {
  269. margin-right: 3px;
  270. color: #bfbfbf;
  271. font-size: 16px;
  272. }
  273. .span {
  274. color: rgba(0, 0, 0, 0.4);
  275. margin-left: 10px;
  276. }
  277. }
  278. }
  279. .van-collapse-item__title--expanded {
  280. .van-cell__title {
  281. .icon {
  282. transform: rotate(90deg);
  283. }
  284. }
  285. }
  286. .van-collapse-item + .van-collapse-item {
  287. margin-top: 12px;
  288. }
  289. }
  290. .list-item {
  291. margin-top: 10px;
  292. }
  293. .add-tag {
  294. font-size: 12px;
  295. color: #2199f8;
  296. line-height: 24px;
  297. }
  298. .footer-data {
  299. display: flex;
  300. align-items: center;
  301. justify-content: space-between;
  302. gap: 12px;
  303. margin-top: 12px;
  304. .footer-l {
  305. display: flex;
  306. gap: 8px;
  307. flex: 1;
  308. .farm-info-footer-item {
  309. display: flex;
  310. align-items: baseline;
  311. border: 0.4px solid rgba(215, 215, 215, 0.5);
  312. padding: 8px 5px 5px;
  313. box-sizing: border-box;
  314. .farm-info-footer-item-label {
  315. font-size: 12px;
  316. color: rgba(32, 32, 32, 0.4);
  317. margin-bottom: 4px;
  318. }
  319. .farm-info-footer-item-value {
  320. font-size: 16px;
  321. color: #202020;
  322. padding-left: 2px;
  323. .unit {
  324. font-size: 12px;
  325. padding-left: 2px;
  326. color: rgba(32, 32, 32, 0.4);
  327. }
  328. }
  329. }
  330. }
  331. .footer-action {
  332. border: 0.5px solid #888B8D;
  333. border-radius: 20px;
  334. padding: 5px 12px;
  335. font-size: 12px;
  336. color: #888B8D;
  337. white-space: nowrap;
  338. cursor: pointer;
  339. flex-shrink: 0;
  340. }
  341. }
  342. }
  343. .footer {
  344. display: flex;
  345. flex-direction: column;
  346. align-items: center;
  347. margin-top: 12px;
  348. .btn {
  349. font-size: 12px;
  350. color: #7f7f7f;
  351. padding: 5px 45px;
  352. background: rgba(201, 201, 201, 0.27);
  353. border-radius: 20px;
  354. }
  355. }
  356. }
  357. .tag-list {
  358. font-size: 14px;
  359. .tag-item + .tag-item {
  360. margin-top: 6px;
  361. }
  362. .tag-item {
  363. padding: 2px 8px;
  364. text-align: center;
  365. &.active {
  366. color: #2199f8;
  367. background: rgba(33, 153, 248, 0.16);
  368. border-radius: 4px;
  369. }
  370. }
  371. }
  372. </style>