farmInfo.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <template>
  2. <custom-header name="农场信息" bgColor="#f2f3f5"></custom-header>
  3. <div class="farm-details-page">
  4. <div class="farm-info">
  5. <div class="map-wrap">
  6. <div class="map-area" ref="mapContainer"></div>
  7. <div class="map-text" @click="handleEditMap">点击编辑地块</div>
  8. </div>
  9. <div class="info-box">
  10. <div class="section-header">
  11. <div class="line-title">基本信息</div>
  12. <div class="edit-btn" @click="handleEditFarmInfo">点击编辑</div>
  13. </div>
  14. <div class="info-list">
  15. <div class="info-row">
  16. <span class="info-label">农场名称:</span>
  17. <span class="info-value">{{ farmInfo.subjectName }}</span>
  18. </div>
  19. <div class="info-row">
  20. <span class="info-label">联系人:</span>
  21. <span class="info-value">{{ farmInfo.contactName }}</span>
  22. </div>
  23. <div class="info-row center-row">
  24. <span class="info-label">联系电话:</span>
  25. <span class="info-value">{{ farmInfo.contactPhone }}</span>
  26. </div>
  27. <div class="info-row">
  28. <span class="info-label">种植品种:</span>
  29. <div class="info-value crop-tags">
  30. <span v-for="crop in farmInfo.regionList" :key="crop.regionId" class="crop-tag">
  31. {{ crop.regionName }}
  32. </span>
  33. <div class="add-variety-btn" @click="handleAddVariety">
  34. <el-icon size="12">
  35. <Plus />
  36. </el-icon>
  37. <span>新增品种</span>
  38. </div>
  39. </div>
  40. </div>
  41. <div class="info-row">
  42. <span class="info-label">农场位置:</span>
  43. <span class="info-value">{{ farmInfo.farmAddress }}</span>
  44. </div>
  45. </div>
  46. </div>
  47. <el-divider class="info-divider" />
  48. <div class="info-box">
  49. <div class="section-header">
  50. <div class="line-title">农场设施</div>
  51. <div class="edit-btn" @click="handleEditFarmFacility">点击编辑</div>
  52. </div>
  53. <div class="info-list">
  54. <div class="info-row">
  55. <span class="info-label">土壤类型:</span>
  56. <span class="info-value">{{ basicFarmInfo.soil }}</span>
  57. </div>
  58. <div class="info-row">
  59. <span class="info-label">灌溉方式:</span>
  60. <div class="info-value crop-tags">
  61. <span v-for="method in basicFarmInfo.irrigation" :key="method.code" class="crop-tag">
  62. {{ method.name }}
  63. </span>
  64. </div>
  65. </div>
  66. <div class="info-row info-row-column">
  67. <span class="info-label">农机设备:</span>
  68. <div class="info-value device-value">
  69. <div class="device-box">
  70. <div class="device-item" v-for="device in basicFarmInfo.machineryList"
  71. :key="device.code">
  72. <span class="device-name">{{ device.name }}</span>
  73. <span class="device-count">{{ device.quantity || 0 }}{{ device.unit }}</span>
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. <div class="info-row info-row-column">
  79. <span class="info-label">希望改善问题:</span>
  80. <div class="info-value problem-tags">
  81. <span v-for="item in basicFarmInfo.improvementProblems" :key="item.code"
  82. class="problem-tag">
  83. {{ item.name }}
  84. </span>
  85. </div>
  86. </div>
  87. </div>
  88. </div>
  89. </div>
  90. </div>
  91. <FarmInfoPopup ref="farmInfoPopupRef" :farmId="route.query.subjectId" @success="fetchFarmSubjectDetail" />
  92. </template>
  93. <script setup>
  94. import { ref, onMounted, nextTick } from "vue";
  95. import customHeader from "@/components/customHeader.vue";
  96. import { useRouter, useRoute } from "vue-router";
  97. import DrawRegionMap from "@/views/old_mini/interactionList/map/drawRegionMap.js";
  98. import * as util from "@/common/ol_common.js";
  99. import { ElMessage } from "element-plus";
  100. import { useStore } from "vuex";
  101. import FarmInfoPopup from "@/views/old_mini/home/components/farmInfoPopup.vue";
  102. const router = useRouter();
  103. const route = useRoute();
  104. const store = useStore();
  105. const farmInfo = ref({});
  106. const mapContainer = ref(null);
  107. const drawRegionMap = new DrawRegionMap();
  108. const initMap = () => {
  109. if (!mapContainer.value) return;
  110. if (drawRegionMap.kmap) return;
  111. const info = farmInfo.value || {};
  112. drawRegionMap.initMap(info.farmLocation, mapContainer.value, false, true, false);
  113. // 回显农场区域,多边形 WKT 数组(有就画,没有就不画)
  114. let geometryArr = [];
  115. // 优先使用 regionList 里的 geom:有值才渲染
  116. if (Array.isArray(info.regionList) && info.regionList.length > 0) {
  117. info.regionList.forEach((item) => {
  118. if (item?.geom) {
  119. geometryArr.push(item?.geom)
  120. }
  121. });
  122. }
  123. if (geometryArr.length) {
  124. // 农场信息页:地块用绿色展示;第三参留空表示面积仍按地块自动计算
  125. drawRegionMap.setAreaGeometry(Array.from(geometryArr), true, undefined, {
  126. fill: "rgba(0, 57, 44, 0.5)",
  127. stroke: "#18AA8B",
  128. });
  129. }
  130. // 在区域中心落一个点位(使用与勾画页相同的图标)
  131. try {
  132. const geom = util.wktCastGeom(info.farmLocation);
  133. if (geom && typeof geom.getFirstCoordinate === "function") {
  134. const coord = geom.getFirstCoordinate();
  135. drawRegionMap.setMapPoint(coord);
  136. }
  137. } catch (e) {
  138. // 解析失败则忽略点位
  139. }
  140. };
  141. const destroyMap = () => {
  142. if (drawRegionMap && drawRegionMap.kmap && drawRegionMap.destroyMap) {
  143. drawRegionMap.destroyMap();
  144. }
  145. };
  146. onMounted(() => {
  147. fetchFarmSubjectDetail();
  148. fetchBasicFarmFormData();
  149. });
  150. function fetchFarmSubjectDetail() {
  151. VE_API.basic_farm.fetchFarmSubjectDetail({ subjectId: route.query.subjectId }).then(({ data }) => {
  152. farmInfo.value = data || {};
  153. nextTick(() => {
  154. destroyMap();
  155. initMap();
  156. });
  157. });
  158. }
  159. const basicFarmInfo = ref({});
  160. function fetchBasicFarmFormData() {
  161. VE_API.basic_farm.fetchBasicFarmFormData({ subjectId: route.query.subjectId }).then(({ data, code }) => {
  162. if (code === 0) {
  163. basicFarmInfo.value = {
  164. ...data,
  165. soil: data.soilTypes.find(item => item.selected).name,
  166. irrigation: data.irrigationMethods.filter(item => item.selected),
  167. machineryList: data.machinery.filter(item => item.selected),
  168. improvementProblems: data.improvementAreas.filter(item => item.selected),
  169. }
  170. }
  171. });
  172. }
  173. const farmInfoPopupRef = ref(null);
  174. const handleEditFarmInfo = () => {
  175. // // 回显地块:存到 polygonData,创建页会优先使用这里的数据
  176. // if (data.geomWkt) {
  177. // const polygonData = {
  178. // geometryArr: [data.geomWkt],
  179. // mianji: data.mianji,
  180. // isConfirmed: true,
  181. // };
  182. // store.commit("home/SET_FARM_POLYGON", polygonData);
  183. // } else {
  184. // store.commit("home/SET_FARM_POLYGON", null);
  185. // }
  186. // const params = {
  187. // ...farmInfo.value,
  188. // name: farmInfo.value.subjectName,
  189. // fzr: farmInfo.value.contactName,
  190. // tel: farmInfo.value.contactPhone,
  191. // mianji: farmInfo.value.farmArea,
  192. // address: farmInfo.value.farmAddress,
  193. // };
  194. // // 回显其他表单字段
  195. // store.commit("home/SET_EDIT_FARM_DATA", params);
  196. // // 带上 from=details,创建页提交/取消后能正确返回
  197. // router.push(`/create_farm?type=edit&farmId=${route.query.subjectId}&from=details`);
  198. farmInfoPopupRef.value.handleShow();
  199. };
  200. const handleEditFarmFacility = () => {
  201. router.push(`/prescription?subjectId=${route.query.subjectId}`);
  202. };
  203. // 点击编辑地块
  204. const handleEditMap = () => {
  205. const mapCenter = farmInfo.value.farmLocation || undefined;
  206. if (farmInfo.value.regionList.length) {
  207. // type=view 进入查看态;rangeWkt 用于回显多个地块
  208. router.push({
  209. path: "/draw_area",
  210. query: {
  211. type: "viewOnly",
  212. subjectId: route.query.subjectId
  213. },
  214. });
  215. } else {
  216. ElMessage.warning("暂无种植作物,无法编辑地块");
  217. }
  218. };
  219. const handleAddVariety = () => {
  220. router.push(`/interaction?addVariety=true&subjectId=${route.query.subjectId}`);
  221. };
  222. </script>
  223. <style lang="scss" scoped>
  224. .farm-details-page {
  225. background: #f2f3f5;
  226. height: calc(100vh - 60px);
  227. padding: 10px 12px;
  228. overflow: auto;
  229. .line-title {
  230. position: relative;
  231. padding-left: 14px;
  232. font-size: 16px;
  233. &::before {
  234. content: "";
  235. position: absolute;
  236. left: 5px;
  237. top: 50%;
  238. transform: translateY(-50%);
  239. width: 4px;
  240. height: 15px;
  241. background: #2199f8;
  242. border-radius: 20px;
  243. }
  244. }
  245. .farm-info {
  246. background: #fff;
  247. border-radius: 8px;
  248. padding: 10px;
  249. .map-wrap {
  250. position: relative;
  251. .map-area {
  252. width: 100%;
  253. height: 142px;
  254. clip-path: inset(0px round 5px);
  255. }
  256. .map-text {
  257. position: absolute;
  258. right: 13px;
  259. bottom: 8px;
  260. font-size: 12px;
  261. color: #ffffff;
  262. background: rgba(0, 0, 0, 0.5);
  263. padding: 8px 12px;
  264. border-radius: 25px;
  265. border: 1px solid rgba(255, 255, 255, 0.5);
  266. }
  267. }
  268. .info-box {
  269. margin-top: 12px;
  270. .section-header {
  271. display: flex;
  272. align-items: center;
  273. justify-content: space-between;
  274. }
  275. .edit-btn {
  276. padding: 4px 12px;
  277. font-size: 12px;
  278. color: #86909c;
  279. border-radius: 999px;
  280. border: 0.5px solid #d0d3d8;
  281. background-color: #ffffff;
  282. }
  283. .info-list {
  284. margin-top: 10px;
  285. margin-left: 5px;
  286. .info-row {
  287. display: flex;
  288. align-items: flex-start;
  289. margin-bottom: 6px;
  290. &.center-row {
  291. align-items: center;
  292. }
  293. .info-label {
  294. min-width: 80px;
  295. color: #4E5969;
  296. }
  297. .crop-tags {
  298. display: flex;
  299. align-items: center;
  300. flex-wrap: wrap;
  301. gap: 6px;
  302. .crop-tag {
  303. padding: 2px 8px;
  304. background: #E8F3FF;
  305. color: #2199f8;
  306. border-radius: 2px;
  307. font-size: 12px;
  308. }
  309. .add-variety-btn {
  310. display: flex;
  311. align-items: center;
  312. gap: 3px;
  313. padding: 3px 6px;
  314. border: 1px solid #DCDCDC;
  315. border-radius: 3px;
  316. background: #fff;
  317. font-size: 12px;
  318. }
  319. }
  320. .problem-tags {
  321. display: flex;
  322. flex-wrap: wrap;
  323. gap: 6px;
  324. .problem-tag {
  325. padding: 2px 8px;
  326. background: rgba(58, 173, 148, 0.1);
  327. color: #3AAD94;
  328. border-radius: 2px;
  329. font-size: 13px;
  330. }
  331. }
  332. .device-value {
  333. width: 100%;
  334. }
  335. .device-box {
  336. padding: 6px;
  337. border-radius: 4px;
  338. border: 0.5px solid rgba(33, 153, 248, 0.2);
  339. display: grid;
  340. grid-template-columns: repeat(2, minmax(0, 1fr));
  341. column-gap: 12px;
  342. row-gap: 4px;
  343. .device-item {
  344. display: flex;
  345. align-items: center;
  346. justify-content: space-between;
  347. padding: 4px 0;
  348. min-width: 0;
  349. gap: 8px;
  350. font-size: 13px;
  351. color: #1D2129;
  352. .device-count {
  353. padding: 2px 8px;
  354. background: #E8F3FF;
  355. color: #2199f8;
  356. border-radius: 2px;
  357. }
  358. }
  359. }
  360. }
  361. .info-row-column {
  362. display: flex;
  363. flex-direction: column;
  364. gap: 4px;
  365. }
  366. }
  367. }
  368. }
  369. }
  370. </style>