interact.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  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. {{ item?.farmName }}
  53. <div class="info-tag-wrap">
  54. <div class="tag-item primary">
  55. {{ item?.typeName }}
  56. </div>
  57. <div class="tag-item second">托管客户</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, onMounted, ref, watch } from "vue";
  108. import { useStore } from "vuex";
  109. import { List as VanList } from "vant";
  110. import IndexMap from "../../farm_manage/map/index";
  111. import { useRouter } from "vue-router";
  112. import uploadExecute from "./uploadExecute.vue";
  113. import priceSheetPopup from "@/components/popup/priceSheetPopup.vue";
  114. import { ElMessage } from "element-plus";
  115. import activeUploadPopup from "@/components/popup/activeUploadPopup.vue";
  116. import AgriculturalInteractionCard from "@/components/pageComponents/AgriculturalInteractionCard.vue";
  117. const store = useStore();
  118. const router = useRouter();
  119. const indexMap = new IndexMap();
  120. const mapContainer = ref(null);
  121. const tabBarHeight = computed(() => store.state.home.tabBarHeight);
  122. const uploadExecuteRef = ref(null);
  123. const selectParma = ref({
  124. farmWorkTypeId: null,
  125. districtCode: null,
  126. });
  127. // 任务列表数据(用于显示,可能被筛选)
  128. const taskList = ref([]);
  129. // 各状态任务数量
  130. const taskCounts = ref([0, 0, 0]);
  131. // 当前选中的筛选索引
  132. const activeIndex = ref(2);
  133. const noData = ref(false);
  134. const loading = ref(false);
  135. // 分页相关
  136. const page = ref(0);
  137. const limit = ref(10);
  138. const loadingMore = ref(false);
  139. const finished = ref(false);
  140. // 查询未来农事预警
  141. const getFutureFarmWorkWarning = async (item) => {
  142. const res = await VE_API.home.listFutureFarmWorkWarning({ farmId: item.farmId });
  143. item.timelineList = res.data || [];
  144. };
  145. const taskItemRefs = ref([]);
  146. const handleUploadSuccess = async () => {
  147. // 刷新列表
  148. await resetAndLoad();
  149. // 等待 DOM 更新完成,refs 被重新收集
  150. await nextTick();
  151. // 更新所有task-item的triggerImg
  152. taskItemRefs.value.forEach((ref) => {
  153. if (ref && ref.updateTriggerImg) {
  154. ref.updateTriggerImg();
  155. }
  156. });
  157. };
  158. const cityCode = ref("");
  159. //根据城市的坐标返回区县列表
  160. const districtList = ref([]);
  161. function getDistrictListByCity() {
  162. VE_API.z_farm_work_record.getDistrictListByCity({ point: mapPoint.value }).then(({ data }) => {
  163. districtList.value = data || [];
  164. // cityCode.value = data[0].code.slice(0, -2);
  165. cityCode.value = "";
  166. districtList.value.unshift({ code: cityCode.value, name: "全部" });
  167. selectParma.value.districtCode = cityCode.value;
  168. resetAndLoad();
  169. });
  170. }
  171. //农事类型列表
  172. const farmWorkTypeList = ref([]);
  173. function getFarmWorkTypeList() {
  174. VE_API.z_farm_work_record.getFarmWorkTypeList().then(({ data }) => {
  175. farmWorkTypeList.value = data;
  176. farmWorkTypeList.value.unshift({ id: 0, name: "全部" });
  177. });
  178. }
  179. const mapPoint = ref(null);
  180. onMounted(() => {
  181. mapPoint.value = store.state.home.miniUserLocationPoint;
  182. // getDistrictListByCity();
  183. resetAndLoad();
  184. getFarmWorkTypeList();
  185. nextTick(() => {
  186. indexMap.initMap(mapPoint.value, mapContainer.value, true);
  187. });
  188. });
  189. // 监听 activeIndex 变化,重新加载数据
  190. watch(activeIndex, () => {
  191. resetAndLoad();
  192. });
  193. // 加载列表数据(支持分页)
  194. async function getSimpleList(isLoadMore = false) {
  195. if (!isLoadMore) {
  196. // 重置分页
  197. page.value = 0;
  198. finished.value = false;
  199. taskList.value = [];
  200. taskItemRefs.value = [];
  201. loading.value = true;
  202. } else {
  203. loadingMore.value = true;
  204. }
  205. const params = {
  206. ...selectParma.value,
  207. page: page.value,
  208. limit: limit.value,
  209. flowStatus: 5,
  210. };
  211. try {
  212. const { data } = await VE_API.home.listUnansweredFarms(params);
  213. if (!isLoadMore) {
  214. loading.value = false;
  215. } else {
  216. loadingMore.value = false;
  217. }
  218. if (data && data.length > 0) {
  219. // 为每个item初始化timelineList
  220. const newItems = data.map((item) => {
  221. let sourceData = item?.latestPhenologyProgressBroadcast?.sourceData;
  222. if (sourceData) {
  223. try {
  224. sourceData = JSON.parse(sourceData);
  225. } catch (e) {
  226. console.error("解析sourceData失败:", e);
  227. sourceData = null;
  228. }
  229. }
  230. return {
  231. ...item,
  232. sourceData,
  233. timelineList: [],
  234. };
  235. });
  236. // 串行请求,为每个农场获取时间轴数据
  237. for (let i = 0; i < newItems.length; i++) {
  238. await getFutureFarmWorkWarning(newItems[i]);
  239. }
  240. // 追加数据
  241. taskList.value = [...taskList.value, ...newItems];
  242. // 更新分页
  243. page.value += 1;
  244. // 判断是否还有更多数据
  245. if (data.length < limit.value) {
  246. finished.value = true;
  247. }
  248. // 更新地图数据
  249. indexMap.initData(taskList.value);
  250. } else {
  251. finished.value = true;
  252. if (taskList.value.length === 0) {
  253. noData.value = true;
  254. }
  255. }
  256. } catch (error) {
  257. console.error("获取任务列表失败:", error);
  258. if (!isLoadMore) {
  259. loading.value = false;
  260. } else {
  261. loadingMore.value = false;
  262. }
  263. finished.value = true;
  264. if (taskList.value.length === 0) {
  265. noData.value = true;
  266. }
  267. }
  268. }
  269. // 滚动加载更多
  270. const onLoad = () => {
  271. if (!finished.value && !loadingMore.value) {
  272. getSimpleList(true);
  273. }
  274. };
  275. // 重置并重新加载
  276. const resetAndLoad = () => {
  277. getSimpleList(false);
  278. };
  279. function handleActiveFilter(i) {
  280. activeIndex.value = i;
  281. selectParma.value.districtCode = cityCode.value;
  282. selectParma.value.farmWorkTypeId = null;
  283. }
  284. const showUploadExecutePopup = (item) => {
  285. if (item?.executeEvidence.length) {
  286. onlyShare.value = true;
  287. } else {
  288. onlyShare.value = false;
  289. }
  290. setTimeout(() => {
  291. uploadExecuteRef.value.showPopup(item);
  292. }, 10);
  293. };
  294. function toDetail(item) {
  295. // if (activeIndex.value === 0) {
  296. // router.push({
  297. // path: "/modify_work",
  298. // query: { id: item.id },
  299. // });
  300. // } else {
  301. // }
  302. router.push({
  303. path: "/completed_work",
  304. query: { miniJson: JSON.stringify({ id: item.id }) },
  305. });
  306. }
  307. const onlyShare = ref(false);
  308. const phenologyList = ref([
  309. {
  310. id: 1,
  311. name: "花芽分化",
  312. },
  313. {
  314. id: 2,
  315. name: "开花",
  316. },
  317. {
  318. id: 3,
  319. name: "成熟",
  320. },
  321. ]);
  322. const activeUploadPopupRef = ref(null);
  323. function handleSelectCurrentPhenology(item) {
  324. activeUploadPopupRef.value.showPopup({
  325. gardenIdVal: item.farmId,
  326. problemTitleVal: "进入 物候期 的时间",
  327. imgDescVal: "请上传凭证(转入农事任务凭证)",
  328. arrangeIdVal: item.farmWorkArrangeId,
  329. selectCurrentPhenologyVal: true,
  330. phenologyListVal: phenologyList.value,
  331. });
  332. }
  333. function handleRemindCustomer(item) {
  334. router.push({
  335. path: "/remind_customer",
  336. query: { farmId: item.farmId },
  337. });
  338. }
  339. </script>
  340. <style lang="scss" scoped>
  341. .task-page {
  342. width: 100%;
  343. height: calc(100vh - 50px - 50px);
  344. overflow: auto;
  345. box-sizing: border-box;
  346. background: #f5f7fb;
  347. .map-container {
  348. width: 100%;
  349. height: 162px;
  350. clip-path: inset(0px round 8px);
  351. }
  352. .select-group {
  353. display: flex;
  354. padding: 0px 12px 0 12px;
  355. .select-item {
  356. width: 100%;
  357. ::v-deep {
  358. .el-select__wrapper {
  359. text-align: center;
  360. gap: 2px;
  361. box-shadow: none;
  362. justify-content: center;
  363. background: none;
  364. }
  365. .el-select__selection {
  366. flex: none;
  367. width: fit-content;
  368. }
  369. .el-select__placeholder {
  370. position: static;
  371. transform: none;
  372. width: fit-content;
  373. color: rgba(0, 0, 0, 0.2);
  374. }
  375. .el-select__caret {
  376. color: rgba(0, 0, 0, 0.2);
  377. }
  378. }
  379. }
  380. }
  381. .task-top {
  382. padding: 10px 12px 0 12px;
  383. }
  384. .task-content-loading {
  385. height: 80px;
  386. border-radius: 8px;
  387. position: absolute;
  388. top: 60px;
  389. left: 0;
  390. width: 100%;
  391. }
  392. .task-content {
  393. min-height: 80px;
  394. }
  395. .empty-data {
  396. text-align: center;
  397. font-size: 14px;
  398. color: #6f7274;
  399. padding: 20px 0;
  400. }
  401. .task-list {
  402. position: relative;
  403. background: #fff;
  404. padding: 12px 12px 8px 12px;
  405. }
  406. .list-filter {
  407. display: flex;
  408. align-items: center;
  409. justify-content: space-around;
  410. .filter-item {
  411. padding: 0 12px;
  412. height: 28px;
  413. color: rgba(0, 0, 0, 0.5);
  414. font-size: 14px;
  415. line-height: 28px;
  416. border-radius: 20px;
  417. &.active {
  418. color: #2199f8;
  419. background: rgba(33, 153, 248, 0.2);
  420. }
  421. }
  422. }
  423. .task-item {
  424. border-radius: 12px;
  425. border: 0.3px solid rgba(0, 0, 0, 0.2);
  426. padding: 12px;
  427. }
  428. .task-item + .task-item {
  429. margin-top: 10px;
  430. }
  431. .img-text-wrap {
  432. display: flex;
  433. align-items: flex-start;
  434. justify-content: space-between;
  435. padding-bottom: 10px;
  436. border-bottom: 0.5px solid rgba(0, 0, 0, 0.1);
  437. .left-wrap {
  438. display: flex;
  439. align-items: center;
  440. .left-img {
  441. width: 40px;
  442. height: 40px;
  443. border-radius: 6px;
  444. img {
  445. width: 100%;
  446. height: 100%;
  447. object-fit: contain;
  448. }
  449. }
  450. .right-text {
  451. padding-left: 8px;
  452. .farm-info {
  453. font-size: 14px;
  454. color: #1d2129;
  455. display: flex;
  456. align-items: center;
  457. .info-tag-wrap {
  458. margin-left: 10px;
  459. display: flex;
  460. align-items: center;
  461. gap: 4px;
  462. .tag-item {
  463. height: 20px;
  464. line-height: 20px;
  465. padding: 0 8px;
  466. border-radius: 2px;
  467. font-size: 12px;
  468. &.second {
  469. color: #ff953d;
  470. background: rgba(255, 149, 61, 0.1);
  471. }
  472. &.primary {
  473. color: #2199f8;
  474. background: #e8f3ff;
  475. }
  476. }
  477. }
  478. }
  479. .farm-addr {
  480. padding-top: 2px;
  481. font-size: 12px;
  482. color: #86909c;
  483. }
  484. }
  485. }
  486. .right-wrap {
  487. display: flex;
  488. align-items: center;
  489. justify-content: center;
  490. text-align: center;
  491. color: #fff;
  492. background: #2199f8;
  493. font-size: 12px;
  494. flex: none;
  495. width: 44px;
  496. height: 44px;
  497. padding: 8px;
  498. border-radius: 5px;
  499. box-sizing: border-box;
  500. .click-item {
  501. display: flex;
  502. align-items: center;
  503. gap: 2px;
  504. }
  505. .follow-text {
  506. color: #d0d0d0;
  507. }
  508. }
  509. }
  510. .item-bottom {
  511. padding-top: 10px;
  512. .bottom-tag {
  513. display: flex;
  514. gap: 10px;
  515. .tag-card {
  516. flex: 1;
  517. border-radius: 2px;
  518. padding: 4px;
  519. box-sizing: border-box;
  520. border: 0.4px solid rgba(215, 215, 215, 0.5);
  521. .card-content {
  522. display: flex;
  523. flex-direction: column;
  524. align-items: center;
  525. justify-content: center;
  526. text-align: center;
  527. .card-main-text {
  528. font-size: 16px;
  529. font-weight: 500;
  530. color: #202020;
  531. margin-bottom: 2px;
  532. }
  533. .card-sub-text {
  534. font-size: 10px;
  535. color: rgba(32, 32, 32, 0.4);
  536. display: flex;
  537. align-items: center;
  538. gap: 4px;
  539. .card-icon {
  540. display: inline-flex;
  541. align-items: center;
  542. justify-content: center;
  543. width: 12px;
  544. height: 12px;
  545. color: #2199f8;
  546. }
  547. }
  548. }
  549. &.active {
  550. background: rgba(33, 153, 248, 0.1);
  551. border: 0.5px solid #2199f8;
  552. .card-content {
  553. .card-main-text {
  554. color: #2199f8;
  555. }
  556. .card-sub-text {
  557. color: #2199f8;
  558. }
  559. }
  560. }
  561. }
  562. }
  563. }
  564. .item-footer {
  565. margin-top: 10px;
  566. padding-top: 11px;
  567. border-top: 1px solid rgba(0, 0, 0, 0.1);
  568. display: flex;
  569. align-items: center;
  570. justify-content: space-between;
  571. font-size: 12px;
  572. .footer-l {
  573. color: #8b8b8b;
  574. font-size: 12px;
  575. &.primary-btn {
  576. display: inline-flex;
  577. align-items: center;
  578. border: 1px solid #2199f8;
  579. background: rgba(33, 153, 248, 0.1);
  580. padding: 0 12px;
  581. height: 32px;
  582. box-sizing: border-box;
  583. display: flex;
  584. align-items: center;
  585. border-radius: 20px;
  586. color: #2199f8;
  587. .share-icon {
  588. width: 12px;
  589. padding-right: 4px;
  590. }
  591. }
  592. &.farm-name-text {
  593. font-size: 14px;
  594. color: #6f7274;
  595. .name-text {
  596. padding-left: 4px;
  597. }
  598. }
  599. }
  600. .footer-r {
  601. display: flex;
  602. align-items: center;
  603. .btn {
  604. height: 32px;
  605. line-height: 32px;
  606. padding: 0 12px;
  607. border-radius: 20px;
  608. display: flex;
  609. align-items: center;
  610. box-sizing: border-box;
  611. &.second {
  612. // border: 1px solid #8B8B8B;
  613. // color: #8B8B8B;
  614. color: #2199f8;
  615. background: rgba(33, 153, 248, 0.1);
  616. }
  617. &.primary {
  618. background: #2199f8;
  619. color: #fff;
  620. }
  621. .btn-icon {
  622. padding-right: 4px;
  623. }
  624. &.warning {
  625. color: #ff953d;
  626. background: #fff;
  627. border: 1px solid #ff953d;
  628. }
  629. &.secondary-text {
  630. color: #2199f8;
  631. border: 1px solid #2199f8;
  632. }
  633. }
  634. .btn + .btn {
  635. margin-left: 8px;
  636. }
  637. }
  638. }
  639. }
  640. </style>