Blame view

src/views/workflow/components/dialog/zsdy.vue 31.5 KB
1
<!--
yuanbo committed
2
 * @Description:
3
 * @Autor: renchao
4
 * @LastEditTime: 2024-01-22 16:34:15
5
-->
蔡俊立 committed
6
<template>
renchao@pashanhoo.com committed
7
  <div>
8
    <div class="zsdy-content" v-Loading="loading">
renchao@pashanhoo.com committed
9 10 11 12 13
      <el-form
        :model="ruleForm"
        ref="ruleForm"
        label-width="120px">
        <el-form-item label="印刷序列号:" prop="ysxlh">
14
          <el-row>
15
            <el-col :span="18">
16 17 18 19 20 21 22 23 24
              <el-select v-model="ruleForm.ysxlh" @change="handleSelect" :disabled="disabled" placeholder="请选择">
                <el-option
                  v-for="item in ysxlh"
                  :key="item.ysxlh"
                  :label="item.ysxlh"
                  :value="item.ysxlh">
                </el-option>
              </el-select>
            </el-col>
25 26 27 28 29 30
            <el-col :span="4" v-if="this.formData.bdcqzlx==1">
              <el-tabs v-model="activeTitle">
                <el-tab-pane label="第一页" name="title1"></el-tab-pane>
                <el-tab-pane label="第二页" name="title2"></el-tab-pane>
              </el-tabs>
            </el-col>
31
            <el-col :span="2" v-if="this.formData.ysxlh" style="float:right">
renchao@pashanhoo.com committed
32
              <el-button type="primary" @click="handleZF" v-if="disabled">作废</el-button>
33 34 35
            </el-col>
          </el-row>

renchao@pashanhoo.com committed
36 37
        </el-form-item>
      </el-form>
38
      <div class="zs-content">
39 40 41
        <canvas ref="zs1" width="1024" v-show="this.formData.bdcqzlx==1 && activeTitle=='title1'" height="739"></canvas>
        <canvas ref="zs" width="1024" v-show="this.formData.bdcqzlx==1 && activeTitle=='title2'" height="739"></canvas>
        <canvas ref="zm" width="1169" v-show="this.formData.bdcqzlx==2" height="828"></canvas>
42
      </div>
renchao@pashanhoo.com committed
43
    </div>
renchao@pashanhoo.com committed
44 45 46 47
    <!-- 打印模板需要此模块 -->
    <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>
renchao@pashanhoo.com committed
48
    <div class="text-center pt-10">
renchao@pashanhoo.com committed
49
      <el-button @click="$popupCacel">取消</el-button>
50
      <el-button type="primary" @click="handlePrint" v-if="disabled">打印</el-button>
51
      <el-button type="primary" @click="handleSubmit" v-else>确定</el-button>
蔡俊立 committed
52
    </div>
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

    <el-dialog title="证书作废" :visible.sync="invalidDiglog" width="40%" :modal-append-to-body="false" top="30vh">
      <div class="invalid-diglog">
        <div class="invalid-title">
          <i class="el-icon-question invalid-icon"></i>
          <div class="invalid-body">您确定作废证书并再次打印?印刷序列号{{bdcqz.ysxlh}}</div>
        </div>
        <div class="invalid-reson">作废原因:</div>
        <el-input v-model="zfyy" placeholder="请输入作废原因" type="textarea" :rows="4"></el-input>
        <div class="text-center pt-10">
          <el-button @click="closeInvalidDiglog">取 消</el-button>
          <el-button type="primary" @click="confirmInvalid">确 定</el-button>
        </div>
      </div>
    </el-dialog>
renchao@pashanhoo.com committed
68
  </div>
蔡俊立 committed
69 70 71
</template>

<script>
72
  import QRCode from 'qrcode'
renchao@pashanhoo.com committed
73 74
  import store from '@/store/index.js'
  import { datas } from "../../javascript/zsyl.js";
renchao@pashanhoo.com committed
75 76
  import { getPrintTemplateByCode } from "@/api/print";
  import { getLodop } from "@/utils/LodopFuncs"
77
  import { readYsxlh, certificate, getBdcqzDetail, invalidCertificate } from "@/api/bdcqz.js";
