index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. <template>
  2. <div class="base-container">
  3. <fnHeader></fnHeader>
  4. <div class="top-bg"></div>
  5. <div class="top">
  6. <div class="back btn" @click="goBack">
  7. <img class="icon" src="@/assets/images/common/back-icon.png" alt="" />
  8. <span>返回</span>
  9. </div>
  10. <div class="search">
  11. <el-select
  12. v-model="locationVal"
  13. filterable
  14. remote
  15. effect="dark"
  16. reserve-keyword
  17. placeholder="搜索地区"
  18. :remote-method="remoteMethod"
  19. :loading="loading"
  20. @change="handleSearchRes"
  21. class="v-select"
  22. >
  23. <template #prefix>
  24. <el-icon class="el-input__icon"><search /></el-icon>
  25. </template>
  26. <el-option
  27. v-for="(item, index) in locationOptions.list"
  28. :key="index"
  29. :label="item.title"
  30. :value="item.point"
  31. >
  32. <span>{{ item.title }}</span>
  33. <span class="sub-title"
  34. >{{ item.province }}{{ item.city }}{{ item.district }}</span
  35. >
  36. </el-option>
  37. </el-select>
  38. <div class="upload btn" @click="handleExport">
  39. <img class="icon" src="@/assets/images/common/back-icon.png" alt="" />
  40. <span>导出</span>
  41. </div>
  42. </div>
  43. </div>
  44. <div class="content">
  45. <div class="box">
  46. <div class="map-box">
  47. <div ref="mapRef" class="map"></div>
  48. </div>
  49. <div class="tool-group">
  50. <!-- <div class="btn">
  51. <img
  52. class="icon"
  53. src="@/assets/images/common/back-black-icon.png"
  54. alt=""
  55. />
  56. <span>撤销</span>
  57. </div>
  58. <div class="btn">
  59. <el-icon size="15"><CloseBold /></el-icon>
  60. <span>删除点</span>
  61. </div> -->
  62. <div class="btn delete" @click="handleDelete" v-show="isEdit">
  63. <el-icon size="15" color="#fff"><CloseBold /></el-icon>
  64. <span>删除地块</span>
  65. </div>
  66. </div>
  67. <div class="edit-popup" v-show="isEdit">
  68. <div class="edit-title">
  69. <div class="name">
  70. <img src="@/assets/images/common/chart-icon.png" alt="" />
  71. <span>地块属性</span>
  72. </div>
  73. <div v-show="disabledForm" class="edit" @click="handleEdit">
  74. 编辑
  75. </div>
  76. </div>
  77. <div class="edit-cont">
  78. <el-form
  79. :inline="true"
  80. :disabled="disabledForm"
  81. :model="formInline"
  82. label-position="top"
  83. class="form-inline"
  84. >
  85. <el-form-item label="农场地址">
  86. <el-input
  87. v-model="formInline.address"
  88. placeholder="请输入农场地址"
  89. clearable
  90. />
  91. </el-form-item>
  92. <el-form-item label="农场名称">
  93. <el-input
  94. v-model="formInline.farmName"
  95. placeholder="请输入农场名称"
  96. clearable
  97. />
  98. </el-form-item>
  99. <el-form-item label="创建时间">
  100. <el-input v-model="formInline.createDate" clearable disabled />
  101. </el-form-item>
  102. <el-form-item label="农场面积">
  103. <el-input v-model="formInline.area" disabled clearable />
  104. </el-form-item>
  105. <el-form-item label="作物物种">
  106. <el-input
  107. v-model="formInline.speciesTypeName"
  108. placeholder="请输入作物物种"
  109. clearable
  110. />
  111. </el-form-item>
  112. <el-form-item label="客户姓名">
  113. <el-input
  114. v-model="formInline.masterName"
  115. placeholder="请输入姓名"
  116. clearable
  117. />
  118. </el-form-item>
  119. <el-form-item label="联系电话">
  120. <el-input
  121. v-model="formInline.masterTel"
  122. placeholder="请输入联系电话"
  123. clearable
  124. />
  125. </el-form-item>
  126. </el-form>
  127. <div class="list-box" v-show="pointList.length > 0">
  128. <span>边界点经纬度</span>
  129. <div class="list-cont">
  130. <div
  131. class="list-item"
  132. v-for="(item, index) in pointList"
  133. :key="index"
  134. >
  135. <span>A{{ index + 1 }}</span>
  136. <div class="item-box">
  137. 北纬{{ item.lat }},东经{{ item.lnt }}
  138. </div>
  139. </div>
  140. </div>
  141. </div>
  142. </div>
  143. <div class="edit-footer">
  144. <div @click="onCancel" class="btn cancel">取消</div>
  145. <div @click="onSubmit" class="btn save">保存</div>
  146. </div>
  147. </div>
  148. </div>
  149. </div>
  150. </div>
  151. <!-- 导出弹窗 -->
  152. <el-dialog
  153. v-model="dialogVisible"
  154. width="82%"
  155. center
  156. :show-close="false"
  157. modal-class="dialog-dark"
  158. >
  159. <div>
  160. <el-table :data="gridData" border max-height="600" class="table-dark">
  161. <el-table-column
  162. property="farmName"
  163. label="农场名称"
  164. show-overflow-tooltip
  165. />
  166. <el-table-column
  167. property="address"
  168. label="农场地址"
  169. width="230"
  170. show-overflow-tooltip
  171. />
  172. <el-table-column property="createDate" label="创建时间" width="170" />
  173. <el-table-column property="mu" label="农场面积">
  174. <template #default="scope">
  175. <span>{{ scope.row.mu.toFixed(2) }}亩</span>
  176. </template>
  177. </el-table-column>
  178. <el-table-column property="speciesTypeName" label="作物物种" />
  179. <el-table-column property="masterName" label="客户姓名" />
  180. <el-table-column property="masterTel" label="联系电话" />
  181. <el-table-column
  182. property="points"
  183. label="边界点经纬度"
  184. width="480"
  185. show-overflow-tooltip
  186. />
  187. </el-table>
  188. </div>
  189. <template #footer>
  190. <div class="dialog-footer">
  191. <el-button class="btn" @click="dialogVisible = false">取消</el-button>
  192. <el-button class="btn" type="primary" @click="handleDowload">
  193. 下载
  194. </el-button>
  195. </div>
  196. </template>
  197. </el-dialog>
  198. </template>
  199. <script setup>
  200. import { onMounted, ref, reactive, watchEffect } from "vue";
  201. import fnHeader from "@/components/fnHeader.vue";
  202. import AuthenticMap from "./authenticMap";
  203. import { mapData } from "./authenticMap";
  204. import { useRouter } from "vue-router";
  205. import { ElMessage, ElMessageBox } from "element-plus";
  206. import { dateFormat } from "@/utils/date_util";
  207. import { exportExcel } from "@/utils/index";
  208. const router = useRouter();
  209. let authenticMap = new AuthenticMap();
  210. const mapRef = ref();
  211. const location = ref("POINT (113.78049350268851 23.419886891845312)");
  212. onMounted(() => {
  213. getList(true);
  214. });
  215. // 获取地块列表
  216. const plotList = ref([]);
  217. const getList = (isInitMap = false,a=false) => {
  218. VE_API.authentic.getList().then(({ code, data }) => {
  219. if (code !== 0) return authenticMap.initMap(location.value, mapRef.value);
  220. plotList.value = data || [];
  221. if (isInitMap) {
  222. authenticMap.initMap(data[0].point, mapRef.value);
  223. const geom = [];
  224. data.forEach((item) => {
  225. geom.push({ featureWkt: item.geom });
  226. });
  227. authenticMap.setAreaGeometry(geom);
  228. }
  229. if(a){
  230. const geom = [];
  231. console.log('data',data);
  232. data.forEach((item) => {
  233. geom.push({ featureWkt: item.geom });
  234. });
  235. authenticMap.setAreaGeometry(geom);
  236. authenticMap.c()
  237. }
  238. // const geom = [];
  239. // data.forEach((item) => {
  240. // geom.push({ featureWkt: item.geom });
  241. // });
  242. // authenticMap.setAreaGeometry(geom);
  243. // authenticMap.c()
  244. authenticMap.addPoint(data);
  245. });
  246. };
  247. // 搜索
  248. const locationVal = ref("");
  249. const loading = ref(false);
  250. const MAP_KEY = "CZLBZ-LJICQ-R4A5J-BN62X-YXCRJ-GNBUT";
  251. const handleSearchRes = (v) => {
  252. authenticMap.setMapCenter(v);
  253. };
  254. const locationOptions = reactive({
  255. list: [],
  256. });
  257. const remoteMethod = async (keyword) => {
  258. if (keyword) {
  259. locationOptions.list = [];
  260. loading.value = true;
  261. const params = {
  262. key: MAP_KEY,
  263. keyword,
  264. // location: store.getters.userLocation,
  265. location: "22.574540836684672,113.1093017627431",
  266. };
  267. await VE_API.old_mini_map
  268. .getCtiyList({ word: keyword })
  269. .then(({ data }) => {
  270. if (data && data.length) {
  271. data.forEach((item) => {
  272. item.point = item.location.lat + "," + item.location.lng;
  273. locationOptions.list.push(item);
  274. });
  275. }
  276. });
  277. VE_API.old_mini_map.search(params).then(({ data }) => {
  278. loading.value = false;
  279. data.forEach((item) => {
  280. item.point = item.location.lat + "," + item.location.lng;
  281. locationOptions.list.push(item);
  282. });
  283. });
  284. } else {
  285. locationOptions.list = [];
  286. }
  287. };
  288. const initForm = {
  289. address: "",
  290. farmName: "",
  291. createDate: "",
  292. area: "",
  293. speciesTypeName: "",
  294. masterName: "",
  295. masterTel: "",
  296. geom: "",
  297. };
  298. const formInline = reactive({
  299. ...initForm,
  300. });
  301. const disabledForm = ref(false);
  302. const isEdit = ref(false);
  303. // 编辑
  304. const handleEdit = () => {
  305. disabledForm.value = false;
  306. };
  307. // 取消
  308. const onCancel = () => {
  309. isEdit.value = false;
  310. authenticMap.startDraw();
  311. // authenticMap.b();
  312. // console.log('mapData.curPointData.id',mapData.curPointData.id);
  313. // if (!mapData.curPointData.id || mapData.selectPointArr.length) return;
  314. authenticMap.setPoint("point");
  315. };
  316. // 保存
  317. const onSubmit = () => {
  318. VE_API.authentic.saveData(formInline).then((res) => {
  319. if (formInline.id) {
  320. onCancel();
  321. } else {
  322. isEdit.value = false;
  323. authenticMap.startDraw();
  324. }
  325. // authenticMap.b()
  326. getList();
  327. });
  328. };
  329. // 返回
  330. const goBack = () => {
  331. router.go(-1);
  332. };
  333. function updateFormInline(newData) {
  334. Object.assign(formInline, newData);
  335. }
  336. const handleDelete = () => {
  337. if (!mapData.curPointData.id) return ElMessage("请选择地块");
  338. const id = mapData.selectPointArr.map((item) => item.values_.id);
  339. ElMessageBox.confirm("您确定删除该地块吗?", "提示", {
  340. confirmButtonText: "确认",
  341. cancelButtonText: "取消",
  342. type: "warning",
  343. })
  344. .then(() => {
  345. VE_API.authentic
  346. .deleteData({ id:id[0] })
  347. .then((res) => {
  348. authenticMap.b();
  349. onCancel();
  350. getList(false,true);
  351. });
  352. })
  353. .catch(() => {});
  354. };
  355. // 导出
  356. const gridData = ref([]);
  357. const dialogVisible = ref(false);
  358. const handleExport = () => {
  359. if (mapData.selectPointArr.length < 1) return ElMessage("请选择地块");
  360. const ids = mapData.selectPointArr.map((item) => item.values_.id);
  361. VE_API.authentic.exportData(ids).then(({ data }) => {
  362. gridData.value = data.map((item) => {
  363. return {
  364. ...item,
  365. createDate: dateFormat(
  366. new Date(item.createDate),
  367. "YYYY-mm-dd HH:MM:SS"
  368. ),
  369. };
  370. });
  371. dialogVisible.value = true;
  372. });
  373. };
  374. // 下载
  375. const handleDowload = () => {
  376. const fieldLabels = [
  377. "农场名称",
  378. "农场地址",
  379. "创建时间",
  380. "农场面积",
  381. "作物物种",
  382. "客户姓名",
  383. "联系电话",
  384. "边界点经纬度",
  385. ];
  386. const fieldKeys = [
  387. "farmName",
  388. "address",
  389. "createDate",
  390. "mu",
  391. "speciesTypeName",
  392. "masterName",
  393. "masterTel",
  394. "points",
  395. ];
  396. const fileName = "农场数据" + dateFormat(new Date(), "YYYY-mm-dd");
  397. exportExcel(gridData.value, fieldLabels, fieldKeys, fileName);
  398. };
  399. const pointList = ref([]);
  400. // 获取编辑回显数据
  401. const getDetailsData = (id) => {
  402. VE_API.authentic.getDetails({ id }).then(({ data }) => {
  403. isEdit.value = true;
  404. disabledForm.value = true;
  405. data.createDate = dateFormat(
  406. new Date(data.createDate),
  407. "YYYY-mm-dd HH:MM:SS"
  408. );
  409. updateFormInline({ ...data });
  410. const { area } = authenticMap.getAreaGeometry();
  411. formInline.area = area + "亩";
  412. // 经纬度列表
  413. const arr = JSON.parse(data.points);
  414. pointList.value = arr.map((item) => {
  415. return {
  416. lat: item[1].toString().slice(0, 6),
  417. lnt: item[0].toString().slice(0, 7),
  418. };
  419. });
  420. authenticMap.endEdit();
  421. });
  422. };
  423. watchEffect(() => {
  424. updateFormInline({ ...initForm });
  425. pointList.value = [];
  426. isEdit.value = false;
  427. if (mapData.isEdit && mapData.selectPointArr.length < 2) {
  428. isEdit.value = true;
  429. disabledForm.value = false;
  430. const { geometryArr, area } = authenticMap.getAreaGeometry();
  431. const lastItem = geometryArr[geometryArr.length - 1];
  432. formInline.geom = lastItem.featureWkt;
  433. formInline.area = area + "亩";
  434. formInline.createDate = dateFormat(new Date(), "YYYY-mm-dd HH:MM:SS");
  435. authenticMap.endEdit();
  436. }
  437. if (mapData.isEditArea) {
  438. const { geometryArr, area } = authenticMap.getAreaGeometry();
  439. formInline.geom = geometryArr[0].featureWkt;
  440. formInline.area = area + "亩";
  441. }
  442. if (
  443. mapData.curPointData.id &&
  444. !mapData.isEdit &&
  445. mapData.selectPointArr.length === 1
  446. ) {
  447. const id = mapData.selectPointArr.map((item) => item.values_.id);
  448. getDetailsData(id[0]);
  449. }
  450. });
  451. </script>
  452. <style lang="scss" scoped>
  453. .base-container {
  454. width: 100%;
  455. height: 100vh;
  456. color: #fff;
  457. box-sizing: border-box;
  458. z-index: 1;
  459. position: relative;
  460. .top-bg {
  461. position: absolute;
  462. top: 0;
  463. width: 100%;
  464. height: 74px;
  465. background: #101010;
  466. z-index: -1;
  467. }
  468. .btn {
  469. display: flex;
  470. align-items: center;
  471. padding: 6px 16px;
  472. border-radius: 4px;
  473. cursor: pointer;
  474. .icon {
  475. width: 13px;
  476. height: 13px;
  477. }
  478. span {
  479. margin-left: 10px;
  480. }
  481. }
  482. .top {
  483. display: flex;
  484. justify-content: space-between;
  485. width: 100%;
  486. height: 40px;
  487. background: #101010;
  488. padding: 17px 20px 0 20px;
  489. box-sizing: border-box;
  490. display: flex;
  491. align-items: center;
  492. .back {
  493. border: 1px solid rgba(255, 255, 255, 0.4);
  494. }
  495. .search {
  496. display: flex;
  497. .v-select {
  498. width: 300px;
  499. ::v-deep {
  500. .el-select__wrapper {
  501. background: #101010;
  502. box-shadow: none;
  503. border: 1px solid rgba(255, 255, 255, 0.7);
  504. .el-select__input {
  505. color: #fff;
  506. }
  507. }
  508. }
  509. }
  510. .upload {
  511. background: #2199f8;
  512. margin-left: 25px;
  513. }
  514. }
  515. }
  516. .content {
  517. width: 100%;
  518. height: calc(100% - 74px - 40px);
  519. box-sizing: border-box;
  520. background: #101010;
  521. padding: 13px 20px 20px 20px;
  522. .box {
  523. border: 1px solid rgba(255, 255, 255, 0.4);
  524. border-radius: 8px;
  525. padding: 20px;
  526. box-sizing: border-box;
  527. background: #232323;
  528. width: 100%;
  529. height: 100%;
  530. position: relative;
  531. .map-box {
  532. width: 100%;
  533. height: 100%;
  534. border-radius: 4px;
  535. border: 1px solid rgba(255, 255, 255, 0.4);
  536. .map {
  537. width: 100%;
  538. height: 100%;
  539. }
  540. }
  541. .tool-group {
  542. position: absolute;
  543. display: flex;
  544. right: calc(500px + 36px);
  545. top: 42px;
  546. .btn {
  547. background: #fff;
  548. color: #000;
  549. margin-right: 10px;
  550. }
  551. .delete {
  552. background: #e45c5c;
  553. color: #fff;
  554. }
  555. }
  556. .edit-popup {
  557. width: 500px;
  558. height: calc(100% - 53px - 20px);
  559. position: absolute;
  560. top: 36px;
  561. right: 36px;
  562. border: 1px solid rgba(255, 255, 255, 0.4);
  563. border-radius: 8px;
  564. background: #232323;
  565. .edit-title {
  566. padding: 0 10px;
  567. background: rgba(68, 68, 68, 0.4);
  568. border-bottom: 1px solid rgba(68, 68, 68, 0.4);
  569. display: flex;
  570. align-items: center;
  571. justify-content: space-between;
  572. .name {
  573. display: flex;
  574. padding: 12px 0px;
  575. align-items: center;
  576. }
  577. span {
  578. margin-left: 8px;
  579. font-size: 18px;
  580. font-family: "SOURCEHANTIFINE";
  581. }
  582. .edit {
  583. color: #2199f8;
  584. padding: 6px 20px;
  585. border: 1px solid #2199f8;
  586. border-radius: 4px;
  587. cursor: pointer;
  588. }
  589. }
  590. .edit-cont {
  591. padding: 16px;
  592. width: calc(100% - 32px);
  593. height: calc(100% - 64px - 84px);
  594. .form-inline {
  595. ::v-deep {
  596. .el-input {
  597. width: 200px;
  598. --el-input-placeholder-color: #666666;
  599. }
  600. .el-form-item__label {
  601. color: #bbbbbb;
  602. }
  603. .el-input__wrapper {
  604. background: #232323;
  605. border: 1px solid #444444;
  606. box-shadow: none;
  607. .el-input__inner {
  608. color: #fff;
  609. }
  610. }
  611. }
  612. }
  613. .list-box {
  614. width: 100%;
  615. span {
  616. color: #bbbbbb;
  617. }
  618. .list-cont {
  619. width: 100%;
  620. height: 234px;
  621. border-radius: 4px;
  622. margin-top: 5px;
  623. background: rgba(68, 68, 68, 0.4);
  624. display: flex;
  625. flex-wrap: wrap;
  626. align-content: flex-start;
  627. justify-content: space-between;
  628. padding: 12px 16px;
  629. box-sizing: border-box;
  630. overflow-y: auto;
  631. .list-item {
  632. width: 47.5%;
  633. margin-bottom: 12px;
  634. .item-box {
  635. padding: 8px;
  636. border: 1px solid #444444;
  637. border-radius: 4px;
  638. margin-top: 5px;
  639. }
  640. }
  641. }
  642. }
  643. }
  644. .edit-footer {
  645. width: 100%;
  646. height: 64px;
  647. display: flex;
  648. align-items: center;
  649. justify-content: flex-end;
  650. box-sizing: border-box;
  651. padding: 12px 16px;
  652. border-top: 1px solid rgba(68, 68, 68, 0.4);
  653. background: rgba(68, 68, 68, 0.4);
  654. .btn {
  655. padding: 10px 35px;
  656. }
  657. .cancel {
  658. border: 1px solid rgba(255, 255, 255, 0.4);
  659. margin-right: 16px;
  660. }
  661. .save {
  662. background: #2199f8;
  663. }
  664. }
  665. }
  666. }
  667. }
  668. }
  669. .dialog-footer {
  670. .btn {
  671. width: 200px;
  672. height: 40px;
  673. }
  674. }
  675. </style>