add.vue
9.38 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<template>
<div>
<el-form :model="formInline" :rules="rulesHetong" ref="heForm" label-width="130px" class="demo-ruleForm">
<el-form-item label="退租日期" prop="exitDate">
<el-input v-model="info.applicationTime" disabled></el-input>
</el-form-item>
<!-- <el-form-item label="退租原因" prop="reasonForExit">
<el-input maxlength="200" show-word-limit rows="4" v-model="formInline.reasonForExit" placeholder="请输入退租原因"
type="textarea" />
</el-form-item> -->
<el-form-item label="待缴租金" prop="outstandingRent">
<el-input v-model="formInline.outstandingRent" placeholder="请输入"></el-input>
</el-form-item>
<el-form-item label="退租须知" prop="exitNotice">
<!-- <wang-editor v-model="formInline.exitNotice" ref="editor" :height="200"></wang-editor> -->
<el-input maxlength="200" show-word-limit rows="4" v-model="formInline.exitNotice" placeholder="请输入" type="textarea" />
</el-form-item>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item>
<div style="margin-top: 20px">
<el-button @click="yulanShow()" style="background-color: #3F9B6A;color: #fff;">预览</el-button>
<el-button @click="close()" class="buttonHover"
style="color: #606266;border: 1px solid #DBDBDB;background-color: #fff;">取消</el-button>
</div>
</el-form-item>
</el-col>
</el-row>
</el-form>
<el-dialog :visible.sync="yulan" custom-class="actSpye_dialog" style="padding: 0;" width="50%" center
:close-on-click-modal="false" append-to-body>
<div style="padding:50px 40px;">
<div class="form-container" ref="contentToConvert" style="background-color:#fff;">
<div class="form-header">退租告知单</div>
<div class="form-group">
<label for="remarks">退租日期:</label>
<div style="padding:20px;width:100%;border: 1px solid #ccc;" v-html="info.applicationTime"></div>
</div>
<!-- <div class="form-group">
<label for="remarks">退租原因:</label>
<div style="padding:20px;width:100%;border: 1px solid #ccc;" v-html="formInline.reasonForExit"></div>
</div> -->
<div class="form-group">
<label for="remarks">待缴租金:</label>
<div style="padding:20px;width:100%;border: 1px solid #ccc;" v-html="formInline.outstandingRent"></div>
</div>
<div class="form-group">
<label for="remarks">退租须知:</label>
<div style="padding:20px;width:100%;border: 1px solid #ccc;" v-html="formInline.exitNotice"></div>
</div>
</div>
<div style="justify-content:flex-end;margin:20px 20px 0 0;display:flex;">
<el-button @click="downloadPdf" style="background-color: #3F9B6A;color: #fff">下载</el-button>
<!-- <el-button style="background-color: #3F9B6A;color: #fff">打印</el-button> -->
<el-button @click="add" style="background-color: #3F9B6A;color: #fff">发送</el-button>
</div>
</div>
</el-dialog>
</div>
</template>
<script>
import {
cereTerminateNotice,
uploadQuestion
} from '../../../api/commodityLease.js'
import jsPDF from 'jspdf'
import wangEditor from "@/components/editor/index"
import html2canvas from 'html2canvas'
import { title } from '@/settings.js';
export default {
components: {
wangEditor
},
data() {
return {
yulan: false,
shopList: [],
formInline: {
// 合同ID
contractId: null,
// 租户ID,外键关联Tenants表
tenantId: null,
// 租户手机号
tenantPhone: '',
// 退租日期
exitDate: '',
// 退租原因
reasonForExit: '',
// 待缴租金
outstandingRent: null,
// 退租须知
exitNotice: '',
// 通知类型
noticeType: '1'
},
rulesHetong: {
exitDate: [{
required: true,
message: '请输入退租日期',
trigger: 'blur'
}],
// reasonForExit: [{
// required: true,
// message: '请选择退租原因',
// trigger: 'change'
// }],
outstandingRent: [{
required: true,
message: '请输入待缴租金',
trigger: 'blur'
}],
exitNotice: [{
required: true,
message: '请输入退租须知',
trigger: 'blur'
}],
noticeType: [{
required: true,
message: '请选择通知类型',
trigger: 'change'
}]
},
xudan: {
tuizhu: '',
yuan: '',
daijiao: '',
zhifu: '',
zhifushuo: '',
zhuangxiu: '',
noto: '',
},
};
},
props: {
info: {
type: Object,
default: {}
}
},
created() {
},
methods: {
// 下载
async downloadPdf() {
const content = this.$refs.contentToConvert;
// 使用 html2canvas 将 div 渲染为画布
const canvas = await html2canvas(content);
// 获取画布的图像数据
const imgData = canvas.toDataURL('image/png');
// 创建一个新的 PDF 文档
const pdf = new jsPDF('p', 'mm', 'a4');
// 添加图像到 PDF,第二个参数是图像格式,第三个参数是缩放比例
const imgWidth = 190; // 图像的宽度(mm)
const imgHeight = (canvas.height * imgWidth) / canvas.width; // 保持图像的宽高比
pdf.addImage(imgData, 'PNG', 10, 10, imgWidth, imgHeight); // 10, 10 是图像在 PDF 中的位置(mm)
// 保存 PDF 文件
pdf.save('downloaded.pdf');
},
yulanShow() {
this.formInline.exitDate = this.info.applicationTime
this.$refs.heForm.validate((valid) => {
console.log(valid)
if (valid) {
this.yulan = true
} else {
this.$message({
message: '请填写完整信息',
type: 'error'
})
return;
}
})
},
URLtoFile(dataurl, filename) {
let arr = dataurl.split(','),
mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]),
n = bstr.length,
u8arr = new Uint8Array(n);
while(n--){
u8arr[n] = bstr.charCodeAt(n);
}
return new File([u8arr], filename, {type:mime});
},
async add() {
let that = this
console.log({...this.info})
const content = this.$refs.contentToConvert;
// 使用 html2canvas 将 div 渲染为画布
const canvas = await html2canvas(content);
// return
this.formInline.contractId = this.info.id
this.formInline.tenantId = this.info.relatedMerchants
this.formInline.tenantPhone = this.info.tenantTelephone
this.formInline.exitDate = this.info.applicationTime
const formData = new FormData()
const file = this.URLtoFile(canvas.toDataURL('image/png'), 'filename.png');
formData.append('file',file)
let sasd = await uploadQuestion(formData)
console.log(sasd.data,'12312412412')
// return
this.formInline.pdfUrl = sasd.data
console.log({...this.formInline})
// return
let info = {
type:'租赁提醒',
phone:this.info.createUser,
content:{
type:'2',
title:'退租告知单',
content:this.formInline.pdfUrl
},
}
console.log(']]]]]]')
let res = await that.$setmsg(info);
console.log(res)
if (res.code == 200) {
this.$message({
message: '发送成功',
type: 'success'
})
this.$emit('removeonaction', '1')
} else {
this.$message({
message: '发送失败',
type: 'error'
})
}
},
close() {
this.$emit('removeonaction', '1')
}
},
};
</script>
<style lang="css">
.el-upload {
display: block;
text-align: left;
}
.el-dialog__header {
background-color: #F2F3F5;
text-align: left;
}
.el-dialog__title {
line-height: 30px;
font-size: 15px;
color: #303133;
}
.form-container {
max-width: 600px;
margin: 0px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #fff;
}
.form-group {
margin-bottom: 15px;
display: flex;
align-items: center
}
.form-group label {
display: block;
font-weight: bold;
margin-bottom: 5px;
width: 152px;
}
.form-group input,
.form-group textarea {
width: 100%;
padding: 8px;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 4px;
}
.form-group textarea {
resize: vertical;
}
.form-header {
text-align: center;
margin-bottom: 20px;
font-size: 1.5em;
font-weight: bold;
}
.jianju {
margin-bottom: 10px;
}
.titles {
position: relative;
padding-left: 10px;
}
.titles::before {
content: '';
width: 2px;
height: 10px;
background-color: #3F9B6A;
position: absolute;
top: 2px;
left: 0;
}
</style>