addMaterialGroupDia.vue
4.88 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<template>
<div>
<el-dialog :title="title" :visible.sync="dialogVisible" width="720px" :before-close="!dialogVisible">
<el-form ref="materialGroupAddForm" :model="materialGroupAddForm" @submit.native.prevent label-width="110px" :rules="materialGroupAddRules">
<el-form-item label="分组名称:" prop="materialGroupName">
<el-input v-model="materialGroupAddForm.materialGroupName" maxlength="8" show-word-limit :size="size" placeholder="请输入分组名称" style="width: 567px" @keyup.enter.native="submitForm"></el-input>
</el-form-item>
<!-- <el-form-item label="业务类型:" prop="businessType">
<el-checkbox-group class="checkbox-group" :max="3" v-model="materialGroupAddForm.businessType">
<el-checkbox v-for="item in businessTypes" :key="item.id" :label="item.dictLabel"></el-checkbox>
</el-checkbox-group>
</el-form-item>
<span class="tips">添加业务类型,该素材组里面的所有素材均会添加此业务类型</span> -->
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false" :size="size">取 消</el-button>
<el-button type="primary" @click="submitForm" :size="size">确定</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
export default {
name: 'addMaterialGroupDia',
props: {
eventBus: Object
// businessTypes: {
// type: Array
// }
},
data() {
return {
title: '创建素材组',
dialogVisible: false,
materialGroupAddForm: {
id: '',
materialGroupName: '',
businessType: []
},
groupCounter: [],
materialGroupAddRules: {
materialGroupName: [
{ required: true, message: '请输入分组名称', trigger: 'blur' },
{ max: 16, message: '分组名称最长为8个字', trigger: 'blur' }
]
}
}
},
methods: {
init(addOrEdit, value, group) {
// this.findAllDictData('business_type')
this.dialogVisible = true
this.materialGroupAddForm = {
materialGroupName: ''
// businessType: []
}
this.groupCounter = group
if (addOrEdit == 2) {
this.title = '编辑素材组'
if (!value) {
this.materialGroupAddForm.materialGroupName = '新车素材组'
return
}
var params = {}
params.id = value.id
this.$apis.material.materialGroupDetail(params).then(res => {
this.materialGroupAddForm = res
// if (res.businessType) {
// this.materialGroupAddForm.businessType = this.materialGroupAddForm.businessType.split(',')
// } else {
// this.materialGroupAddForm.businessType = []
// }
})
}
// Object.assign(this.materialGroupAddForm, value)
},
// 获取所有业务类型
// findAllDictData(dictType) {
// var params = {
// dictType
// }
// this.$apis.material.findAllDictData(params).then(res => {
// if (res) {
// if (dictType == 'business_type') {
// this.businessTypes = res
// }
// }
// })
// },
getParams() {
var params = JSON.parse(JSON.stringify(this.materialGroupAddForm))
return params
},
// 提交创建素材组
submitForm() {
this.$refs.materialGroupAddForm.validate(valid => {
if (valid) {
var params = this.getParams()
params.orderFlag = true
// 判断是创建还是编辑
if (this.materialGroupAddForm.id) {
this.eventBus.$emit('editMaterialGroup', params)
this.dialogVisible = false
return
}
// 判断素材组名称是否重复
var groupName = []
this.groupCounter.forEach(item => {
groupName.push(item.materialGroupName)
})
var idx = groupName.indexOf(this.materialGroupAddForm.materialGroupName)
if (idx != -1) {
this.$message({
message: '素材组名称不能重复',
type: 'warning'
})
return
}
this.eventBus.$emit('addMaterialGroup', params)
this.dialogVisible = false
} else {
this.$message({
message: '请输入素材组名称',
type: 'warning'
})
return false
}
})
}
// handleCheckChange(val) {
// console.log(val)
// this.materialGroupAddForm.businessType = val
// // console.log(this.materialGroupAddForm);
// }
}
}
</script>
<style lang="scss" scope>
.checkbox-group {
width: 567px;
box-sizing: border-box;
background: #f5f5f5;
padding: 16px 0 0 16px;
.el-checkbox {
width: 140px;
margin: 0;
padding: 0;
}
}
.tips {
font-size: 12px;
color: #666666;
display: block;
margin: -10px 0 0 110px;
}
</style>