1.第一步,先在父组件中引用,设置ref的值
append-to-body width="1000px" title="编辑" :close-on-click-modal="false"> :visible.sync="dialogEditVisible" />
2.引入和注册组件:
import DialogEdit from './edit'
export default {
components: { Pagination,DialogAdd,DialogEdit,DialogView},
3.需要再data中设置对话框默认不打开:
dialogEditVisible: false,
4.在父组件中mothod中实现调用对话框的方法:
handleEdit(scope) {
this.dialogEditVisible = true
this.$nextTick(() => {
//this.$refs.dialogEdit
this.$refs.dialogEdit.getDetailed()
})
},
5.创建一个vue组件,名字为edit.vue,并且在method中添加getDetailed() ,这个方法:
getDetailed() { const loading = this.$loading({ lock: true, text: 'Loading', spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.7)' }) getInfo({ code: this.proid }).then(response => { this.form = response.data.mdProjectInfo, loading.close() }).catch(function() { loading.close() }) },
import { saveData,getInfo,edit} from '@/api/records'
import { getAllList } from '@/api/maApplicationInfo'
import { Message } from 'element-ui'
export default {
inject: ['getList'],
props: { // 第二种方式
proid: {
type: String,
required: true
}
},
data() {
return {
form: {},
types: [],
symbols: []
}
},
created() {
this.getproject()
},
methods: {
getDetailed() {
const loading = this.$loading({
lock: true,
text: 'Loading',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
})
getInfo({ code: this.proid }).then(response => {
this.form = response.data.mdProjectInfo,
loading.close()
}).catch(function() {
loading.close()
})
},
getproject(){
getAllList().then(response=> {
this.symbols = response.data
})
},
selectGoodsByGroupId(val) { // 根据设备组id获取相应的商品
if (val != null && val !== '' && val !== undefined) {
for (var i = 0; i < this.symbols.length; i++) {
if (this.symbols[i].id === val) {
this.form.userId = this.symbols[i].customerMid
}
}
}
},
save(){
this.form.startTime = this.form.itemTime[0]
this.form.endTime = this.form.itemTime[1]
const loading = this.$loading({
lock: true,
text: 'Loading',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
})
edit(this.form).then(response => {
Message({
message: '编辑成功',
type: 'success',
duration: 5 * 1000
})
this.$emit('update:visible', false)
loading.close()
this.getList()
}).catch(response => {
loading.close()
this.getList()
})
},
closePage() {
this.$emit('update:visible', false)
}
}
}
相关文章
发表评论