export default {
    isType(obj) {
        //类型判断
        var regexp = /\s(\w+)\]/;
        var result = regexp.exec(Object.prototype.toString.call(obj))[1];
        return result;
    },
    //深拷贝公共方法
   deep(dest,obj){ //dest表示 对象 ； obj传入的值
      var date = dest;//定义的变量
      for(var key in obj){  //拿到键的值  key
          if(typeof obj[key] === 'object'){  //类型检测
              // constructor (属性检测)判断类型是数组还是对象
              date[key] = (obj[key].constructor === Array) ? [] : {};
              this.deep(date[key], obj[key]);
          }else{ //如果obj[key] 不是对象类型，直接复制
              date[key] = obj[key]
          }
      }
      return date;
  },
    dateFormat(time) {
        const t = new Date(time * 1000);
        // 日期格式
        const format = 'Y-m-d h:i:s';
        const year = t.getFullYear();
        // 由于 getMonth 返回值会比正常月份小 1
        const month = t.getMonth() + 1;
        const day = t.getDate();
        const hours = t.getHours();
        const minutes = t.getMinutes();
        const seconds = t.getSeconds();
        const hash = {
            Y: year,
            m: month,
            d: day,
            h: hours,
            i: minutes,
            s: seconds,
        };
        return format.replace(/\w/g, (o) => {
            return hash[o];
        });
    },
    replaceDate(str, flag) {
        //时间戳转换
        if (str) {
            str = str.toString().length == 10 ? str * 1000 : str;
            let now = str ? new Date(str) : new Date(),
                y = now.getFullYear(),
                m = now.getMonth() + 1,
                d = now.getDate();
            if (flag) {
                return y + '-' + (m < 10 ? '0' + m : m) + '-' + (d < 10 ? '0' + d : d);
            }
            return (
                y +
                '-' +
                (m < 10 ? '0' + m : m) +
                '-' +
                (d < 10 ? '0' + d : d) +
                ' ' +
                now.toTimeString().substr(0, 8)
            );
        } else {
            return null;
        }
    },
    replaceDateNoHMS(str) {
        //时间戳转换
        if (str) {
            str = str.toString().length == 10 ? str * 1000 : str;
            let now = str ? new Date(str) : new Date(),
                y = now.getFullYear(),
                m = now.getMonth() + 1,
                d = now.getDate();
            return y + '-' + (m < 10 ? '0' + m : m) + '-' + (d < 10 ? '0' + d : d);
        } else {
            return null;
        }
    },
    //时间转换
    setDate(time) {
        let data = '';
        if (Object.prototype.toString.call(time) === '[object Date]') {
            data = new Date(time).toLocaleDateString().replace(/\//g, '-');
        }
        return data;
    },
    uniquesObjs(obj) {
        //去除统一数组中相同的对象
        let uniques = [];
        let stringify = {};
        for (let i = 0; i < obj.length; i++) {
            let keys = Object.keys(obj[i]);
            keys.sort(function(a, b) {
                return Number(a) - Number(b);
            });
            let str = '';
            for (let j = 0; j < keys.length; j++) {
                str += JSON.stringify(keys[j]);
                str += JSON.stringify(obj[i][keys[j]]);
            }
            if (!stringify.hasOwnProperty(str)) {
                uniques.push(obj[i]);
                stringify[str] = true;
            }
        }
        uniques = uniques;
        return uniques;
    },
    throttle(func, wait) {
        //节流
        let timer = null;
        let fn = function() {
            if (!timer) {
                let args = Array.from(arguments);
                timer = setTimeout(() => {
                    func.apply(this, args);
                    timer = null;
                }, wait);
            }
        };
        return fn;
    },
    shake(func, t) {
        //防抖
        let fn = function() {
            let args = Array.from(arguments);
            clearTimeout(func.id);
            func.id = setTimeout(() => {
                func.apply(this, args);
            }, t);
        };
        return fn;
    },
    objToParams(obj) {
        let result = '';
        for (let i in obj) {
            result += `&${i}=${obj[i]}`;
        }
        result = '?' + result.substr(1, result.length - 1);
        return result;
    },
    computedForm(array, header) {
        const result = array.reduce((pre, cur) => {
            const data = header.filter(
                (row) => (cur.is_show && row.serverName == cur.key) && (
                    row.title = cur.title, row.name == 'Input' ? row.placeholder = `请输入${cur.title}` : row.name == 'Select' ? row.placeholder = `请选择${cur.title}` : ''
                )
            );
            if (data && data.length == 1) {
                return pre.concat(data);
            } else {
                return pre;
            }
        }, []);
        return result;
    },
    computedHeader(array, header) {
        const result = array.reduce((pre, cur) => {
            const data = header.filter((row) => (cur.is_show && row.key == cur.key) && (row.title = cur.title));
            if (data && data.length == 1) {
                return pre.concat(data);
            } else {
                return pre;
            }
        }, []);
        return result;
    },
    PrintChipsUsb(contents,type,printerUsbPort,sub_type) {
      //30*50
         if(sub_type==1){
          let data = {};
          // let url = "http://192.168.0.145:888/postek/print"; //request_url
         //request_url
          data.reqParam = "1"; //这个一般不用改，如需改，查api
          let printparamsJsonArray = [];
          // let IP = "192.168.1.58";//print_url
          // let IP = "192.168.0.199"; //print_url
          // printparamsJsonArray.push({printPort:"1",printName:"POSTEK TX3r"});
          printparamsJsonArray.push({ PTK_OpenUSBPort:printerUsbPort});
          printparamsJsonArray.push({ PTK_ClearBuffer: "" });
          printparamsJsonArray.push({ PTK_SetDirection: "B" });
          printparamsJsonArray.push({ PTK_SetPrintSpeed: "4" });
          printparamsJsonArray.push({ PTK_SetDarkness: "10" });
          printparamsJsonArray.push({
            PTK_SetLabelHeight: type!=1&&type!=100?240 + "," + 24 + ",0,false":624 + "," + 24 + ",0,false",
          });
          printparamsJsonArray.push({ PTK_SetLabelWidth: 1080 });
          // 打印类型 1江山 2贝斯特
          if (type == 1) {
            contents.map((content) => {
              //江山打印格式
              //上
              const printContent_l1 = `单号：${content.order_no}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "100,40,60,0,微软雅黑,1,700,0,0,0," + printContent_l1,
              });
              const printContent_l1_2 = `型号：${content.product_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "600,40,60,0,微软雅黑,1,700,0,0,0," + printContent_l1_2,
              });
              const printContent_l2 = `尺寸：${content.measure}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "100,110,60,0,微软雅黑,1,700,0,0,0," + printContent_l2,
              });
              const printContent_l2_2 = `工艺：${content.process_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "600,110,60,0,微软雅黑,1,700,0,0,0," + printContent_l2_2,
              });
              const printContent_l3 = `颜色：${content.color_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "100,250,60,0,微软雅黑,1,700,0,0,0," + printContent_l3,
              });
              const printContent_l3_2 = `部件：${content.part_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "100,180,60,0,微软雅黑,1,700,0,0,0," + printContent_l3_2,
              });
              //下
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "100,435,45,0,微软雅黑,1,700,0,0,0," + printContent_l1,
              });
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "600,435,45,0,微软雅黑,1,700,0,0,0," + printContent_l1_2,
              });
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "100,480,45,0,微软雅黑,1,700,0,0,0," + printContent_l2,
              });
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "600,480,45,0,微软雅黑,1,700,0,0,0," + printContent_l2_2,
              });
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "100,525,45,0,微软雅黑,1,700,0,0,0," + printContent_l3,
              });
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "600,525,45,0,微软雅黑,1,700,0,0,0," + printContent_l3_2,
              });
              printparamsJsonArray.push({
                PTK_RWRFIDLabel:
                  "1,0,0," + content.chip.length / 2 + ",1," + content.chip,
              });
              printparamsJsonArray.push({ PTK_PrintLabel: "1,1" });
            });
          } else if(type==100) {
            contents.map((content) => {
              //贝斯特打印格式
              //上
              const printContent_l1 = `项目：${content.client_name}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "150,40,60,0,微软雅黑,1,700,0,0,0," + printContent_l1,
              });
              const printContent_l1_2 = `区域：${
                content.house ? content.house + "-" : ""
              }${content.layer ? content.layer : ""}${
                content.position ? content.position : ""
              }`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "650,40,60,0,微软雅黑,1,700,0,0,0," + printContent_l1_2,
              });
              const printContent_l2 = `房号：${content.number_detail}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "150,110,60,0,微软雅黑,1,700,0,0,0," + printContent_l2,
              });
              const printContent_l2_2 = `产品：${content.product_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "650,110,60,0,微软雅黑,1,700,0,0,0," + printContent_l2_2,
              });
              const printContent_l3 = `图号：${content.url_number}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "150,180,60,0,微软雅黑,1,700,0,0,0," + printContent_l3,
              });
              const printContent_l3_2 = `部件：${content.part_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "650,180,60,0,微软雅黑,1,700,0,0,0," + printContent_l3_2,
              });
              const printContent_l4 = `木皮：${content.color_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "150,320,60,0,微软雅黑,1,700,0,0,0," + printContent_l4,
              });
              const printContent_l4_2 = `尺寸：${content.measure}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "150,250,60,0,微软雅黑,1,700,0,0,0," + printContent_l4_2,
              });
              let space_str = '\u0000'
               let printContent_l5_data= (function() {
                let hexCharCodeStr = content.chip;
                let trimedStr = hexCharCodeStr.trim();
                let rawStr = trimedStr.substr(0,2).toLowerCase() === "0x"?trimedStr.substr(2):trimedStr;
                let len = rawStr.length;
                 if(len % 2 !== 0) {
                   alert("Illegal Format ASCII Code!");
                   return "";}
                  let curCharCode;
                  let resultStr = [];
                  for(var i = 0; i < len;i = i + 2) {
                   curCharCode = parseInt(rawStr.substr(i, 2), 16); // ASCII Code Value
                     resultStr.push(String.fromCharCode(curCharCode));
                  }
                  return resultStr.join("");
           })();
               printContent_l5_data = printContent_l5_data.replace(space_str,'')
               const printContent_l5 = `芯片编码：${printContent_l5_data}`;
              //  console.log(printContent_l5_data)
              printparamsJsonArray.push({
                PTK_DrawText_TrueTypeEx:
                  "970,330,25,0,微软雅黑,1,700,0,0,0,11,0,0,0," + printContent_l5,
              });
              //下
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "150,435,45,0,微软雅黑,1,700,0,0,0," + printContent_l1,
              });
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "650,435,45,0,微软雅黑,1,700,0,0,0," + printContent_l1_2,
              });
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "150,480,45,0,微软雅黑,1,700,0,0,0," + printContent_l2,
              });
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "650,480,45,0,微软雅黑,1,700,0,0,0," + printContent_l2_2,
              });
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "150,525,45,0,微软雅黑,1,700,0,0,0," + printContent_l3,
              });
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "650,525,45,0,微软雅黑,1,700,0,0,0," + printContent_l3_2,
              });
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "150,570,45,0,微软雅黑,1,700,0,0,0," + printContent_l4,
              });
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "650,570,45,0,微软雅黑,1,700,0,0,0," + printContent_l4_2,
              });
                printparamsJsonArray.push({
                PTK_DrawText_TrueTypeEx:
                  "970,530,25,0,微软雅黑,1,700,0,0,0,10,0,0,0," + printContent_l5,
              });
              // 17，35 420
              printparamsJsonArray.push({
                PTK_RWRFIDLabel:
                  "1,0,0," + content.chip.length / 2 + ",1," + content.chip,
              });
              printparamsJsonArray.push({ PTK_PrintLabel: "1,1" });
            });
          }else{
            contents.map((content) => {
              //贝斯特打印格式
              //上
              const printContent_l1 = `项目：${content.client_name}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "90,40,40,0,微软雅黑,1,700,0,0,0," + printContent_l1,
              });
              const printContent_l1_2 = `区域：${
                content.house ? content.house + "-" : ""
              }${content.layer ? content.layer : ""}${
                content.position ? content.position : ""
              }`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "464,40,40,0,微软雅黑,1,700,0,0,0," + printContent_l1_2,
              });
              const printContent_l2 = `房号：${content.number_detail}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "90,90,40,0,微软雅黑,1,700,0,0,0," + printContent_l2,
              });
              const printContent_l2_2 = `产品：${content.product_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "464,90,40,0,微软雅黑,1,700,0,0,0," + printContent_l2_2,
              });
              const printContent_l3 = `图号：${content.url_number}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "464,140,40,0,微软雅黑,1,700,0,0,0," + printContent_l3,
              });
              const printContent_l3_2 = `部件：${content.part_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "90,140,40,0,微软雅黑,1,700,0,0,0," + printContent_l3_2,
              });
              const printContent_l4 = `木皮：${content.color_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "464,190,40,0,微软雅黑,1,700,0,0,0," + printContent_l4,
              });
              const printContent_l4_2 = `尺寸：${content.measure}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "90,190,40,0,微软雅黑,1,700,0,0,0," + printContent_l4_2,
              });
              let space_str = '\u0000'
               let printContent_l5_data= (function() {
                let hexCharCodeStr = content.chip;
                let trimedStr = hexCharCodeStr.trim();
                let rawStr = trimedStr.substr(0,2).toLowerCase() === "0x"?trimedStr.substr(2):trimedStr;
                let len = rawStr.length;
                 if(len % 2 !== 0) {
                   alert("Illegal Format ASCII Code!");
                   return "";}
                  let curCharCode;
                  let resultStr = [];
                  for(var i = 0; i < len;i = i + 2) {
                   curCharCode = parseInt(rawStr.substr(i, 2), 16); // ASCII Code Value
                     resultStr.push(String.fromCharCode(curCharCode));
                  }
                  return resultStr.join("");
           })();
               printContent_l5_data = printContent_l5_data.replace(space_str,'')
              //  const printContent_l5 = `芯片编码：${printContent_l5_data}`;
              const printContent_l5 = printContent_l5_data;
              //  console.log(printContent_l5_data)
              printparamsJsonArray.push({
                PTK_DrawText_TrueTypeEx:
                  "800,152,25,0,微软雅黑,1,700,0,0,0,11,0,0,0," + printContent_l5,
              });
              //下
              // printparamsJsonArray.push({
              //   PTK_DrawText_TrueType:
              //     "150,435,45,0,微软雅黑,1,700,0,0,0," + printContent_l1,
              // });
              // printparamsJsonArray.push({
              //   PTK_DrawText_TrueType:
              //     "650,435,45,0,微软雅黑,1,700,0,0,0," + printContent_l1_2,
              // });
              // printparamsJsonArray.push({
              //   PTK_DrawText_TrueType:
              //     "150,480,45,0,微软雅黑,1,700,0,0,0," + printContent_l2,
              // });
              // printparamsJsonArray.push({
              //   PTK_DrawText_TrueType:
              //     "650,480,45,0,微软雅黑,1,700,0,0,0," + printContent_l2_2,
              // });
              // printparamsJsonArray.push({
              //   PTK_DrawText_TrueType:
              //     "150,525,45,0,微软雅黑,1,700,0,0,0," + printContent_l3,
              // });
              // printparamsJsonArray.push({
              //   PTK_DrawText_TrueType:
              //     "650,525,45,0,微软雅黑,1,700,0,0,0," + printContent_l3_2,
              // });
              // printparamsJsonArray.push({
              //   PTK_DrawText_TrueType:
              //     "150,570,45,0,微软雅黑,1,700,0,0,0," + printContent_l4,
              // });
              // printparamsJsonArray.push({
              //   PTK_DrawText_TrueType:
              //     "650,570,45,0,微软雅黑,1,700,0,0,0," + printContent_l4_2,
              // });
              //   printparamsJsonArray.push({
              //   PTK_DrawText_TrueTypeEx:
              //     "970,530,25,0,微软雅黑,1,700,0,0,0,10,0,0,0," + printContent_l5,
              // });
              // 17，35 420
              printparamsJsonArray.push({
                PTK_RWRFIDLabel:
                  "1,0,0," + content.chip.length / 2 + ",1," + content.chip,
              });
              printparamsJsonArray.push({ PTK_PrintLabel: "1,1" });
            });
          }
          printparamsJsonArray.push({ PTK_CloseUSBPort: "" });
          data.printparams = printparamsJsonArray;
          let sub_data = JSON.parse(JSON.stringify(data));
          sub_data.printparams = JSON.stringify(sub_data.printparams);
         return sub_data
        }
        //70*20
        if(sub_type==2){
          let data = {};
          // let url = "http://192.168.0.145:888/postek/print"; //request_url
         //request_url
          data.reqParam = "1"; //这个一般不用改，如需改，查api
          let printparamsJsonArray = [];
          // let IP = "192.168.1.58";//print_url
          // let IP = "192.168.0.199"; //print_url
          // printparamsJsonArray.push({printPort:"1",printName:"POSTEK TX3r"});
          printparamsJsonArray.push({ PTK_OpenUSBPort:printerUsbPort});
          printparamsJsonArray.push({ PTK_ClearBuffer: "" });
          printparamsJsonArray.push({ PTK_SetDirection: "B" });
          printparamsJsonArray.push({ PTK_SetPrintSpeed: "4" });
          printparamsJsonArray.push({ PTK_SetDarkness: "10" });
          printparamsJsonArray.push({
            PTK_SetLabelHeight: 330 + "," + 24 + ",0,false",
          });
          printparamsJsonArray.push({ PTK_SetLabelWidth: 1080 });
          // 打印类型 1江山 2贝斯特
          if (type == 1) {
            contents.map((content) => {
              //江山打印格式
              //上
              const printContent_l1 = `单号：${content.order_no}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "100,40,60,0,微软雅黑,1,700,0,0,0," + printContent_l1,
              });
              const printContent_l1_2 = `型号：${content.product_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "600,40,60,0,微软雅黑,1,700,0,0,0," + printContent_l1_2,
              });
              const printContent_l2 = `尺寸：${content.measure}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "100,110,60,0,微软雅黑,1,700,0,0,0," + printContent_l2,
              });
              const printContent_l2_2 = `工艺：${content.process_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "600,110,60,0,微软雅黑,1,700,0,0,0," + printContent_l2_2,
              });
              const printContent_l3 = `颜色：${content.color_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "100,250,60,0,微软雅黑,1,700,0,0,0," + printContent_l3,
              });
              const printContent_l3_2 = `部件：${content.part_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "100,180,60,0,微软雅黑,1,700,0,0,0," + printContent_l3_2,
              });
              //下
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "100,435,45,0,微软雅黑,1,700,0,0,0," + printContent_l1,
              });
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "600,435,45,0,微软雅黑,1,700,0,0,0," + printContent_l1_2,
              });
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "100,480,45,0,微软雅黑,1,700,0,0,0," + printContent_l2,
              });
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "600,480,45,0,微软雅黑,1,700,0,0,0," + printContent_l2_2,
              });
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "100,525,45,0,微软雅黑,1,700,0,0,0," + printContent_l3,
              });
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "600,525,45,0,微软雅黑,1,700,0,0,0," + printContent_l3_2,
              });
              printparamsJsonArray.push({
                PTK_RWRFIDLabel:
                  "1,0,0," + content.chip.length / 2 + ",1," + content.chip,
              });
              printparamsJsonArray.push({ PTK_PrintLabel: "1,1" });
            });
          } else {
            contents.map((content) => {
              //贝斯特打印格式
              //上
              const printContent_l1 = `项目：${content.client_name}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "364,20,40,0,微软雅黑,1,700,0,0,0," + printContent_l1,
              });
               const printContent_l4_2 = `尺寸：${content.measure}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "612,20,40,0,微软雅黑,1,700,0,0,0," + printContent_l4_2,
              });
             
              const printContent_l3_2 = `部件：${content.part_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "364,70,40,0,微软雅黑,1,700,0,0,0," + printContent_l3_2,
              });
              const printContent_l3 = `图号：${content.url_number}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "732,70,40,0,微软雅黑,1,700,0,0,0," + printContent_l3,
              });
              const printContent_l1_2 = `区域：${
                content.house ? content.house + "-" : ""
              }${content.layer ? content.layer : ""}${
                content.position ? content.position : ""
              }`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "364,120,40,0,微软雅黑,1,700,0,0,0," + printContent_l1_2,
              });
              const printContent_l2 = `房号：${content.number_detail}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "364,170,40,0,微软雅黑,1,700,0,0,0," + printContent_l2,
              });
              const printContent_l2_2 = `产品：${content.product_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "364,220,40,0,微软雅黑,1,700,0,0,0," + printContent_l2_2,
              });
              const printContent_l4 = `木皮：${content.color_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "364,270,40,0,微软雅黑,1,700,0,0,0," + printContent_l4,
              });
              let space_str = '\u0000'
               let printContent_l5_data= (function() {
                let hexCharCodeStr = content.chip;
                let trimedStr = hexCharCodeStr.trim();
                let rawStr = trimedStr.substr(0,2).toLowerCase() === "0x"?trimedStr.substr(2):trimedStr;
                let len = rawStr.length;
                 if(len % 2 !== 0) {
                   alert("Illegal Format ASCII Code!");
                   return "";}
                  let curCharCode;
                  let resultStr = [];
                  for(var i = 0; i < len;i = i + 2) {
                   curCharCode = parseInt(rawStr.substr(i, 2), 16); // ASCII Code Value
                     resultStr.push(String.fromCharCode(curCharCode));
                  }
                  return resultStr.join("");
           })();
               printContent_l5_data = printContent_l5_data.replace(space_str,'')
              //  const printContent_l5 = `芯片编码：${printContent_l5_data}`;
               const printContent_l5 = printContent_l5_data;
              //  console.log(printContent_l5_data)
              printparamsJsonArray.push({
                PTK_DrawText_TrueTypeEx:
                  "792,250,25,0,微软雅黑,1,700,0,0,0,11,0,0,0," + printContent_l5,
              });
              //下
            //   printparamsJsonArray.push({
            //     PTK_DrawText_TrueType:
            //       "150,435,45,0,微软雅黑,1,700,0,0,0," + printContent_l1,
            //   });
            //   printparamsJsonArray.push({
            //     PTK_DrawText_TrueType:
            //       "650,435,45,0,微软雅黑,1,700,0,0,0," + printContent_l1_2,
            //   });
            //   printparamsJsonArray.push({
            //     PTK_DrawText_TrueType:
            //       "150,480,45,0,微软雅黑,1,700,0,0,0," + printContent_l2,
            //   });
            //   printparamsJsonArray.push({
            //     PTK_DrawText_TrueType:
            //       "650,480,45,0,微软雅黑,1,700,0,0,0," + printContent_l2_2,
            //   });
            //   printparamsJsonArray.push({
            //     PTK_DrawText_TrueType:
            //       "150,525,45,0,微软雅黑,1,700,0,0,0," + printContent_l3,
            //   });
            //   printparamsJsonArray.push({
            //     PTK_DrawText_TrueType:
            //       "650,525,45,0,微软雅黑,1,700,0,0,0," + printContent_l3_2,
            //   });
            //   printparamsJsonArray.push({
            //     PTK_DrawText_TrueType:
            //       "150,570,45,0,微软雅黑,1,700,0,0,0," + printContent_l4,
            //   });
            //   printparamsJsonArray.push({
            //     PTK_DrawText_TrueType:
            //       "650,570,45,0,微软雅黑,1,700,0,0,0," + printContent_l4_2,
            //   });
            //     printparamsJsonArray.push({
            //     PTK_DrawText_TrueTypeEx:
            //       "970,530,25,0,微软雅黑,1,700,0,0,0,10,0,0,0," + printContent_l5,
            //   });
            //   // 17，35 420
              printparamsJsonArray.push({
                PTK_RWRFIDLabel:
                  "1,0,0," + content.chip.length / 2 + ",1," + content.chip,
              });
              printparamsJsonArray.push({ PTK_PrintLabel: "1,1" });
            });
          }
          printparamsJsonArray.push({ PTK_CloseUSBPort: "" });
          data.printparams = printparamsJsonArray;
          let sub_data = JSON.parse(JSON.stringify(data));
          sub_data.printparams = JSON.stringify(sub_data.printparams);
         return sub_data
        }
        //17*90
        if(sub_type==3){
          let data = {};
          // let url = "http://192.168.0.145:888/postek/print"; //request_url
         //request_url
          data.reqParam = "1"; //这个一般不用改，如需改，查api
          let printparamsJsonArray = [];
          // let IP = "192.168.1.58";//print_url
          // let IP = "192.168.0.199"; //print_url
          // printparamsJsonArray.push({printPort:"1",printName:"POSTEK TX3r"});
          printparamsJsonArray.push({ PTK_OpenUSBPort:printerUsbPort});
          printparamsJsonArray.push({ PTK_ClearBuffer: "" });
          printparamsJsonArray.push({ PTK_SetDirection: "B" });
          printparamsJsonArray.push({ PTK_SetPrintSpeed: "4" });
          printparamsJsonArray.push({ PTK_SetDarkness: "10" });
          printparamsJsonArray.push({
            PTK_SetLabelHeight: type!=1?204 + "," + 24 + ",0,false":624 + "," + 24 + ",0,false",
          });
          printparamsJsonArray.push({ PTK_SetLabelWidth: 1080 });
          // 打印类型 1江山 2贝斯特
          if (type == 1) {
            contents.map((content) => {
              //江山打印格式
              //上
              const printContent_l1 = `单号：${content.order_no}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "100,40,60,0,微软雅黑,1,700,0,0,0," + printContent_l1,
              });
              const printContent_l1_2 = `型号：${content.product_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "600,40,60,0,微软雅黑,1,700,0,0,0," + printContent_l1_2,
              });
              const printContent_l2 = `尺寸：${content.measure}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "100,110,60,0,微软雅黑,1,700,0,0,0," + printContent_l2,
              });
              const printContent_l2_2 = `工艺：${content.process_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "600,110,60,0,微软雅黑,1,700,0,0,0," + printContent_l2_2,
              });
              const printContent_l3 = `颜色：${content.color_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "100,250,60,0,微软雅黑,1,700,0,0,0," + printContent_l3,
              });
              const printContent_l3_2 = `部件：${content.part_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "100,180,60,0,微软雅黑,1,700,0,0,0," + printContent_l3_2,
              });
              //下
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "100,435,45,0,微软雅黑,1,700,0,0,0," + printContent_l1,
              });
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "600,435,45,0,微软雅黑,1,700,0,0,0," + printContent_l1_2,
              });
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "100,480,45,0,微软雅黑,1,700,0,0,0," + printContent_l2,
              });
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "600,480,45,0,微软雅黑,1,700,0,0,0," + printContent_l2_2,
              });
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "100,525,45,0,微软雅黑,1,700,0,0,0," + printContent_l3,
              });
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "600,525,45,0,微软雅黑,1,700,0,0,0," + printContent_l3_2,
              });
              printparamsJsonArray.push({
                PTK_RWRFIDLabel:
                  "1,0,0," + content.chip.length / 2 + ",1," + content.chip,
              });
              printparamsJsonArray.push({ PTK_PrintLabel: "1,1" });
            });
          } else {
            contents.map((content) => {
              //贝斯特打印格式
              //上
              const printContent_l1 = `项目：${content.client_name}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "150,15,45,0,微软雅黑,1,700,0,0,0," + printContent_l1,
              });
              const printContent_l1_2 = `区域：${
                content.house ? content.house + "-" : ""
              }${content.layer ? content.layer : ""}${
                content.position ? content.position : ""
              }`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "650,15,45,0,微软雅黑,1,700,0,0,0," + printContent_l1_2,
              });
              const printContent_l2 = `房号：${content.number_detail}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "150,60,45,0,微软雅黑,1,700,0,0,0," + printContent_l2,
              });
              const printContent_l2_2 = `产品：${content.product_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "650,60,45,0,微软雅黑,1,700,0,0,0," + printContent_l2_2,
              });
              const printContent_l3 = `图号：${content.url_number}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "150,105,45,0,微软雅黑,1,700,0,0,0," + printContent_l3,
              });
              const printContent_l3_2 = `部件：${content.part_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "650,105,45,0,微软雅黑,1,700,0,0,0," + printContent_l3_2,
              });
              const printContent_l4 = `木皮：${content.color_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "150,150,45,0,微软雅黑,1,700,0,0,0," + printContent_l4,
              });
              const printContent_l4_2 = `尺寸：${content.measure}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "650,150,45,0,微软雅黑,1,700,0,0,0," + printContent_l4_2,
              });
              let space_str = '\u0000'
               let printContent_l5_data= (function() {
                let hexCharCodeStr = content.chip;
                let trimedStr = hexCharCodeStr.trim();
                let rawStr = trimedStr.substr(0,2).toLowerCase() === "0x"?trimedStr.substr(2):trimedStr;
                let len = rawStr.length;
                 if(len % 2 !== 0) {
                   alert("Illegal Format ASCII Code!");
                   return "";}
                  let curCharCode;
                  let resultStr = [];
                  for(var i = 0; i < len;i = i + 2) {
                   curCharCode = parseInt(rawStr.substr(i, 2), 16); // ASCII Code Value
                     resultStr.push(String.fromCharCode(curCharCode));
                  }
                  return resultStr.join("");
           })();
               printContent_l5_data = printContent_l5_data.replace(space_str,'')
               const printContent_l5 =printContent_l5_data;
              //  console.log(printContent_l5_data)
              printparamsJsonArray.push({
                PTK_DrawText_TrueTypeEx:
                  "990,135,25,0,微软雅黑,1,700,0,0,0,11,0,0,0," + printContent_l5,
              });
              // 17，35 420
              printparamsJsonArray.push({
                PTK_RWRFIDLabel:
                  "1,0,0," + content.chip.length / 2 + ",1," + content.chip,
              });
              printparamsJsonArray.push({ PTK_PrintLabel: "1,1" });
            });
          }
          printparamsJsonArray.push({ PTK_CloseUSBPort: "" });
          data.printparams = printparamsJsonArray;
          let sub_data = JSON.parse(JSON.stringify(data));
          sub_data.printparams = JSON.stringify(sub_data.printparams);
         return sub_data
        }
        //竖着打印纸48*160
        if(sub_type==4){
          let data = {};
          // let url = "http://192.168.0.145:888/postek/print"; //request_url
         //request_url
          data.reqParam = "1"; //这个一般不用改，如需改，查api
          let printparamsJsonArray = [];
          // let IP = "192.168.1.58";//print_url
          // let IP = "192.168.0.199"; //print_url
          // printparamsJsonArray.push({printPort:"1",printName:"POSTEK TX3r"});
          printparamsJsonArray.push({ PTK_OpenUSBPort:printerUsbPort});
          printparamsJsonArray.push({ PTK_ClearBuffer: "" });
          printparamsJsonArray.push({ PTK_SetDirection: "B" });
          printparamsJsonArray.push({ PTK_SetPrintSpeed: "4" });
          printparamsJsonArray.push({ PTK_SetDarkness: "10" });
          printparamsJsonArray.push({
            PTK_SetLabelHeight: 1896 + "," + 24 + ",0,false",
          });
          printparamsJsonArray.push({ PTK_SetLabelWidth: 1080 });
            contents.map((content) => {
              const printContent_l1 = `项目：${content.client_name}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "870,0,100,0,微软雅黑,2,700,0,0,0," + printContent_l1,
              });
              const printContent_l1_2 = `区域：${
                content.house ? content.house + "-" : ""
              }${content.layer ? content.layer : ""}${
                content.position ? content.position : ""
              }`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "870,780,100,0,微软雅黑,2,700,0,0,0," + printContent_l1_2,
              });
              const printContent_l2 = `房号：${content.number_detail}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "720,0,100,0,微软雅黑,2,700,0,0,0," + printContent_l2,
              });
              const printContent_l2_2 = `产品：${content.product_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "720,780,100,0,微软雅黑,2,700,0,0,0," + printContent_l2_2,
              });
              const printContent_l3 = `图号：${content.url_number}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "570,0,100,0,微软雅黑,2,700,0,0,0," + printContent_l3,
              });
              const printContent_l3_2 = `部件：${content.part_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "570,780,100,0,微软雅黑,2,700,0,0,0," + printContent_l3_2,
              });
              const printContent_l4 = `木皮：${content.color_title}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "420,0,100,0,微软雅黑,2,700,0,0,0," + printContent_l4,
              });
              const printContent_l4_2 = `尺寸：${content.measure}`;
              printparamsJsonArray.push({
                PTK_DrawText_TrueType:
                  "420,780,100,0,微软雅黑,2,700,0,0,0," + printContent_l4_2,
              });
              let space_str = '\u0000'
               let printContent_l5_data= (function() {
                let hexCharCodeStr = content.chip;
                let trimedStr = hexCharCodeStr.trim();
                let rawStr = trimedStr.substr(0,2).toLowerCase() === "0x"?trimedStr.substr(2):trimedStr;
                let len = rawStr.length;
                 if(len % 2 !== 0) {
                   alert("Illegal Format ASCII Code!");
                   return "";}
                  let curCharCode;
                  let resultStr = [];
                  for(var i = 0; i < len;i = i + 2) {
                   curCharCode = parseInt(rawStr.substr(i, 2), 16); // ASCII Code Value
                     resultStr.push(String.fromCharCode(curCharCode));
                  }
                  return resultStr.join("");
           })();
               printContent_l5_data = printContent_l5_data.replace(space_str,'')
               const printContent_l5 =printContent_l5_data;
              //  console.log(printContent_l5_data)
              printparamsJsonArray.push({
                PTK_DrawText_TrueTypeEx:
                  "380,1610,45,0,微软雅黑,2,700,0,0,0,11,0,0,0," + printContent_l5,
              });
              // 17，35 420
              printparamsJsonArray.push({
                PTK_RWRFIDLabel:
                  "1,0,0," + content.chip.length / 2 + ",1," + content.chip,
              });
              printparamsJsonArray.push({ PTK_PrintLabel: "1,1" });
            });
          printparamsJsonArray.push({ PTK_CloseUSBPort: "" });
          data.printparams = printparamsJsonArray;
          let sub_data = JSON.parse(JSON.stringify(data));
          sub_data.printparams = JSON.stringify(sub_data.printparams);
         return sub_data
        }
        if(sub_type==5){
          let data = {};
          // let url = "http://192.168.0.145:888/postek/print"; //request_url
         //request_url
          data.reqParam = "1"; //这个一般不用改，如需改，查api
          let printparamsJsonArray = [];
          // let IP = "192.168.1.58";//print_url
          // let IP = "192.168.0.199"; //print_url
          // printparamsJsonArray.push({printPort:"1",printName:"POSTEK TX3r"});
          printparamsJsonArray.push({ PTK_OpenUSBPort:printerUsbPort});
          printparamsJsonArray.push({ PTK_ClearBuffer: "" });
          printparamsJsonArray.push({ PTK_SetDirection: "B" });
          printparamsJsonArray.push({ PTK_SetPrintSpeed: "4" });
          printparamsJsonArray.push({ PTK_SetDarkness: "10" });
          printparamsJsonArray.push({
            PTK_SetLabelHeight: 624 + "," + 24 + ",0,false",
          });
          printparamsJsonArray.push({ PTK_SetLabelWidth: 1080 });
          contents.map((content) => {
            //贝斯特打印格式
            //上
            const printContent_l1 = `项目：${content.client_name}`;
            printparamsJsonArray.push({
              PTK_DrawText_TrueType:
                "80,40,60,0,微软雅黑,1,700,0,0,0," + printContent_l1,
            });
            const printContent_l1_2 = `区域：${
              content.house ? content.house + "-" : ""
            }${content.layer ? content.layer : ""}${
              content.position ? content.position : ""
            }`;
            printparamsJsonArray.push({
              PTK_DrawText_TrueType:
                "580,40,60,0,微软雅黑,1,700,0,0,0," + printContent_l1_2,
            });
            const printContent_l2 = `房号：${content.number_detail}`;
            printparamsJsonArray.push({
              PTK_DrawText_TrueType:
                "80,110,60,0,微软雅黑,1,700,0,0,0," + printContent_l2,
            });
            const printContent_l2_2 = `产品：${content.product_title}`;
            printparamsJsonArray.push({
              PTK_DrawText_TrueType:
                "580,110,60,0,微软雅黑,1,700,0,0,0," + printContent_l2_2,
            });
            const printContent_l3 = `图号：${content.url_number}`;
            printparamsJsonArray.push({
              PTK_DrawText_TrueType:
                "80,180,60,0,微软雅黑,1,700,0,0,0," + printContent_l3,
            });
            const printContent_l3_2 = `部件：${content.part_title}`;
            printparamsJsonArray.push({
              PTK_DrawText_TrueType:
                "580,180,60,0,微软雅黑,1,700,0,0,0," + printContent_l3_2,
            });
            const printContent_l4 = `木皮：${content.color_title}`;
            printparamsJsonArray.push({
              PTK_DrawText_TrueType:
                "80,320,60,0,微软雅黑,1,700,0,0,0," + printContent_l4,
            });
            const printContent_l4_2 = `尺寸：${content.measure}`;
            printparamsJsonArray.push({
              PTK_DrawText_TrueType:
                "80,250,60,0,微软雅黑,1,700,0,0,0," + printContent_l4_2,
            });
            let space_str = '\u0000'
             let printContent_l5_data= (function() {
              let hexCharCodeStr = content.chip;
              let trimedStr = hexCharCodeStr.trim();
              let rawStr = trimedStr.substr(0,2).toLowerCase() === "0x"?trimedStr.substr(2):trimedStr;
              let len = rawStr.length;
               if(len % 2 !== 0) {
                 alert("Illegal Format ASCII Code!");
                 return "";}
                let curCharCode;
                let resultStr = [];
                for(var i = 0; i < len;i = i + 2) {
                 curCharCode = parseInt(rawStr.substr(i, 2), 16); // ASCII Code Value
                   resultStr.push(String.fromCharCode(curCharCode));
                }
                return resultStr.join("");
         })();
             printContent_l5_data = printContent_l5_data.replace(space_str,'')
             const printContent_l5 = `芯片编码：${printContent_l5_data}`;
            //  console.log(printContent_l5_data)
            printparamsJsonArray.push({
              PTK_DrawText_TrueTypeEx:
                "900,330,25,0,微软雅黑,1,700,0,0,0,10,0,0,0," + printContent_l5,
            });
            //下
            printparamsJsonArray.push({
              PTK_DrawText_TrueType:
                "80,435,45,0,微软雅黑,1,700,0,0,0," + printContent_l1,
            });
            printparamsJsonArray.push({
              PTK_DrawText_TrueType:
                "580,435,45,0,微软雅黑,1,700,0,0,0," + printContent_l1_2,
            });
            printparamsJsonArray.push({
              PTK_DrawText_TrueType:
                "80,480,45,0,微软雅黑,1,700,0,0,0," + printContent_l2,
            });
            printparamsJsonArray.push({
              PTK_DrawText_TrueType:
                "580,480,45,0,微软雅黑,1,700,0,0,0," + printContent_l2_2,
            });
            printparamsJsonArray.push({
              PTK_DrawText_TrueType:
                "80,525,45,0,微软雅黑,1,700,0,0,0," + printContent_l3,
            });
            printparamsJsonArray.push({
              PTK_DrawText_TrueType:
                "580,525,45,0,微软雅黑,1,700,0,0,0," + printContent_l3_2,
            });
            printparamsJsonArray.push({
              PTK_DrawText_TrueType:
                "80,570,45,0,微软雅黑,1,700,0,0,0," + printContent_l4,
            });
            printparamsJsonArray.push({
              PTK_DrawText_TrueType:
                "580,570,45,0,微软雅黑,1,700,0,0,0," + printContent_l4_2,
            });
              printparamsJsonArray.push({
              PTK_DrawText_TrueTypeEx:
                "900,530,25,0,微软雅黑,1,700,0,0,0,10,0,0,0," + printContent_l5,
            });
            // 17，35 420
            printparamsJsonArray.push({
              PTK_RWRFIDLabel:
                "1,0,0," + content.chip.length / 2 + ",1," + content.chip,
            });
            printparamsJsonArray.push({ PTK_PrintLabel: "1,1" });
          });
          printparamsJsonArray.push({ PTK_CloseUSBPort: "" });
          data.printparams = printparamsJsonArray;
          let sub_data = JSON.parse(JSON.stringify(data));
          sub_data.printparams = JSON.stringify(sub_data.printparams);
         return sub_data
        }
      },
};