made delete component reusable, added error and success place holder

This commit is contained in:
Chad Derya 2019-09-09 19:03:32 +01:00
parent 0ee3fc3722
commit 51aeb7629f
2 changed files with 59 additions and 34 deletions

View File

@ -1,14 +1,15 @@
<template> <template>
<div> <div>
<el-button icon="el-icon-delete" size="mini" type="danger" @click=" dialogVisible=true"> <el-button icon="el-icon-delete" size="mini" type="danger" @click="openDeletePopup">
Delete Delete
</el-button> </el-button>
<el-dialog :visible.sync="dialogVisible"> <el-dialog :visible.sync="dialogVisible">
<div v-if="viewState==='initialState'">
<div> <div>
<h3> <h3>
Are you sure you want to delete this {{ type }} ? Are you sure you want to delete this {{ type }} ?
</h3> </h3>
<p>To delete this {{ type }}, type in <b>{{ name }}</b> and click delete</p> <p>To delete this {{ type }}, type in <b>{{ item.name }}</b> and click delete</p>
</div> </div>
<el-row :gutter="20"> <el-row :gutter="20">
<el-col :span="12" :offset="6"> <el-col :span="12" :offset="6">
@ -23,6 +24,13 @@
<el-button type="danger" :disabled="isNameCorrect" @click="handleSubmit"> <el-button type="danger" :disabled="isNameCorrect" @click="handleSubmit">
Confirm Confirm
</el-button> </el-button>
</div>
<div v-else-if="viewState==='Success'">
<h1>SUCCESS you can now close this popup</h1>
</div>
<div v-else-if="viewState==='Error'">
<h1>ERROR please try again, if the error persist contact Chadmin!</h1>
</div>
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
@ -32,34 +40,49 @@
export default { export default {
props: { props: {
color: { item: {
type: Object,
default: function() {
return {
name: 'BROKEN!-KEROSENOS-BROKEN!',
_id: 'THIS-ID-IS-BROKEN!'
}
}
},
type: {
type: String, type: String,
default: '#1890ff' default: 'chad'
} }
}, },
data() { data() {
return { return {
dialogVisible: false, dialogVisible: false,
isNameCorrect: true,
input: '', input: '',
type: 'product', isNameCorrect: false,
name: 'Kerosenos' viewState: 'initialState'
} }
}, },
methods: { methods: {
openDeletePopup() {
this.dialogVisible = true
this.viewState = 'initialState'
},
checkAllSuccess() { checkAllSuccess() {
return Object.keys(this.listObj).every(item => this.listObj[item].hasSuccess) return Object.keys(this.listObj).every(item => this.listObj[item].hasSuccess)
}, },
handleSubmit() { handleSubmit() {
const arr = Object.keys(this.listObj).map(v => this.listObj[v]) console.log(this.input)
if (!this.checkAllSuccess()) { console.log(this.item._id)
this.$message('Please wait for all images to be uploaded successfully. If there is a network problem, please refresh the page and upload again!') if (this.input) {
return this.viewState = 'Success'
} else if (!this.input) {
this.viewState = 'Error'
} }
this.$emit('successCBK', arr) // const arr = Object.keys(this.listObj).map(v => this.listObj[v])
this.listObj = {} // if (!this.checkAllSuccess()) {
this.fileList = [] // this.$message('Please wait for all images to be uploaded successfully. If there is a network problem, please refresh the page and upload again!')
this.dialogVisible = false // return
// }
}, },
handleSuccess(response, file) { handleSuccess(response, file) {
const uid = file.uid const uid = file.uid

View File

@ -41,8 +41,10 @@
</el-button> </el-button>
</router-link> </router-link>
<editorImage /> <editorImage
:item="scope.row"
:type="'Product'"
/>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>