interact.vue 22 KB

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