maintain.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. <!-- -->
  2. <template>
  3. <div class="maintainbox">
  4. <div class="maintainbox_search">
  5. <el-input
  6. v-model="monitorname"
  7. placeholder="请输入监测点名称"
  8. size="mini"
  9. ></el-input>
  10. <el-button type="info" @click="search" size="mini">搜索</el-button>
  11. <el-button
  12. type="info"
  13. size="mini"
  14. @click="(addtraptf = true), (addtitle = '新增监测点')"
  15. >添加监测点</el-button
  16. >
  17. <el-button type="info" size="mini" @click="addtraptf = true"
  18. >导入监测点</el-button
  19. >
  20. </div>
  21. <el-card class="box-card" style="margin-top: 15px">
  22. <div class="cbdboxs_table" v-loading="loading">
  23. <el-table :data="tableData" style="width: 100%" :stripe="true" :height="48*13">
  24. <el-table-column prop="index" label="序号"> </el-table-column>
  25. <el-table-column
  26. prop="point_name"
  27. label="监测点名称"
  28. ></el-table-column>
  29. <el-table-column prop="lng" label="经度">
  30. <template slot-scope="scope">
  31. <span>{{ ToDegrees(scope.row.lng, "lng") }}</span>
  32. </template>
  33. </el-table-column>
  34. <el-table-column prop="lat" label="纬度">
  35. <template slot-scope="scope">
  36. <span>{{ ToDegrees(scope.row.lat, "lat") }}</span>
  37. </template>
  38. </el-table-column>
  39. <el-table-column prop="messages" label="简介"></el-table-column>
  40. <el-table-column label="操作" width="300">
  41. <template slot-scope="scope">
  42. <span
  43. style="color: #409eff; margin-right: 5px;cursor: pointer;"
  44. @click="alter(scope.row)"
  45. >编辑</span
  46. >
  47. <span
  48. style="color: #409eff; margin-right: 5px;cursor: pointer;"
  49. @click="deletemain(scope.row)"
  50. >删除</span
  51. >
  52. </template>
  53. </el-table-column>
  54. </el-table>
  55. </div>
  56. <el-pagination
  57. background
  58. layout="prev, pager, next,jumper"
  59. :total="total"
  60. :page-size="20"
  61. @current-change="pageChange"
  62. >
  63. </el-pagination>
  64. </el-card>
  65. <el-dialog
  66. :title="addtitle"
  67. :visible.sync="addtraptf"
  68. width="30%"
  69. @close="resetForm('ruleForm')"
  70. >
  71. <div>
  72. <el-form
  73. :model="ruleForm"
  74. :rules="rules"
  75. ref="ruleForm"
  76. label-width="100px"
  77. class="demo-ruleForm"
  78. >
  79. <el-form-item label="诱捕器名称" prop="point_name">
  80. <el-input v-model="ruleForm.point_name"></el-input>
  81. </el-form-item>
  82. <div class="addtrapbox">
  83. <el-form-item label="所在纬度" prop="lng">
  84. <el-input v-model="ruleForm.lng"></el-input>
  85. <p style="height: 24px; padding-left: 16px">
  86. {{ ToDegrees(ruleForm.lng, "lng") }}
  87. </p>
  88. </el-form-item>
  89. <el-form-item label="所在纬度" prop="lat">
  90. <el-input v-model="ruleForm.lat"></el-input>
  91. <p style="height: 24px; padding-left: 16px">
  92. {{ ToDegrees(ruleForm.lat, "lat") }}
  93. </p>
  94. </el-form-item>
  95. </div>
  96. <div class="buttonbox">
  97. <el-button type="info" size="mini" @click="dingwei"
  98. >地图选点</el-button
  99. >
  100. </div>
  101. <el-form-item label="监测点描述" prop="messages">
  102. <el-input type="textarea" v-model="ruleForm.messages"></el-input>
  103. </el-form-item>
  104. </el-form>
  105. </div>
  106. <span slot="footer" class="dialog-footer">
  107. <el-button @click="resetForm('ruleForm')" size="mini">取 消</el-button>
  108. <el-button type="primary" @click="submitForm('ruleForm')" size="mini"
  109. >确 定</el-button
  110. >
  111. </span>
  112. </el-dialog>
  113. <el-dialog
  114. class="map_dialog"
  115. title="地图选点"
  116. :visible.sync="addLocationDialogVisible"
  117. width="820px"
  118. @closed="addLocationDialogClosed"
  119. >
  120. <el-form
  121. :inline="true"
  122. :model="locationForm"
  123. class="demo-form-inline"
  124. size="mini"
  125. >
  126. <el-form-item label="经度">
  127. <el-input clearable v-model="locationForm.lng"></el-input>
  128. </el-form-item>
  129. <el-form-item label="纬度">
  130. <el-input clearable v-model="locationForm.lat"></el-input>
  131. </el-form-item>
  132. <el-form-item>
  133. <el-button type="primary" size="mini" @click="locationSearch"
  134. >定位</el-button
  135. >
  136. </el-form-item>
  137. <el-form-item label="">
  138. <el-input
  139. placeholder="请输入地区检索"
  140. v-model="addr"
  141. clearable
  142. @change="addrChange()"
  143. ></el-input>
  144. </el-form-item>
  145. </el-form>
  146. <div class="amap-demo" id="mapContainer2" style="height: 400px"></div>
  147. <span slot="footer" class="dialog-footer">
  148. <el-button @click="addLocationDialogVisible = false" size="mini"
  149. >取 消</el-button
  150. >
  151. <el-button type="primary" @click="addLocationSubm" size="mini"
  152. >确 定</el-button
  153. >
  154. </span>
  155. </el-dialog>
  156. </div>
  157. </template>
  158. <script>
  159. //这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  160. export default {
  161. //import引入的组件需要注入到对象中才能使用
  162. components: {},
  163. data() {
  164. var checklnglat = (rule, value, callback) => {
  165. if (isNaN(value)) {
  166. callback(new Error("请输入数字"));
  167. } else {
  168. callback();
  169. }
  170. };
  171. //这里存放数据
  172. return {
  173. monitorname: "", //搜索 监测点名称
  174. addtraptf: false, //添加框
  175. loading: false, //加载框
  176. page: 1, //页码
  177. total: 10, //数据总条数,
  178. tableData: [],
  179. ruleForm: {
  180. point_name: "",
  181. lng: "",
  182. lat: "",
  183. messages: "",
  184. },
  185. rules: {
  186. point_name: [
  187. { required: true, message: "请输入诱捕器名称", trigger: "blur" },
  188. ],
  189. lng: [
  190. { required: true, message: "请输入经度", trigger: "blur" },
  191. // { validator: checklnglat, trigger: "blur" },
  192. ],
  193. lat: [
  194. { required: true, message: "请输入纬度", trigger: "blur" },
  195. // { validator: checklnglat, trigger: "blur" },
  196. ],
  197. // messages: [
  198. // { required: true, message: "请输入监测点描述", trigger: "blur" },
  199. // ],
  200. },
  201. addtitle: "新增监测点",
  202. point_id: "",
  203. //地图属性
  204. addLocationDialogVisible: false,
  205. locationForm: {
  206. lng: "",
  207. lat: "",
  208. },
  209. addr: "", //搜索栏地址
  210. address: "", //地图上标签地址
  211. center: [114.05, 22.55],
  212. };
  213. },
  214. //监听属性 类似于data概念
  215. computed: {},
  216. //监控data中的数据变化
  217. watch: {},
  218. //方法集合
  219. methods: {
  220. getmaintainlist() {
  221. this.loading = true;
  222. this.$axios({
  223. method: "POST",
  224. url: "/api/api_gateway?method=monitor_manage.maintain.checkpoint_list",
  225. data: this.qs.stringify({
  226. page_size: 20,
  227. page: this.page,
  228. org_name: this.monitorname, // 非必传(string) 诱剂名称 搜索项
  229. }),
  230. }).then((res) => {
  231. this.loading = false;
  232. console.log(res.data.data);
  233. this.total = res.data.data.total_item;
  234. this.tableData = res.data.data.page_list;
  235. for (var i = 0; i < this.tableData.length; i++) {
  236. this.tableData[i]["index"] = i + 1;
  237. }
  238. });
  239. },
  240. search() {
  241. this.getmaintainlist();
  242. },
  243. pageChange(e) {
  244. //当页码更改时
  245. // console.log(e)
  246. this.queryInfo.page = e;
  247. this.getmaintainlist();
  248. },
  249. submitForm(formName) {
  250. console.log(this.ruleForm);
  251. this.$refs[formName].validate((valid) => {
  252. if (valid) {
  253. if (this.addtitle == "新增监测点") {
  254. this.$axios({
  255. method: "POST",
  256. url: "/api/api_gateway?method=monitor_manage.maintain.checkpoint_add",
  257. data: this.qs.stringify({
  258. point_name: this.ruleForm.point_name, // 非必传(num) 诱捕器id 修改项
  259. lat: this.ToDigital(this.ruleForm.lat), // 必传(string) 纬度
  260. lng: this.ToDigital(this.ruleForm.lng), // 必传(string) 经度
  261. messages: this.ruleForm.messages,
  262. }),
  263. }).then((res) => {
  264. console.log(res);
  265. if (res.data.data) {
  266. this.$message({
  267. showClose: true,
  268. message: "添加成功!",
  269. type: "success",
  270. });
  271. this.addtraptf = false;
  272. this.getmaintainlist();
  273. } else {
  274. this.$message({
  275. showClose: true,
  276. message: "添加失败" + res.data.message,
  277. type: "warning",
  278. });
  279. }
  280. });
  281. } else if (this.addtitle == "修改监测点") {
  282. this.$axios({
  283. method: "POST",
  284. url: "/api/api_gateway?method=monitor_manage.maintain.checkpoint_modify",
  285. data: this.qs.stringify({
  286. point_id: this.point_id,
  287. point_name: this.ruleForm.point_name, // 非必传(num) 诱捕器id 修改项
  288. lat: this.ToDigital(this.ruleForm.lat), // 必传(string) 纬度
  289. lng: this.ToDigital(this.ruleForm.lng), // 必传(string) 经度
  290. messages: this.ruleForm.messages,
  291. }),
  292. }).then((res) => {
  293. console.log(res);
  294. if (res.data.data) {
  295. this.$message({
  296. showClose: true,
  297. message: "修改成功!",
  298. type: "success",
  299. });
  300. this.addtraptf = false;
  301. this.getmaintainlist();
  302. } else {
  303. this.$message({
  304. showClose: true,
  305. message: "修改失败" + res.data.message,
  306. type: "warning",
  307. });
  308. }
  309. });
  310. }
  311. } else {
  312. this.$message({
  313. message: "请将信息填写完全",
  314. type: "warning",
  315. });
  316. return false;
  317. }
  318. });
  319. },
  320. resetForm(formName) {
  321. this.addtraptf = false;
  322. this.$refs[formName].resetFields();
  323. for (var key in this.ruleForm) {
  324. this.ruleForm[key] = "";
  325. }
  326. },
  327. alter(data) {
  328. console.log(data);
  329. this.ruleForm.point_name = data.point_name;
  330. this.ruleForm.lng = data.lng;
  331. this.ruleForm.lat = data.lat;
  332. this.ruleForm.messages = data.messages;
  333. this.addtitle = "修改监测点";
  334. this.addtraptf = true;
  335. this.point_id = data.point_id;
  336. },
  337. deletemain(data) {
  338. var str = "您确定删除编号为<" + data.point_name + ">的监测点吗?";
  339. this.$confirm(str, "删除监测点", {
  340. confirmButtonText: "确定",
  341. cancelButtonText: "取消",
  342. })
  343. .then(() => {
  344. this.$axios({
  345. method: "POST",
  346. url: "/api/api_gateway?method=monitor_manage.maintain.checkpoint_delete",
  347. data: this.qs.stringify({
  348. point_id: data.point_id,
  349. }),
  350. }).then((res) => {
  351. console.log(res);
  352. if (res.data.data) {
  353. this.$message({
  354. showClose: true,
  355. message: "删除成功!",
  356. type: "success",
  357. });
  358. this.getmaintainlist();
  359. } else {
  360. this.$message({
  361. showClose: true,
  362. message: "删除失败," + res.data.message,
  363. type: "warning",
  364. });
  365. }
  366. });
  367. })
  368. .catch(() => {
  369. this.$message({
  370. type: "info",
  371. message: "已取消删除",
  372. });
  373. });
  374. },
  375. init() {
  376. // console.log(document.getElementById("mapContainer2"));
  377. var map = new AMap.Map("mapContainer2", {
  378. center: this.center,
  379. resizeEnable: true,
  380. zoom: 10,
  381. lang: "en",
  382. });
  383. AMap.plugin(["AMap.ToolBar", "AMap.Geocoder"], () => {
  384. map.addControl(new AMap.ToolBar());
  385. this.geocoder = new AMap.Geocoder({
  386. city: "全国",
  387. radius: 1000,
  388. });
  389. });
  390. setTimeout(() => {
  391. var marker = new AMap.Marker({
  392. position: this.center,
  393. });
  394. console.log(this.center);
  395. marker.setMap(map);
  396. }, 1000);
  397. this.map = map;
  398. this.testevent();
  399. },
  400. addrChange() {
  401. //位置搜索
  402. var marker = new AMap.Marker();
  403. this.geocoder.getLocation(this.addr, (status, result) => {
  404. if (status === "complete" && result.geocodes.length) {
  405. var lnglat = result.geocodes[0].location;
  406. marker.setPosition(lnglat);
  407. this.map.add(marker);
  408. this.map.setFitView(marker);
  409. this.locationForm = {
  410. lat: lnglat.lat,
  411. lng: lnglat.lng,
  412. };
  413. } else {
  414. this.$message.error("根据地址查询位置失败");
  415. }
  416. });
  417. },
  418. // 地图点击事件
  419. testevent() {
  420. this.map.on("click", (ev) => {
  421. var lnglat = [ev.lnglat.lng, ev.lnglat.lat];
  422. this.locationForm = { lng: lnglat[0], lat: lnglat[1] };
  423. this.map.clearMap();
  424. var marker = new AMap.Marker({
  425. position: lnglat,
  426. });
  427. marker.setMap(this.map);
  428. this.getAddress(lnglat);
  429. setTimeout(() => {
  430. new AMap.InfoWindow({
  431. content: "<h5>" + "当前选中地址" + "</h5>" + this.address,
  432. offset: new AMap.Pixel(0, -32),
  433. }).open(this.map, lnglat);
  434. }, 100);
  435. });
  436. },
  437. getAddress(lnglat) {
  438. AMap.plugin("AMap.Geocoder", () => {
  439. this.geocoder.getAddress(lnglat, (status, result) => {
  440. if (status === "complete" && result.info === "OK") {
  441. this.address = result.regeocode.formattedAddress;
  442. }
  443. });
  444. });
  445. },
  446. addLocationSubm() {
  447. //点击确定
  448. this.ruleForm.lng = this.locationForm.lng;
  449. this.ruleForm.lat = this.locationForm.lat;
  450. this.addLocationDialogVisible = false;
  451. },
  452. addLocationDialogClosed() {
  453. //弹框关闭时
  454. this.locationForm = { lat: "", lng: "" };
  455. this.center = [];
  456. this.map = null;
  457. },
  458. locationSearch() {
  459. if (this.locationForm.lat && this.locationForm.lng) {
  460. let lnglat = [this.locationForm.lng, this.locationForm.lat];
  461. var marker = new AMap.Marker({
  462. position: lnglat,
  463. });
  464. marker.setMap(this.map);
  465. } else {
  466. this.$message.warning("请输入经纬度!");
  467. // return fasle;
  468. }
  469. },
  470. dingwei(data) {
  471. if (this.ruleForm.lng != "" && this.ruleForm.lng != 0) {
  472. if (isNaN(this.ruleForm.lng)) {
  473. this.center[0] = this.ToDigital(this.ruleForm.lng);
  474. } else {
  475. this.center[0] = this.ruleForm.lng;
  476. }
  477. }
  478. if (this.ruleForm.lat != "" && this.ruleForm.lat != 0) {
  479. if (isNaN(this.ruleForm.lat)) {
  480. this.center[1] = this.ToDigital(this.ruleForm.lat);
  481. } else {
  482. this.center[1] = this.ruleForm.lat;
  483. }
  484. }
  485. this.addLocationDialogVisible = true;
  486. setTimeout(() => {
  487. // console.log(this.center);
  488. this.init();
  489. }, 500);
  490. },
  491. //度转度°分′秒″
  492. ToDegrees(val, type) {
  493. if (typeof val == "undefined" || val == "" || isNaN(val)) {
  494. return val;
  495. }
  496. val = val.toString()
  497. var A = "";
  498. if (type == "lng") {
  499. A = val > 0 ? "E" : "W";
  500. } else if (type == "lat") {
  501. A = val > 0 ? "N" : "S";
  502. }
  503. var i = val.indexOf(".");
  504. var strDu = i < 0 ? val : val.substring(0, i); //获取度
  505. var strFen = 0;
  506. var strMiao = 0;
  507. if (i > 0) {
  508. var strFen = "0" + val.substring(i);
  509. strFen = strFen * 60 + "";
  510. i = strFen.indexOf(".");
  511. if (i > 0) {
  512. strMiao = "0" + strFen.substring(i);
  513. strFen = strFen.substring(0, i); //获取分
  514. strMiao = strMiao * 60 + "";
  515. i = strMiao.indexOf(".");
  516. strMiao = strMiao.substring(0, i + 4); //取到小数点后面三位
  517. strMiao = parseFloat(strMiao).toFixed(2); //精确小数点后面两位
  518. }
  519. }
  520. console.log(strDu, strFen, strMiao);
  521. return strDu + "°" + strFen + "′" + strMiao + "″" + A;
  522. },
  523. //度°分′秒″转度
  524. ToDigital(lnglat) {
  525. if (!isNaN(lnglat)) {
  526. return lnglat;
  527. }
  528. console.log(lnglat);
  529. var strDu, strFen, strMiao;
  530. var duindex = lnglat.indexOf("°"); //字符度的下标
  531. var fenindex = lnglat.indexOf("′"); //字符分的下标
  532. var miaoindex = lnglat.indexOf("″"); //字符秒的下标
  533. strDu = lnglat.slice(0, duindex);
  534. strFen = lnglat.slice(duindex + 1, fenindex);
  535. strMiao = lnglat.slice(fenindex + 1, miaoindex);
  536. // len = len > 6 || typeof len == "undefined" ? 6 : len; //精确到小数点后最多六位
  537. strDu =
  538. typeof strDu == "undefined" || strDu == "" ? 0 : parseFloat(strDu);
  539. strFen =
  540. typeof strFen == "undefined" || strFen == ""
  541. ? 0
  542. : parseFloat(strFen) / 60;
  543. strMiao =
  544. typeof strMiao == "undefined" || strMiao == ""
  545. ? 0
  546. : parseFloat(strMiao) / 3600;
  547. var digital = strDu + strFen + strMiao;
  548. if (digital == 0) {
  549. return "";
  550. } else {
  551. return digital.toFixed(6);
  552. }
  553. },
  554. },
  555. beforeCreate() {}, //生命周期 - 创建之前
  556. //生命周期 - 创建完成(可以访问当前this实例)
  557. created() {},
  558. beforeMount() {}, //生命周期 - 挂载之前
  559. //生命周期 - 挂载完成(可以访问DOM元素)
  560. mounted() {
  561. this.getmaintainlist();
  562. },
  563. beforeUpdate() {}, //生命周期 - 更新之前
  564. updated() {}, //生命周期 - 更新之后
  565. beforeDestroy() {}, //生命周期 - 销毁之前
  566. destroyed() {}, //生命周期 - 销毁完成
  567. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  568. };
  569. </script>
  570. <style lang="less" scoped>
  571. .maintainbox_search {
  572. display: flex;
  573. /deep/.el-input {
  574. width: 220px;
  575. margin-right: 15px;
  576. }
  577. }
  578. .addtrapbox {
  579. display: flex;
  580. }
  581. .buttonbox {
  582. margin-bottom: 23px;
  583. padding-left: 100px;
  584. }
  585. /deep/.el-button--info {
  586. background-color: #409eff;
  587. border-color: #409eff;
  588. }
  589. </style>