|
|
|
@ -2,7 +2,7 @@ |
|
|
|
|
<div class="wrap"> |
|
|
|
|
<el-card shadow="hover" class="mgb20"> |
|
|
|
|
<div class="flex-between"> |
|
|
|
|
<div class="per_title" v-preventReClick @click="$router.back()"> |
|
|
|
|
<div class="per_title" v-preventReClick @click="back"> |
|
|
|
|
<i class="el-icon-arrow-left"></i> |
|
|
|
|
<span class="per_back">返回</span> |
|
|
|
|
<span class="per_school" v-text="isDetail ? '查看源模型' : (id ? '编辑源模型' : '新增源模型')"></span> |
|
|
|
@ -66,9 +66,19 @@ export default { |
|
|
|
|
value: 'id' |
|
|
|
|
}, |
|
|
|
|
codeKey: 1, |
|
|
|
|
submiting: false |
|
|
|
|
submiting: false, |
|
|
|
|
updateTime: 0 |
|
|
|
|
}; |
|
|
|
|
}, |
|
|
|
|
watch: { |
|
|
|
|
// 监听信息是否有更改,有的话页面离开的时候要询问是否要保存 |
|
|
|
|
form: { |
|
|
|
|
handler(){ |
|
|
|
|
this.updateTime++ |
|
|
|
|
}, |
|
|
|
|
deep:true |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
mounted() { |
|
|
|
|
this.getType() |
|
|
|
|
}, |
|
|
|
@ -91,6 +101,7 @@ export default { |
|
|
|
|
list.map(e => { |
|
|
|
|
// 取得父级id跟子级id的集合 |
|
|
|
|
if (id === e.id) { |
|
|
|
|
parentId.shift() // 全部的id要去掉 |
|
|
|
|
this.categoryIdCus = [...parentId, e.id] |
|
|
|
|
} else { |
|
|
|
|
e.children && this.handleId(e.children, id, [...parentId, e.id]) |
|
|
|
@ -112,7 +123,7 @@ export default { |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
handleLeaf(data) |
|
|
|
|
this.categoryList = data |
|
|
|
|
this.categoryList = data[0].children |
|
|
|
|
if (this.id) { |
|
|
|
|
this.getData() |
|
|
|
|
} else { |
|
|
|
@ -121,13 +132,13 @@ export default { |
|
|
|
|
}).catch(res => {}) |
|
|
|
|
}, |
|
|
|
|
// 保存 |
|
|
|
|
submit(postStatus){ |
|
|
|
|
submit(postStatus, fromBack){ |
|
|
|
|
if (this.submiting) return false |
|
|
|
|
const { modelName, categoryId, modelDemo } = this.form |
|
|
|
|
const categoryIdCus = this.categoryIdCus |
|
|
|
|
const id = this.id |
|
|
|
|
if (!modelName) return this.$message.error('请输入模型名称') |
|
|
|
|
if (!categoryIdCus.length) return this.$message.error('请选择模型分类') |
|
|
|
|
if (categoryIdCus[0] === 1) return this.$message.error('请选择模型分类') |
|
|
|
|
if (postStatus) { |
|
|
|
|
if (!modelDemo) return this.$message.error('请输入模型代码') |
|
|
|
|
} |
|
|
|
@ -142,19 +153,41 @@ export default { |
|
|
|
|
data.id = id |
|
|
|
|
this.$post(this.api.updateSysModelDemo, data).then(res => { |
|
|
|
|
this.$message.success('编辑成功') |
|
|
|
|
this.$router.back() |
|
|
|
|
fromBack || this.$router.back() |
|
|
|
|
}).catch(res => { |
|
|
|
|
this.submiting = false |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
this.$post(this.api.saveSysModelDemo, data).then(res => { |
|
|
|
|
this.$message.success('新增成功') |
|
|
|
|
this.$router.back() |
|
|
|
|
fromBack || this.$router.back() |
|
|
|
|
}).catch(res => { |
|
|
|
|
this.submiting = false |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
// 返回上一页 |
|
|
|
|
backPage() { |
|
|
|
|
this.$router.back() |
|
|
|
|
}, |
|
|
|
|
// 返回 |
|
|
|
|
back() { |
|
|
|
|
const id = this.id |
|
|
|
|
const updateTime = this.updateTime |
|
|
|
|
// 更改了信息才需要提示 |
|
|
|
|
if ((id && updateTime > 1) || (!id && updateTime)) { |
|
|
|
|
this.$confirm(`编辑的内容未保存,是否保存?`, '提示', { |
|
|
|
|
type: 'warning' |
|
|
|
|
}).then(() => { |
|
|
|
|
this.submit(this.postStatus ? 1 : 0, 1) |
|
|
|
|
this.backPage() |
|
|
|
|
}).catch(() => { |
|
|
|
|
this.backPage() |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
this.backPage() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
</script> |
|
|
|
|