index.vue 13 KB

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