add.vue 9.38 KB
<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>