guoyuji
2024-09-03 76bf2824bf55e8f4c3ccbc14b3b2719bf8fb219f
north-glass-erp/northglass-erp/src/components/pp/PrintCustomLabel.vue
@@ -37,6 +37,12 @@
const route = currentRoute.value
let type = props.type
let faceOrientation = props.faceOrientation
if (type.indexOf("英文")>-1 && faceOrientation==="此面为室内面"){
  faceOrientation='INSIDE'
}
else if (type.indexOf("英文")>-1 && faceOrientation==="此面为室外面"){
  faceOrientation='OUTSIDE'
}
let lableType = props.lableType
data.value.printList = JSON.parse(props.list)
onMounted(() => {
@@ -56,7 +62,6 @@
              }
            }
          }
        } else {
          ElMessage.warning(res.msg)
          router.push("/login")
@@ -69,69 +74,67 @@
// 打印方法
const printFlowCard = () => {
  // 需要打印的局部区域赋予"print-wrap"的id
  let el = document.getElementById("print");
  let doc = document;
  let body = doc.body || doc.getElementsByTagName("body")[0];
  let printId = "print-" + Date.now();
  // 创建无副作用的打印容器(因不确定页面的打印元素有无其它样式)
  let content = doc.createElement("div");
  content.id = printId;
  // 样式控制与打印无关的元素隐藏
  let style = doc.createElement("style");
  style.innerHTML =
      "body>#" +
      printId +
      "{display:none}@media print{body>:not(#" +
      printId +
      "){display:none !important}body>#" +
      printId +
      "{display:block;padding-top:1px}}";
  //
  content.innerHTML = el.outerHTML;
  body.appendChild(style);
  // 与style元素设置的样式相配合
  // 把打印内容的元素添加到body(作为body的子元素,可用body的子选择器 '>' 控制打印样式)
  body.appendChild(content);
  setTimeout(() => {
    window.print();
    body.removeChild(content);
    body.removeChild(style);
  }, 20);
}
//修改相同产品名称标签
const updataProductName = () => {
  for (let i = 0; i < lastList.value.length; i++) {
    let prefix = lastList.value[i].processId.substring(0, 11);
    let orderId= lastList.value[i].orderId
    let enName= lastList.value[i].productAbbreviation
    let project=lastList.value[i].project
    lastList.value.forEach(obj => {
      if (prefix === obj.processId.substring(0, 11)){
        obj.productAbbreviation = enName
      }
      if (orderId === obj.orderId){
        obj.project=project
      }
    })
const updateProductName = (event, index,id) => {
  // 创建映射对象
  const propertyMapping = {};
  labelList.forEach(item => {
    propertyMapping[item.name] = item.title;
  });
  // 输入的值
  const newValue = event.target.innerText;
  const parts = newValue.split(':');
  const result = parts[1]; // 获取冒号后的部分
  // 获取映射中所有的键
  const keys = Object.keys(propertyMapping);
  // 根据 index 获取对应的属性名
  const propertyName = keys[index];
  // 如果映射中没有该 index,直接返回
  if (!propertyName) {
    console.warn('Unsupported index:', index);
    return;
  }
  // 遍历 lastList 并更新对应的属性
  lastList.value.forEach(obj => {
    // 获取前缀和 orderId
    const prefix = obj.processId.substring(0, 11);
    const orderId = obj.orderId;
    const glassNumber=lastList.value[id].glassNumber
    const customerName = obj.customerName
    // 根据 propertyName 更新属性
    if (propertyName === 'productAbbreviation' && prefix === obj.processId.substring(0, 11)) {
      obj.productAbbreviation = result;
    }
    if (propertyName === 'project' && orderId === obj.orderId) {
      obj.project = result;
    }
    if (propertyName === 'productName' && prefix === obj.processId.substring(0, 11)){
      obj.productName = result;
    }
    if (propertyName === 'customerName' && orderId === obj.orderId){
      obj.customerName = result;
    }
  });
}
</script>
<template>
    <div id="print" :class="company.printLabel.className.custom.printFlowCardName()">
      <div v-for="(item1,id) in lastList" :class="company.printLabel.className.custom.entiretyName()">
      <div v-for="(item1,index) in lastList" :class="company.printLabel.className.custom.entiretyName()">
        <div class="row4">{{ faceOrientation }}</div>
        <div v-for="(item,id) in labelList" :class="company.printLabel.className.custom.contentRowName()">
          <div v-if="item.title==null" class="row1">{{ item.title }}</div>
          <div v-else class="row1">{{ item.title }}:</div>
          <div class="row2" style="width: 100%;"><input v-model="item1[item.name]"  @keyup="updataProductName()" style="border: none;"/></div>
          <div v-if="item1[item.name] != null && item1[item.name] !== ''" class="row1"  contenteditable="true" @input="updateProductName($event, id,index)" v-text="item.title+':'+item1[item.name]"></div>
<!--          <div class="row2" style="width: 100%;"><input class="contentRow2" v-model="item1[item.name]"  @keyup="updataProductName()" style="border: none;"/></div>-->
<!--          <div v-if="item1[item.name] != null && item1[item.name] !== ''" class="row2" style="width: 100%;" contenteditable="true" @input="updateProductName($event, id)" v-text="item1[item.name]"></div>-->
        </div>
        <div v-html="company.printLabel.custom(item1)"></div>
      </div>
@@ -148,10 +151,25 @@
  padding: 0;
}
textarea {
  border: none; /* 取消默认边框 */
  padding: 0; /* 取消默认内边距 */
  margin: 0; /* 取消默认外边距 */
  resize: none; /* 禁用调整大小功能 */
  font-family: Arial; /* 设置自定义字体 */
  font-size: 12px; /* 设置自定义字体大小 */
  line-height: 1; /* 设置行高 */
  width: 100%; /* 设置宽度为100% */
  height: auto; /* 高度根据内容自动调整 */
  box-sizing: border-box; /* 使宽高包括内边距和边框 */
  overflow-y: hidden;
}
body {
  overflow: hidden;
  font-family: Arial, sans-serif;
  font-size: 10px;
  font-family: Arial;
  font-size: 7px;
}
#printButton {
@@ -212,14 +230,13 @@
}
.contentRow .row1 {
  width: 30%;
  font-weight: bolder;
  width: 100%;
}
.entirety_finished .row4 {
  font-weight: bolder;
  text-align: right;
  margin-right: 10px;
  margin-right: 20px;
}
.contentRow .row1, .contentRow .row2 {
@@ -234,7 +251,7 @@
@page {
  size: auto;  /* auto is the initial value */
  margin: 13mm 4mm 0mm 6mm;  /* this affects the margin in the printer settings */
  margin: 13mm 5mm 0mm 7mm;  /* this affects the margin in the printer settings */
}
@media print {