renchao@pashanhoo.com committed
78 79
  export default {
    props: {
renchao@pashanhoo.com committed
80 81 82 83 84 85
      formData: {
        type: Object,
        default: () => {
          return {}
        }
      }
86
    },
renchao@pashanhoo.com committed
87 88
    data () {
      return {
89
        activeTitle: 'title1',
90 91
        // 详细信息
        bdcqz: {},
92
        key: 0,
93
        disabled: false,
94
        // 不动产证书图片地址
95
        imgSrc1: require('@/image/bdcqz/bdcqzs1.jpg'),
96
        imgSrc: require('@/image/bdcqz/bdcqzs2.jpg'),
97
        bdczmSrc: require('@/image/bdcqz/bdczm.jpg'),
98
        loading: false,
renchao@pashanhoo.com committed
99 100 101 102
        //印刷序列号集合
        ysxlh: [],
        //列名称对象
        columns: [],
103 104
        //tab选择绑定值
        activeName: '',
105 106
        invalidDiglog: false,
        zfyy: "",
renchao@pashanhoo.com committed
107 108 109 110 111
        ruleForm: {
          bsmBdcqz: "",
          szmc: "不动产权证书",
          bdcqzlx: "",
          szzh: "",
renchao@pashanhoo.com committed
112
          ysxlh: ""
113
        }
renchao@pashanhoo.com committed
114 115
      }
    },
116
    mounted () {
renchao@pashanhoo.com committed
117
      store.dispatch('user/refreshPage', false)
renchao@pashanhoo.com committed
118 119
      this.columns = datas.columns()
      this.ysxlhList()
120 121 122 123
      // 获取详细信息
      this.getDetail()
      if (this.formData.ysxlh) {
        this.disabled = true
124
      } else {
125
        this.disabled = false
126
      }
renchao@pashanhoo.com committed
127 128
    },
    methods: {
yuanbo committed
129
      /**
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
       * @description: 获取详细信息
       * @author: renchao
       */
      getDetail () {
        this.loading = true
        getBdcqzDetail(this.formData.bsmBdcqz).then(res => {
          this.bdcqz = res.result
          this.loading = false
          if (this.bdcqz.ysxlh) this.ruleForm.ysxlh = this.bdcqz.ysxlh
          if (this.bdcqz.bdcqzlx == 1) {
            this.drawTextOnImage()
          } else {
            this.drawTextzmImage()
          }
        })
      },
      /**
yuanbo committed
147 148 149
       * @description: 获取印刷序列号列表
       * @author: renchao
       */
renchao@pashanhoo.com committed
150
      ysxlhList () {
151
        readYsxlh({ zslx: this.formData.bdcqzlx }).then((res) => {
renchao@pashanhoo.com committed
152 153 154
          if (res.code === 200) {
            this.ysxlh = res.result;
          }
renchao@pashanhoo.com committed
155
        })
renchao@pashanhoo.com committed
156
      },
yuanbo committed
157 158 159 160 161
      /**
       * @description: handleSelect
       * @param {*} val
       * @author: renchao
       */
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
      handleSelect (val) {
        this.bdcqz.ysxlh = this.ruleForm.ysxlh
        if (this.bdcqz.bdcqzlx == 1) {
          this.drawTextOnImage()
        } else {
          this.drawTextzmImage()
        }
      },
      /**
      * @description: closeInvalidDiglog
      * @author: renchao
      */
      closeInvalidDiglog () {
        this.zfyy = "";
        this.invalidDiglog = false
      },
yuanbo committed
178 179 180 181
      /**
       * @description: handleZF
       * @author: renchao
       */
renchao@pashanhoo.com committed
182 183 184
      handleZF () {
        this.invalidDiglog = true
      },
185 186 187 188 189
      /**
       * @description: 作废缮证信息
       * @author: renchao
       */
      confirmInvalid () {
renchao@pashanhoo.com committed
190
        store.dispatch('user/reWorkFresh', false)
191 192 193 194 195 196 197 198 199 200 201 202 203
        invalidCertificate({ bsmBdcqz: this.bdcqz.bsmBdcqz, zfyy: this.zfyy }).then((res) => {
          if (res.code === 200) {
            this.$message.success("作废成功");
            this.disabled = false
            this.invalidDiglog = false;
            this.zfyy = ''
            this.ruleForm.ysxlh = ''
            this.bdcqz.ysxlh = ''
            if (this.bdcqz.bdcqzlx == 1) {
              this.drawTextOnImage()
            } else {
              this.drawTextzmImage()
            }
renchao@pashanhoo.com committed
204
            store.dispatch('user/reWorkFresh', true)
205 206 207 208 209
          } else {
            this.$message.error(res.message);
          }
        })
      },
yuanbo committed
210 211 212 213
      /**
       * @description: 不动产证书
       * @author: renchao
       */
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
      drawTextOnImage1 () {
        const canvas = this.$refs.zs1;
        const context = canvas.getContext('2d');
        const image = new Image();
        image.onload = () => {
          context.drawImage(image, 0, 0);
          context.font = '18px 楷体';
          context.fillStyle = '#000000';
          let date = this.bdcqz.djsj.split(' ')[0].split('/');
          let nian = date[0]
          let yue = date[1]
          let ri = date[2]
          this.bdcqz.nian = nian
          this.bdcqz.yue = yue
          this.bdcqz.ri = ri
          context.fillText(nian ? nian : '', 780, 499);
          context.fillText(yue ? yue : '', 840, 499);
          context.fillText(ri ? ri : '', 885, 499);
          QRCode.toDataURL(this.bdcqz.bdcqzh, { margin: 0 })
            .then(url => {
              const qrImage = new Image();
              this.bdcqz.qrImage = url; // 将二维码图片的 URL 存储到 bdcqz 对象的 qrImage 属性中
              qrImage.onload = () => {
                context.drawImage(qrImage, 670, 400, 100, 100);
              };
              qrImage.src = url;
            })
            .catch(error => {
              console.error(error);
            });
          context.fillText(this.bdcqz.bdcqzbm ? this.bdcqz.bdcqzbm : '', 745, 633);
        };
        image.src = this.imgSrc1;
      },
248
      drawTextOnImage () {
249
        this.drawTextOnImage1()
250 251
        function getByteLen (val) {
          var len = 0;
252
          if (!val) return len;
253 254 255 256 257 258 259 260 261 262
          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;
        }
263 264 265 266 267
        const canvas = this.$refs.zs;
        const context = canvas.getContext('2d');
        const image = new Image();
        image.onload = () => {
          context.drawImage(image, 0, 0);
renchao@pashanhoo.com committed
268
          context.font = '18px 楷体';
269
          context.fillStyle = '#000000';
270 271
          context.fillText(this.bdcqz.sjjc ? this.bdcqz.sjjc : '', 60, 56);
          context.fillText(this.bdcqz.djnd ? this.bdcqz.djnd : '', 113, 56);
272 273 274 275 276 277 278 279 280 281
          // context.fillText(this.bdcqz.sxqc ? this.bdcqz.sxqc : '', 180, 56);

          if (getByteLen(this.bdcqz.sxqc) > 14) {
            const originalFont = context.font;
            // 设置新的字体大小
            context.font = '14px 楷体'; // 替换为你想要的字体和大小
            // 绘制 bdcdyh
            context.fillText(this.bdcqz.sxqc ? this.bdcqz.sxqc : '', 165, 56);
            // 恢复原始字体设置
            context.font = originalFont;
282 283
          } else {
            context.fillText(this.bdcqz.sxqc ? this.bdcqz.sxqc : '', 170, 56);
284 285
          }

286 287 288
          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);
289

290 291
          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)
292
          context.fillText(this.bdcdyh ? this.bdcdyh : '', 129, 223);
293 294


295

296 297 298 299
          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);
          let lines6 = this.bdcqz.mj ? this.bdcqz.mj.split(' ') : [];
300
          if (getByteLen(this.bdcqz.mj) > 37) {
301 302
            lines6.forEach((line, index) => {
              const y = 378 + (index * 27); // 每行文本的垂直位置
303 304 305 306 307
              let currentLine = '';
              let arr = [];
              for (let word of line) {
                const testLine = currentLine + word;
                const lineWidth = context.measureText(testLine).width;
308
                if (lineWidth <= 336) {
309 310 311 312 313 314 315 316
                  currentLine = testLine;
                } else {
                  arr.push(currentLine);
                  currentLine = word;
                }
              }
              arr.push(currentLine);
              arr.forEach((line, index) => {
317
                context.fillText(line, 129, y + (index * 20)); // 调整行高
318 319 320
              })
            })
          } else {
321 322 323 324 325 326 327
            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;
328
                if (lineWidth <= 336) {
329 330 331 332 333 334 335 336 337 338 339
                  currentLine = testLine;
                } else {
                  arr.push(currentLine);
                  currentLine = word;
                }
              }
              arr.push(currentLine);
              arr.forEach((line, index) => {
                context.fillText(line, 129, y + (index * 20)); // 调整行高
              })
            })
