yyb
20 小时以前 25508db9e43fe793d7a34fa2d8ca1d7244d887a6
pages/wareHouse/nuclearScale/nuclearscalerecord.vue
@@ -8,9 +8,10 @@
      </view>
    </u-navbar>
    <view class="wrap">
      <scroll-view class="finishProductIn-locno-scroll-list" scroll-y="true" @scrolltolower="loadMore">
         <scroll-view class="finishProductIn-locno-scroll-list" scroll-y="true" @scrolltolower="getmoreList()">
        <u-cell-group class="finishProductIn-locno-scroll-list-group" :border="false">
          <view class="content" v-for="(item, index) in list" :key="item.locNo" :index="index" @click="selectNo(item)">
               <view class="content" v-for="(item, index) in list" :key="item.locNo" :index="index"
                  @click="selectNo(item)">
            <view class="content-header">
              <view class="content-header-title">{{ index + 1 }}</view>
            </view>
@@ -21,7 +22,7 @@
                  <view class="_label-name">批次号:</view>
                </view>
                <view class="_content">
                  {{ item.value0 }}
                           {{ item.outBatchNo }}
                </view>
              </view>
              <view class="row-list">
@@ -30,7 +31,7 @@
                  <view class="_label-name">产品描述:</view>
                </view>
                <view class="_content">
                  {{ item.value1 }}
                           {{ item.netWeight }}
                </view>
              </view>
              <view class="row-list">
@@ -39,7 +40,7 @@
                  <view class="_label-name">零件号:</view>
                </view>
                <view class="_content">
                  {{ item.value2 }}
                           {{ item.partNo }}
                </view>
              </view>
              <view class="row-list">
@@ -48,7 +49,7 @@
                  <view class="_label-name">毛重:</view>
                </view>
                <view class="_content">
                  {{ item.value3 }}
                           {{ item.grossWeight }}
                </view>
              </view>
              <view class="row-list">
@@ -57,7 +58,7 @@
                  <view class="_label-name">盘重:</view>
                </view>
                <view class="_content">
                  {{ item.value4 }}
                           {{ item.trayWeight }}
                </view>
              </view>
              <view class="row-list">
@@ -75,7 +76,7 @@
                  <view class="_label-name">核磅重量:</view>
                </view>
                <view class="_content">
                  {{ item.value6 }}
                           {{ item.netWeight }}
                </view>
              </view>
              <view class="row-list">
@@ -90,22 +91,37 @@
            </view>
          </view>
        </u-cell-group>
        <view class="loadmore" @click="loadMore">
          <u-loadmore :status="loadStatus"></u-loadmore>
            <view class="loadmore" @click="getmoreList()">
               <u-loadmore :status="status" :load-text="loadText" @loadmore="getmoreList()" />
        </view>
      </scroll-view>
    </view>
    <u-toast ref="uToast" />
    <view v-if="maskShow" class="uni-mask" @touchmove.stop.prevent="moveHandle" @click="maskclose">
      <scroll-view class="uni-scroll_box" scroll-y @touchmove.stop.prevent="moveHandle" @click.stop="moveHandle">
        <view class="uni-list-box" v-for="(item, index) in listDevice" :key="index" @click="tapQuery(item)">
          <view>
            <view class="uni-list_name">名称:{{ item.name }}</view>
            <view class="uni-list_item">UUID:{{ item.address }}</view>
      <u-modal v-model="maskShow" title="" v-for="(item, index) in listDevice" :key="index"
         :show-confirm-button="true" @confirm="tapQuery(item)">
         <view class="packing-registration-param-view" @touchmove.stop.prevent="moveHandle" @click="maskclose">
            <scroll-view class="uni-scroll_box" scroll-y @touchmove.stop.prevent="moveHandle"
               @click.stop="moveHandle">
               <view class="packing-registration-param-item param-extra">
                  <view class="packing-registration-param-item-left">
                     <text class="item-one">名称:</text>
                  </view>
                  <view class="packing-registration-param-item-right">
                     <text class="item-one">{{ item.name }}</text>
                  </view>
               </view>
               <view class="packing-registration-param-item param-extra">
                  <view class="packing-registration-param-item-left">
                     <text class="item-one">UUID:</text>
                  </view>
                  <view class="packing-registration-param-item-right">
                     <text class="item-one">{{ item.address }}</text>
          </view>
        </view>
      </scroll-view>
    </view>
      </u-modal>
  </view>
