index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. <collapse v-model="activeNames" class="collapse-list">
  16. <collapse-item :name="index" v-for="(item, index) in dataList" :key="index" :is-link="false">
  17. <template #title>
  18. <el-icon class="icon"><CaretRight /></el-icon>
  19. {{ item.name }}
  20. <span class="span">{{ item.children?.length || 0 }}</span>
  21. </template>
  22. <template #value>
  23. <div @click.stop="hadnleManage(item)" class="text">管理</div>
  24. </template>
  25. <farm-info-card
  26. v-for="ele in item.children"
  27. :key="ele.agriculturalStoreId"
  28. class="list-item"
  29. :data="{
  30. ...ele,
  31. farmName: ele.name,
  32. area: ele.mianji + '亩',
  33. variety: ele.speciesName,
  34. address: ele.address,
  35. maxWidth: '90px',
  36. }"
  37. @click="handleItemClick(ele)"
  38. >
  39. <template #right>
  40. <div @click.stop="handleChat(ele)">{{ ele.receiveUserId ? '在线沟通' : '分享认领' }}</div>
  41. </template>
  42. </farm-info-card>
  43. </collapse-item>
  44. </collapse>
  45. </div>
  46. <div class="footer">
  47. <div class="btn" @click="showPopup">新建分组</div>
  48. </div>
  49. </div>
  50. <!-- 添加分组弹窗 -->
  51. <add-popup :show="showGroupPopup"></add-popup>
  52. <fn-share-sheet class="share-sheet" v-model:show="showShare" @select="onSelect" :options="[{ name: '微信', icon: 'wechat' }]" />
  53. </template>
  54. <script setup>
  55. import { Collapse, CollapseItem } from "vant";
  56. import { ref, onMounted, computed } from "vue";
  57. import wx from "weixin-js-sdk";
  58. import { useRouter } from "vue-router";
  59. import addPopup from "./components/addPopup.vue";
  60. import FarmInfoCard from "@/components/pageComponents/FarmInfoCard.vue";
  61. import { useStore } from "vuex";
  62. import FnShareSheet from "@/components/pageComponents/FnShareSheet.vue";
  63. const router = useRouter();
  64. const store = useStore();
  65. const tabBarHeight = computed(() => store.state.home.tabBarHeight);
  66. onMounted(() => {
  67. getUserList();
  68. });
  69. const activeNames = ref([1]);
  70. const dataList = ref([
  71. {
  72. name: "Vip客户",
  73. isGroup: 0,
  74. children: [],
  75. },
  76. {
  77. name: "农场客户",
  78. isGroup: 1,
  79. children: [],
  80. },
  81. ]);
  82. const getUserList = async () => {
  83. const { data } = await VE_API.farm.userFarmSelectOption({ agriculturalQuery: true });
  84. if (data.length) {
  85. // 清空现有的子项
  86. dataList.value[0].children = [];
  87. dataList.value[1].children = data || [];
  88. getLatestBroadcast();
  89. }
  90. };
  91. const getLatestBroadcast = () => {
  92. VE_API.user.getLatestBroadcast({sourceTypes:[0,1]}).then(({ data }) => {
  93. if (data && typeof data === 'object') {
  94. // 遍历广播数据,key 是 farmId(字符串格式)
  95. Object.keys(data).forEach(farmIdStr => {
  96. const farmId = Number(farmIdStr);
  97. const broadcasts = data[farmIdStr] || [];
  98. // 在农场列表中找到对应的农场
  99. const farmItem = dataList.value[1].children.find(item => item.id === farmId || item.farmId === farmId);
  100. if (farmItem && broadcasts.length > 0) {
  101. // 将广播数据合并到农场项中
  102. farmItem.broadcasts = broadcasts;
  103. }
  104. });
  105. }
  106. });
  107. };
  108. const input = ref("");
  109. //新建分组
  110. const showGroupPopup = ref(false);
  111. const showPopup = () => {
  112. showGroupPopup.value = !showGroupPopup.value;
  113. };
  114. // 新增客户
  115. const handleAddClient = () => {
  116. router.push("/create_farm?type=client&from=user");
  117. };
  118. // 管理
  119. const hadnleManage = (value) => {
  120. router.push(`/user_manage?name=${value.name}&total=${value.children.length}&isGroup=${value.isGroup}`);
  121. };
  122. const showShare = ref(false);
  123. const onSelect = () => {
  124. const query = {
  125. agriculturalStoreId: shareData.value.agriculturalStoreId,
  126. farmId: shareData.value.id,
  127. speciesName: shareData.value.speciesName,
  128. containerId: shareData.value.containerId,
  129. };
  130. wx.miniProgram.navigateTo({
  131. url: `/pages/subPages/share_page/index?pageParams=${JSON.stringify(query)}&type=shareFarm`,
  132. });
  133. };
  134. const shareData = ref({});
  135. // 在线沟通
  136. const handleChat = (data) => {
  137. if(data.receiveUserId){
  138. router.push(`/chat_frame?userId=${data.receiveUserId}&farmId=${data.id}`);
  139. }else{
  140. showShare.value = true;
  141. shareData.value = data;
  142. }
  143. };
  144. // 处理列表项点击
  145. const handleItemClick = (data) => {
  146. router.push(`/farm_details?farmId=${data.id}&agriculturalStoreId=${data.agriculturalStoreId}&receiveUserId=${data.receiveUserId}`);
  147. };
  148. </script>
  149. <style lang="scss" scoped>
  150. .user-index {
  151. width: 100%;
  152. height: 100vh;
  153. box-sizing: border-box;
  154. padding: 10px 12px;
  155. background: #f5f7fb;
  156. .user-header {
  157. display: flex;
  158. align-items: center;
  159. justify-content: space-between;
  160. .search {
  161. width: 90px;
  162. margin-right: 10px;
  163. --el-input-placeholder-color: rgba(0, 0, 0, 0.5);
  164. ::v-deep {
  165. .el-input__wrapper {
  166. box-shadow: none;
  167. border: 1px solid rgba(0, 0, 0, 0.5);
  168. background: transparent;
  169. border-radius: 20px;
  170. }
  171. .el-input__prefix,
  172. .el-input__inner {
  173. color: #000;
  174. }
  175. }
  176. }
  177. .button {
  178. width: calc(100% - 100px);
  179. background: #fff;
  180. display: flex;
  181. align-items: center;
  182. justify-content: center;
  183. padding: 8px;
  184. border-radius: 20px;
  185. img {
  186. width: 20px;
  187. height: 17px;
  188. margin-right: 6px;
  189. }
  190. }
  191. }
  192. .list {
  193. width: 100%;
  194. margin-top: 12px;
  195. height: calc(100% - 90px);
  196. .collapse-list {
  197. height: 100%;
  198. overflow: auto;
  199. }
  200. .text {
  201. color: #7c7c7c;
  202. }
  203. ::v-deep {
  204. .van-collapse-item__content {
  205. padding: 0;
  206. }
  207. .van-cell {
  208. border-radius: 5px 5px 0 0;
  209. justify-content: space-between;
  210. .van-cell__value {
  211. flex: none;
  212. }
  213. .van-cell__title {
  214. display: flex;
  215. align-items: center;
  216. .icon {
  217. margin-right: 3px;
  218. color: #bfbfbf;
  219. font-size: 16px;
  220. }
  221. .span {
  222. color: rgba(0, 0, 0, 0.4);
  223. margin-left: 10px;
  224. }
  225. }
  226. }
  227. .van-collapse-item__title--expanded {
  228. .van-cell__title {
  229. .icon {
  230. transform: rotate(90deg);
  231. }
  232. }
  233. }
  234. .van-collapse-item + .van-collapse-item {
  235. margin-top: 12px;
  236. }
  237. }
  238. .list-item {
  239. & + .list-item {
  240. margin: 0;
  241. }
  242. }
  243. }
  244. .footer {
  245. display: flex;
  246. flex-direction: column;
  247. align-items: center;
  248. margin-top: 12px;
  249. .btn {
  250. font-size: 12px;
  251. color: #7f7f7f;
  252. padding: 5px 45px;
  253. background: rgba(201, 201, 201, 0.27);
  254. border-radius: 20px;
  255. }
  256. }
  257. }
  258. </style>