chenhaozhe
2025-08-12 5070a2136a290d2de489cdb7b4d2ae7bc094a91e
pages/caigoudingdan/generate.vue
@@ -39,21 +39,24 @@
         </view>
         <view class="form-item">
            <view class="title">每箱数量:</view>
            <view class="right">
               <input v-model="baseInfo.HMinQty" type="number" placeholder="请输入数量" @confirm="getNum()"
            <view class="righton">
               <input disabled v-model="baseInfo.HMinQty" type="number" placeholder="请输入数量" @confirm="getNum()"
                  @blur="getNum()" />
            </view>
         </view>
         <view class="buttons">
            <button class="btn-b" size="mini" type="default" @tap="getList()">条码生成</button>
            <button class="btn-c" size="mini" type="default" @tap="search">打印</button>
            <button class="btn-c" :disabled="codeGenComplete == false" size="mini" type="default"
               @tap="search">打印</button>
            <!-- <button class="btn-c" size="mini" type="default"
                  @tap="exit">退出</button> -->
         </view>
      </view>
      <view style="width: 100%;height: 16rpx;background-color: #e5e5e5;"></view>
      <view class="list" v-for="(item,index) in listData" :key="index" @tap="toSon(item)">
         <uni-card :title="item.物料代码" :extra="'No. ' + Number(index+1)" style="margin: 10px;">
      <view class="list" v-for="(item,index) in listData" :key="item['行号']">
         <uni-card :title="item.物料代码" :extra="'行号. ' + item['行号']" style="margin: 10px;">
            <view class="card-detail">
               <view class="detail">
                  <text>物料名称:</text>{{item.物料名称}}
@@ -70,11 +73,14 @@
            </view>
         </uni-card>
      </view>
      <labelPrinterComponentVue ref="labelPrinter" :printInfo="printInfo" :printMode="'cpcl'">
      </labelPrinterComponentVue>
      <view class="over" v-if="listData.length == 0">暂无数据</view>
      <view class="over" v-if="listData.length != 0">已到底</view>
      <view>
         <labelPrinterComponentVue ref="labelPrinter" :printInfo="printInfo" :printMode="'cpcl'">
         </labelPrinterComponentVue>
      </view>
   </view>
