提交 | 用户 | age
|
133cfa
|
1 |
<!-- 文档编辑 --> |
L |
2 |
<template> |
|
3 |
<div class="app-container"> |
|
4 |
<el-form ref="agreementForm" label-position="left" :model="mData" label-width="150px" :rules="rules"> |
|
5 |
<el-form-item v-if="haveTitle" label="标题:"> |
|
6 |
<!-- <el-input v-model="mData.title" placeholder="请输入标题" class="com-edit-input" /> --> |
|
7 |
<div class="com-edit-input">{{ titleOptions[type-1] }}</div> |
|
8 |
</el-form-item> |
|
9 |
<el-form-item v-if="haveContent" label="文档详情:" prop="content"> |
|
10 |
<WangEnduit :catchdata="catchData" :content="mData.content" :rangenum="rangenum" /> |
|
11 |
</el-form-item> |
|
12 |
</el-form> |
|
13 |
<div class="com-edit-bottom-btns flex flex-align-center"> |
|
14 |
<el-button size="small" @click="jumpBack">取消</el-button> |
|
15 |
<el-button type="primary" size="small" @click="submit">保存</el-button> |
|
16 |
</div> |
|
17 |
</div> |
|
18 |
</template> |
|
19 |
|
|
20 |
<script> |
|
21 |
import mixin_upload from '@/mixins/upload.js' // 通用上传图片预览 |
|
22 |
import WangEnduit from '@/components/WangEnduit' // 富文本 |
|
23 |
export default { |
|
24 |
name: 'Agreement', |
|
25 |
components: { WangEnduit }, |
|
26 |
mixins: [mixin_upload], |
|
27 |
data() { |
|
28 |
return { |
|
29 |
type: this.$route.meta.type, // 协议类型 |
|
30 |
// 富文本 |
|
31 |
rangenum: null, |
|
32 |
|
|
33 |
titleOptions: ['报价公告及违规规则', '竞价平台中标原则及公告', '操作流程说明'], |
|
34 |
|
|
35 |
mData: { |
|
36 |
title: '', // 标题 |
|
37 |
content: '' // 富文本 |
|
38 |
}, |
|
39 |
|
|
40 |
// 表单校验 |
|
41 |
rules: { |
|
42 |
title: [ |
|
43 |
{ required: true, message: '标题不能为空', trigger: 'change' } |
|
44 |
], |
|
45 |
content: [ |
|
46 |
{ required: true, message: '文档详情不能为空' } |
|
47 |
], |
|
48 |
uploadImgs: [ |
|
49 |
{ required: true, message: '请选择图片', trigger: 'change' } |
|
50 |
] |
|
51 |
} |
|
52 |
} |
|
53 |
}, |
|
54 |
computed: { |
|
55 |
haveTitle() { |
|
56 |
return true |
|
57 |
}, |
|
58 |
haveContent() { |
|
59 |
return true |
|
60 |
} |
|
61 |
}, |
|
62 |
watch: { |
|
63 |
$route() { |
|
64 |
this.init() |
|
65 |
} |
|
66 |
}, |
|
67 |
mounted() { |
|
68 |
this.init() |
|
69 |
}, |
|
70 |
methods: { |
|
71 |
init() { |
|
72 |
this.getAgreementData() |
|
73 |
}, |
|
74 |
|
|
75 |
// 获取文章详情 |
|
76 |
getAgreementData() { |
|
77 |
this.postFN({ |
|
78 |
url: 'admin/sysTextExplain/detail', |
|
79 |
params: { type: this.type }, |
|
80 |
udData: {}, |
|
81 |
mockData: { |
|
82 |
code: 100, msg: '', |
|
83 |
data: { |
|
84 |
id: 'xxx', |
|
85 |
content: '<p>文本</p>' |
|
86 |
} |
|
87 |
} |
|
88 |
}, (inf) => { |
|
89 |
if (inf) this.$set(this.mData, 'content', inf.content || '') |
|
90 |
// 清空富文本 |
|
91 |
this.rangenum = null |
|
92 |
}) |
|
93 |
}, |
|
94 |
|
|
95 |
// 富文本相关 |
|
96 |
// 富文本编辑器的内容赋值 |
|
97 |
catchData(content) { |
|
98 |
if (content === '<p><br></p>') content = '' |
|
99 |
try { |
|
100 |
const currentRange = window.getSelection().getRangeAt(0) |
|
101 |
this.rangenum = currentRange |
|
102 |
} catch (e) { |
|
103 |
// |
|
104 |
} |
|
105 |
this.mData.content = content |
|
106 |
this.$refs.agreementForm.validateField('content') |
|
107 |
}, |
|
108 |
// 富文本相关 |
|
109 |
|
|
110 |
jumpBack() { |
|
111 |
this.$router.go(-1) |
|
112 |
}, |
|
113 |
|
|
114 |
// 表单验证 |
|
115 |
submit() { |
|
116 |
this.$refs['agreementForm'].validate(valid => { |
|
117 |
if (valid) { |
|
118 |
this.submitReq() |
|
119 |
} |
|
120 |
}) |
|
121 |
}, |
|
122 |
// 提交 |
|
123 |
submitReq() { |
|
124 |
var { mData } = this |
|
125 |
var params = { |
|
126 |
type: this.type, |
|
127 |
// title: mData.title, |
|
128 |
content: mData.content |
|
129 |
} |
|
130 |
|
|
131 |
if (!this.haveContent) { |
|
132 |
params.content = '无' |
|
133 |
} |
|
134 |
// if (!this.haveTitle) { |
|
135 |
// params.title = '无' |
|
136 |
// } |
|
137 |
|
|
138 |
this.postFN({ |
|
139 |
url: 'admin/sysTextExplain/edit', |
|
140 |
params: params, |
|
141 |
mockData: { |
|
142 |
code: 100, |
|
143 |
msg: '', |
|
144 |
data: {} |
|
145 |
} |
|
146 |
}, () => { |
|
147 |
this.$messageSuc('保存成功') |
|
148 |
}) |
|
149 |
} |
|
150 |
} |
|
151 |
} |
|
152 |
</script> |
|
153 |
|
|
154 |
<style lang="less"> |
|
155 |
|
|
156 |
</style> |