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
<template>
<el-dialog
:title="dialogObj.title"
:visible.sync="dialogObj.show"
center
width="800px">
<el-form :model="form" :rules="rules" ref="form">
<el-form-item label="合同协议名称" prop="contract_name" label-width="120px">
<el-input v-model="form.contract_name" clearable></el-input>
</el-form-item>
<el-form-item label="类型" prop="contract_type" label-width="120px">
<el-select v-model="form.contract_type" placeholder="请选择" clearable>
<el-option label="用户协议" value="0"></el-option>
<el-option label="正式课合同" value="1"></el-option>
</el-select>
</el-form-item>
<el-form-item label="关联商品" label-width="120px">
<el-select multiple v-model="form.goods_ids" placeholder="请选择" clearable
:popper-class="'refresh-select-multi width-480'" style="width: 480px">
<el-option
v-for="data in goodslist"
:key="data.id"
:label="`【${data.id}】${data.name}`"
:value="data.id">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="合同/协议文本" prop="" label-width="120px" required>
<!-- <el-input type="textarea" :rows="10" v-model="form.contract_text"></el-input>-->
<editor-detail :lookData="form.contract_text"/>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogObj.show = false">取 消</el-button>
<el-button type="primary" @click="sub">保 存</el-button>
</span>
</el-dialog>
</template>
<script>
import {contractGoodslistApi, contractAddApi, contractEditApi} from "../../service/api";
import editorDetail from "./editorDetail";
export default {
name: "dialogObj",
props: [
'dialogObj'
],
components: {
editorDetail
},
data() {
return {
form: {
contract_name: '',
contract_type: '',
goods_ids: [],
contract_text: {
detail: ""
}
},
goodslist: [],
rules: {
contract_name: [
{required: true, message: '请输入赠品名称'},
{max: 20, message: '合同协议名称不能超过20汉字'}
],
contract_type: [
{required: true, message: '请选择类型', trigger: 'change'}
]
}
}
},
methods: {
sub() {
this.$refs['form'].validate((valid) => {
if (valid) {
if (!this.form.contract_text.detail) {
this.$message({
message: '合同/协议文本不能为空',
type: 'error'
});
return;
}
let json = {
contract_name: this.form.contract_name,
contract_type: this.form.contract_type,
goods_ids: this.form.goods_ids.join(','),
contract_text: this.form.contract_text.detail
};
switch (this.dialogObj.type) {
case 0:
contractAddApi(json).then(res => {
this.$message({
type: 'success',
message: '新增成功!'
});
this.$emit("reflash");
this.dialogObj.show = false;
});
break;
case 1:
contractEditApi(this.dialogObj.id, json).then(res => {
this.$message({
type: 'success',
message: '修改成功!'
});
this.$emit("reflash");
this.dialogObj.show = false;
});
break;
}
} else {
return false;
}
});
}
},
created() {
contractGoodslistApi().then(res => {
this.goodslist = res.goods_list;
});
},
watch: {
'dialogObj.show'() {
this.$nextTick(() => {
this.form.goods_ids = [];
this.form.contract_text.detail = '';
this.$refs['form'].resetFields();
if (this.dialogObj.type == 1) {
let goods_ids_arr = [];
if (this.dialogObj.goods_ids) {
this.dialogObj.goods_ids.split(',').map(i => {
goods_ids_arr.push(Number(i));
});
}
this.form.name = this.dialogObj.name;
this.form.contract_name = this.dialogObj.contract_name;
this.form.contract_type = this.dialogObj.contract_type.toString();
this.form.goods_ids = goods_ids_arr;
this.form.contract_text.detail = this.dialogObj.contract_text;
}
});
}
}
}
</script>
<style scoped>
</style>