</template>
@@ -85,9 +91,15 @@
   import {
      CommonUtils
   } from "../../utils/common";
   import {
      nextTick
   } from "vue";
   import labelPrinterComponentVue from "@/components/labelPrinterComponent/labelPrinterComponent.vue"
   export default {
      data() {
         return {
            billNo: '',
            lineNo: 0,
            printInfo: "",
            userInfo: getUserInfo(),
            serverUrl: uni.getStorageSync('serverUrl') || 'http://47.96.97.237/API',
@@ -95,38 +107,59 @@
            linterid: '',
            HEntryID: '',
            hmaterid: '',
            codeGenComplete: false,
            baseInfo: {
               HBillNo: '',
               HMainID: '',
               HSubID: '',
               HOrderBillNo: '',
               HMaterID: '',
               // barCodeNo: '',
               HBillNo: '',
               HBillLineNo: '',
               HMaterNumber: '',
               HMaterName: '',
               HMaterModel: '',
               HQty: '',
               HPcsName: '',
               HBatchNo: '',
               HQty: 0,
               HMTONo: '',
               HQty: '',
               HMinQty: '',
               HBQty: '',
               HSupName: '',
               HSupNameShort: '',
               HMinQty: 0,
               HBQty: 0,
               HSupID: '',
               HUnitID: '',
               HDate: '',
               HSourceBillNo: '',
               HMaker: getUserInfo()["Czymc"],
               HSupNumber: '',
               HCoilNO: '',
               HFurnaceNO: '',
               HFactory: '',
            },
            sWhere: '',
            listData: [],
         }
      },
      components: {
         labelPrinterComponentVue
      },
      onLoad(e) {
         console.log(e)
         console.log("页面传递参数: ", e)
         this.OperationType = e.OperationType
         this.linterid = e.linterid
         this.hmaterid = e.hmaterid
         this.billNo = e.billNo
         this.baseInfo.HBillNo = e.billNo
         this.baseInfo.HBillLineNo = e.lineNo
         this.lineNo = e.lineNo
         this.getData()
      },
      methods: {
         getData() {
            CommonUtils.doRequest(
               "/Cg_POOrderBill/list", {
                  sWhere: ` and hmainid = ${this.linterid} and HMaterID  = ${this.hmaterid}`
                  ,user: this.userInfo.Czymc
                  sWhere: ` and 单据号 = '${this.billNo}' and 行号 = ${this.lineNo}`,
                  user: this.userInfo.Czymc,
               },
               (res) => {
                  console.log('采购订单: ', res)
@@ -135,17 +168,32 @@
                     count
                  } = res.data
                  if (count > 0) {
                     this.baseInfo = {
                        HMainID: data[0]['hmainid'],
                        HSubID: data[0]['HEntryID'],
                        HBillNo: data[0]['单据号'],
                        HMaterID: data[0]['HMaterID'],
                        HMaterNumber: data[0]['物料代码'],
                        HMaterName: data[0]['物料名称'],
                        HMaterModel: data[0]['规格型号'],
                        HQty: data[0]['数量'],
                        HMTONo: data[0]['计划跟踪号']
                     }
                     let d = data[0]
                     this.baseInfo = Object.assign(this.baseInfo, {
                        HMaterNumber: d['物料编码'],
                        HMaterName: d['物料名称'],
                        HMaterModel: d['规格型号'],
                        // HBatchNo: d['批号'],
                        HQty: d['数量'],
                        HMinQty: d['数量'],
                        HBQty: d['数量'],
                        HSupID: d['HSupID'],
                        HSupNumber: d['供应商代码'],
                        HSupName: d['供应商'],
                        HUnitID: d['HUnitID'],
                        HPcsName: d['计量单位'],
                        HSupNameShort: d['供应商'],
                        HMTONo: d['计划跟踪号'].trim(),
                        HMainID: d['hmainid'],
                        HSubID: d['HEntryID'],
                        HMaterID: d['HMaterID'],
                        HDate: d['日期'],
                        HCoilNO: d['款号'],
                        HFurnaceNO: d['分组'],
                        HFactory: d['客户编号']
                     })
                     console.log(this.baseInfo)
                     // CommonUtils.playSound(1)
                     this.listData = data
                  } else {
                     uni.showToast({
@@ -169,157 +217,75 @@
            }
         },
         async search() {
            // #ifndef APP-PLUS
            uni.showModal({
               content: "不支持蓝牙打印功能,请切换手机...",
            })
            return
            // #endif
            if (this.$printer.isConnected() === false) {
               this.$refs.labelPrinter.openPopup()
            } else {
               // this.printInfo = async () => {
               //    let cpcl = await this.$printer.cpcl().clear()
               //       .page(new CPage({
               //          width: 608,
               //          height: 400
               //       }))
               //       .qrcode(new CQRCode({
               //          x: 500,
               //          y: 30,
               //          width: 3,
               //          content: this.generatedBarCode,
               //          codeRotation: CCodeRotation.ROTATION_0,
               //          level: CCorrectLevel.L
               //       }))
               //       .text(new CText({
               //          x: 30,
               //          y: 30,
               //          content: "供应商: ",
               //          font: CFont.TSS24
               //       }))
               //       .text(new CText({
               //          x: 30,
               //          y: 80,
               //          content: "供应商料号: ",
               //          font: CFont.TSS24
               //       }))
               //       .text(new CText({
               //          x: 30,
               //          y: 130,
               //          content: "物料编码: ",
               //          font: CFont.TSS24
               //       }))
               //       .text(new CText({
               //          x: 30,
               //          y: 180,
               //          content: "物料分组: ",
               //          font: CFont.TSS24
               //       }))
               //       .text(new CText({
               //          x: 300,
               //          y: 180,
               //          content: "规格型号: ",
               //          font: CFont.TSS24
               //       }))
               //       .text(new CText({
               //          x: 30,
               //          y: 230,
               //          content: "数量: ",
               //          font: CFont.TSS24
               //       }))
               //       .text(new CText({
               //          x: 300,
               //          y: 230,
               //          content: "日期: ",
               //          font: CFont.TSS24
               //       }))
               //       .text(new CText({
               //          x: 30,
               //          y: 280,
               //          content: "检验员: ",
               //          font: CFont.TSS24
               //       }))
               //       .text(new CText({
               //          x: 300,
               //          y: 280,
               //          content: "计划跟踪号: ",
               //          font: CFont.TSS24
               //       }))
               //       .text(new CText({
               //          x: 30,
               //          y: 330,
               //          content: "检验结果: ",
               //          font: CFont.TSS24
               //       }))
               //       .box(new CBox({
               //          topLeftX: 260,
               //          topLeftY: 320,
               //          bottomRightX: 280,
               //          bottomRightY: 340,
               //          lineWidth: 4,
               //       }))
               //       .text(new CText({
               //          x: 290,
               //          y: 320,
               //          content: "合格",
               //          font: CFont.TSS24
               //       }))
               //       .box(new CBox({
               //          topLeftX: 360,
               //          topLeftY: 320,
               //          bottomRightX: 380,
               //          bottomRightY: 340,
               //          lineWidth: 4,
               //       }))
               //       .text(new CText({
               //          x: 390,
               //          y: 320,
               //          content: "不合格",
               //          font: CFont.TSS24
               //       }))
               //       .box(new CBox({
               //          topLeftX: 480,
               //          topLeftY: 320,
               //          bottomRightX: 500,
               //          bottomRightY: 340,
               //          lineWidth: 4,
               //       }))
               //       .text(new CText({
               //          x: 510,
               //          y: 320,
               //          content: "特采",
               //          font: CFont.TSS24
               //       }))
               //       .form(new CForm())
               //       .print();
               //    console.log(cpcl.command().string())
               //    return cpcl.command().binary()
               // }
               // await this.$nextTick(() => {
               //    this.$refs.labelPrinter.execPrint()
               // })
               let printContent = []
               let printInfoBuffer = []
               let count = 0
               for (let listOne of this.listData) {
                  let HBarCodeNoStr =
                     `${this.baseInfo.HBillNo}@${this.baseInfo.HBillLineNo}@${this.baseInfo.HMaterNumber || ''}@${this.baseInfo.HMTONo || ''}@${this.baseInfo.HQty || 0}@${this.baseInfo.HSupNumber  || ''}`
                  let pcsInfo = this.baseInfo.HPcsName ? '(' + this.baseInfo.HPcsName + ')' : ''
               this.printInfo = `! 0 200 200 400 1
                  printContent.push(`! 0 200 200 400 1
PAGE-WIDTH 608
SETQRVER 3
B QR 500 30 M 2 U 3
LA,${this.generatedBarCode}
B QR 475 15 Q 0 U 3
LA,${HBarCodeNoStr}
ENDQR
T 24 0 30 30 供应商:
T 24 0 30 80 供应商料号:
T 24 0 30 130 物料编码:
T 24 0 30 180 物料分组:
T 24 0 300 180 规格型号:
T 24 0 30 230 数量:
T 24 0 300 230 日期:
T 24 0 30 280 检验员:
T 24 0 300 280 计划跟踪号:
T 24 0 30 330 检验结果:
BOX 260 330 280 350 4
T 24 0 290 330 合格
BOX 360 330 380 350 4
T 24 0 390 330 不合格
BOX 480 330 500 350 4
T 24 0 510 330 特采
T 24 0 0 30 供应商: ${this.baseInfo.HSupName}
T 55 0 0 55 (Supplier)
T 24 0 0 75 供应商料号:  ${this.baseInfo.HMaterNumber}
T 55 0 0 100 (Supplier Sku No.)
T 24 0 0 120 物料名称: ${this.baseInfo.HMaterName}
T 55 0 0 145 (Material Code)
T 24 0 0 165 款号: ${this.baseInfo.HCoilNO}
T 55 0 0 190 (Style No.)
T 24 0 300 165 客户编号: ${this.baseInfo.HFactory}
T 55 0 300 190 (Consumer No.)
T 24 0 0 210 分组: ${this.baseInfo.HFurnaceNO || ''}
T 55 0 0 235 (Group)
T 24 0 300 210 规格: ${this.baseInfo.HMaterModel}
T 55 0 300 235 (SKU NO.)
T 24 0 0 255 数量:  ${ parseFloat(this.baseInfo.HQty || 0).toFixed(0) } ${pcsInfo}
T 55 0 0 280 (Quantity)
T 24 0 300 255 日期: ${this.baseInfo.HDate || ''}
T 55 0 300 280 (Date)
T 24 0 0 300 检验员:
T 55 0 0 325 (QC)
T 24 0 300 300 采购单号: ${this.baseInfo.HBillNo || ''}
T 55 0 300 325 (Purchase Order No.)
T 24 0 0 345 检验结果:
T 55 0 0 370 (Inspection status)
BOX 240 345 260 365 4
T 24 0 270 345 合格
T 55 0 250 370 (Pass)
BOX 340 345 360 365 4
T 24 0 370 345 不合格
T 55 0 370 370 (Fail)
BOX 460 345 480 365 4
T 24 0 490 345 特采
T 55 0 440 370 (Spec. accepted)
FORM
PRINT`
PRINT`)
                  count++;
                  if (count == 10) {
                     printInfoBuffer.push(printContent.join("\r\n"))
                     count = 0
                     printContent = []
                  }
               }
               printInfoBuffer.push(printContent.join("\r\n"))
               this.printInfo = JSON.stringify(printInfoBuffer)
               printInfoBuffer = []
               await this.$nextTick(() => {
                  this.$refs.labelPrinter.execPrint()
@@ -327,6 +293,8 @@
            }
         },
         getList() {
            let HBarCodeNoStr =
               `${this.baseInfo.HBillNo}@${this.baseInfo.HBillLineNo}@${this.baseInfo.HMaterNumber || ''}@${this.baseInfo.HMTONo || ''}@${this.baseInfo.HQty || 0}@${this.baseInfo.HSupNumber  || ''}`
            var sMain = []
            sMain[0] = this.baseInfo
            var sMainStr = JSON.stringify(sMain);
@@ -335,38 +303,65 @@
            //获取选择的工厂代码
            var CampanyName = "xxx";
            //获取选择的源单类型
            var HSourceBillType = "收料通知单";
            var HSourceBillType = "采购订单";
            //获取选择的条码类型
            var HSelectBarCodeType = "唯一条码";
            var HSelectBarCodeType = "品种条码";
            //获取当前登录人员
            var UserName = uni.getStorageSync('HUserName');
            var sMainSub = sMainStr + ';' + HOrgType + ';' + HSourceBillType + ';' + HSelectBarCodeType + ';' +
               CampanyName + ';' + UserName;
            uni.request({
               url: this.serverUrl + '/Sc_BarCode/Sub_SaveBill',
               method: 'POST',
               data: {
            let sMainSub = sMainStr + ';' + HOrgType + ';' + HSourceBillType + ';' + HSelectBarCodeType + ';' +
               CampanyName + ';' + UserName + ';' + HBarCodeNoStr +
               ';' + this.baseInfo.HFactory + ';' + this.baseInfo.HCoilNO +
               ';' + this.baseInfo.HFurnaceNO  + '';
            CommonUtils.doRequest(
               "/Sc_BarCode/SaveBarCode_NoGenerate", {
                  msg: sMainSub,
                  CampanyName: CampanyName
               },
               success: (res) => {
                  if (res.data.count == 1) {
                     this.listData = res.data.data
                  } else {
               (res) => {
                  console.log(res)
                  let {
                     data,
                     count,
                     Message
                  } = res.data
                  if (count > 0) {
                     // this.generatedBarCode = data[0]['条码编号']/
                     // console.log(this.generatedBarCode)
                     uni.showToast({
                        title: res.data.Message,
                        icon: 'none'
                        icon: 'none',
                        title: Message
                     })
                     this.codeGenComplete = true
                     this.buttonStatus = {
                        btn1: true,
                        btn2: false
                     }
                     for (let listOne of this.listData) {
                        listOne['条码编号'] = HBarCodeNoStr
                     }
                  } else {
                     this.buttonStatus = {
                        btn1: false,
                        btn2: false
                     }
                     uni.showToast({
                        icon: 'none',
                        title: Message
                     })
                  }
               },
               fail: (res) => {
                  console.log(res);
               (err) => {
                  this.buttonStatus = {
                     btn1: false,
                     btn2: false
                  }
                  uni.showToast({
                     title: '接口请求失败',
                     icon: 'none'
                     icon: 'none',
                     title: err
                  })
               },
            });
               "POST"
            )
         }
      }
   }
@@ -394,20 +389,20 @@
      }
      .right {
         width: 450rpx;
         flex: 1;
         border-radius: 22rpx;
         border: 1px solid #acacac;
      }
      .righton {
         width: 450rpx;
         flex: 1;
         border-radius: 22rpx;
         border: 1px solid #e4e4e4;
         background-color: #e4e4e4;
      }
      input {
         width: 100%;
         width: inherit;
         padding: 8rpx 20rpx;
         font-size: 30rpx;
      }
@@ -425,6 +420,11 @@
         height: 66rpx;
         line-height: 66rpx;
         font-size: 28rpx;
      }
      button[disabled] {
         background-color: #acacac;
         color: #fff;
      }
      .btn-a {
@@ -445,6 +445,7 @@
   .list {
      width: 100%;
      word-break: break-all;
      .card-detail {
         width: 100%;