index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. <template>
  2. <div class="create-farm">
  3. <custom-header :name="isClient ? '新增用户' : '创建农场'"></custom-header>
  4. <!-- 地图 -->
  5. <div class="map-container" ref="mapContainer"></div>
  6. <div class="farm-content">
  7. <div class="top-mask"></div>
  8. <div class="farm-filter">
  9. <el-select
  10. v-model="locationVal"
  11. filterable
  12. remote
  13. reserve-keyword
  14. placeholder="搜索位置"
  15. :remote-method="remoteMethod"
  16. :loading="loading"
  17. @change="handleSearchRes"
  18. popper-class="location-search-popper"
  19. >
  20. <el-option
  21. v-for="(item, index) in locationOptions.list"
  22. :key="index"
  23. :label="item.title"
  24. :value="{ value: item.point, item }"
  25. >
  26. <span>{{ item.title }}</span>
  27. <span class="sub-title">{{ item.province }}{{ item.city }}{{ item.district }}</span>
  28. </el-option>
  29. </el-select>
  30. </div>
  31. <!-- 创建 -->
  32. <div class="create-wrap">
  33. <div class="create-box">
  34. <div class="box-content">
  35. <div class="create-title">
  36. <img class="title-icon" src="@/assets/img/home/create-icon.png" alt="" />
  37. {{ isClient ? '新增用户' : '创建农场' }}
  38. </div>
  39. <div class="create-content">
  40. <div class="create-from">
  41. <el-form
  42. ref="ruleFormRef"
  43. :model="ruleForm"
  44. :rules="rules"
  45. label-width="auto"
  46. class="demo-ruleForm"
  47. >
  48. <el-form-item label="农场位置" prop="position">
  49. <div class="position-wrap">
  50. <el-input
  51. placeholder="农场位置"
  52. readonly
  53. v-model="ruleForm.position"
  54. autocomplete="off"
  55. />
  56. <div class="draw-btn" @click="toSubPage">点击勾选地块</div>
  57. </div>
  58. </el-form-item>
  59. <el-form-item label="农场面积" prop="area">
  60. <div class="area-box">
  61. <el-input
  62. placeholder="勾选地块获得农场面积"
  63. v-model="ruleForm.area"
  64. autocomplete="off"
  65. style="width: fit-content;"
  66. />
  67. <div class="unit">亩</div>
  68. </div>
  69. </el-form-item>
  70. <el-form-item label="种植作物" prop="period">
  71. <div class="select-wrap">
  72. <el-select class="select-item" v-model="ruleForm.type" placeholder="作物类型">
  73. <el-option label="荔枝" value="lichi" />
  74. <el-option label="龙眼" value="ly" />
  75. </el-select>
  76. <el-select
  77. v-model="ruleForm.period"
  78. placeholder="物候期"
  79. class="period-select select-item"
  80. >
  81. <el-option label="秋梢期" value="秋梢期" />
  82. <el-option label="开花期" value="开花期" />
  83. <el-option label="膨果期" value="膨果期" />
  84. <el-option label="成熟期" value="成熟期" />
  85. </el-select>
  86. </div>
  87. </el-form-item>
  88. <el-form-item label="农场名称" prop="name">
  89. <el-input
  90. placeholder="请输入您的农场名称"
  91. v-model="ruleForm.name"
  92. autocomplete="off"
  93. />
  94. </el-form-item>
  95. </el-form>
  96. </div>
  97. <div class="create-btn">
  98. <div class="btn-item sencond-btn" @click="resetForm(ruleFormRef)">取消</div>
  99. <div class="btn-item primary-btn" @click="submitForm(ruleFormRef)">{{ isClient ? '添加' : '立即创建' }}</div>
  100. </div>
  101. </div>
  102. </div>
  103. </div>
  104. </div>
  105. </div>
  106. </div>
  107. </template>
  108. <script setup>
  109. import customHeader from "@/components/customHeader.vue";
  110. import IndexMap from "./map/index.js";
  111. import { useRoute, useRouter } from "vue-router";
  112. import { mapLocation } from "./map/index.js"
  113. import { onMounted, ref, reactive, watch, onActivated } from "vue";
  114. import { useStore } from "vuex";
  115. import { convertPointToArray } from "@/utils/index";
  116. const route = useRoute();
  117. const router = useRouter();
  118. const store = useStore();
  119. const indexMap = new IndexMap();
  120. const mapContainer = ref(null);
  121. onMounted(() => {
  122. centerPoint.value = store.state.home.miniUserLocationPoint
  123. indexMap.initMap(centerPoint.value, mapContainer.value);
  124. const arr = convertPointToArray(centerPoint.value)
  125. getLocationName(`${arr[1]},${arr[0]}`)
  126. });
  127. const polygonArr = ref(null)
  128. const isClient = ref(false);
  129. onActivated(() => {
  130. if (route.query.type) {
  131. isClient.value = true;
  132. }
  133. // 绘制勾画范围
  134. const polygonData = store.state.home.polygonData
  135. if (polygonData) {
  136. indexMap.setAreaGeometry(polygonData?.geometryArr)
  137. polygonArr.value = polygonData.geometryArr
  138. ruleForm.area = polygonData.area
  139. }
  140. })
  141. // 搜索
  142. const MAP_KEY = "CZLBZ-LJICQ-R4A5J-BN62X-YXCRJ-GNBUT";
  143. const locationVal = ref(null);
  144. const locationOptions = reactive({
  145. list: [],
  146. });
  147. const loading = ref(false);
  148. const remoteMethod = async (keyword) => {
  149. if (keyword) {
  150. locationOptions.list = [];
  151. loading.value = true;
  152. const params = {
  153. key: MAP_KEY,
  154. keyword,
  155. location: route.query.userLocation || "113.61702297075017,23.584863449735067",
  156. };
  157. await VE_API.old_mini_map.getCtiyList({ word: keyword }).then(({ data }) => {
  158. if (data && data.length) {
  159. data.forEach((item) => {
  160. item.point = item.location.lat + "," + item.location.lng;
  161. locationOptions.list.push(item);
  162. });
  163. }
  164. });
  165. VE_API.old_mini_map.search(params).then(({ data }) => {
  166. loading.value = false;
  167. data.forEach((item) => {
  168. item.point = item.location.lat + "," + item.location.lng;
  169. locationOptions.list.push(item);
  170. });
  171. });
  172. } else {
  173. locationOptions.list = [];
  174. }
  175. };
  176. const handleSearchRes = (v) => {
  177. const parts = v.value.split(",");
  178. const coordinateArray = [parseFloat(parts[1]), parseFloat(parts[0])];
  179. indexMap.setMapPosition(coordinateArray);
  180. centerPoint.value = `POINT (${coordinateArray[0]} ${coordinateArray[1]})`
  181. ruleForm.position = v.item?.title || v.item?.address;
  182. pointAddress.value = v.item?.province + v.item?.city + v.item?.district
  183. };
  184. // 表单
  185. const ruleFormRef = ref(null);
  186. const ruleForm = reactive({
  187. position: "",
  188. area: "",
  189. type: "",
  190. period: "",
  191. name: "",
  192. });
  193. const rules = reactive({
  194. position: [{ required: true, message: "请选择农场位置", trigger: "blur" }],
  195. area: [{ required: true, message: "请勾选地块获得农场面积", trigger: "blur" }],
  196. type: [{ required: true, message: "请选择品类", trigger: "blur" }],
  197. period: [{ required: true, message: "请选择物候期", trigger: "blur" }],
  198. name: [{ required: true, message: "请输入您的农场名称", trigger: "blur" }],
  199. });
  200. const submitForm = (formEl) => {
  201. if (!formEl) return;
  202. formEl.validate((valid) => {
  203. if (valid) {
  204. const params = {
  205. ...ruleForm,
  206. gemo: polygonArr.value
  207. }
  208. console.log("submit!", params);
  209. } else {
  210. console.log("error submit!");
  211. }
  212. });
  213. };
  214. const resetForm = (formEl) => {
  215. if (!formEl) return;
  216. formEl.resetFields();
  217. router.go(-1);
  218. };
  219. const centerPoint = ref(null)
  220. function toSubPage() {
  221. router.push(`/edit_map?mapCenter=${centerPoint.value}&pointName=${ruleForm.position}&pointAddress=${pointAddress.value}`);
  222. }
  223. const pointAddress = ref(null)
  224. function getLocationName(location) {
  225. const params = {
  226. key: MAP_KEY,
  227. location,
  228. };
  229. VE_API.old_mini_map.location(params).then(({ result }) => {
  230. // locationVal.value = result.formatted_addresses.recommend;
  231. const add = result.formatted_addresses?.recommend
  232. ? result.formatted_addresses.recommend
  233. : result.address + "";
  234. ruleForm.position = add
  235. pointAddress.value = result.address
  236. });
  237. }
  238. watch(() => mapLocation.data,(newValue, oldValue) => {
  239. if (newValue) {
  240. centerPoint.value = `POINT (${newValue[0]} ${newValue[1]})`
  241. getLocationName(`${newValue[1]},${newValue[0]}`)
  242. }
  243. })
  244. </script>
  245. <style lang="scss" scoped>
  246. .create-farm {
  247. position: relative;
  248. width: 100%;
  249. height: 100vh;
  250. overflow: hidden;
  251. .map-container {
  252. width: 100%;
  253. height: calc(100% - 240px);
  254. }
  255. .farm-content {
  256. position: absolute;
  257. top: 40px;
  258. left: 0;
  259. width: 100%;
  260. height: calc(100% - 40px);
  261. pointer-events: none;
  262. z-index: 2;
  263. .top-mask {
  264. height: 100px;
  265. position: absolute;
  266. z-index: 2;
  267. top: 0;
  268. left: 0;
  269. width: 100%;
  270. background: linear-gradient(0deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.6) 100%);
  271. }
  272. }
  273. .farm-filter {
  274. pointer-events: all;
  275. margin: 12px;
  276. position: relative;
  277. z-index: 10;
  278. background: rgba(0, 0, 0, 0.3);
  279. border-radius: 20px;
  280. border: 1px solid rgba(255, 255, 255, 0.4);
  281. &::before {
  282. content: "";
  283. position: absolute;
  284. left: 12px;
  285. top: 9px;
  286. width: 14px;
  287. height: 14px;
  288. background: url("@/assets/img/home/search.png") no-repeat center center / 100% 100%;
  289. }
  290. ::v-deep {
  291. .el-select__wrapper {
  292. background: none;
  293. box-shadow: none;
  294. padding-left: 34px;
  295. font-size: 12px;
  296. .el-select__selected-item,
  297. .el-select__placeholder,
  298. .el-select__input {
  299. color: rgba(255, 255, 255, 0.6);
  300. &.is-transparent {
  301. color: #ccc;
  302. font-size: 12px;
  303. }
  304. }
  305. }
  306. .el-select {
  307. transition: all 0.3s;
  308. .el-input.is-focus .el-input__wrapper {
  309. box-shadow: none !important;
  310. }
  311. }
  312. .el-input {
  313. .el-input__wrapper {
  314. background: none;
  315. box-shadow: none;
  316. padding-left: 18px;
  317. font-size: 11px;
  318. .el-input__inner {
  319. color: rgba(255, 255, 255, 0.6);
  320. }
  321. &.is-focus {
  322. .el-input__inner {
  323. color: #ccc;
  324. font-size: 11px;
  325. }
  326. }
  327. }
  328. }
  329. }
  330. }
  331. .create-wrap {
  332. position: absolute;
  333. bottom: 0px;
  334. left: 0;
  335. width: 100%;
  336. background: linear-gradient(180deg, transparent 0%, #f5f7fb 20%);
  337. }
  338. .create-box {
  339. pointer-events: all;
  340. margin: 0 12px 10px 12px;
  341. width: calc(100% - 24px);
  342. background: #e0f1fe;
  343. border-radius: 14px;
  344. .box-content {
  345. position: relative;
  346. &::after {
  347. position: absolute;
  348. right: 10px;
  349. top: 2px;
  350. content: "";
  351. width: 79px;
  352. height: 72px;
  353. background: url("@/assets/img/home/creat-bg.png") no-repeat center / 100% 100%;
  354. }
  355. }
  356. .create-title {
  357. display: flex;
  358. align-items: center;
  359. padding: 12px 6px 12px 12px;
  360. color: #0089f5;
  361. font-size: 18px;
  362. font-weight: bold;
  363. .title-icon {
  364. width: 18px;
  365. padding-right: 10px;
  366. }
  367. }
  368. .create-content {
  369. background: #fff;
  370. border-radius: 14px;
  371. padding: 12px;
  372. position: relative;
  373. z-index: 2;
  374. .create-from {
  375. .select-wrap {
  376. display: flex;
  377. // width: 86%;
  378. ::v-deep {
  379. .el-input__wrapper {
  380. background: none;
  381. box-shadow: none;
  382. }
  383. .el-input__inner {
  384. font-size: 14px;
  385. color: rgba(0, 0, 0, 0.5);
  386. }
  387. .el-select__wrapper {
  388. background: none;
  389. box-shadow: none;
  390. gap: 2px;
  391. padding: 4px 2px;
  392. justify-content: center;
  393. }
  394. .el-select__selection {
  395. flex: none;
  396. width: fit-content;
  397. }
  398. .el-select__placeholder {
  399. color: #000;
  400. position: static;
  401. transform: none;
  402. width: fit-content;
  403. }
  404. }
  405. // .select-item {
  406. // width: fit-content;
  407. // }
  408. .period-select {
  409. margin-left: 6px;
  410. }
  411. .select-item {
  412. min-width: 76px;
  413. }
  414. }
  415. ::v-deep {
  416. .el-form-item__label {
  417. color: #000;
  418. }
  419. .el-form-item__error {
  420. top: 117%;
  421. }
  422. .el-form-item {
  423. position: relative;
  424. &::after {
  425. content: "";
  426. position: absolute;
  427. left: 60px;
  428. bottom: -5px;
  429. width: calc(100% - 60px);
  430. height: 1px;
  431. background: rgba(0, 0, 0, 0.08);
  432. }
  433. }
  434. .el-input__wrapper {
  435. box-shadow: none;
  436. padding: 1px 6px;
  437. // border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  438. }
  439. }
  440. .area-box {
  441. display: flex;
  442. align-items: center;
  443. width: 100%;
  444. justify-content: space-between;
  445. .unit {
  446. padding-right: 10px;
  447. }
  448. }
  449. .position-wrap {
  450. display: flex;
  451. justify-content: space-between;
  452. align-items: center;
  453. .draw-btn {
  454. flex: none;
  455. padding: 0 12px;
  456. height: 30px;
  457. line-height: 30px;
  458. box-sizing: border-box;
  459. color: #2199f8;
  460. border: 1px solid #2199f8;
  461. background: rgba(33, 153, 248, 0.1);
  462. border-radius: 20px;
  463. font-size: 12px;
  464. }
  465. }
  466. }
  467. .create-btn {
  468. display: flex;
  469. align-items: center;
  470. width: 100%;
  471. padding-top: 10px;
  472. .btn-item {
  473. flex: 1;
  474. text-align: center;
  475. padding: 0 11px;
  476. height: 40px;
  477. line-height: 40px;
  478. border-radius: 34px;
  479. font-size: 16px;
  480. box-sizing: border-box;
  481. &.sencond-btn {
  482. border: 1px solid rgba(153, 153, 153, 0.5);
  483. color: #666666;
  484. }
  485. &.primary-btn {
  486. background: linear-gradient(180deg, #76c3ff, #2199f8);
  487. color: #fff;
  488. }
  489. }
  490. .btn-item + .btn-item {
  491. margin-left: 5px;
  492. }
  493. }
  494. }
  495. }
  496. }
  497. </style>
  498. <style lang="scss">
  499. .location-search-popper {
  500. .el-select-dropdown__list {
  501. max-width: 96vw;
  502. overflow-x: auto;
  503. }
  504. .sub-title {
  505. padding-left: 6px;
  506. font-size: 12px;
  507. color: #ccc;
  508. }
  509. }
  510. </style>