interact.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  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 active">
  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">冲梢风险</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(false);
  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. resetAndLoad();
  196. });
  197. // 监听 activeIndex 变化,重新加载数据
  198. watch(activeIndex, () => {
  199. resetAndLoad();
  200. });
  201. // 加载列表数据(支持分页)
  202. async function getSimpleList(isLoadMore = false) {
  203. if (!isLoadMore) {
  204. // 重置分页
  205. page.value = 0;
  206. finished.value = false;
  207. taskList.value = [];
  208. taskItemRefs.value = [];
  209. loading.value = true;
  210. } else {
  211. loadingMore.value = true;
  212. }
  213. const params = {
  214. ...selectParma.value,
  215. page: page.value,
  216. limit: limit.value,
  217. flowStatus: 5,
  218. };
  219. try {
  220. const { data } = await VE_API.home.listUnansweredFarms(params);
  221. if (!isLoadMore) {
  222. loading.value = false;
  223. } else {
  224. loadingMore.value = false;
  225. }
  226. if (data && data.length > 0) {
  227. // 为每个item初始化timelineList
  228. const newItems = data.map((item) => {
  229. let sourceData = item?.latestPhenologyProgressBroadcast?.sourceData;
  230. if (sourceData) {
  231. try {
  232. sourceData = JSON.parse(sourceData);
  233. } catch (e) {
  234. console.error("解析sourceData失败:", e);
  235. sourceData = null;
  236. }
  237. }
  238. return {
  239. ...item,
  240. sourceData,
  241. timelineList: [],
  242. };
  243. });
  244. // 串行请求,为每个农场获取时间轴数据
  245. for (let i = 0; i < newItems.length; i++) {
  246. await getFutureFarmWorkWarning(newItems[i]);
  247. }
  248. // 追加数据
  249. const newTaskList = [...taskList.value, ...newItems];
  250. taskList.value = newTaskList.filter(item => item.timelineList.length > 0);
  251. // 更新分页
  252. page.value += 1;
  253. // 判断是否还有更多数据
  254. if (data.length < limit.value) {
  255. finished.value = true;
  256. }
  257. // 更新地图数据
  258. indexMap.initData(taskList.value,'','farmPoint');
  259. } else {
  260. finished.value = true;
  261. if (taskList.value.length === 0) {
  262. noData.value = true;
  263. }
  264. }
  265. } catch (error) {
  266. console.error("获取任务列表失败:", error);
  267. if (!isLoadMore) {
  268. loading.value = false;
  269. } else {
  270. loadingMore.value = false;
  271. }
  272. finished.value = true;
  273. if (taskList.value.length === 0) {
  274. noData.value = true;
  275. }
  276. }
  277. }
  278. // 滚动加载更多
  279. const onLoad = () => {
  280. if (!finished.value && !loadingMore.value) {
  281. getSimpleList(true);
  282. }
  283. };
  284. // 重置并重新加载
  285. const resetAndLoad = () => {
  286. getSimpleList(false);
  287. };
  288. function handleActiveFilter(i) {
  289. activeIndex.value = i;
  290. selectParma.value.districtCode = cityCode.value;
  291. selectParma.value.farmWorkTypeId = null;
  292. }
  293. const showUploadExecutePopup = (item) => {
  294. if (item?.executeEvidence.length) {
  295. onlyShare.value = true;
  296. } else {
  297. onlyShare.value = false;
  298. }
  299. setTimeout(() => {
  300. uploadExecuteRef.value.showPopup(item);
  301. }, 10);
  302. };
  303. function toDetail(item) {
  304. // if (activeIndex.value === 0) {
  305. // router.push({
  306. // path: "/modify_work",
  307. // query: { id: item.id },
  308. // });
  309. // } else {
  310. // }
  311. router.push({
  312. path: "/completed_work",
  313. query: { miniJson: JSON.stringify({ id: item.id }) },
  314. });
  315. }
  316. const onlyShare = ref(false);
  317. const phenologyList = ref([
  318. {
  319. id: 1,
  320. name: "花芽分化",
  321. },
  322. {
  323. id: 2,
  324. name: "开花",
  325. },
  326. {
  327. id: 3,
  328. name: "成熟",
  329. },
  330. ]);
  331. const activeUploadPopupRef = ref(null);
  332. function handleSelectCurrentPhenology(item) {
  333. activeUploadPopupRef.value.showPopup({
  334. gardenIdVal: item.farmId,
  335. problemTitleVal: "进入 物候期 的时间",
  336. imgDescVal: "请上传凭证(转入农事任务凭证)",
  337. arrangeIdVal: item.farmWorkArrangeId,
  338. selectCurrentPhenologyVal: true,
  339. phenologyListVal: phenologyList.value,
  340. });
  341. }
  342. function handleRemindCustomer(item) {
  343. router.push({
  344. path: "/remind_customer",
  345. query: { farmId: item.farmId },
  346. });
  347. }
  348. </script>
  349. <style lang="scss" scoped>
  350. .task-page {
  351. width: 100%;
  352. height: calc(100vh - 50px - 50px);
  353. overflow: auto;
  354. box-sizing: border-box;
  355. background: #f5f7fb;
  356. .map-container {
  357. width: 100%;
  358. height: 162px;
  359. clip-path: inset(0px round 8px);
  360. }
  361. .select-group {
  362. display: flex;
  363. padding: 0px 12px 0 12px;
  364. .select-item {
  365. width: 100%;
  366. ::v-deep {
  367. .el-select__wrapper {
  368. text-align: center;
  369. gap: 2px;
  370. box-shadow: none;
  371. justify-content: center;
  372. background: none;
  373. }
  374. .el-select__selection {
  375. flex: none;
  376. width: fit-content;
  377. }
  378. .el-select__placeholder {
  379. position: static;
  380. transform: none;
  381. width: fit-content;
  382. color: rgba(0, 0, 0, 0.2);
  383. }
  384. .el-select__caret {
  385. color: rgba(0, 0, 0, 0.2);
  386. }
  387. }
  388. }
  389. }
  390. .task-top {
  391. padding: 10px 12px 0 12px;
  392. }
  393. .task-content-loading {
  394. height: 80px;
  395. border-radius: 8px;
  396. position: absolute;
  397. top: 60px;
  398. left: 0;
  399. width: 100%;
  400. }
  401. .task-content {
  402. min-height: 80px;
  403. }
  404. .empty-data {
  405. text-align: center;
  406. font-size: 14px;
  407. color: #6f7274;
  408. padding: 20px 0;
  409. }
  410. .task-list {
  411. position: relative;
  412. background: #fff;
  413. padding: 12px 12px 8px 12px;
  414. }
  415. .list-filter {
  416. display: flex;
  417. align-items: center;
  418. justify-content: space-around;
  419. .filter-item {
  420. padding: 0 12px;
  421. height: 28px;
  422. color: rgba(0, 0, 0, 0.5);
  423. font-size: 14px;
  424. line-height: 28px;
  425. border-radius: 20px;
  426. &.active {
  427. color: #2199f8;
  428. background: rgba(33, 153, 248, 0.2);
  429. }
  430. }
  431. }
  432. .task-item {
  433. border-radius: 12px;
  434. border: 0.3px solid rgba(0, 0, 0, 0.2);
  435. padding: 12px;
  436. }
  437. .task-item + .task-item {
  438. margin-top: 10px;
  439. }
  440. .img-text-wrap {
  441. display: flex;
  442. align-items: flex-start;
  443. justify-content: space-between;
  444. padding-bottom: 10px;
  445. border-bottom: 0.5px solid rgba(0, 0, 0, 0.1);
  446. .left-wrap {
  447. display: flex;
  448. align-items: center;
  449. width: calc(100% - 45px);
  450. .left-img {
  451. width: 40px;
  452. height: 40px;
  453. border-radius: 6px;
  454. img {
  455. width: 100%;
  456. height: 100%;
  457. object-fit: contain;
  458. }
  459. }
  460. .right-text {
  461. padding-left: 8px;
  462. width: calc(100% - 50px);
  463. .farm-info {
  464. font-size: 14px;
  465. color: #1d2129;
  466. display: flex;
  467. align-items: center;
  468. .farm-name{
  469. max-width: calc(100% - 133px);
  470. }
  471. .info-tag-wrap {
  472. margin-left: 10px;
  473. display: flex;
  474. align-items: center;
  475. gap: 4px;
  476. .tag-item {
  477. height: 20px;
  478. line-height: 20px;
  479. padding: 0 8px;
  480. border-radius: 2px;
  481. font-size: 12px;
  482. color: #848282;
  483. background-color: rgba(148, 148, 148, 0.1);
  484. &.second {
  485. color: #ff953d;
  486. background: rgba(255, 149, 61, 0.1);
  487. }
  488. &.primary {
  489. color: #2199f8;
  490. background: #e8f3ff;
  491. }
  492. }
  493. }
  494. }
  495. .farm-addr {
  496. padding-top: 2px;
  497. font-size: 12px;
  498. color: #86909c;
  499. }
  500. }
  501. }
  502. .right-wrap {
  503. display: flex;
  504. align-items: center;
  505. justify-content: center;
  506. text-align: center;
  507. color: #fff;
  508. background: #2199f8;
  509. font-size: 12px;
  510. flex: none;
  511. width: 44px;
  512. height: 44px;
  513. padding: 8px;
  514. border-radius: 5px;
  515. box-sizing: border-box;
  516. .click-item {
  517. display: flex;
  518. align-items: center;
  519. gap: 2px;
  520. }
  521. .follow-text {
  522. color: #d0d0d0;
  523. }
  524. }
  525. }
  526. .item-bottom {
  527. padding-top: 10px;
  528. .bottom-tag {
  529. display: flex;
  530. gap: 10px;
  531. .tag-card {
  532. flex: 1;
  533. border-radius: 2px;
  534. padding: 4px;
  535. box-sizing: border-box;
  536. border: 0.4px solid rgba(215, 215, 215, 0.5);
  537. .card-content {
  538. display: flex;
  539. flex-direction: column;
  540. align-items: center;
  541. justify-content: center;
  542. text-align: center;
  543. .card-main-text {
  544. font-size: 16px;
  545. font-weight: 500;
  546. color: #202020;
  547. margin-bottom: 2px;
  548. }
  549. .card-sub-text {
  550. font-size: 10px;
  551. color: rgba(32, 32, 32, 0.4);
  552. display: flex;
  553. align-items: center;
  554. gap: 4px;
  555. .card-icon {
  556. display: inline-flex;
  557. align-items: center;
  558. justify-content: center;
  559. width: 12px;
  560. height: 12px;
  561. color: #2199f8;
  562. }
  563. }
  564. }
  565. &.active {
  566. background: rgba(33, 153, 248, 0.1);
  567. border: 0.5px solid #2199f8;
  568. .card-content {
  569. .card-main-text {
  570. color: #2199f8;
  571. }
  572. .card-sub-text {
  573. color: #2199f8;
  574. }
  575. }
  576. }
  577. }
  578. }
  579. }
  580. .item-footer {
  581. margin-top: 10px;
  582. padding-top: 11px;
  583. border-top: 1px solid rgba(0, 0, 0, 0.1);
  584. display: flex;
  585. align-items: center;
  586. justify-content: space-between;
  587. font-size: 12px;
  588. .footer-l {
  589. color: #8b8b8b;
  590. font-size: 12px;
  591. &.primary-btn {
  592. display: inline-flex;
  593. align-items: center;
  594. border: 1px solid #2199f8;
  595. background: rgba(33, 153, 248, 0.1);
  596. padding: 0 12px;
  597. height: 32px;
  598. box-sizing: border-box;
  599. display: flex;
  600. align-items: center;
  601. border-radius: 20px;
  602. color: #2199f8;
  603. .share-icon {
  604. width: 12px;
  605. padding-right: 4px;
  606. }
  607. }
  608. &.farm-name-text {
  609. font-size: 14px;
  610. color: #6f7274;
  611. .name-text {
  612. padding-left: 4px;
  613. }
  614. }
  615. }
  616. .footer-r {
  617. display: flex;
  618. align-items: center;
  619. .btn {
  620. height: 32px;
  621. line-height: 32px;
  622. padding: 0 12px;
  623. border-radius: 20px;
  624. display: flex;
  625. align-items: center;
  626. box-sizing: border-box;
  627. &.second {
  628. // border: 1px solid #8B8B8B;
  629. // color: #8B8B8B;
  630. color: #2199f8;
  631. background: rgba(33, 153, 248, 0.1);
  632. }
  633. &.primary {
  634. background: #2199f8;
  635. color: #fff;
  636. }
  637. .btn-icon {
  638. padding-right: 4px;
  639. }
  640. &.warning {
  641. color: #ff953d;
  642. background: #fff;
  643. border: 1px solid #ff953d;
  644. }
  645. &.secondary-text {
  646. color: #2199f8;
  647. border: 1px solid #2199f8;
  648. }
  649. }
  650. .btn + .btn {
  651. margin-left: 8px;
  652. }
  653. }
  654. }
  655. }
  656. </style>