340
          }
341 342
          // 权利其他状态
          const maxWidth = 332; // 最大宽度限制
343
          let lines = this.bdcqz.qlqtzk ? this.bdcqz.qlqtzk.split('\n').filter(i => i && i.trim()) : [];
344
          for (let i = 0; i < lines.length; i++) {
345 346
            let num = Math.ceil(getByteLen(lines[i]) / 37)
            if (getByteLen(lines[i]) > 37) {
347 348 349 350 351 352 353 354 355 356 357
              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;
                }
358
              }
359
              arr.push(currentLine);
360 361
              if (i > 0) {
                arr.forEach((line, index) => {
362
                  context.fillText(line, 129, 495 + (29 * (i - 1)) + 4 * num + (index * 14)); // 调整行高
363 364 365
                })
              } else {
                arr.forEach((line, index) => {
366
                  context.fillText(line, 129, 493 + (26 * (i - 1)) + (index * 14)); // 调整行高
367 368
                })
              }
369
            } else {
370
              if (i > 0) {
371
                context.fillText(lines[i] ? lines[i] : '', 129, 500 + 4 * num + (29 * (i - 1)));
372
              } else {
373
                context.fillText(lines[i] ? lines[i] : '', 129, 505 + (27 * (i - 1)));
374
              }
375
            }
