farmInfoPopup.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <Popup
  3. v-model:show="show"
  4. :overlay-style="{ zIndex: 9999 }"
  5. teleport="body"
  6. class="farm-info-popup"
  7. closeable>
  8. <div class="popup-content-box">
  9. <div class="popup-title">基本信息</div>
  10. <div class="popup-content">
  11. <div class="map-box">
  12. <div class="map" ref="mapContainer"></div>
  13. <!-- <div class="map-text" @click="handleEditMap">点击编辑地块</div> -->
  14. </div>
  15. <cell-group inset class="cell-group">
  16. <field v-model="farmInfo.name" readonly label="农场名称" />
  17. <field readonly label="农场面积">
  18. <template #input>
  19. <span>{{ farmInfo.mianji }}亩</span>
  20. </template>
  21. </field>
  22. <field readonly label="种植作物">
  23. <template #input>
  24. <span>{{ farmInfo.speciesName }}-{{ farmInfo.typeName }}</span>
  25. </template>
  26. </field>
  27. <!-- <field v-model="farmInfo.userType" readonly label="客户类型">
  28. <template #input>
  29. <span>{{ userTypeMap[farmInfo.userType] }}</span>
  30. </template>
  31. </field> -->
  32. <field v-model="farmInfo.fzr" readonly label="联系人" />
  33. <field v-model="farmInfo.tel" readonly label="联系电话" />
  34. <field class="address-field" v-model="farmInfo.address" readonly label="农场位置" />
  35. <field v-model="farmInfo.baseType" readonly label="基地类型">
  36. <template #input>
  37. <!-- <span>{{ userTypeMap[farmInfo.userType] }}</span> -->
  38. <span>{{ farmInfo?.baseType }}</span>
  39. </template>
  40. </field>
  41. <checkbox
  42. v-if="!showBtn"
  43. class="checkbox"
  44. icon-size="16px"
  45. shape="square"
  46. v-model="farmInfo.defaultOption"
  47. >是否勾选为默认农场</checkbox
  48. >
  49. </cell-group>
  50. </div>
  51. <div class="popup-footer" v-if="!showBtn || showEditBtn">
  52. <div class="footer-btn no-btn" @click="handleCancel">取消</div>
  53. <div class="footer-btn yes-btn" @click="handleEdit">去编辑</div>
  54. </div>
  55. </div>
  56. </Popup>
  57. </template>
  58. <script setup>
  59. import { Popup, Field, CellGroup, Checkbox } from "vant";
  60. import { ref, nextTick } from "vue";
  61. import { useRouter } from "vue-router";
  62. import IndexMap from "../map/index.js";
  63. import { useStore } from "vuex";
  64. const userTypeMap = {
  65. 1: "普通用户",
  66. 2: "托管用户",
  67. 3: "优质客户",
  68. };
  69. const props = defineProps({
  70. farmId: {
  71. type: [Number, String],
  72. default: null,
  73. },
  74. showBtn: {
  75. type: Boolean,
  76. default: false,
  77. },
  78. showEditBtn: {
  79. type: Boolean,
  80. default: false,
  81. },
  82. });
  83. const store = useStore();
  84. const router = useRouter();
  85. const show = ref(false);
  86. const mapContainer = ref(null);
  87. const indexMap = new IndexMap();
  88. // 农场信息
  89. const farmInfo = ref();
  90. const handleShow = () => {
  91. VE_API.farm.getFarmDetail({ farmId: props.farmId }).then((res) => {
  92. if (res.code === 0) {
  93. farmInfo.value = res.data;
  94. show.value = true;
  95. nextTick(() => {
  96. const point = farmInfo.value.pointWkt;
  97. const geometryArr = farmInfo.value.geomWkt;
  98. // 如果地图已经初始化,则更新中心点和地块;否则初始化地图
  99. if (indexMap.kmap) {
  100. indexMap.updateCenter(point);
  101. // 如果有地块数据,则添加地块
  102. if (geometryArr && geometryArr.length > 0) {
  103. indexMap.setAreaGeometry([geometryArr]);
  104. }
  105. } else {
  106. indexMap.initMap(point, mapContainer.value);
  107. // 初始化地图后,如果有地块数据,则添加地块
  108. if (geometryArr && geometryArr.length > 0) {
  109. indexMap.setAreaGeometry([geometryArr]);
  110. }
  111. }
  112. });
  113. }
  114. });
  115. };
  116. const handleEditMap = () => {
  117. // 在跳转前,将当前农场的地块数据存储到store中
  118. if (farmInfo.value.geomWkt) {
  119. const polygonData = {
  120. geometryArr: [farmInfo.value.geomWkt],
  121. isConfirmed: false,
  122. };
  123. store.commit("home/SET_FARM_POLYGON", polygonData);
  124. }
  125. router.push(
  126. `/edit_map?mapCenter=${farmInfo.value.pointWkt}&pointName=${farmInfo.value.address}&pointAddress=${JSON.parse(
  127. farmInfo.value.district
  128. )}&type=edit`
  129. );
  130. };
  131. const handleEdit = () => {
  132. setTimeout(() => {
  133. show.value = false;
  134. }, 150);
  135. // 在跳转前,将当前农场的地块数据存储到store中
  136. if (farmInfo.value.geomWkt) {
  137. const polygonData = {
  138. geometryArr: [farmInfo.value.geomWkt],
  139. mianji: farmInfo.value.mianji,
  140. isConfirmed: true, // 编辑模式下标记为已确认
  141. };
  142. store.commit("home/SET_FARM_POLYGON", polygonData);
  143. }
  144. // 将农场数据存储到store中,供编辑页面使用
  145. store.commit("home/SET_EDIT_FARM_DATA", farmInfo.value);
  146. const from = props.showEditBtn ? "details" : "monitor";
  147. router.push(`/create_farm?type=edit&farmId=${props.farmId}&from=${from}`);
  148. };
  149. const handleCancel = () => {
  150. show.value = false;
  151. };
  152. defineExpose({ handleShow });
  153. </script>
  154. <style lang="scss" scoped>
  155. .farm-info-popup {
  156. width: 100%;
  157. border-radius: 8px;
  158. z-index: 9999 !important;
  159. overflow: hidden;
  160. .popup-content-box {
  161. background: url("@/assets/img/home/popup-mask.png") no-repeat center left / 100% 100%;
  162. padding: 20px;
  163. }
  164. ::v-deep {
  165. .van-popup__close-icon {
  166. color: #000;
  167. }
  168. }
  169. .popup-title {
  170. text-align: center;
  171. font-size: 24px;
  172. font-family: "PangMenZhengDao";
  173. }
  174. .popup-content {
  175. margin: 12px 0;
  176. .map-box {
  177. width: 100%;
  178. height: 150px;
  179. position: relative;
  180. .map {
  181. width: 100%;
  182. height: 100%;
  183. clip-path: inset(0px round 5px);
  184. pointer-events: none;
  185. }
  186. .map-text {
  187. position: absolute;
  188. right: 6px;
  189. bottom: 8px;
  190. font-size: 12px;
  191. color: #ffffff;
  192. padding: 8px 12px;
  193. border-radius: 20px;
  194. background: rgba(0, 0, 0, 0.5);
  195. border: 1px solid rgba(255, 255, 255, 0.5);
  196. }
  197. }
  198. .cell-group {
  199. margin: 12px 0 0;
  200. .address-field {
  201. position: relative;
  202. &::before {
  203. position: absolute;
  204. box-sizing: border-box;
  205. content: " ";
  206. pointer-events: none;
  207. right: 16px;
  208. bottom: 0;
  209. left: 16px;
  210. border-bottom: 1px solid #ebedf0;
  211. transform: scaleY(0.5);
  212. }
  213. }
  214. }
  215. }
  216. .checkbox {
  217. pointer-events: none;
  218. padding: 12px 14px;
  219. }
  220. .popup-footer {
  221. display: flex;
  222. gap: 13px;
  223. .footer-btn {
  224. text-align: center;
  225. flex: 1;
  226. padding: 8px 0;
  227. border-radius: 25px;
  228. }
  229. .no-btn {
  230. color: #666666;
  231. border: 1px solid #999999;
  232. }
  233. .yes-btn {
  234. background: #2199f8;
  235. color: #fff;
  236. }
  237. }
  238. }
  239. </style>