IndexEdit.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <div>
  3. <el-dialog
  4. v-loading="loading"
  5. :show-close="false"
  6. :close-on-click-modal="false"
  7. :visible.sync="isShow"
  8. :title="'编辑学校'"
  9. :fullscreen="false"
  10. width="700px"
  11. custom-class="xl-dialog"
  12. center
  13. >
  14. <base-form ref="ruleForm" class="lib-edit" :data="formData" :is-inline="false" label-width="110px" :insertSlotArr="[9]">
  15. <div slot="OI9" class="scoped-other-form">
  16. <el-form-item label="点位坐标" class="scoped-item-two item">
  17. 纬度N<el-input v-model="cObj.latitude" disabled />
  18. 经度E<el-input v-model="cObj.longitude" disabled />
  19. <el-button type="primary" class="map-btn" size="small" @click="handleMap">点击从地图获取</el-button>
  20. </el-form-item>
  21. </div>
  22. <div slot="footer" style="padding-top: 20px;">
  23. <el-button class="xl-form-btn t2" @click="close">关 闭</el-button>
  24. <el-button class="xl-form-btn t1" @click="close('confirm')">确定</el-button>
  25. </div>
  26. </base-form>
  27. </el-dialog>
  28. <handle-map :is-show="isShowMap" @close="closeMap" />
  29. </div>
  30. </template>
  31. <script>
  32. import handleMap from '@/components/Common/Map'
  33. export default {
  34. components: { handleMap },
  35. mixins,
  36. props: {
  37. isShow: Boolean,
  38. curObj: Object
  39. },
  40. inject: ['parentData'],
  41. data() {
  42. return {
  43. formData: [],
  44. loading: true,
  45. cObj: {},
  46. isShowMap: false
  47. }
  48. },
  49. watch: {
  50. isShow: function(val) {
  51. if (val) {
  52. if (val) {
  53. if (this.curObj.id) {
  54. this.$api.school.admschooldetail({id: this.curObj.id}).then(res => {
  55. let curData = res || {}
  56. this.cObj = curData || {}
  57. this.getDef()
  58. })
  59. } else {
  60. this.cObj = this.curObj
  61. this.getDef()
  62. }
  63. }
  64. }
  65. },
  66. },
  67. methods: {
  68. getDef (str) {
  69. let params = { ...this.cObj }
  70. if (str === 'school_type') {
  71. params = {...this.$refs.ruleForm.baseForm}
  72. }
  73. const disabled = false
  74. if (!params.pri_image) params.pri_image = 'http://img.honglounews.com/20210429034015-4091.png'
  75. let remoteOptionsHouse = []
  76. if (params.estate_list && params.estate_list.length > 0) {
  77. params.estate_id_list = params.estate_list.map(item => {
  78. remoteOptionsHouse.push({ keyRO: item.estate_name, valRO: item.id })
  79. return item.id
  80. })
  81. } else {
  82. params.estate_list = []
  83. }
  84. if (params.school_type === '2') {
  85. this.formData = [
  86. { label: '学校名称', key: 'school_name' },
  87. { label: '所属区域', key: 'area_type', type: 'select', class: 'c-2', options: this.$dictData.area_type },
  88. { label: '学校属性', key: 'school_attrib', type: 'select', class: 'c-2', options: this.$dictData.school_attrib },
  89. { label: '学校类型', key: 'school_type', type: 'select', class: 'c-2', options: this.$dictData.school_type, changeHandle: this.typeChange },
  90. // { label: '学校分类', key: 'school_cate', type: 'select', class: 'c-2', options: this.$dictData.school_cate },
  91. { label: '学校预警', key: 'school_warn', type: 'select', class: 'c-2', options: this.$dictData.school_warn },
  92. { label: '主图', key: 'pri_image', type: 'upload', class: 'c-2' },
  93. { label: '学区范围图', key: 'district_img', type: 'upload', class: 'c-2' },
  94. { label: '学区范围', key: 'district',type: 'textarea' },
  95. { label: '所属楼盘', key: 'estate_id_list', multiple: true, type: 'selectRemote',
  96. remoteParams: { skey: 'estate_name', api: `house.admestatelist`, opKey: 'estate_name', opVal: 'id' },
  97. remoteOptions: remoteOptionsHouse
  98. },
  99. { label: '学校地址', key: 'address' },
  100. { label: '学费', key: 'tuition', class: 'c-2', type: 'inputFont', appendFont: '万元/年' },
  101. { label: '有无住宿', key: 'is_live', type: 'select', class: 'c-2', options: this.$dictData.sys_yesno2 },
  102. ]
  103. } else {
  104. this.formData = [
  105. { label: '学校名称', key: 'school_name' },
  106. { label: '所属区域', key: 'area_type', type: 'select', class: 'c-2', options: this.$dictData.area_type },
  107. { label: '学校属性', key: 'school_attrib', type: 'select', class: 'c-2', options: this.$dictData.school_attrib },
  108. { label: '学校类型', key: 'school_type', type: 'select', class: 'c-2', options: this.$dictData.school_type, changeHandle: this.typeChange },
  109. // { label: '学校分类', key: 'school_cate', type: 'select', class: 'c-2', options: this.$dictData.school_cate },
  110. { label: '学校预警', key: 'school_warn', type: 'select', class: 'c-2', options: this.$dictData.school_warn },
  111. { label: '主图', key: 'pri_image', type: 'upload', class: 'c-2' },
  112. { label: '学区范围图', key: 'district_img', type: 'upload', class: 'c-2' },
  113. { label: '学区范围', key: 'district',type: 'textarea' },
  114. { label: '所属楼盘', key: 'estate_id_list', multiple: true, type: 'selectRemote',
  115. remoteParams: { skey: 'estate_name', api: `house.admestatelist`, opKey: 'estate_name', opVal: 'id' },
  116. remoteOptions: remoteOptionsHouse
  117. },
  118. { label: '学校地址', key: 'address' },
  119. ]
  120. }
  121. this.setDefaultValue(params)
  122. },
  123. typeChange () {
  124. this.getDef('school_type')
  125. },
  126. close(str) {
  127. if (str === 'confirm') {
  128. this.$refs['ruleForm'].$refs['baseForm'].validate((valid) => {
  129. if (valid) {
  130. const oldform = this.$refs.ruleForm.baseForm
  131. const newForm = { ...oldform }
  132. if (this.curObj.id) newForm.id = this.curObj.id
  133. if (newForm.estate_id_list && newForm.estate_id_list.length > 0) {
  134. newForm.estate_id_list = newForm.estate_id_list.join(',')
  135. } else {
  136. newForm.estate_id_list = ''
  137. }
  138. newForm.longitude = this.cObj.longitude
  139. newForm.latitude = this.cObj.latitude
  140. if (!newForm.longitude) return this.$msgw('请选择经度!')
  141. else if (!newForm.latitude) return this.$msgw('请选择纬度!')
  142. let apiStr = 'admschooladd'
  143. if (newForm.id) apiStr = 'admschooledit'
  144. this.$api.school[apiStr](newForm).then(data => {
  145. this.$msgs(newForm.id ? '编辑成功' : '新增成功')
  146. this.$emit('close', newForm)
  147. })
  148. }
  149. })
  150. } else {
  151. this.$emit('close')
  152. this.setDefaultValue()
  153. }
  154. },
  155. handleMap() { // 定位
  156. this.isShowMap = true
  157. const pointObj = {
  158. latitude: this.cObj.latitude || '',
  159. longitude: this.cObj.longitude || '',
  160. address: this.cObj.address || ''
  161. }
  162. this.$root.$emit('handleMap', pointObj)
  163. },
  164. closeMap(obj) {
  165. if (obj) {
  166. const oldform = this.$refs.ruleForm.baseForm
  167. const newForm = { ...oldform, ...obj }
  168. this.cObj = newForm
  169. this.setDefaultValue(newForm)
  170. }
  171. this.isShowMap = false
  172. }
  173. }
  174. }
  175. </script>
  176. <style lang="scss" scoped>
  177. @import '../../../../styles/libEdit.scss';
  178. .lib-edit {
  179. padding-top: 0;
  180. ::v-deep .el-form-item {
  181. margin-bottom: 10px;
  182. }
  183. ::v-deep .el-date-editor.el-input {
  184. width: 100%;
  185. }
  186. }
  187. .scoped-other-form {
  188. .scoped-item-two {
  189. .el-input {
  190. display: inline-block;
  191. width: 115px;
  192. margin: 0 10px;
  193. ::v-deep input {
  194. text-align: center;
  195. }
  196. }
  197. }
  198. }
  199. .map-btn{
  200. height: 36px;
  201. }
  202. </style>