interact.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. <template>
  2. <div class="task-page" :style="{ height: `calc(100vh - ${tabBarHeight}px - 50px)` }">
  3. <div class="task-top">
  4. <div class="map-container" ref="mapContainer"></div>
  5. </div>
  6. <div class="task-list">
  7. <!-- <div class="list-filter">
  8. <div class="filter-item" :class="{ active: activeIndex === 0 }" @click="handleActiveFilter(0)">
  9. 待确认({{ taskCounts[0] || 0 }})
  10. </div>
  11. <div class="filter-item" :class="{ active: activeIndex === 2 }" @click="handleActiveFilter(2)">
  12. 已确认({{ taskCounts[2] || 0 }})
  13. </div>
  14. <div class="filter-item" :class="{ active: activeIndex === 3 }" @click="handleActiveFilter(3)">
  15. 待提醒({{ taskCounts[3] || 0 }})
  16. </div>
  17. </div> -->
  18. <!-- <div class="select-group">
  19. <el-select
  20. class="select-item"
  21. v-model="selectParma.farmWorkTypeId"
  22. placeholder="用户类型"
  23. @change="getSimpleList"
  24. >
  25. <el-option v-for="item in farmWorkTypeList" :key="item.id" :label="item.name" :value="item.id" />
  26. </el-select>
  27. <el-select
  28. class="select-item"
  29. v-model="selectParma.districtCode"
  30. placeholder="切换作物"
  31. @change="getSimpleList"
  32. >
  33. <el-option v-for="item in districtList" :key="item.code" :label="item.name" :value="item.code" />
  34. </el-select>
  35. </div> -->
  36. <van-list
  37. v-model:loading="loadingMore"
  38. :finished="finished"
  39. finished-text=""
  40. @load="onLoad"
  41. :immediate-check="false"
  42. >
  43. <div class="task-content" v-loading="loading && taskList.length === 0">
  44. <div class="task-item" v-for="(item, index) in taskList" :key="item.id || index">
  45. <div class="img-text-wrap">
  46. <div class="left-wrap">
  47. <div class="left-img">
  48. <img src="@/assets/img/home/farm.png" alt="" />
  49. </div>
  50. <div class="right-text">
  51. <div class="farm-info">
  52. <div class="farm-name van-ellipsis">{{ item?.farmName }}</div>
  53. <div class="info-tag-wrap">
  54. <div class="tag-item primary">
  55. {{ item?.typeName }}
  56. </div>
  57. <div class="tag-item" :class="{ 'second': item.userType === 2 }">{{ item.userType === 1 ? '普通客户' : '托管客户' }}</div>
  58. </div>
  59. </div>
  60. <div class="farm-addr">{{ item?.address }}</div>
  61. </div>
  62. </div>
  63. <div class="right-wrap" @click.stop="handleRemindCustomer(item)">提醒客户</div>
  64. </div>
  65. <div class="item-bottom">
  66. <div class="bottom-tag">
  67. <div class="tag-card" :class="{ active: item.sourceData?.daysUntilNext < 5 }">
  68. <div class="card-content">
  69. <div class="card-main-text">{{ item.sourceData?.currentPhenologyName || '--' }}</div>
  70. <div class="card-sub-text">
  71. 当前物候期
  72. <!-- <span class="card-icon" @click="handleSelectCurrentPhenology(item)">
  73. <el-icon><Edit /></el-icon>
  74. </span> -->
  75. </div>
  76. </div>
  77. </div>
  78. <div class="tag-card">
  79. <div class="card-content">
  80. <div class="card-main-text">{{ item.sourceData?.currentPhenologyStartDate || '--' }}</div>
  81. <div class="card-sub-text">起始时间</div>
  82. </div>
  83. </div>
  84. <div class="tag-card">
  85. <div class="card-content">
  86. <div class="card-main-text">{{ item.sourceData?.daysUntilNext || '--' }}天</div>
  87. <div class="card-sub-text">预计下次物候</div>
  88. </div>
  89. </div>
  90. </div>
  91. <!-- 时间轴组件 -->
  92. <AgriculturalInteractionCard :item="item" @updateList="resetAndLoad" />
  93. </div>
  94. </div>
  95. <div class="empty-data" v-if="!loading && taskList.length === 0">暂无数据</div>
  96. </div>
  97. </van-list>
  98. </div>
  99. </div>
  100. <upload-execute ref="uploadExecuteRef" :onlyShare="onlyShare" @uploadSuccess="handleUploadSuccess" />
  101. <!-- 服务报价单 -->
  102. <price-sheet-popup :key="activeIndex" ref="priceSheetPopupRef"></price-sheet-popup>
  103. <!-- 新增:激活上传弹窗 -->
  104. <active-upload-popup ref="activeUploadPopupRef" @handleUploadSuccess="handleUploadSuccess"></active-upload-popup>
  105. </template>
  106. <script setup>
  107. import { computed, nextTick, onActivated, onMounted, ref, watch } from "vue";
  108. import { useRoute } from "vue-router";
  109. import { useStore } from "vuex";
  110. import { List as VanList } from "vant";
  111. import IndexMap from "../../farm_manage/map/index";
  112. import { useRouter } from "vue-router";
  113. import uploadExecute from "./uploadExecute.vue";
  114. import priceSheetPopup from "@/components/popup/priceSheetPopup.vue";
  115. import { ElMessage } from "element-plus";
  116. import activeUploadPopup from "@/components/popup/activeUploadPopup.vue";
  117. import AgriculturalInteractionCard from "@/components/pageComponents/AgriculturalInteractionCard.vue";
  118. const store = useStore();
  119. const router = useRouter();
  120. const route = useRoute();
  121. const indexMap = new IndexMap();
  122. const mapContainer = ref(null);
  123. const tabBarHeight = computed(() => store.state.home.tabBarHeight);
  124. const uploadExecuteRef = ref(null);
  125. const selectParma = ref({
  126. farmWorkTypeId: null,
  127. districtCode: null,
  128. });
  129. // 任务列表数据(用于显示,可能被筛选)
  130. const taskList = ref([]);
  131. // 各状态任务数量
  132. const taskCounts = ref([0, 0, 0]);
  133. // 当前选中的筛选索引
  134. const activeIndex = ref(2);
  135. const noData = ref(false);
  136. const loading = ref(true);
  137. // 分页相关
  138. const page = ref(0);
  139. const limit = ref(10);
  140. const loadingMore = ref(false);
  141. const finished = ref(false);
  142. // 查询未来农事预警
  143. const getFutureFarmWorkWarning = async (item) => {
  144. const res = await VE_API.home.listFutureFarmWorkWarning({ farmId: item.farmId });
  145. item.timelineList = res.data || [];
  146. };
  147. const taskItemRefs = ref([]);
  148. const handleUploadSuccess = async () => {
  149. // 刷新列表
  150. await resetAndLoad();
  151. // 等待 DOM 更新完成,refs 被重新收集
  152. await nextTick();
  153. // 更新所有task-item的triggerImg
  154. taskItemRefs.value.forEach((ref) => {
  155. if (ref && ref.updateTriggerImg) {
  156. ref.updateTriggerImg();
  157. }
  158. });
  159. };
  160. const cityCode = ref("");
  161. //根据城市的坐标返回区县列表
  162. const districtList = ref([]);
  163. function getDistrictListByCity() {
  164. VE_API.z_farm_work_record.getDistrictListByCity({ point: mapPoint.value }).then(({ data }) => {
  165. districtList.value = data || [];
  166. // cityCode.value = data[0].code.slice(0, -2);
  167. cityCode.value = "";
  168. districtList.value.unshift({ code: cityCode.value, name: "全部" });
  169. selectParma.value.districtCode = cityCode.value;
  170. resetAndLoad();
  171. });
  172. }
  173. //农事类型列表
  174. const farmWorkTypeList = ref([]);
  175. function getFarmWorkTypeList() {
  176. VE_API.z_farm_work_record.getFarmWorkTypeList().then(({ data }) => {
  177. farmWorkTypeList.value = data;
  178. farmWorkTypeList.value.unshift({ id: 0, name: "全部" });
  179. });
  180. }
  181. const mapPoint = ref(null);
  182. onMounted(() => {
  183. mapPoint.value = store.state.home.miniUserLocationPoint;
  184. // getDistrictListByCity();
  185. resetAndLoad();
  186. getFarmWorkTypeList();
  187. nextTick(() => {
  188. indexMap.initMap(mapPoint.value, mapContainer.value, true);
  189. });
  190. });
  191. onActivated(() => {
  192. if (route.query.noReload) {
  193. return;
  194. }
  195. // 确保地图已初始化,使用 nextTick 等待 DOM 更新
  196. nextTick(() => {
  197. // 检查地图实例是否已初始化
  198. if (!indexMap.kmap) {
  199. // 如果地图未初始化,重新初始化
  200. if (mapContainer.value) {
  201. mapPoint.value = store.state.home.miniUserLocationPoint;
  202. indexMap.initMap(mapPoint.value, mapContainer.value, true);
  203. // 等待地图初始化完成后再加载数据
  204. setTimeout(() => {
  205. resetAndLoad();
  206. }, 300);
  207. return;
  208. }
  209. } else {
  210. // 如果地图已初始化,需要等待 tab 切换完成,容器完全可见后再更新尺寸
  211. // Tab 切换时容器可能被隐藏,需要更长的延迟确保容器可见
  212. if (mapContainer.value && indexMap.kmap.map) {
  213. // 检查容器是否可见
  214. const checkAndUpdateSize = () => {
  215. const container = mapContainer.value;
  216. if (container) {
  217. const rect = container.getBoundingClientRect();
  218. // 如果容器可见(有宽度和高度),更新地图尺寸
  219. if (rect.width > 0 && rect.height > 0) {
  220. indexMap.kmap.map.updateSize();
  221. } else {
  222. // 如果容器不可见,继续等待
  223. setTimeout(checkAndUpdateSize, 100);
  224. }
  225. }
  226. };
  227. // 延迟检查,确保 tab 切换完成
  228. setTimeout(checkAndUpdateSize, 200);
  229. }
  230. }
  231. resetAndLoad();
  232. });
  233. });
  234. // 监听 activeIndex 变化,重新加载数据
  235. watch(activeIndex, () => {
  236. resetAndLoad();
  237. });
  238. // 加载列表数据(支持分页)
  239. async function getSimpleList(isLoadMore = false) {
  240. if (!isLoadMore) {
  241. // 重置分页
  242. page.value = 0;
  243. finished.value = false;
  244. taskList.value = [];
  245. taskItemRefs.value = [];
  246. loading.value = true;
  247. } else {
  248. loadingMore.value = true;
  249. }
  250. const params = {
  251. ...selectParma.value,
  252. page: page.value,
  253. limit: limit.value,
  254. flowStatus: 5,
  255. };
  256. try {
  257. const { data } = await VE_API.home.listUnansweredFarms(params);
  258. if (data && data.length > 0) {
  259. // 为每个item初始化timelineList
  260. const newItems = data.map((item) => {
  261. let sourceData = item?.latestPhenologyProgressBroadcast?.sourceData;
  262. if (sourceData) {
  263. try {
  264. sourceData = JSON.parse(sourceData);
  265. } catch (e) {
  266. console.error("解析sourceData失败:", e);
  267. sourceData = null;
  268. }
  269. }
  270. return {
  271. ...item,
  272. sourceData,
  273. timelineList: [],
  274. };
  275. });
  276. // 串行请求,为每个农场获取时间轴数据
  277. for (let i = 0; i < newItems.length; i++) {
  278. await getFutureFarmWorkWarning(newItems[i]);
  279. }
  280. // 追加数据
  281. const newTaskList = [...taskList.value, ...newItems];
  282. taskList.value = newTaskList.filter(item => item.timelineList.length > 0);
  283. // 更新分页
  284. page.value += 1;
  285. // 判断是否还有更多数据
  286. if (data.length < limit.value) {
  287. finished.value = true;
  288. }
  289. // 更新地图数据
  290. indexMap.initData(taskList.value,'','farmPoint');
  291. } else {
  292. finished.value = true;
  293. if (taskList.value.length === 0) {
  294. noData.value = true;
  295. }
  296. }
  297. // 数据处理完成后再设置loading为false
  298. if (!isLoadMore) {
  299. loading.value = false;
  300. } else {
  301. loadingMore.value = false;
  302. }
  303. } catch (error) {
  304. console.error("获取任务列表失败:", error);
  305. if (!isLoadMore) {
  306. loading.value = false;
  307. } else {
  308. loadingMore.value = false;
  309. }
  310. finished.value = true;
  311. if (taskList.value.length === 0) {
  312. noData.value = true;
  313. }
  314. }
  315. }
  316. // 滚动加载更多
  317. const onLoad = () => {
  318. if (!finished.value && !loadingMore.value) {
  319. getSimpleList(true);
  320. }
  321. };
  322. // 重置并重新加载
  323. const resetAndLoad = () => {
  324. getSimpleList(false);
  325. };
  326. function handleActiveFilter(i) {
  327. activeIndex.value = i;
  328. selectParma.value.districtCode = cityCode.value;
  329. selectParma.value.farmWorkTypeId = null;
  330. }
  331. const showUploadExecutePopup = (item) => {
  332. if (item?.executeEvidence.length) {
  333. onlyShare.value = true;
  334. } else {
  335. onlyShare.value = false;
  336. }
  337. setTimeout(() => {
  338. uploadExecuteRef.value.showPopup(item);
  339. }, 10);
  340. };
  341. function toDetail(item) {
  342. // if (activeIndex.value === 0) {
  343. // router.push({
  344. // path: "/modify_work",
  345. // query: { id: item.id },
  346. // });
  347. // } else {
  348. // }
  349. router.push({
  350. path: "/completed_work",
  351. query: { miniJson: JSON.stringify({ id: item.id }) },
  352. });
  353. }
  354. const onlyShare = ref(false);
  355. const phenologyList = ref([
  356. {
  357. id: 1,
  358. name: "花芽分化",
  359. },
  360. {
  361. id: 2,
  362. name: "开花",
  363. },
  364. {
  365. id: 3,
  366. name: "成熟",
  367. },
  368. ]);
  369. const activeUploadPopupRef = ref(null);
  370. function handleSelectCurrentPhenology(item) {
  371. activeUploadPopupRef.value.showPopup({
  372. gardenIdVal: item.farmId,
  373. problemTitleVal: "进入 物候期 的时间",
  374. imgDescVal: "请上传凭证(转入农事任务凭证)",
  375. arrangeIdVal: item.farmWorkArrangeId,
  376. selectCurrentPhenologyVal: true,
  377. phenologyListVal: phenologyList.value,
  378. });
  379. }
  380. function handleRemindCustomer(item) {
  381. router.push({
  382. path: "/remind_customer",
  383. query: { farmId: item.farmId },
  384. });
  385. }
  386. </script>
  387. <style lang="scss" scoped>
  388. .task-page {
  389. width: 100%;
  390. height: calc(100vh - 50px - 50px);
  391. overflow: auto;
  392. box-sizing: border-box;
  393. background: #f5f7fb;
  394. .map-container {
  395. width: 100%;
  396. height: 162px;
  397. clip-path: inset(0px round 8px);
  398. }
  399. .select-group {
  400. display: flex;
  401. padding: 0px 12px 0 12px;
  402. .select-item {
  403. width: 100%;
  404. ::v-deep {
  405. .el-select__wrapper {
  406. text-align: center;
  407. gap: 2px;
  408. box-shadow: none;
  409. justify-content: center;
  410. background: none;
  411. }
  412. .el-select__selection {
  413. flex: none;
  414. width: fit-content;
  415. }
  416. .el-select__placeholder {
  417. position: static;
  418. transform: none;
  419. width: fit-content;
  420. color: rgba(0, 0, 0, 0.2);
  421. }
  422. .el-select__caret {
  423. color: rgba(0, 0, 0, 0.2);
  424. }
  425. }
  426. }
  427. }
  428. .task-top {
  429. padding: 10px 12px 0 12px;
  430. }
  431. .task-content-loading {
  432. height: 80px;
  433. border-radius: 8px;
  434. position: absolute;
  435. top: 60px;
  436. left: 0;
  437. width: 100%;
  438. }
  439. .task-content {
  440. min-height: 80px;
  441. }
  442. .empty-data {
  443. text-align: center;
  444. font-size: 14px;
  445. color: #6f7274;
  446. padding: 20px 0;
  447. }
  448. .task-list {
  449. position: relative;
  450. background: #fff;
  451. padding: 12px 12px 8px 12px;
  452. }
  453. .list-filter {
  454. display: flex;
  455. align-items: center;
  456. justify-content: space-around;
  457. .filter-item {
  458. padding: 0 12px;
  459. height: 28px;
  460. color: rgba(0, 0, 0, 0.5);
  461. font-size: 14px;
  462. line-height: 28px;
  463. border-radius: 20px;
  464. &.active {
  465. color: #2199f8;
  466. background: rgba(33, 153, 248, 0.2);
  467. }
  468. }
  469. }
  470. .task-item {
  471. border-radius: 12px;
  472. border: 0.3px solid rgba(0, 0, 0, 0.2);
  473. padding: 12px;
  474. }
  475. .task-item + .task-item {
  476. margin-top: 10px;
  477. }
  478. .img-text-wrap {
  479. display: flex;
  480. align-items: flex-start;
  481. justify-content: space-between;
  482. padding-bottom: 10px;
  483. border-bottom: 0.5px solid rgba(0, 0, 0, 0.1);
  484. .left-wrap {
  485. display: flex;
  486. align-items: center;
  487. width: calc(100% - 45px);
  488. .left-img {
  489. width: 40px;
  490. height: 40px;
  491. border-radius: 6px;
  492. img {
  493. width: 100%;
  494. height: 100%;
  495. object-fit: contain;
  496. }
  497. }
  498. .right-text {
  499. padding-left: 8px;
  500. width: calc(100% - 50px);
  501. .farm-info {
  502. font-size: 14px;
  503. color: #1d2129;
  504. display: flex;
  505. align-items: center;
  506. .farm-name{
  507. max-width: calc(100% - 133px);
  508. }
  509. .info-tag-wrap {
  510. margin-left: 10px;
  511. display: flex;
  512. align-items: center;
  513. gap: 4px;
  514. .tag-item {
  515. height: 20px;
  516. line-height: 20px;
  517. padding: 0 8px;
  518. border-radius: 2px;
  519. font-size: 12px;
  520. color: #848282;
  521. background-color: rgba(148, 148, 148, 0.1);
  522. &.second {
  523. color: #ff953d;
  524. background: rgba(255, 149, 61, 0.1);
  525. }
  526. &.primary {
  527. color: #2199f8;
  528. background: #e8f3ff;
  529. }
  530. }
  531. }
  532. }
  533. .farm-addr {
  534. padding-top: 2px;
  535. font-size: 12px;
  536. color: #86909c;
  537. }
  538. }
  539. }
  540. .right-wrap {
  541. display: flex;
  542. align-items: center;
  543. justify-content: center;
  544. text-align: center;
  545. color: #fff;
  546. background: #2199f8;
  547. font-size: 12px;
  548. flex: none;
  549. width: 44px;
  550. height: 44px;
  551. padding: 8px;
  552. border-radius: 5px;
  553. box-sizing: border-box;
  554. .click-item {
  555. display: flex;
  556. align-items: center;
  557. gap: 2px;
  558. }
  559. .follow-text {
  560. color: #d0d0d0;
  561. }
  562. }
  563. }
  564. .item-bottom {
  565. padding-top: 10px;
  566. .bottom-tag {
  567. display: flex;
  568. gap: 10px;
  569. .tag-card {
  570. flex: 1;
  571. border-radius: 2px;
  572. padding: 4px;
  573. box-sizing: border-box;
  574. border: 0.4px solid rgba(215, 215, 215, 0.5);
  575. .card-content {
  576. display: flex;
  577. flex-direction: column;
  578. align-items: center;
  579. justify-content: center;
  580. text-align: center;
  581. height: 100%;
  582. .card-main-text {
  583. font-size: 16px;
  584. font-weight: 500;
  585. color: #202020;
  586. margin-bottom: 2px;
  587. }
  588. .card-sub-text {
  589. font-size: 10px;
  590. color: rgba(32, 32, 32, 0.4);
  591. display: flex;
  592. align-items: center;
  593. gap: 4px;
  594. .card-icon {
  595. display: inline-flex;
  596. align-items: center;
  597. justify-content: center;
  598. width: 12px;
  599. height: 12px;
  600. color: #2199f8;
  601. }
  602. }
  603. }
  604. &.active {
  605. background: rgba(33, 153, 248, 0.1);
  606. border: 0.5px solid #2199f8;
  607. .card-content {
  608. .card-main-text {
  609. color: #2199f8;
  610. }
  611. .card-sub-text {
  612. color: #2199f8;
  613. }
  614. }
  615. }
  616. }
  617. }
  618. }
  619. .item-footer {
  620. margin-top: 10px;
  621. padding-top: 11px;
  622. border-top: 1px solid rgba(0, 0, 0, 0.1);
  623. display: flex;
  624. align-items: center;
  625. justify-content: space-between;
  626. font-size: 12px;
  627. .footer-l {
  628. color: #8b8b8b;
  629. font-size: 12px;
  630. &.primary-btn {
  631. display: inline-flex;
  632. align-items: center;
  633. border: 1px solid #2199f8;
  634. background: rgba(33, 153, 248, 0.1);
  635. padding: 0 12px;
  636. height: 32px;
  637. box-sizing: border-box;
  638. display: flex;
  639. align-items: center;
  640. border-radius: 20px;
  641. color: #2199f8;
  642. .share-icon {
  643. width: 12px;
  644. padding-right: 4px;
  645. }
  646. }
  647. &.farm-name-text {
  648. font-size: 14px;
  649. color: #6f7274;
  650. .name-text {
  651. padding-left: 4px;
  652. }
  653. }
  654. }
  655. .footer-r {
  656. display: flex;
  657. align-items: center;
  658. .btn {
  659. height: 32px;
  660. line-height: 32px;
  661. padding: 0 12px;
  662. border-radius: 20px;
  663. display: flex;
  664. align-items: center;
  665. box-sizing: border-box;
  666. &.second {
  667. // border: 1px solid #8B8B8B;
  668. // color: #8B8B8B;
  669. color: #2199f8;
  670. background: rgba(33, 153, 248, 0.1);
  671. }
  672. &.primary {
  673. background: #2199f8;
  674. color: #fff;
  675. }
  676. .btn-icon {
  677. padding-right: 4px;
  678. }
  679. &.warning {
  680. color: #ff953d;
  681. background: #fff;
  682. border: 1px solid #ff953d;
  683. }
  684. &.secondary-text {
  685. color: #2199f8;
  686. border: 1px solid #2199f8;
  687. }
  688. }
  689. .btn + .btn {
  690. margin-left: 8px;
  691. }
  692. }
  693. }
  694. }
  695. </style>