</template>
<script>
@@ -141,47 +157,34 @@
        backgroundRepeat: 'no-repeat',
      },
      keywords: '',
      alllist: [],
      originList: [],
      query: {
        current: 1,
        size: 10
            list: [],
            total: 0,
            pageNum: 1,
            pageSize: 10,
            status: 'loading',
            loadText: {
               loadmore: "加载更多...",
               loading: "努力加载中...",
               nomore: "没有更多了",
      },
      list: [
        {
          value0: '123456789',
          value1: '123456789',
          value2: '123456789',
          value3: '123456789',
          value4: '123456789',
          value5: '123456789',
          value6: '123456789',
          value7: '123456789'
        },
        {
          value0: '123456789',
          value1: '123456789',
          value2: '123456789',
          value3: '123456789',
          value4: '123456789',
          value5: '123456789',
          value6: '123456789',
          value7: '123456789'
        }
      ],
      count: 0,
      loadStatus: 'loading',
      maskShow: false,
      listDevice: [], //蓝牙设备数据
      pritList: []
            pritList: [],
            printDensity: 3, // 默认打印浓度
            labelType: 1, // 默认标签类型 *
            // 1:间隙纸
            // 2:黑标纸
            // 3:连续纸
            // 4:定孔纸
            // 5:透明纸
            printMode: 2, // 默认打印模式
            //   1:热敏
            //    2:热转印
            connectedDevice: null // 已连接的打印机
    };
  },
  onLoad() {
    this.$u.api.finishProductIn.fetchList().then(res => {
      this.alllist = res.data
      this.originList = res.data
      this.loadList()
    })
         this.getlist()
    // 初始化SDK
    jcapi.initSDK()
    // 监听页码回调
@@ -190,59 +193,116 @@
    })
    // 监听错误回调
    jcapi.didReadPrintErrorInfo(function (r) {
         jcapi.didReadPrintErrorInfo((r) => {
      console.log(r)
      if (r.code == 23) {
        // 打印机断开连接
        _this.connectedDevice = null
      }
               this.connectedDevice = null
               uni.showToast({
                  icon: 'none',
                  title: '打印机连接已断开,请重新连接',
                  duration: 2 * 1000
               })
            } else {
      uni.showToast({
        icon: 'none',
        title: JSON.stringify(r),
        duration: 2 * 1000
      })
            }
    })
  },
  methods: {
    loadMore() {
      if (this.loadStatus == "nomore" || this.loadStatus == "loading") {
        return
         getmoreList() {
            if (this.pageSize >= this.total) {
               this.status = "nomore";
               return;
      }
      this.loadStatus = "loading";
            this.status = "loading";
      setTimeout(() => {
        this.query.current += 1;
        this.loadList();
      }, 100);
               this.pageSize += this.pageSize;
               this.getlist();
            }, 1000);
    },
    loadList() {
      const data = this.originList.slice((this.query.current - 1) * this.query.size, this.query.current * this.query.size)
      this.list = this.list.concat(data);
      this.loadStatus = "loadmore";
      if (!data || data.length < this.query.size) {
        this.loadStatus = "nomore";
         getlist() {
            this.$u.api.workReporting
               .getWorkshopOrder({
                  current: this.pageNum,
                  size: this.pageSize
               })
               .then((res) => {
                  this.list = res.data.records;
                  this.total = res.data.total;
                  if (this.pageSize >= this.total) {
                     this.status = "nomore";
                  } else {
                     this.status = "loadmore";
      }
               });
    },
    search(value) {
      this.list = [];
      this.query.current = 1;
      if (value) {
        this.originList = this.alllist.filter(item => item.locNo.includes(value))
               this.list = [];
               this.pageSize = 10;
               this.$u.api.workReporting
                  .getWorkshopOrder({
                     current: this.pageNum,
                     size: this.pageSize,
                     moNo: value,
                  })
                  .then((res) => {
                     this.list = res.data.records;
                     this.total = res.data.total;
                     if (this.pageSize >= this.total) {
                        this.status = "nomore";
      } else {
        this.originList = this.alllist
                        this.status = "loadmore";
      }
      this.loadList()
                  });
            } else {
               this.getlist();
            }
    },
    // 打印单个信息
         // 检查蓝牙连接状态
         async checkBluetoothConnection() {
            if (!this.connectedDevice) return false;
            // 尝试发送一个简单命令检查连接状态
            return new Promise(resolve => {
               jcapi.checkPrinterStatus(this.connectedDevice.address, r => {
                  if (r && r.code === 0) {
                     resolve(true);
                  } else {
                     // 连接已断开
                     this.connectedDevice = null;
                     resolve(false);
                  }
               });
            });
         },
    selectNo(item) {
      let that = this
      uni.showModal({
        title: '提示',
        content: '是否打印装箱单?',
        showCancel: true,
        success: function (res) {
               success: async function(res) {
          if (res.confirm) {
                     // 检查蓝牙连接状态
                     const isConnected = await that.checkBluetoothConnection();
                     if (isConnected) {
                        // 已连接,直接打印
                        that.pritList = [item]
                        that.pritList.forEach(async item => {
                           await that.printQrCode(item)
                        })
                     } else {
                        // 未连接或连接已断开,搜索设备
            that.searchDevice()
            that.pritList = [item]
                     }
          }
        }
      });
@@ -254,10 +314,21 @@
        title: '提示',
        content: '是否打印装箱单?',
        showCancel: true,
        success: function (res) {
               success: async function(res) {
          if (res.confirm) {
                     // 检查蓝牙连接状态
                     const isConnected = await that.checkBluetoothConnection();
                     if (isConnected) {
                        // 已连接,直接打印
                        that.pritList = that.list
                        that.pritList.forEach(async item => {
                           await that.printQrCode(item)
                        })
                     } else {
                        // 未连接或连接已断开,搜索设备
            that.searchDevice()
            that.pritList = this.list
                        that.pritList = that.list
                     }
          }
        }
      });
@@ -270,9 +341,11 @@
    },
    //打印二维码
    async printQrCode(item) {
            console.log('item de shuju ', item)
      const params = {
        rwMatlBindId: item.id
      }
            };
            try {
      let res = await this.$u.api.dailyPaper.zongjianLabelInfo(params)
      if (!res.data) {
        this.$refs.uToast.show({
@@ -281,72 +354,98 @@
        })
        return
      }
            // const res = {
            //    ht: 'HT20250717995352665',
            //    lj: '88.118.1/A0611091',
            //    ljms: '铜单线 裸铜-TY-圆形-3.0',
            //    fh: '1083.6',
            //    scdt: '2025-07-14 13:46:55.0',
            //    scph: '2025071273-3',
            //    fhdw: '江东合金技术有限公司',
            //    shdw: '昆山泰德通铜业有限公司',
            // }
            // 从API响应中提取所需数据
            const {
               ht,
               lj,
               ljms,
               fh,
               scdt,
               scph,
               fhdw,
               shdw
            } = res.data
            // const jsonString = JSON.stringify(res.data)
      // 初始化画板
      jcapi.initDrawingBoard({
        width: 50,
        height: 100,
        rotate: 0
               width: 70,
               height: 49,
               rotate: 90
      });
      // // 绘制二维码
            // 绘制二维码
            const qrContent =
               `ht:${ht}\nlj:${lj}\nljms:${ljms}\nfh:${fh}\nscdt:${scdt}\nscph:${scph}\nfhdw:${fhdw}\nshdw:${shdw}`;
      jcapi.drawLabelQrCode({
        x: 14.5,
        y: 74,
        width: 20,
        height: 20,
        value: jsonString,
               x: 43.5,
               y: 2,
               width: 24,
               height: 24,
               value: qrContent,
        rotate: 0,
        codeType: QrCodeType.QrCode,
      });
            // getDrawLabelLine   (x坐标,y坐标,线条宽度,线条高度,旋转角度,线条类型)
      // 绘制横线 实线8条
      let sum = 4;
      for (let i = 1; i < 13; i++) {
        this.getDrawLabelLine(4, sum, 46, 0.5, 0, LineType.Solid) // 实线
        sum = (i * 6) + 4
      }
      // 二维码大框
      this.getDrawLabelLine(4, 97, 46, 0.5, 0, LineType.Solid) // 实线9
            this.getDrawLabelLine(1, 1, 67, 0.5, 0, LineType.Solid)
            this.getDrawLabelLine(1, 6, 42, 0.3, 0, LineType.Solid)
            this.getDrawLabelLine(1, 11, 42, 0.3, 0, LineType.Solid)
            this.getDrawLabelLine(1, 16, 42, 0.3, 0, LineType.Solid)
            this.getDrawLabelLine(1, 21, 42, 0.3, 0, LineType.Solid)
            this.getDrawLabelLine(1, 27, 67, 0.3, 0, LineType.Solid)
            this.getDrawLabelLine(1, 32, 67,0.3, 0, LineType.Solid)
            this.getDrawLabelLine(1, 37, 67, 0.3, 0, LineType.Solid)
            this.getDrawLabelLine(1, 42, 67, 0.3, 0, LineType.Solid)
            this.getDrawLabelLine(1, 47, 67, 0.5, 0, LineType.Solid)
      //绘制竖线
      this.getDrawLabelLine(4, 4, 0.5, 97, 0, LineType.Solid) // 竖线1
      this.getDrawLabelLine(20, 4, 0.5, 66, 0, LineType.Solid) // 竖线2
      this.getDrawLabelLine(44.5, 4, 0.5, 97, 0, LineType.Solid) // 竖线2
            this.getDrawLabelLine(1, 1, 0.5, 46, 0, LineType.Solid) // 竖线1
            this.getDrawLabelLine(43, 1, 0.3, 26, 0, LineType.Solid) // 竖线2
            this.getDrawLabelLine(68, 1, 0.5, 46, 0, LineType.Solid) // 竖线2
            // getDrawLabelText   (1.x坐标,2.y坐标,3.文本框宽度,4.文本框高度,5.绘制文字内容,6.字体大小(默认高度4mm),7.旋转角度,8.换行方式,9.⾏间隔,10.字间隔,11.文字水平布局,12文字垂直布局)
            // 标题
            this.getDrawLabelText(3, 2.5, 40, 8, '中天科技装箱清单', 2.5, 0, LineModeType.AutoHeight, 0, 0, 1, 1,1)
      // 填冲文字标题
      this.getDrawLabelText(5, 5, 20, 20, '编 号:', 3.6, 0, LineModeType.AutoHeight, 0, 0, 0, 1)
      this.getDrawLabelText(5, 11, 20, 20, '工单号:', 3.6, 0, LineModeType.AutoHeight, 0, 0, 0, 1)
      this.getDrawLabelText(5, 17, 20, 20, '牌 号:', 3.6, 0, LineModeType.AutoHeight, 0, 0, 0, 1)
      this.getDrawLabelText(5, 23, 20, 20, '片宽(mm):', 3.6, 0, LineModeType.AutoHeight, 0, 0, 0, 1)
      this.getDrawLabelText(5, 29, 20, 20, '厚度(mm):', 3.6, 0, LineModeType.AutoHeight, 0, 0, 0, 1)
      this.getDrawLabelText(5, 35, 20, 20, '重量(KG):', 3.6, 0, LineModeType.AutoHeight, 0, 0, 0, 1)
      this.getDrawLabelText(5, 41, 20, 20, '长度(m):', 3.6, 0, LineModeType.AutoHeight, 0, 0, 0, 1)
      this.getDrawLabelText(5, 47, 20, 20, '生产人:', 3.6, 0, LineModeType.AutoHeight, 0, 0, 0, 1)
      this.getDrawLabelText(5, 53, 20, 20, '生产时间:', 3.4, 0, LineModeType.AutoHeight, 0, 0, 0, 1)
      this.getDrawLabelText(5, 59, 20, 20, '厂家:', 3.4, 0, LineModeType.AutoHeight, 0, 0, 0, 1)
      this.getDrawLabelText(5, 65, 20, 20, '铁损:', 3.4, 0, LineModeType.AutoHeight, 0, 0, 0, 1)
      // // 填冲参数值
      this.getDrawLabelText(22, 5, 35, 12, labelNo, 3, 0, LineModeType.AutoHeight, 0, 0, 0, 0)
      this.getDrawLabelText(22, 11, 35, 12, optaskNo, 3, 0, LineModeType.AutoHeight, 0, 0, 0, 0)
      this.getDrawLabelText(22, 17, 35, 12, grade, 3, 0, LineModeType.AutoHeight, 0, 0, 0, 0)
      this.getDrawLabelText(22, 23, 35, 12, sliceWidth, 3, 0, LineModeType.AutoHeight, 0, 0, 0, 0)
      this.getDrawLabelText(22, 29, 35, 12, thickness, 3, 0, LineModeType.AutoHeight, 0, 0, 0, 0)
      this.getDrawLabelText(22, 35, 35, 12, wweight, 3, 0, LineModeType.AutoHeight, 0, 0, 0, 0)
      this.getDrawLabelText(22, 41, 35, 12, llength, 3, 0, LineModeType.AutoHeight, 0, 0, 0, 0)
      this.getDrawLabelText(22, 47, 35, 12, reportName, 2, 0, LineModeType.AutoHeight, 0, 0, 0, 0)
      this.getDrawLabelText(22, 53, 35, 12, reportTime, 3, 0, LineModeType.AutoHeight, 0, 0, 0, 0)
      this.getDrawLabelText(22, 59, 35, 12, supplierVenderName, 3, 0, LineModeType.AutoHeight, 0, 0, 0, 0)
      this.getDrawLabelText(22, 65, 35, 12, ironLoss, 3, 0, LineModeType.AutoHeight, 0, 0, 0, 0)
            this.getDrawLabelText(2, 7, 25, 8, '合同号:', 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 1,1)
            this.getDrawLabelText(2, 12, 25, 8, '零件号:', 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 1,1)
            this.getDrawLabelText(2, 17, 25, 8, '零件描述:', 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 1,1)
            this.getDrawLabelText(2, 22.5, 25, 8, '发货/装箱数:', 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 1,1)
            this.getDrawLabelText(2, 27.5, 25, 8, '生产日期:', 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 1,1)
            this.getDrawLabelText(2, 32.5, 25, 8, '生产批号:', 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 1,1)
            this.getDrawLabelText(2, 37.5, 25, 8, '发货单位:', 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 1,1)
            this.getDrawLabelText(2, 42.5, 25, 8, '收货单位:', 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 1,1)
            // 填冲参数值
            this.getDrawLabelText(11, 7, 30, 8, ht, 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 0,1)
            this.getDrawLabelText(11, 12, 32, 8, lj, 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 0,1)
            this.getDrawLabelText(14, 17, 30, 8, ljms, 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 0,1)
            this.getDrawLabelText(17, 22.5, 27, 8, fh, 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 0,1)
            this.getDrawLabelText(14, 27.5, 55, 8, scdt, 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 0,1)
            this.getDrawLabelText(14, 32.5, 55, 8, scph, 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 0,1)
            this.getDrawLabelText(14, 37.5,55, 8, fhdw, 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 0,1)
            this.getDrawLabelText(14, 42.5, 55, 8, shdw, 2.5, 0, LineModeType.AutoHeight, 0, 0, 0, 0,1)
      // 生成打印数据
      let imageJsonObj = jcapi.generateLabelJson()
      // 设置打印任务
            let imageJsonObj111 = jcapi.generatePrintPreviewImage(imageJsonObj)
            console.log('预览', imageJsonObj111)
            // // 设置打印任务
      jcapi.startJob({
        totalCount: 1,
        density: this.printDensity,
        labelType: this.labelType,
        printMode: this.printMode,
      }, function (r) {
               console.log('打印', r)
        if (r.code == 0) {
          // 打印数据
          jcapi.printData(imageJsonObj, {
@@ -354,14 +453,24 @@
          }, function (r) {
            if (r.code == 0) {
              console.log("打印成功")
                        uni.showToast({
                           title: '打印成功',
                           icon: 'success'
                        })
            } else {
              console.log("打印失败")
                        uni.showToast({
                           title: '打印失败: ' + (r.msg || '未知错误'),
                           icon: 'none'
                        })
            }
          })
        } else {
          console.log("设置打印任务失败")
        }
      })
    },
    tapQuery(item) {
      this.maskShow = false
@@ -371,7 +480,7 @@
      jcapi.openPrinterByDevice({
        address: item.address,
        name: item.name,
        deviceType: item.deviceType // 设备类型:0-蓝牙,1-网络
               deviceType: 0 // 设备类型:0-蓝牙,1-网络
      }, function (r) {
        uni.showToast({
          title: (r.code == 0) ? "连接成功" : "连接失败",
@@ -379,8 +488,16 @@
        })
        if (r.code == 0) {
          _this.connectedDevice = item
                  // 添加打印列表空值检查
                  if (!_this.pritList || _this.pritList.length === 0) {
                     uni.showToast({
                        title: '没有可打印的数据',
                        icon: 'none'
                     })
                     return
                  }
          // 绘标签进行打印
          _this.pritList.forEac(async item => {
                  _this.pritList.forEach(async item => {
            await _this.printQrCode(item)
          })
        }
@@ -399,13 +516,24 @@
            console.log("device:" + JSON.stringify(r))
            // 搜索到设备回调
            uni.hideLoading()
                     // 如果之前有连接的设备但不在搜索结果中,说明设备已更换
                     if (_this.connectedDevice && !r.some(dev => dev.address === _this.connectedDevice.address)) {
                        _this.connectedDevice = null;
                        uni.showToast({
                           icon: 'none',
                           title: '已连接的蓝牙设备已更换,请重新选择',
                           duration: 2000
                        });
                     }
            _this.listDevice = r;
            _this.maskShow = true
          })
        },
        fail(e) {
          uni.showModal({
            confirmText: "打开蓝牙失败"
                     title: '提示',
                     content: '打开蓝牙失败,请检查蓝牙是否开启',
                     showCancel: false
          })
          console.log("开启蓝牙设备失败" + e)
        }
@@ -423,7 +551,9 @@
      });
    },
    // 填冲文字标题
    getDrawLabelText(x, y, width, height, value, fontSize, rotate, lineMode, lineSpace, letterSpace, textAlignHorizontal, textAlignVertical) {
         getDrawLabelText(x, y, width, height, value, fontSize, rotate, lineMode, lineSpace, letterSpace,
            textAlignHorizontal, textAlignVertical,bold) {
      jcapi.drawLabelText({
        x: x,
        y: y,
@@ -436,7 +566,8 @@
        lineSpace: lineSpace,
        letterSpace: letterSpace,
        textAlignHorizontal: textAlignHorizontal,
        textAlignVertical: textAlignVertical
               textAlignVertical: textAlignVertical,
               bold:bold
      })
    },