376 377
          }

378
          let lines1 = this.bdcqz.fj ? this.bdcqz.fj.split('\n').filter(i => i && i.trim()) : [];
379
          lines1.forEach((line, index) => {
380
            const y = 100 + (index * 30); // 每行文本的垂直位置
381 382 383 384 385 386 387 388 389 390 391 392 393 394
            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) => {
395
              context.fillText(line, 580, y + (index * 30)); // 调整行高
396 397
            })
          })
398
          let lines3 = this.bdcqz.syqx ? this.bdcqz.syqx.split(' ') : [];
399
          if (getByteLen(this.bdcqz.syqx) > 37) {
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
            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)); // 调整行高
              })
            })
          }

441
          let lines2 = this.bdcqz.zl ? this.bdcqz.zl.split(' ') : [];
442
          if (getByteLen(this.bdcqz.zl) > 37) {
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
            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)); // 调整行高
              })
            })
          }
483 484
        }
        image.src = this.imgSrc
renchao@pashanhoo.com committed
485
      },
yuanbo committed
486
      /**
487 488 489 490 491 492
       * @description: 不动产证明
       * @author: renchao
       */
      drawTextzmImage () {
        function getByteLen (val) {
          var len = 0;
493
          if (!val) return len;
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
          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.zm;
        const context = canvas.getContext('2d');
        const image = new Image();
        image.onload = () => {
          context.drawImage(image, 0, 0);
renchao@pashanhoo.com committed
510
          context.font = '18px 楷体';
511 512
          context.fillStyle = '#000000';
          // ysxlh
513
          context.fillText(this.bdcqz.ysxlh ? this.bdcqz.ysxlh : '', 280, 712);
514
          // djsj
515 516
          if (this.bdcqz.djsj) {
            let djsjList = this.bdcqz.djsj.split(' ')[0].split('/')
517 518 519 520
            context.fillText(djsjList[0] ? djsjList[0] : '', 327, 580);
            context.fillText(djsjList[1] ? djsjList[1] : '', 393, 580);
            context.fillText(djsjList[2] ? djsjList[2] : '', 443, 580);
          }
521 522
          context.fillText(this.bdcqz.sjjc ? this.bdcqz.sjjc : '', 620, 125);
          context.fillText(this.bdcqz.djnd ? this.bdcqz.djnd : '', 665, 125);
523 524 525 526 527 528 529 530 531 532 533 534
          // context.fillText(this.bdcqz.sxqc ? this.bdcqz.sxqc : '', 750, 125);

          if (getByteLen(this.bdcqz.sxqc) > 14) {
            const originalFont = context.font;
            // 设置新的字体大小
            context.font = '14px 楷体'; // 替换为你想要的字体和大小
            // 绘制 bdcdyh
            context.fillText(this.bdcqz.sxqc ? this.bdcqz.sxqc : '', 725, 125);
            // 恢复原始字体设置
            context.font = originalFont;
          }

535 536
          context.fillText(this.bdcqz.sxh ? this.bdcqz.sxh : '', 960, 123);
          context.fillText(this.bdcqz.zmqlhsx ? this.bdcqz.zmqlhsx : '', 775, 180);
537 538 539
          // context.fillText(this.bdcqz.qlr ? this.bdcqz.qlr : '', 775, 228);
          // 权利人
          let qlrlines = this.bdcqz.qlr ? this.bdcqz.qlr.split(' ') : [];
540
          if (getByteLen(this.bdcqz.qlr) >= 34) {
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
            qlrlines.forEach((line, index) => {
              let currentLine = '';
              let arr = [];
              for (let word of line) {
                const testLine = currentLine + word;
                const lineWidth = context.measureText(testLine).width;
                if (lineWidth <= 295) {
                  currentLine = testLine;
                } else {
                  arr.push(currentLine);
                  currentLine = word;
                }
              }
              arr.push(currentLine);
              arr.forEach((line, index) => {
                context.fillText(line, 775, 218 + (index * 20)); // 调整行高
              })
            })
          } else {
            qlrlines.forEach((line, index) => {
              let currentLine = '';
              let arr = [];
              for (let word of line) {
                const testLine = currentLine + word;
                const lineWidth = context.measureText(testLine).width;
                if (lineWidth <= 295) {
                  currentLine = testLine;
                } else {
                  arr.push(currentLine);
                  currentLine = word;
                }
              }
              arr.push(currentLine);
              arr.forEach((line, index) => {
                context.fillText(line, 775, 228 + (index * 20)); // 调整行高
              })
            })
          }
          // 义务人
580
          context.fillText(this.bdcqz.ywr ? this.bdcqz.ywr : '', 775, 275);
581
          let lines2 = this.bdcqz.zl ? this.bdcqz.zl.split(' ') : [];
582
          if (getByteLen(this.bdcqz.zl) > 37) {
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
            lines2.forEach((line, index) => {
              const y = 315 + (index * 20); // 每行文本的垂直位置
              let currentLine = '';
              let arr = [];
              for (let word of line) {
                const testLine = currentLine + word;
                const lineWidth = context.measureText(testLine).width;
                if (lineWidth <= 295) {
                  currentLine = testLine;
                } else {
                  arr.push(currentLine);
                  currentLine = word;
                }
              }
              arr.push(currentLine);
              arr.forEach((line, index) => {
                context.fillText(line, 775, y + (index * 20)); // 调整行高
              })
            })
          } else {
            lines2.forEach((line, index) => {
              const y = 325 + (index * 20); // 每行文本的垂直位置
              let currentLine = '';
              let arr = [];
              for (let word of line) {
                const testLine = currentLine + word;
                const lineWidth = context.measureText(testLine).width;
                if (lineWidth <= 295) {
                  currentLine = testLine;
                } else {
                  arr.push(currentLine);
                  currentLine = word;
                }
              }
              arr.push(currentLine);
              arr.forEach((line, index) => {
                context.fillText(line, 775, y + (index * 20)); // 调整行高
              })
            })
          }
623
          // bdcdyh
624 625
          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)
626 627 628 629 630
          // 保存当前字体设置
          const originalFont = context.font;
          // 设置新的字体大小
          context.font = '16px 楷体'; // 替换为你想要的字体和大小
          // 绘制 bdcdyh
631
          context.fillText(this.bdcdyh ? this.bdcdyh : '', 775, 373);
632 633
          // 恢复原始字体设置
          context.font = originalFont;
634
          // qlqtzk
635
          const maxWidth = 290; // 最大宽度限制
636
          let lines = this.bdcqz.qlqtzk ? this.bdcqz.qlqtzk.split('\n').filter(i => i && i.trim()) : [];
637
          for (let i = 0; i < lines.length; i++) {
638
            console.log(getByteLen(lines[i]));
639 640
            let num = Math.ceil(getByteLen(lines[i]) / 37)
            if (getByteLen(lines[i]) > 37) {
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
              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);
              if (i > 0) {
                arr.forEach((line, index) => {
656
                  context.fillText(line, 770, 438 + (24 * (i - 1)) + 5 * num + (index * 17)); // 调整行高
657 658 659
                })
              } else {
                arr.forEach((line, index) => {
660
                  context.fillText(line, 770, 438 + (24 * (i - 1)) + (index * 17)); // 调整行高
661 662 663 664
                })
              }
            } else {
              if (i > 0) {
665
                context.fillText(lines[i] ? lines[i] : '', 770, 447 + 6 * num + (25 * (i - 1)));
666
              } else {
667
                context.fillText(lines[i] ? lines[i] : '', 770, 447 + (25 * (i - 1)));
668 669 670 671
              }
            }
          }
          // fj
672
          let lines1 = this.bdcqz.fj ? this.bdcqz.fj.split('\n').filter(i => i && i.trim()) : [];
673
          for (let i = 0; i < lines1.length; i++) {
674 675
            let num = Math.ceil(getByteLen(lines1[i]) / 37)
            if (getByteLen(lines1[i]) > 37) {
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
              let currentLine = '';
              let arr = [];
              for (let word of lines1[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);
              if (i > 0) {
                arr.forEach((line, index) => {
691
                  context.fillText(line, 770, 610 + (25 * (i - 1)) + 5 * num + (index * 22)); // 调整行高
692 693 694
                })
              } else {
                arr.forEach((line, index) => {
695
                  context.fillText(line, 770, 610 + (25 * (i - 1)) + (index * 22)); // 调整行高
696 697 698 699
                })
              }
            } else {
              if (i > 0) {
700
                context.fillText(lines1[i] ? lines1[i] : '', 770, 610 + 5 * num + (24 * (i - 1)));
701
              } else {
702
                context.fillText(lines1[i] ? lines1[i] : '', 770, 610 + (24 * (i - 1)));
703 704 705 706 707 708
              }
            }
          }
        }
        image.src = this.bdczmSrc;
      },
