|
@@ -8,10 +8,10 @@
|
|
|
</el-form-item>
|
|
|
<el-form-item label="父编号" prop="parentId">
|
|
|
<TreeSelect
|
|
|
- v-model="formData.parentId"
|
|
|
- :options="categoryTree"
|
|
|
- :normalizer="normalizer"
|
|
|
- placeholder="请选择父编号"
|
|
|
+ v-model="formData.parentId"
|
|
|
+ :options="categoryTree"
|
|
|
+ :normalizer="normalizer"
|
|
|
+ placeholder="请选择父编号"
|
|
|
/>
|
|
|
</el-form-item>
|
|
|
</el-form>
|
|
@@ -24,7 +24,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
- import * as CategoryApi from '@/api/infra/demo'
|
|
|
+ import * as CategoryApi from '@/api/infra/demo';
|
|
|
import TreeSelect from "@riophae/vue-treeselect";
|
|
|
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
|
|
|
export default {
|
|
@@ -56,71 +56,54 @@
|
|
|
},
|
|
|
methods: {
|
|
|
/** 打开弹窗 */
|
|
|
- open(id) {
|
|
|
+ async open(id) {
|
|
|
this.dialogVisible = true;
|
|
|
this.reset();
|
|
|
- const that = this;
|
|
|
// 修改时,设置数据
|
|
|
if (id) {
|
|
|
this.formLoading = true;
|
|
|
try {
|
|
|
- CategoryApi.getCategory(id).then(res=>{
|
|
|
- that.formData = res.data;
|
|
|
- that.title = "修改分类";
|
|
|
- })
|
|
|
+ const res = await CategoryApi.getCategory(id);
|
|
|
+ this.formData = res.data;
|
|
|
+ this.title = "修改分类";
|
|
|
} finally {
|
|
|
this.formLoading = false;
|
|
|
}
|
|
|
}
|
|
|
this.title = "新增分类";
|
|
|
- this.getCategoryTree();
|
|
|
+ await this.getCategoryTree();
|
|
|
},
|
|
|
/** 提交按钮 */
|
|
|
- submitForm() {
|
|
|
- this.formLoading = true;
|
|
|
+ async submitForm() {
|
|
|
+ // 校验主表
|
|
|
+ await this.$refs["formRef"].validate();
|
|
|
+ this.formLoading = true;
|
|
|
try {
|
|
|
- const that = this;
|
|
|
- let data = this.formData;
|
|
|
- let validate = false;
|
|
|
- // 校验主表
|
|
|
- this.getRef("formRef").validate(valid => {
|
|
|
- validate = valid;
|
|
|
- });
|
|
|
- // 所有表单校验通过后方可提交
|
|
|
- if (!validate) {
|
|
|
- return;
|
|
|
- }
|
|
|
- // 修改的提交
|
|
|
+ const data = this.formData;
|
|
|
+ // 修改的提交
|
|
|
if (data.id) {
|
|
|
- CategoryApi.updateCategory(data).then(response => {
|
|
|
- that.$modal.msgSuccess("修改成功");
|
|
|
- that.dialogVisible = false;
|
|
|
- that.$emit('success');
|
|
|
- });
|
|
|
+ await CategoryApi.updateCategory(data);
|
|
|
+ this.$modal.msgSuccess("修改成功");
|
|
|
+ this.dialogVisible = false;
|
|
|
+ this.$emit('success');
|
|
|
return;
|
|
|
}
|
|
|
// 添加的提交
|
|
|
- CategoryApi.createCategory(data).then(response => {
|
|
|
- that.$modal.msgSuccess("新增成功");
|
|
|
- that.dialogVisible = false;
|
|
|
- that.$emit('success');
|
|
|
- });
|
|
|
- }finally {
|
|
|
+ await CategoryApi.createCategory(data);
|
|
|
+ this.$modal.msgSuccess("新增成功");
|
|
|
+ this.dialogVisible = false;
|
|
|
+ this.$emit('success');
|
|
|
+ } finally {
|
|
|
this.formLoading = false;
|
|
|
}
|
|
|
},
|
|
|
- getRef(refName){
|
|
|
- return this.$refs[refName];
|
|
|
- },
|
|
|
/** 获得分类树 */
|
|
|
- getCategoryTree() {
|
|
|
- const that = this;
|
|
|
- that.categoryTree = [];
|
|
|
- CategoryApi.getCategoryList().then(res=>{
|
|
|
- const root = { id: 0, name: '顶级分类', children: [] };
|
|
|
- root.children = this.handleTree(res.data, 'id', 'parentId')
|
|
|
- that.categoryTree.push(root)
|
|
|
- });
|
|
|
+ async getCategoryTree() {
|
|
|
+ this.categoryTree = [];
|
|
|
+ const res = await CategoryApi.getCategoryList();
|
|
|
+ const root = { id: 0, name: '顶级分类', children: [] };
|
|
|
+ root.children = this.handleTree(res.data, 'id', 'parentId')
|
|
|
+ this.categoryTree.push(root)
|
|
|
},
|
|
|
/** 转换分类数据结构 */
|
|
|
normalizer(node) {
|
|
@@ -141,7 +124,7 @@
|
|
|
parentId: undefined,
|
|
|
};
|
|
|
this.resetForm("formRef");
|
|
|
- },
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
</script>
|