DialogForm.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <el-dialog
  3. v-if="visible"
  4. :title="form.id?'编辑场馆':'新建场馆'"
  5. :visible.sync="visible"
  6. width="900px"
  7. >
  8. <el-form v-loading="isLoading" :model="form" label-width="100px">
  9. <el-row>
  10. <el-col :span="12">
  11. <el-form-item label="名称">
  12. <el-input v-model="form.name"/>
  13. </el-form-item>
  14. </el-col>
  15. <el-col :span="12">
  16. <el-form-item label="开放时间">
  17. <el-input v-model="form.businessHours"/>
  18. </el-form-item>
  19. </el-col>
  20. </el-row>
  21. <el-form-item label="图片">
  22. <el-upload
  23. :file-list="fileList"
  24. action="#"
  25. list-type="picture-card"
  26. name="fileData"
  27. :http-request="uploaderHandle"
  28. :on-success="uploadSuccess"
  29. :auto-upload="true"
  30. >
  31. <i slot="default" class="el-icon-plus"/>
  32. </el-upload>
  33. </el-form-item>
  34. <el-form-item label="地址">
  35. <el-input v-model="form.address"/>
  36. </el-form-item>
  37. <el-row>
  38. <el-col :span="12">
  39. <el-form-item label="联系人">
  40. <el-input v-model="form.contacts"/>
  41. </el-form-item>
  42. </el-col>
  43. <el-col :span="12">
  44. <el-form-item label="联系电话">
  45. <el-input v-model="form.contactNumber"/>
  46. </el-form-item>
  47. </el-col>
  48. </el-row>
  49. <el-form-item label="简介">
  50. <el-input v-model="form.brief" type="textarea" rows="10"/>
  51. </el-form-item>
  52. <div id="amapcontainer" style="width: 100%;height: 400px"/>
  53. </el-form>
  54. <div slot="footer" class="dialog-footer">
  55. <el-button @click="visible = false">取 消</el-button>
  56. <el-button type="primary" @click="handleSubmit">确 定</el-button>
  57. </div>
  58. </el-dialog>
  59. </template>
  60. <script>
  61. import { uploaderHandle } from '@/api/upload'
  62. import AMapLoader from '@amap/amap-jsapi-loader'
  63. import { save, updateById } from '@/api/bz/base/venue'
  64. export default {
  65. data() {
  66. return {
  67. visible: false,
  68. isLoading: false,
  69. listAllAuthorities: [],
  70. form: {},
  71. fileList: [],
  72. map: null,
  73. marker: null,
  74. lng: null,
  75. lat: null
  76. }
  77. },
  78. mounted() {
  79. },
  80. methods: {
  81. uploaderHandle,
  82. uploadSuccess(res, file, fileList) {
  83. file.url = res.url
  84. this.fileList = fileList
  85. },
  86. open(data) {
  87. this.visible = true
  88. this.isLoading = false
  89. this.form = Object.assign({}, data)
  90. this.initMap()
  91. },
  92. initMap() {
  93. const _this = this
  94. AMapLoader.load({
  95. key: '173fa0186964179b9c6f43d59f72172f',
  96. version: '2.0',
  97. plugins: ['AMap.ToolBar', 'AMap.Scale']
  98. }).then((AMap) => {
  99. this.map = new AMap.Map('amapcontainer', {
  100. zoom: 15
  101. })
  102. _this.map.on('click', function(e) {
  103. _this.lng = e.lnglat.lng
  104. _this.lat = e.lnglat.lat
  105. if (_this.marker) {
  106. _this.marker.setPosition([e.lnglat.lng, e.lnglat.lat])
  107. } else {
  108. _this.marker = new AMap.Marker({
  109. position: [e.lnglat.lng, e.lnglat.lat],
  110. clickable: true,
  111. map: _this.map
  112. })
  113. }
  114. })
  115. }).catch(e => {
  116. console.log(e)
  117. })
  118. },
  119. handleSubmit() {
  120. console.log(this.fileList)
  121. console.log(this.lng)
  122. console.log(this.lat)
  123. console.log(this.form)
  124. const litpics = []
  125. this.fileList.forEach(o => {
  126. litpics.push(o.url)
  127. })
  128. this.isLoading = true
  129. const param = { ...this.form, lng: this.lng, lat: this.lat, litpics }
  130. if (this.form.id) {
  131. console.log(param)
  132. updateById(this.form.id, param).then(() => {
  133. this.visible = false
  134. this.$emit('ok')
  135. }).finally(() => {
  136. this.isLoading = false
  137. })
  138. } else {
  139. save(param).then(res => {
  140. this.visible = false
  141. this.$emit('ok')
  142. }).finally(() => {
  143. this.isLoading = false
  144. })
  145. }
  146. }
  147. }
  148. }
  149. </script>