123321

<template>
  <px-dialog
    v-model="visible"
    title="添加备注信息"
    :close-on-click-modal="false"
    @close="onClose"
    width="60%"
    @closed="$emit('vanish')"
    class="dialog-head_gray"
  >
    <template #header>
      <div class="dialogHeaderDesc">打印</div>
    </template>
    <div style="display: flex; width: 100%">
      <div style="display: flex; width: 100%; flex-wrap: wrap">
        <div style="display: flex; margin-right: 16px; margin-bottom: 16px">
          <div style="line-height: 30px; height: 30px; width: 80px">打印机名称</div>
          <px-input v-model="formInline.name" placeholder="请输入" clearable style="width: 230px" />
        </div>
        <div style="display: flex; margin-right: 16px; margin-bottom: 16px">
          <div style="line-height: 30px; height: 30px; width: 80px">打印机编码</div>
          <px-input v-model="formInline.encode" placeholder="请输入" clearable style="width: 230px" />
        </div>
        <div style="display: flex; margin-right: 16px; margin-bottom: 16px">
          <div style="line-height: 30px; height: 30px; width: 80px">IP地址</div>
          <px-input v-model="formInline.ipAddress" placeholder="请输入" clearable style="width: 230px" />
        </div>
      </div>
      <div>
        <px-button type="primary" @click="getPrinters">查询</px-button>
      </div>
    </div>
    <px-table :data="tableData" style="width: 100%">
      <px-table-column prop="name" label="打印机名称" width="120" />
      <px-table-column prop="encode" label="打印机编码" width="120" />
      <px-table-column prop="statusDesc" label="状态" width="100" />
      <px-table-column prop="ipAddress" label="IP地址" width="140" />
      <px-table-column prop="printSize" label="打印尺寸" width="140">100*80</px-table-column>
      <px-table-column prop="dpi" label="DPI" width="80" />
      <px-table-column prop="location" label="位置" min-width="160" />
      <px-table-column fixed="right" label="操作" width="120">
        <template #default="{ row }">
          <px-radio-group v-model="selectedPrinterId">
            <px-radio :label="row?.id" size="large">{{ row?.printName }}</px-radio>
          </px-radio-group>
        </template>
      </px-table-column>
    </px-table>
    <template #footer>
      <span class="dialog-footer">
        <px-button type="primary" plain @click="onCancle">取消</px-button>
        <px-button type="primary" @click="onOk">确定</px-button>
      </span>
    </template>
  </px-dialog>
</template>

<script setup lang="ts">
import { PxDialog, PxInput, PxButton, PxTable, PxTableColumn, PxRadioGroup, PxRadio, PxMessage } from 'px-ui'

import { GetPrintList } from '@/api/modules/print'
import { PrintData } from '@/api/modules/common'
import { cleanAndRepairCount } from '@/utils'
import { TAG_NAME } from '@/components/MaterialDetail/components/materialTag/index.data'
import { ConntrolTypeDescriptions, RepairTypesBriefDescriptions } from '@/enums/commonEnum'

interface Props {
  resolve?: (e: string) => void
  reject?: () => void
  data: any[]
  templateId?: string
}

const props = defineProps<Props>()
defineEmits(['vanish'])
const visible = ref(true)

const formInline = ref<any>({
  name: '',
  encode: '',
  ipAddress: ''
})
const selectedPrinterId = shallowRef()

//打印机table数据
const tableData = ref<any[]>([])
async function getPrinters() {
  try {
    const res = await GetPrintList(
      {
        status: 1,
        ...formInline.value
      },
      { pageNo: 1, pageSize: 1000 }
    )
    console.log('sys: 获取的打印机列表=', res)
    tableData.value = res?.data?.records
  } catch (error) {
    console.error('sys: 打印机列表获取错误=', error)
  }
}
getPrinters()

const onClose = () => {
  selectedPrinterId.value = ''
}

const onOk = async () => {
  if (!selectedPrinterId.value) {
    return PxMessage.error('请先选择一个打印机')
  }
  const params = props.data.map((item) => ({
    ...item,
    id: item.id || item.assemblePartsId,
    materialName: item.materialName || item.assemblePartsName,
    fabSN: item.fabBatchNo || item.fabSerialNo,
    notifyMark: item.materialStatusDesc || RepairTypesBriefDescriptions[item.repairType],
    fabPartNo: item.outCleanMaterialNo ? item.outCleanMaterialNo : item.tenMaterialNo || item.materialNo, // 兼容外洗料号
    oderNo: item.outCleanMaterialNo ? item.docId : item.grOrderNo ? item.grOrderNo : item.oaOrderNo, // 兼容外洗送洗单号
    vendorSN: item.vendorSerialNo,
    vendorMaterialNo: item.vendorMaterialNumber,
    cleanOrRepairCount: cleanAndRepairCount(item),
    controlType: item.controlTypeDesc || ConntrolTypeDescriptions[item.controlType],
    tagName: TAG_NAME + (item.transportInBulk === true ? ' K' : ''),
    taxFree:
      item.taxFree == null || item.taxFree === ''
        ? ''
        : item.taxFree == '0'
          ? '免税'
          : item.taxFree == '1'
            ? '非免'
            : '',
    qty: item.qty ?? 1,
    printerIP: tableData.value.find((item: any) => item.id === selectedPrinterId.value)?.ipAddress,
    templateId: props.templateId || 'materialBigLabel'
  }))
  params.forEach((item) => {
    for (const key in item) {
      if (Object.prototype.hasOwnProperty.call(item, key)) {
        item[key] ??= ''
      }
    }
  })
  try {
    await PrintData(params)
    PxMessage.success('打印成功')
    visible.value = false
    props.resolve?.(selectedPrinterId.value)
  } catch (error) {
    console.error('sys: 打印错误=', error)
  }
}

const onCancle = () => {
  visible.value = false
  props.reject?.()
}
</script>
posted @ 2026-01-23 15:57  西口  阅读(8)  评论(2)    收藏  举报