yuanbo committed
709 710 711 712
      /**
       * @description: 打印
       * @author: renchao
       */
713
      handlePrint () {
714
        let that = this
715 716 717 718
        if (this.ruleForm.ysxlh == '') {
          this.$message.error('请选择印刷序列号');
          return;
        }
renchao@pashanhoo.com committed
719
        store.dispatch('user/reWorkFresh', false)
720
        if (this.bdcqz.bdcqzlx == 1) {
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744
          if (this.activeTitle == 'title1') {
            getPrintTemplateByCode({ tmpno: 'zsdy1' }).then(resInfo => {
              if (resInfo.code == 200) {
                //打开模板设计
                let LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
                LODOP.ADD_PRINT_DATA("ProgramData", resInfo.result.tmpcontent); //装载模板
                console.log(that.bdcqz);
                for (let key in that.bdcqz) {
                  LODOP.SET_PRINT_STYLEA(key, "CONTENT", that.bdcqz[key]);
                }
                LODOP.PREVIEW();
              } else {
                that.$message.error(resInfo.message)
              }
              that.$popupCacel()
              //刷新列表
              store.dispatch('user/reWorkFresh', true)
            })
          } else {
            getPrintTemplateByCode({ tmpno: 'zsdy' }).then(resInfo => {
              if (resInfo.code == 200) {
                //打开模板设计
                let LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
                LODOP.ADD_PRINT_DATA("ProgramData", resInfo.result.tmpcontent); //装载模板
745

746 747 748 749 750 751 752 753 754
                that.bdcqz.bdcdyh1 = that.bdcqz.bdcdyh.slice(0, 6) + ' ' + that.bdcqz.bdcdyh.slice(6, 12) + ' ' +
                  that.bdcqz.bdcdyh.slice(12, 19) + ' ' + that.bdcqz.bdcdyh.slice(19, that.bdcqz.bdcdyh.length)
                //todo 调取后端接口获取数据 循环set
                for (let key in that.bdcqz) {
                  LODOP.SET_PRINT_STYLEA(key, "CONTENT", that.bdcqz[key]);
                }
                LODOP.PREVIEW();
              } else {
                that.$message.error(resInfo.message)
755
              }
756 757 758 759 760
              that.$popupCacel()
              //刷新列表
              store.dispatch('user/reWorkFresh', true)
            })
          }
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781
        } else {
          getPrintTemplateByCode({ tmpno: 'zmdy' }).then(resInfo => {
            if (resInfo.code == 200) {
              //打开模板设计
              let LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
              LODOP.ADD_PRINT_DATA("ProgramData", resInfo.result.tmpcontent); //装载模板

              // 年月日
              this.bdcqz.nian = this.bdcqz.djsj.split(' ')[0].split('/')[0]
              this.bdcqz.yue = this.bdcqz.djsj.split(' ')[0].split('/')[1]
              this.bdcqz.ri = this.bdcqz.djsj.split(' ')[0].split('/')[1]
              this.bdcqz.bdcdyh1 = 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)
              //todo 调取后端接口获取数据 循环set
              for (let key in this.bdcqz) {
                LODOP.SET_PRINT_STYLEA(key, "CONTENT", this.bdcqz[key]);
              }
              LODOP.PREVIEW();
            } else {
              this.$message.error(resInfo.message)
            }
782 783 784
            that.$popupCacel()
            //刷新列表
            store.dispatch('user/reWorkFresh', true)
785 786
          })
        }
