deviceInfo-amap.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <style scoped>
  2. .user-panel {
  3. margin: 10px auto;
  4. }
  5. </style>
  6. <template>
  7. <el-dialog
  8. :visible.sync="showDialog"
  9. :title="title"
  10. :modal-append-to-body="false"
  11. style="text-align:left;"
  12. @close="closeDialog"
  13. :close-on-click-modal="false"
  14. >
  15. <div class="user-panel" v-loading="loading">
  16. <el-form ref="form" :model="formModel" :label-width="'100px'">
  17. <el-row>
  18. <el-col :span="24" style="height:400px;">
  19. <!-- <baidu-map
  20. class="bm-view"
  21. :center="mapCenter"
  22. :zoom="mapZoom"
  23. @dblclick="ondblclick"
  24. @dblclick="ondblclick"
  25. :showAddressBar="true"
  26. :autoLocation="true"
  27. :double-click-zoom="false"
  28. :scroll-wheel-zoom="true"
  29. >
  30. <bm-marker :position="pointPosition" :dragging="true" animation="BMAP_ANIMATION_BOUNCE"></bm-marker>
  31. </baidu-map> -->
  32. <el-amap
  33. ref="map"
  34. vid="amapDemo"
  35. :amap-manager="amapManager"
  36. :center="pointPosition"
  37. :zoom="zoom"
  38. :events="events"
  39. class="amap-demo">
  40. <el-amap-marker vid="amapDemo" :position="pointPosition"></el-amap-marker>
  41. </el-amap>
  42. </el-col>
  43. <el-col :span="24">
  44. <el-input v-model="formModel.longtitude" readonly style="width:20%"></el-input>
  45. <el-input v-model="formModel.latitude" readonly style="width:20%"></el-input>
  46. </el-col>
  47. </el-row>
  48. </el-form>
  49. </div>
  50. <span slot="footer" class="dialog-footer">
  51. <el-button @click="closeDialog">取 消</el-button>
  52. <el-button type="primary" @click="handleSubmit" :loading="submitting">确 定</el-button>
  53. </span>
  54. </el-dialog>
  55. </template>
  56. <script>
  57. import Constant from "@/constant";
  58. import deviceInfoApi from "@/api/base/deviceInfo";
  59. import AMap from "vue-amap";
  60. let amapManager = new AMap.AMapManager();
  61. export default {
  62. props: ["businessKey", "title"],
  63. data() {
  64. return {
  65. amapManager,
  66. zoom: 12,
  67. formModel: {},
  68. showDialog: true,
  69. loading: false,
  70. submitting: false,
  71. canQuery: true,
  72. mapZoom: 12,
  73. pointPosition: [112.240222, 30.337053],
  74. showPosition: false,
  75. events: {
  76. click: e => {
  77. var pt = e.lnglat;//点击选择新地址为中心点
  78. console.log(pt);
  79. this.pointPosition = [pt.lng, pt.lat];
  80. this.formModel.longtitude = pt.lng;
  81. this.formModel.latitude = pt.lat;
  82. }
  83. }
  84. };
  85. },
  86. methods: {
  87. mapLoad(longtitude, latitude) {
  88. this.pointPosition = [longtitude,latitude];
  89. },
  90. closeDialog() {
  91. this.$emit("close", false);
  92. },
  93. handleSubmit() {
  94. var self = this;
  95. this.$refs["form"].validate(valid => {
  96. if (valid) {
  97. (function() {
  98. var id = self.formModel.id;
  99. if (id == null || id.length == 0) {
  100. return deviceInfoApi.add(self.formModel);
  101. } else {
  102. return deviceInfoApi.update(self.formModel);
  103. }
  104. })().then(function(response) {
  105. var jsonData = response.data;
  106. if (jsonData.result) {
  107. self.$message({
  108. message: "保存成功!",
  109. type: "success"
  110. });
  111. self.$emit("close", true);
  112. } else {
  113. self.$message({
  114. message: jsonData.message + "",
  115. type: "warning"
  116. });
  117. //self.$emit("close", false);
  118. }
  119. });
  120. }
  121. });
  122. }
  123. },
  124. mounted: function() {
  125. var self = this;
  126. (function() {
  127. if (self.businessKey.length == 0) {
  128. self.$message({
  129. message: "查无学校编号",
  130. type: "warning"
  131. });
  132. return null;
  133. } else {
  134. return deviceInfoApi.edit(self.businessKey);
  135. }
  136. })()
  137. .then(response => {
  138. var jsonData = response.data;
  139. self.loading = false;
  140. if (jsonData.result) {
  141. self.formModel = jsonData.data;
  142. if(self.formModel.longtitude!=null && self.formModel.latitude!=null){
  143. this.mapLoad(self.formModel.longtitude, self.formModel.latitude);
  144. }
  145. } else {
  146. self.$message.error(jsonData.message + "");
  147. }
  148. })
  149. .catch(error => {
  150. self.$message.error(error + "");
  151. });
  152. }
  153. };
  154. </script>
  155. <style>
  156. .bm-view {
  157. width: 100%;
  158. height: 400px;
  159. }
  160. .amap-demo{
  161. width: 100%;
  162. height: 400px;
  163. }
  164. </style>