BusinessDataDetail.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <el-dialog v-if="isShow"
  3. :model-value="isShow"
  4. title="编辑数据"
  5. :width="700"
  6. :close-on-click-modal="false"
  7. :before-close="handleClose"
  8. >
  9. <div id="addData">
  10. <el-form ref="form" :model="formData" :rules="formDataRules" style="margin: 0 15px" :label-width="110">
  11. <el-form-item label="ID:" v-show="false">
  12. <el-input v-model="formData.id" />
  13. </el-form-item>
  14. <el-form-item label="标题:" prop="title" >
  15. <el-input v-model="formData.title" placeholder="请输入标题" :disabled="formData.isDataView" />
  16. </el-form-item>
  17. <el-form-item label="描述:" prop="content">
  18. <el-input v-model="formData.content" placeholder="请输入描述" :disabled="formData.isDataView" />
  19. </el-form-item>
  20. <el-form-item label="类别:" prop="menuId">
  21. <el-select v-model="formData.menuId" placeholder="请选择类别" :disabled="formData.isDataView" >
  22. <el-option
  23. v-for="item in category"
  24. :key="item.value"
  25. :label="item.label"
  26. :value="item.value"
  27. />
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item label="地理信息:" prop="geometryStr" >
  31. <el-input v-model="formData.geometryStr" placeholder="请设置地理信息" :disabled="true" >
  32. <template #prepend>
  33. <el-button @click="handleMapShow(true)">
  34. <span v-if="formData.isDataView">查看</span>
  35. <span v-else>设置</span>
  36. 地理信息
  37. </el-button>
  38. </template>
  39. <template #append>
  40. <el-button @click="handleJsonDataView(true)">
  41. 查看GeoJson
  42. </el-button>
  43. </template>
  44. </el-input>
  45. </el-form-item>
  46. <el-form-item label="地名地址库:" prop="address" >
  47. <el-input v-model="formData.address" placeholder="请输入地名地址库名称" :disabled="formData.isDataView" />
  48. </el-form-item>
  49. </el-form>
  50. </div>
  51. <template #footer>
  52. <el-button type="primary" @click="submit" v-show="!formData.isDataView">保存</el-button>
  53. </template>
  54. </el-dialog>
  55. <OlMap v-if="isMapShow"
  56. :is-show="isMapShow"
  57. :is-view="formData.isDataView"
  58. :menuId="formData.menuId"
  59. :geometryStr="formData.geometryStr"
  60. :callback="setMapData"
  61. :close="handleMapShow">
  62. </OlMap>
  63. <JsonDataView v-if="isJsonDataView"
  64. :is-show="isJsonDataView"
  65. :title="'地理数据预览'"
  66. :data="formData.geometryStr"
  67. :close="handleJsonDataView"
  68. >
  69. </JsonDataView>
  70. </template>
  71. <script>
  72. import OlMap from "@/components/map/OlMap";
  73. import JsonDataView from "@/components/json/JsonDataView";
  74. import api from "@/api/data/BusinessData";
  75. import menuApi from "@/api/data/MenuData";
  76. export default {
  77. data() {
  78. return {
  79. formData: {},
  80. oriFormData: {},
  81. formDataRules: {
  82. title: [
  83. { required: true, message: '请输入标题', trigger: 'change' },
  84. ],
  85. content: [
  86. { required: true, message: '请输入描述', trigger: 'change' },
  87. ],
  88. menuId: [
  89. { required: true, message: '请选择类别', trigger: 'change' },
  90. ],
  91. geometryStr: [
  92. { required: true, message: '请输入Geojson数据', trigger: 'blur' },
  93. ],
  94. // address: [
  95. // { required: true, message: '请输入地名地址库名称', trigger: 'change' },
  96. // ]
  97. },
  98. category: [],
  99. isMapShow: false,
  100. isJsonDataView: false,
  101. }
  102. },
  103. props: {
  104. isShow: Boolean,
  105. item: Object,
  106. close: Function
  107. },
  108. watch: {
  109. "formData.menuId": function (newVal, oldVal) {
  110. let app = this;
  111. if (app.formData.isEdit) {
  112. if (newVal!==app.oriFormData.menuId) {
  113. app.$msgbox.confirm('修改类型需重新设置地理信息,确定要修改吗?','Warning', {
  114. confirmButtonText: '确认修改',
  115. cancelButtonText: '恢复原始类别及地理信息',
  116. type: 'warning',
  117. }).then(()=>{
  118. app.formData.geometryStr = ''
  119. }).catch(()=>{
  120. app.formData.menuId = app.oriFormData.menuId;
  121. app.formData.geometryStr = app.oriFormData.geometryStr;
  122. })
  123. } else {
  124. app.formData.geometryStr = app.oriFormData.geometryStr;
  125. }
  126. }
  127. }
  128. },
  129. mounted() {
  130. this.getMenuData()
  131. this.formData = this.item;
  132. this.oriFormData = JSON.parse(JSON.stringify(this.formData))
  133. },
  134. components: {
  135. OlMap,
  136. JsonDataView,
  137. },
  138. methods: {
  139. handleMapShow(flag) {
  140. if (flag) {
  141. if (this.formData.menuId) {
  142. this.isMapShow = true
  143. } else {
  144. this.$message({message: '请先选择类别', type: 'warning'})
  145. }
  146. } else {
  147. this.isMapShow = false
  148. }
  149. },
  150. getMenuData() {
  151. let app = this;
  152. let params = {
  153. type: "1",
  154. parentId: "3",
  155. }
  156. menuApi.getMenuData(params).then(res=>{
  157. if (res.code===200) {
  158. app.category = res.content
  159. }
  160. })
  161. },
  162. setMapData(geometry) {
  163. this.formData.geometryStr = JSON.stringify(geometry)
  164. },
  165. handleClose() {
  166. this.close();
  167. },
  168. submit() {
  169. let app = this;
  170. app.$refs.form.validate(valid=>{
  171. if (valid) {
  172. if (app.formData.isEdit){
  173. app.updateData();
  174. } else {
  175. app.addData();
  176. }
  177. } else {
  178. app.$message({message: '请完善数据', type: 'warning'})
  179. }
  180. })
  181. },
  182. // 数据录入
  183. addData() {
  184. let app = this;
  185. let params = JSON.parse(JSON.stringify(app.formData));
  186. params['menuNameOne'] = '二维数据'
  187. api.addData(params).then(res=>{
  188. if (res.code===200) {
  189. app.$message({message: '录入成功', type: 'success'})
  190. app.close(true);
  191. }
  192. })
  193. },
  194. // 编辑数据
  195. updateData() {
  196. let app = this;
  197. let params = JSON.parse(JSON.stringify(app.formData));
  198. delete params.createDate;
  199. delete params.updateDate;
  200. api.updateData(params).then(res=>{
  201. if (res.code===200) {
  202. app.$message({message: '修改成功', type: 'success'})
  203. app.close(true);
  204. }
  205. })
  206. },
  207. handleJsonDataView(flag) {
  208. this.isJsonDataView = flag;
  209. }
  210. }
  211. }
  212. </script>
  213. <style>
  214. #addData {
  215. width: 100%;
  216. height: 100%;
  217. }
  218. </style>