renchao@pashanhoo.com committed
787
      },
yuanbo committed
788 789 790 791
      /**
       * @description: 保存打印记录
       * @author: renchao
       */
792
      handleSubmit () {
renchao@pashanhoo.com committed
793
        let that = this
794 795 796 797
        if (this.ruleForm.ysxlh == '') {
          this.$message.error('请选择印刷序列号');
          return;
        }
renchao@pashanhoo.com committed
798
        store.dispatch('user/reWorkFresh', false)
799 800 801 802
        this.ruleForm.bsmBdcqz = this.bdcqz.bsmBdcqz;
        this.ruleForm.bdcqzlx = this.bdcqz.bdcqzlx;
        this.ruleForm.szzh = this.bdcqz.bdcqzh;
        this.bdcqz.ysxlh = this.ruleForm.ysxlh
renchao@pashanhoo.com committed
803 804
        certificate(this.ruleForm).then((res) => {
          if (res.code === 200) {
renchao@pashanhoo.com committed
805
            that.$popupCacel()
806
            this.handlePrint()
renchao@pashanhoo.com committed
807
          } else {
renchao@pashanhoo.com committed
808
            this.$message.error(res.message)
renchao@pashanhoo.com committed
809
          }
810
          store.dispatch('user/reWorkFresh', true)
811 812 813 814
        })
      }
    }
  }
