farmDetails.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. <template>
  2. <div class="farm-details-page">
  3. <custom-header name="农场详情"></custom-header>
  4. <div class="farm-details-content">
  5. <!-- <farm-info-card
  6. v-if="farmDetail.name"
  7. :data="{
  8. farmName: farmDetail.name || '',
  9. userType: farmDetail.userType || '托管客户',
  10. variety: farmDetail.typeName || '',
  11. address: farmDetail.address || '',
  12. }"
  13. @click="handleFarmInfo"
  14. >
  15. <template #right>
  16. <div @click="handleDetail('plan')">农事规划</div>
  17. </template>
  18. </farm-info-card> -->
  19. <tabs v-model:active="activeTab" class="custom-tabs" scrollspy sticky offset-top="40" background="#F2F3F5">
  20. <tab title="作物档案" class="tab-item">
  21. <common-box title="作物档案">
  22. <template #right>
  23. <span @click="handleDetail('crop_record')">查看详情</span>
  24. </template>
  25. <template v-if="farmWorkData.length">
  26. <div class="farm-work-timeline">
  27. <div
  28. class="farm-work-item"
  29. v-for="(item, index) in farmWorkData"
  30. :key="index"
  31. >
  32. <div class="timeline-left">
  33. <div class="timeline-dot"></div>
  34. <div class="timeline-line"></div>
  35. </div>
  36. <div class="timeline-right">
  37. <div class="farm-work-card" :class="['card-' + getRecordTypeText(item.speakTitleName), , {'is-future': item.isFuture}]">
  38. <div class="type-box">{{ item.speakTitleName }}</div>
  39. <div class="farm-work-date" v-html="item.content.renderedContent"></div>
  40. <!-- <div class="farm-work-desc">
  41. <span class="farm-work-action">{{ item.action }}</span>
  42. <span class="farm-work-content">{{ item.content }}</span>
  43. <span>{{ item.text }}</span>
  44. </div> -->
  45. </div>
  46. </div>
  47. </div>
  48. </div>
  49. </template>
  50. <empty
  51. v-else
  52. image="https://birdseye-img.sysuimars.com/birdseye-look-mini/custom-empty-image.png"
  53. image-size="80"
  54. description="暂无数据"
  55. class="empty-state"
  56. />
  57. </common-box>
  58. </tab>
  59. <tab title="农事服务" class="tab-item">
  60. <common-box title="农事服务">
  61. <template #right>
  62. <span @click="handleDetail('service_list')">查看详情</span>
  63. </template>
  64. <tab-list
  65. type="light"
  66. v-model="farmServiceActiveTab"
  67. :tabs="farmServiceTabs"
  68. @change="handleFarmServiceTabChange"
  69. />
  70. <stats-box :stats-data="serviceStatsData" />
  71. <div v-for="(section, index) in detailList" :key="index" class="content-section">
  72. <record-item
  73. :record-item-data="section"
  74. onlyRecipeName
  75. :content-mode="farmServiceActiveTab === 0 ? 'serviceDetail' : ''"
  76. title-mode="default"
  77. :title-right-text="farmServiceActiveTab === 0 ? '生成成果报告' : ''"
  78. :title-right-type="farmServiceActiveTab === 1 ? 'dot' : null"
  79. :title-right-dot-text="farmServiceActiveTab === 1 ? '全区' : ''"
  80. class="recipe-item"
  81. @titleRightClick="handleTitleRightClick"
  82. />
  83. </div>
  84. <empty
  85. v-if="detailList.length === 0"
  86. image="https://birdseye-img.sysuimars.com/birdseye-look-mini/custom-empty-image.png"
  87. image-size="80"
  88. description="暂无数据"
  89. class="empty-state"
  90. />
  91. </common-box>
  92. </tab>
  93. <tab title="作物相册" class="tab-item">
  94. <common-box title="作物相册">
  95. <template #right>
  96. <span @click="handleShareReport()">查看更多</span>
  97. </template>
  98. <div class="photo-img-wrap" v-loading="imgsLoading">
  99. <photo-provider :photo-closable="true">
  100. <photo-consumer
  101. v-for="(src, index) in cropAlbum"
  102. intro="执行照片"
  103. :key="index"
  104. :src="base_img_url2 + src.filename"
  105. >
  106. <div class="photo-img">
  107. <img :src="base_img_url2 + src.filename + resize_300" />
  108. </div>
  109. </photo-consumer>
  110. </photo-provider>
  111. </div>
  112. </common-box>
  113. </tab>
  114. </tabs>
  115. </div>
  116. <div class="custom-bottom-fixed-btns center-btn">
  117. <div class="bottom-btn primary-btn" @click="handleShareFarm">分享认领农场</div>
  118. <!-- <div class="bottom-btn primary-btn" @click="handleChatFarm">在线沟通</div> -->
  119. </div>
  120. </div>
  121. <fn-share-sheet v-model:show="showShare" @select="onSelect" :options="[{ name: '微信', icon: 'wechat' }]" />
  122. <!-- 农场信息 -->
  123. <farm-info-popup
  124. ref="farmInfoRef"
  125. :farmId="farmIdVal"
  126. :showEditBtn="!farmDetail.farmersMiniUserId"
  127. :showBtn="true"
  128. ></farm-info-popup>
  129. </template>
  130. <script setup>
  131. import { ref, onMounted } from "vue";
  132. import { useRoute, useRouter } from "vue-router";
  133. import { Tab, Tabs, Empty } from "vant";
  134. import { base_img_url2, resize_300 } from "@/api/config";
  135. import wx from "weixin-js-sdk";
  136. import customHeader from "@/components/customHeader.vue";
  137. // import FarmInfoCard from "@/components/pageComponents/FarmInfoCard.vue";
  138. import tabList from "@/components/pageComponents/TabList.vue";
  139. import commonBox from "@/components/pageComponents/CommonBox.vue";
  140. import StatsBox from "@/components/pageComponents/StatsBox.vue";
  141. import recordItem from "@/components/recordItem.vue";
  142. import farmInfoPopup from "../home/components/farmInfoPopup.vue";
  143. import FnShareSheet from "@/components/pageComponents/FnShareSheet.vue";
  144. import config from "@/api/config";
  145. import { ElMessage } from "element-plus";
  146. const router = useRouter();
  147. const route = useRoute();
  148. const activeTab = ref(0);
  149. const farmServiceTabs = ["过往服务", "未来服务"];
  150. const farmServiceActiveTab = ref(0);
  151. const farmInfoRef = ref(null);
  152. const handleFarmInfo = () => {
  153. farmInfoRef.value.handleShow();
  154. };
  155. const handleFarmServiceTabChange = (index) => {
  156. if (index === 0) {
  157. getFarmPastServiceCost();
  158. getDetailList();
  159. } else {
  160. getFutureFarmWorkWarning()
  161. }
  162. };
  163. const getFutureFarmWorkWarning = async () => {
  164. const {data} = await VE_API.home.listFutureFarmWorkWarning({ farmId: farmIdVal.value });
  165. let totalCost = 0;
  166. if (data.length > 0) {
  167. totalCost = data.reduce((acc, item) => acc + item.estimatedCost, 0);
  168. detailList.value = data.slice(0, 1);
  169. }
  170. serviceStatsData.value = [
  171. { value: totalCost || 0, unit: "元", desc: "预计成交额" },
  172. { value: data.length || 0, unit: "次", desc: "预计服务次数" },
  173. ];
  174. };
  175. const serviceStatsData = ref([]);
  176. onMounted(() => {
  177. farmIdVal.value = route.query.farmId;
  178. paramsPage.value = {
  179. farmId: farmIdVal.value,
  180. limit: 1,
  181. page: 1,
  182. };
  183. getFarmDetail();
  184. getFarmWorkList();
  185. getDetailList();
  186. getFarmPastServiceCost();
  187. // 获取图片数据
  188. getFarmPhoto();
  189. });
  190. const farmIdVal = ref(null);
  191. const farmDetail = ref({});
  192. const paramsPage = ref({});
  193. const getFarmDetail = () => {
  194. VE_API.user.getFarmDetail({ farmId: farmIdVal.value }).then(({ data }) => {
  195. farmDetail.value = data || {};
  196. });
  197. };
  198. const farmWorkData = ref([]);
  199. const typeObj = {
  200. 物候: '1',
  201. 异常: '2',
  202. 病虫: '3',
  203. 农事: '4',
  204. }
  205. const getRecordTypeText = (recordType) => {
  206. return typeObj[recordType];
  207. }
  208. const getFarmWorkList = () => {
  209. VE_API.container_phenology.getFarmSpeakInfo({ farmId: farmIdVal.value }).then(({ data }) => {
  210. const list = data || [];
  211. const res = list.filter(item => item.content.hasException !== 0);
  212. getPhenologyBroadcast();
  213. // 只展示前三条数据
  214. farmWorkData.value = res.slice(0, 3);
  215. });
  216. };
  217. const getPhenologyBroadcast = () => {
  218. VE_API.container_phenology.phenologyBroadcast({ farmId: farmIdVal.value }).then(({ data }) => {
  219. farmWorkData.value.push({
  220. speakTitleName: "物候",
  221. isFuture: true,
  222. content: {
  223. renderedContent: data.content,
  224. },
  225. });
  226. });
  227. };
  228. const cropAlbum = ref([]);
  229. const imgsLoading = ref(false);
  230. // 获取作物相册的三张照片(参考 patrolPhoto 的获取逻辑)
  231. const getFarmPhoto = async () => {
  232. if (!farmIdVal.value) return;
  233. imgsLoading.value = true;
  234. try {
  235. // 先获取有图片的日期列表
  236. const dateParams = {
  237. farmId: farmIdVal.value,
  238. pageIndex: 0,
  239. limit: 10,
  240. };
  241. const { data: dateData } = await VE_API.farm.findHasImagesDate(dateParams);
  242. const dateList = Array.isArray(dateData) ? dateData : [];
  243. if (!dateList.length) {
  244. cropAlbum.value = [];
  245. return;
  246. }
  247. const result = [];
  248. let dateIndex = 0;
  249. // 按日期依次取图片,直到凑够 3 张或没有更多日期
  250. while (result.length < 3 && dateIndex < dateList.length) {
  251. const currentDate = dateList[dateIndex];
  252. const imgParams = {
  253. farmId: farmIdVal.value,
  254. date: currentDate,
  255. };
  256. const { data } = await VE_API.farm.getImageInfo(imgParams);
  257. const images = (data && Array.isArray(data.images)) ? data.images : [];
  258. images.forEach((item) => {
  259. if (result.length < 3) {
  260. // 统一存成 filename 字段,供模板使用
  261. result.push({
  262. ...item,
  263. filename: item.resFilename || item.filename,
  264. });
  265. }
  266. });
  267. dateIndex += 1;
  268. }
  269. cropAlbum.value = result;
  270. } catch (e) {
  271. console.error("获取农场相册失败", e);
  272. cropAlbum.value = [];
  273. } finally {
  274. imgsLoading.value = false;
  275. }
  276. };
  277. const detailList = ref([]);
  278. const getDetailList = () => {
  279. VE_API.user.farmServiceRecord({ farmId: farmIdVal.value }).then(({ data }) => {
  280. if(data.length > 0) {
  281. detailList.value = [data[0]];
  282. } else {
  283. detailList.value = [];
  284. }
  285. });
  286. };
  287. const getFarmPastServiceCost = () => {
  288. VE_API.user.getFarmPastServiceCost({ farmId: farmIdVal.value }).then(({ data }) => {
  289. serviceStatsData.value = [
  290. { value: data?.totalCost, unit: "元", desc: "成交额" },
  291. { value: data?.serviceCount, unit: "次", desc: "服务次数" },
  292. ];
  293. });
  294. };
  295. const handleDetail = (path) => {
  296. router.push(`/${path}?farmId=${farmIdVal.value}&agriculturalStoreId=${route.query.agriculturalStoreId}`);
  297. };
  298. const handleShareReport = () => {
  299. router.push({
  300. path: "/farm_photo",
  301. query: {
  302. // miniJson: JSON.stringify({ farmId: farmIdVal.value }),
  303. farmId: farmIdVal.value
  304. },
  305. });
  306. };
  307. const showShare = ref(false);
  308. const handleShareFarm = () => {
  309. showShare.value = true;
  310. };
  311. const handleChatFarm = () => {
  312. if (route.query.receiveUserId != "null") {
  313. router.push(`/chat_frame?userId=${route.query.receiveUserId}&farmId=${farmIdVal.value}`);
  314. } else {
  315. ElMessage.warning("尚未绑定用户,暂时无法沟通");
  316. }
  317. };
  318. const onSelect = () => {
  319. const query = {
  320. agriculturalStoreId: route.query.agriculturalStoreId,
  321. farmId: route.query.farmId,
  322. containerId: farmDetail.value.containerId,
  323. speciesName: farmDetail.value.speciesName,
  324. // receiveUserId: route.query.receiveUserId,
  325. };
  326. wx.miniProgram.navigateTo({
  327. url: `/pages/subPages/share_page/index?pageParams=${JSON.stringify(query)}&type=shareFarm`,
  328. });
  329. };
  330. const handleTitleRightClick = (section) => {
  331. router.push({
  332. path: "/achievement_report",
  333. query: { miniJson: JSON.stringify({ id: section.id }) },
  334. });
  335. };
  336. </script>
  337. <style scoped lang="scss">
  338. .farm-details-page {
  339. width: 100%;
  340. height: 100vh;
  341. background: #F2F3F5;
  342. .center-btn {
  343. justify-content: center;
  344. }
  345. .farm-details-content {
  346. box-sizing: border-box;
  347. padding: 10px 12px;
  348. overflow: auto;
  349. height: calc(100% - 40px - 60px);
  350. box-sizing: border-box;
  351. .custom-tabs {
  352. ::v-deep {
  353. .van-tabs__wrap {
  354. height: auto;
  355. }
  356. .van-tabs__nav {
  357. .van-tab {
  358. color: #8b8b8b;
  359. background: #F7F8FA;
  360. height: 34px;
  361. font-weight: 400;
  362. border-radius: 25px;
  363. width: fit-content;
  364. flex: none;
  365. padding: 0 12px;
  366. margin-right: 8px;
  367. }
  368. .van-tab--active {
  369. color: #fff;
  370. background: #2199f8;
  371. font-weight: 400;
  372. }
  373. }
  374. .van-tabs__line {
  375. display: none;
  376. }
  377. .van-tabs__nav--line {
  378. padding: 12px 0;
  379. }
  380. }
  381. .tab-item + .tab-item {
  382. margin-top: 12px;
  383. }
  384. .photo-img-wrap {
  385. display: flex;
  386. flex-wrap: wrap;
  387. gap: 10px;
  388. ::v-deep {
  389. .PhotoConsumer {
  390. width: 31%;
  391. height: 92px;
  392. }
  393. }
  394. .photo-img {
  395. width: 100%;
  396. height: 100%;
  397. position: relative;
  398. box-sizing: border-box;
  399. border: 2px solid transparent;
  400. border-radius: 8px;
  401. overflow: hidden;
  402. img {
  403. width: 100%;
  404. height: 100%;
  405. border-radius: 8px;
  406. object-fit: cover;
  407. }
  408. }
  409. }
  410. }
  411. .question-header {
  412. display: flex;
  413. align-items: center;
  414. margin-bottom: 6px;
  415. gap: 8px;
  416. font-weight: 500;
  417. .question-icon {
  418. width: 22px;
  419. height: 20px;
  420. }
  421. }
  422. .answer-content {
  423. color: #333333;
  424. margin: 6px 0 10px 0;
  425. }
  426. .answer-img {
  427. display: flex;
  428. gap: 5px;
  429. img {
  430. flex: 1;
  431. max-width: 105px;
  432. height: 105px;
  433. border-radius: 5px;
  434. object-fit: cover;
  435. }
  436. }
  437. .content-section {
  438. .recipe-item {
  439. border: 1px solid rgba(0, 0, 0, 0.1);
  440. margin: 12px 0 0 0;
  441. }
  442. }
  443. .plan-tab-item {
  444. .recipe-item {
  445. padding: 0;
  446. }
  447. }
  448. .plan-list-wrapper {
  449. height: 500px;
  450. margin-top: 12px;
  451. }
  452. .report-content {
  453. font-size: 13px;
  454. }
  455. .answer-btn {
  456. display: flex;
  457. align-items: center;
  458. justify-content: space-between;
  459. margin-top: 10px;
  460. > div {
  461. display: flex;
  462. gap: 10px;
  463. }
  464. }
  465. .answer-btn-item {
  466. padding: 7px 12px;
  467. border-radius: 25px;
  468. font-size: 12px;
  469. text-align: center;
  470. background: rgba(33, 153, 248, 0.1);
  471. color: #2199f8;
  472. min-width: 52px;
  473. box-sizing: border-box;
  474. &.primary {
  475. background: #2199f8;
  476. color: #ffffff;
  477. }
  478. }
  479. .empty-state {
  480. ::v-deep .van-empty {
  481. padding: 40px 0;
  482. }
  483. }
  484. .footer-data {
  485. display: flex;
  486. align-items: center;
  487. justify-content: space-between;
  488. gap: 12px;
  489. margin-top: 12px;
  490. .footer-l {
  491. display: flex;
  492. gap: 8px;
  493. flex: 1;
  494. .farm-info-footer-item {
  495. display: flex;
  496. border: 0.4px solid rgba(215, 215, 215, 0.5);
  497. padding: 8px 5px 5px;
  498. box-sizing: border-box;
  499. .farm-info-footer-item-label {
  500. font-size: 12px;
  501. color: rgba(32, 32, 32, 0.4);
  502. margin-bottom: 4px;
  503. }
  504. .farm-info-footer-item-value {
  505. font-size: 16px;
  506. color: #202020;
  507. padding-left: 2px;
  508. .unit {
  509. font-size: 12px;
  510. padding-left: 2px;
  511. color: rgba(32, 32, 32, 0.4);
  512. }
  513. }
  514. }
  515. }
  516. .footer-action {
  517. border: 0.5px solid #888B8D;
  518. border-radius: 20px;
  519. padding: 5px 12px;
  520. font-size: 12px;
  521. color: #888B8D;
  522. white-space: nowrap;
  523. cursor: pointer;
  524. flex-shrink: 0;
  525. }
  526. }
  527. .farm-work-timeline {
  528. padding: 10px 0;
  529. .farm-work-item {
  530. display: flex;
  531. align-items: flex-start;
  532. position: relative;
  533. &:not(:last-child) {
  534. margin-bottom: 20px;
  535. }
  536. .timeline-left {
  537. display: flex;
  538. flex-direction: column;
  539. align-items: center;
  540. margin-right: 12px;
  541. position: relative;
  542. .timeline-dot {
  543. width: 6px;
  544. height: 6px;
  545. border-radius: 50%;
  546. border: 1px solid #2199f8;
  547. flex-shrink: 0;
  548. z-index: 1;
  549. }
  550. .timeline-line {
  551. width: 1px;
  552. height: 48px;
  553. background: #e5e6eb;
  554. position: absolute;
  555. top: 8px;
  556. }
  557. }
  558. .timeline-right {
  559. flex: 1;
  560. .farm-work-card {
  561. border: 1px solid #8bccff;
  562. border-radius: 4px;
  563. background: #f8fcff;
  564. padding: 12px;
  565. display: flex;
  566. align-items: center;
  567. color: #1d2129;
  568. font-size: 14px;
  569. line-height: 22px;
  570. display: flex;
  571. align-items: center;
  572. &.card-1 {
  573. border: 1px solid #8BCCFF;
  574. .type-box {
  575. background: #2199F8;
  576. }
  577. .farm-work-content {
  578. color: #2199F8;
  579. }
  580. }
  581. &.card-4 {
  582. border: 1px solid #FFBB83;
  583. .type-box {
  584. background: #FF953D;
  585. }
  586. .farm-work-content {
  587. color: #FF953D;
  588. }
  589. }
  590. &.card-2, &.card-3 {
  591. border: 1px solid #FF9C9C;
  592. .type-box {
  593. background: #FD7676;
  594. }
  595. .farm-work-content {
  596. color: #FD7676;
  597. }
  598. }
  599. &.is-future {
  600. padding: 0 12px;
  601. // opacity: 0.5;
  602. background: rgba(246, 250, 255, 0.5);
  603. .type-box {
  604. background: rgba(33, 153, 248, 0.5);
  605. }
  606. .farm-work-content {
  607. color: rgba(29, 33, 41, 0.5);
  608. }
  609. }
  610. .type-box {
  611. margin-right: 12px;
  612. padding: 0 5px;
  613. height: 20px;
  614. line-height: 20px;
  615. font-size: 12px;
  616. flex: none;
  617. color: #fff;
  618. border-radius: 0 4px 0 4px;
  619. }
  620. .farm-work-date {
  621. padding-right: 4px;
  622. }
  623. .farm-work-desc {
  624. .farm-work-action {
  625. padding-right: 4px;
  626. }
  627. .farm-work-content {
  628. padding-right: 4px;
  629. }
  630. }
  631. }
  632. }
  633. &.is-estimated {
  634. .timeline-right {
  635. .farm-work-card {
  636. background: rgba(246, 250, 255, 0.5);
  637. border: 1px solid rgba(190, 218, 255, 0.5);
  638. .farm-work-date,
  639. .farm-work-desc {
  640. color: rgba(29, 33, 41, 0.5);
  641. }
  642. }
  643. }
  644. }
  645. }
  646. }
  647. }
  648. }
  649. </style>