towMobile.vue
4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<template>
<el-dialog :title="title" :visible.sync="open" v-if="open" width="600px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="130px">
<el-form-item label="二级分类代码" prop="twoClass">
<el-input v-model="form.twoClass" placeholder="请输入二级分类代码" :disabled='disabled' />
</el-form-item>
<el-form-item label="二级分类名称" prop="name">
<el-input v-model="form.name" placeholder="请输入二级分类名称" :disabled='disabled' />
</el-form-item>
<el-form-item label="所属一级分类名称" prop="targetOneId">
<el-select v-model="form.targetOneId" placeholder="所属一级分类名称" clearable size="small">
<el-option v-for="(item,index) in targetOneList" :key="index" :label="item.name" :value="item.id" />
</el-select>
</el-form-item>
<el-form-item label="备注" prop="note">
<el-input v-model="form.note" type="textarea" placeholder="请输入备注" :disabled='disabled' />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</el-dialog>
</template>
<script>
import { targetTwoSave, targetTwoEdit, targetOneList } from "@/api/postList/list";
export default {
name: 'indexMobile',
dicts: ['index_mobile_type', 'index_type_list'],
data() {
return {
imageUrl: '',
disabled: true,
open: false,
// 弹出层标题
title: "",
// 表单参数
form: {
},
checkList: [],
targetOneList:[],
// 表单校验
rules: {
twoClass: [
{ required: true, message: "二级分类代码不能为空", trigger: "blur" }
],
name: [
{ required: true, message: "二级分类名称不能为空", trigger: "blur" }
],
targetOneId:[
{ required: true, message: "一级分类名称不能为空", trigger: "blur" }
]
},
id: ''
}
},
methods: {
// 取消按钮
cancel() {
this.open = false;
this.form = {}
},
add() {
this.open = true;
this.form = {}
this.id = ''
this.getTargetOneList()
},
edit(res) {
this.open = true;
this.form = res
this.id = res.id
this.getTargetOneList()
},
getTargetOneList() {
targetOneList().then(response => {
if (response.code == 200) {
this.targetOneList = response.data
} else {
}
});
},
/** 提交按钮 */
submitForm: function () {
this.$refs["form"].validate(valid => {
this.form.id = this.id
if (valid) {
if (this.id) {
targetTwoEdit(this.form).then(response => {
if (response.code == 200) {
this.$modal.msgSuccess(response.msg);
this.open = false;
this.$emit("getList")
} else {
this.$modal.msgSuccess(response.msg);
this.open = false;
}
});
} else {
targetTwoSave(this.form).then(response => {
if (response.code == 200) {
this.$modal.msgSuccess(response.msg);
this.open = false;
this.$emit("getList")
} else {
this.$modal.msgSuccess(response.msg);
this.open = false;
}
});
}
}
});
},
}
}
</script>
<style>
.new_dialog {
height: 80%;
overflow: hidden;
overflow-y: scroll;
}
</style>