zsdy.vue 13.9 KB
<!--
 * @Description:
 * @Autor: renchao
 * @LastEditTime: 2023-08-25 16:25:57
-->
<template>
  <div>
    <div class="zsdy-content" v-Loading="loading">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="120px">
        <el-form-item label="印刷序列号:" prop="ysxlh">
          <el-select v-model="ruleForm.ysxlh" placeholder="请选择">
            <el-option
              v-for="item in ysxlh"
              :key="item.ysxlh"
              :label="item.ysxlh"
              :value="item.ysxlh">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div class="zs-content">
        <canvas ref="zs" width="1000" class="zsyl" height="700"></canvas>
      </div>
    </div>
    <!-- 打印模板需要此模块 -->
    <object id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" v-show="false">
      <embed id="LODOP_EM" type="application/x-print-lodop" width="1180" height="720" pluginspage="install_lodop32.exe" />
    </object>
    <div class="text-center pt-10">
      <el-button @click="$popupCacel">取消</el-button>
      <el-button type="primary" @click="handleSubmit">确定</el-button>
    </div>
  </div>
</template>

<script>
  import store from '@/store/index.js'
  import { datas } from "../../javascript/zsyl.js";
  import { getPrintTemplateByCode } from "@/api/print";
  import { getLodop } from "@/utils/LodopFuncs"
  import { readYsxlh, certificate, getSlsqBdcqzList } from "@/api/bdcqz.js";
  export default {
    props: {
      formData: {
        type: Object,
        default: () => {
          return {}
        }
      }
    },
    data () {
      return {
        // 不动产证书图片地址
        imgSrc: require('@/image/bdcqz/bdcqzs2.jpg'),
        loading: false,
        bdcqz: [],
        //印刷序列号集合
        ysxlh: [],
        //列名称对象
        columns: [],
        ruleForm: {
          bsmBdcqz: "",
          szmc: "不动产权证书",
          bdcqzlx: "",
          szzh: "",
          ysxlh: ""
        },
        rules: {
          ysxlh: [
            { required: true, message: "请选择印刷序列号", trigger: "change" }
          ]
        }
      }
    },
    created () {
      store.dispatch('user/refreshPage', false)
      this.columns = datas.columns()
      this.ysxlhList()
      this.getHeadTabBdcqz()
    },
    methods: {
      //获取印刷序列号列表
      /**
       * @description: 获取印刷序列号列表
       * @author: renchao
       */
      ysxlhList () {
        readYsxlh({ zslx: this.formData.bdcqz.bdcqzlx }).then((res) => {
          if (res.code === 200) {
            this.ysxlh = res.result;
          }
        })
      },
      /**
       * @description: 获取受理申请下全部不动产权证
       * @author: renchao
       */
      getHeadTabBdcqz () {
        this.loading = true
        getSlsqBdcqzList({ bsmSlsq: this.formData.bsmSlsq }).then(res => {
          if (res.code == 200) {
            if (res.result && res.result.length > 0) {
              this.bdcqz = res.result[0]
              this.drawTextOnImage()
            }
          }
          this.loading = false
        })
      },
      /**
       * @description: 不动产证书
       * @author: renchao
       */
      drawTextOnImage () {
        function getByteLen (val) {
          var len = 0;
          for (var i = 0; i < val.length; i++) {
            var length = val.charCodeAt(i);
            if (length >= 0 && length <= 128) {
              len += 1;
            } else {
              len += 2;
            }
          }
          return len;
        }
        const canvas = this.$refs.zs;
        const context = canvas.getContext('2d');
        const image = new Image();
        image.onload = () => {
          context.drawImage(image, 0, 0);
          context.font = '16px 楷体';
          context.fillStyle = '#000000';
          context.fillText(this.bdcqz.sjjc ? this.bdcqz.sjjc : '', 60, 56);
          context.fillText(this.bdcqz.djnd ? this.bdcqz.djnd : '', 113, 56);
          context.fillText(this.bdcqz.sxqc ? this.bdcqz.sxqc : '', 180, 56);
          context.fillText(this.bdcqz.sxh ? this.bdcqz.sxh : '', 370, 56);
          context.fillText(this.bdcqz.qlr ? this.bdcqz.qlr : '', 129, 97);
          context.fillText(this.bdcqz.gyqk ? this.bdcqz.gyqk : '', 129, 136);

          this.bdcdyh = this.bdcqz.bdcdyh.slice(0, 6) + ' ' + this.bdcqz.bdcdyh.slice(6, 12) + ' ' +
            this.bdcqz.bdcdyh.slice(12, 19) + ' ' + this.bdcqz.bdcdyh.slice(19, this.bdcqz.bdcdyh.length)
          context.fillText(this.bdcdyh ? this.bdcdyh : '', 129, 223);



          context.fillText(this.bdcqz.qllx ? this.bdcqz.qllx : '', 129, 263);
          context.fillText(this.bdcqz.qlxz ? this.bdcqz.qlxz : '', 129, 303);
          context.fillText(this.bdcqz.yt ? this.bdcqz.yt : '', 129, 346);
          // context.fillText(this.bdcqz.mj ? this.bdcqz.mj : '', 129, 386);
          let lines6 = this.bdcqz.mj ? this.bdcqz.mj.split(' ') : [];
          if (getByteLen(this.bdcqz.mj) > 41) {
            lines6.forEach((line, index) => {
              const y = 378 + (index * 27); // 每行文本的垂直位置
              let currentLine = '';
              let arr = [];
              for (let word of line) {
                const testLine = currentLine + word;
                const lineWidth = context.measureText(testLine).width;
                if (lineWidth <= 330) {
                  currentLine = testLine;
                } else {
                  arr.push(currentLine);
                  currentLine = word;
                }
              }
              arr.push(currentLine);
              arr.forEach((line, index) => {
                context.fillText(line, 129, y + (index * 20)); // 调整行高
              })
            })
          } else {
            lines6.forEach((line, index) => {
              const y = 386 + (index * 27); // 每行文本的垂直位置
              let currentLine = '';
              let arr = [];
              for (let word of line) {
                const testLine = currentLine + word;
                const lineWidth = context.measureText(testLine).width;
                if (lineWidth <= 330) {
                  currentLine = testLine;
                } else {
                  arr.push(currentLine);
                  currentLine = word;
                }
              }
              arr.push(currentLine);
              arr.forEach((line, index) => {
                context.fillText(line, 129, y + (index * 20)); // 调整行高
              })
            })
          }
          // 权利其他状态
          const maxWidth = 332; // 最大宽度限制
          let lines = this.bdcqz.qlqtzk ? this.bdcqz.qlqtzk.split('\n') : [];
          for (let i = 0; i < lines.length; i++) {
            if (getByteLen(lines[i]) > 41) {
              let currentLine = '';
              let arr = [];
              for (let word of lines[i]) {
                const testLine = currentLine + word;
                const lineWidth = context.measureText(testLine).width;
                if (lineWidth <= maxWidth) {
                  currentLine = testLine;
                } else {
                  arr.push(currentLine);
                  currentLine = word;
                }
              }
              arr.push(currentLine);
              arr.forEach((line, index) => {
                context.fillText(line, 129, 490 + (28 * (i - 1)) + (index * 14)); // 调整行高
              })
            } else {
              context.fillText(lines[i] ? lines[i] : '', 129, 495 + (30 * (i - 1)));
            }
          }

          let lines1 = this.bdcqz.fj ? this.bdcqz.fj.split('\n') : [];
          lines1.forEach((line, index) => {
            const y = 100 + (index * 30); // 每行文本的垂直位置
            let currentLine = '';
            let arr = [];
            for (let word of line) {
              const testLine = currentLine + word;
              const lineWidth = context.measureText(testLine).width;
              if (lineWidth <= 395) {
                currentLine = testLine;
              } else {
                arr.push(currentLine);
                currentLine = word;
              }
            }
            arr.push(currentLine);
            arr.forEach((line, index) => {
              context.fillText(line, 580, y + (index * 30)); // 调整行高
            })
          })
          let lines3 = this.bdcqz.syqx ? this.bdcqz.syqx.split(' ') : [];
          if (getByteLen(this.bdcqz.syqx) > 41) {
            lines3.forEach((line, index) => {
              const y = 423 + (index * 27); // 每行文本的垂直位置
              let currentLine = '';
              let arr = [];
              for (let word of line) {
                const testLine = currentLine + word;
                const lineWidth = context.measureText(testLine).width;
                if (lineWidth <= 330) {
                  currentLine = testLine;
                } else {
                  arr.push(currentLine);
                  currentLine = word;
                }
              }
              arr.push(currentLine);
              arr.forEach((line, index) => {
                context.fillText(line, 129, y + (index * 20)); // 调整行高
              })
            })
          } else {
            lines3.forEach((line, index) => {
              const y = 430 + (index * 27); // 每行文本的垂直位置
              let currentLine = '';
              let arr = [];
              for (let word of line) {
                const testLine = currentLine + word;
                const lineWidth = context.measureText(testLine).width;
                if (lineWidth <= 315) {
                  currentLine = testLine;
                } else {
                  arr.push(currentLine);
                  currentLine = word;
                }
              }
              arr.push(currentLine);
              arr.forEach((line, index) => {
                context.fillText(line, 129, y + (index * 20)); // 调整行高
              })
            })
          }

          let lines2 = this.bdcqz.zl ? this.bdcqz.zl.split(' ') : [];
          if (getByteLen(this.bdcqz.zl) > 41) {
            lines2.forEach((line, index) => {
              const y = 170 + (index * 20); // 每行文本的垂直位置
              let currentLine = '';
              let arr = [];
              for (let word of line) {
                const testLine = currentLine + word;
                const lineWidth = context.measureText(testLine).width;
                if (lineWidth <= 336) {
                  currentLine = testLine;
                } else {
                  arr.push(currentLine);
                  currentLine = word;
                }
              }
              arr.push(currentLine);
              arr.forEach((line, index) => {
                context.fillText(line, 129, y + (index * 20)); // 调整行高
              })
            })
          } else {
            lines2.forEach((line, index) => {
              const y = 180 + (index * 20); // 每行文本的垂直位置
              let currentLine = '';
              let arr = [];
              for (let word of line) {
                const testLine = currentLine + word;
                const lineWidth = context.measureText(testLine).width;
                if (lineWidth <= 336) {
                  currentLine = testLine;
                } else {
                  arr.push(currentLine);
                  currentLine = word;
                }
              }
              arr.push(currentLine);
              arr.forEach((line, index) => {
                context.fillText(line, 129, y + (index * 20)); // 调整行高
              })
            })
          }
        }
        image.src = this.imgSrc
      },
      /**
       * @description: handleSubmit
       * @author: renchao
       */
      handleSubmit () {
        this.savePrintRecord()
      },
      /**
       * @description: 保存打印记录
       * @author: renchao
       */
      savePrintRecord () {
        let that = this
        this.ruleForm.bsmBdcqz = this.formData.bdcqz.bsmBdcqz;
        this.ruleForm.bdcqzlx = this.formData.bdcqz.bdcqzlx;
        this.ruleForm.szzh = this.formData.bdcqz.bdcqzh;
        certificate(this.ruleForm).then((res) => {
          if (res.code === 200) {
            that.$popupCacel()
            // this.$message.success("提交成功")
            getPrintTemplateByCode({ tmpno: 'zsdy' }).then(res => {
              if (res.code == 200) {
                getSlsqBdcqzList({ bsmSlsq: this.formData.bsmSlsq }).then(infoRes => {
                  if (infoRes.code == 200) {
                    if (infoRes.result && infoRes.result.length > 0) {
                      //打开模板设计
                      let LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
                      LODOP.ADD_PRINT_DATA("ProgramData", res.result.tmpcontent); //装载模板

                      infoRes.result[0].bdcdyh1 = infoRes.result[0].bdcdyh.slice(0, 6) + ' ' + infoRes.result[0].bdcdyh.slice(6, 12) + ' ' +
                        infoRes.result[0].bdcdyh.slice(12, 19) + ' ' + infoRes.result[0].bdcdyh.slice(19, infoRes.result[0].bdcdyh.length)
                      //todo 调取后端接口获取数据 循环set
                      for (let key in infoRes.result[0]) {
                        LODOP.SET_PRINT_STYLEA(key, "CONTENT", infoRes.result[0][key]);
                      }
                      LODOP.PREVIEW();
                      that.$popupCacel()
                    }
                  }
                })
              } else {
                this.$message.error(res.message)
              }
            })

            //刷新列表
            store.dispatch('user/reWorkFresh', true)
          } else {
            this.$message.error(res.message)
          }
        })
      }
    }
  }
</script>
<style scoped lang="scss">
  @import "~@/styles/mixin.scss";
  .zsdy-content {
    height: 80vh;
    overflow-y: scroll;
  }
  .zs-content {
    text-align: center;
  }
</style>