蔡俊立 committed
815 816
</script>
<style scoped lang="scss">
renchao@pashanhoo.com committed
817
  @import "~@/styles/mixin.scss";
818 819 820 821 822 823 824 825 826
  /deep/.el-tabs__nav-wrap::after {
    display: none;
  }
  /deep/.el-tabs__header {
    margin: 0;
  }
  /deep/.el-form-item--small.el-form-item {
    margin-bottom: 0;
  }
renchao@pashanhoo.com committed
827 828 829 830
  .zsdy-content {
    height: 80vh;
    overflow-y: scroll;
  }
831
  .zs-content {
renchao@pashanhoo.com committed
832
    text-align: center;
蔡俊立 committed
833
  }
834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865
  .invalid-diglog {
    padding-bottom: 20px;
    font-size: 16px;
    font-weight: bold;
    color: rgb(99, 99, 99);

    .invalid-title {
      display: flex;
      align-content: center;

      .invalid-icon {
        color: rgb(254, 148, 0);
        font-size: 34px;
        margin-right: 10px;
      }

      .invalid-body {
        line-height: 40px;
        margin-bottom: 10px;
      }
    }

    .invalid-reson {
      margin-bottom: 10px;
    }

    .dialog-footer {
      margin-top: 10px;
      display: flex;
      justify-content: flex-end;
    }
  }
蔡俊立 committed
866
</style>