Jelajahi Sumber

末班套打优化

unknown 1 bulan lalu
induk
melakukan
2285ae41eb

+ 1 - 1
fastadmin/application/api/controller/ps/Workorder.php

@@ -36,7 +36,7 @@ class Workorder extends Api
     {
         $limit = $this->request->request('limit/d', 10);
         $keyword = $this->request->request('keyword', '', 'trim');
-        $query = $this->model->order('id desc');
+        $query = $this->model->with(['product'])->order('id desc');
         if ($keyword !== '') {
             $query->where('no|batch_no|customer|product_name', 'like', '%' . $keyword . '%');
         }

+ 63 - 31
vue/src/components/PrintDialog.vue

@@ -52,7 +52,7 @@
           </el-form-item>
 
           <el-form-item label="名称">
-            <el-input v-model="form.name" :placeholder="form.biz_type === 'product' ? '产品名称' : '产品 / 工单名称'" />
+            <el-input v-model="form.name" :placeholder="form.biz_type === 'product' ? '产品名称' : '工单名称'" />
           </el-form-item>
 
           <el-form-item label="总数量">
@@ -169,7 +169,10 @@ const props = defineProps({
   bizType: { type: String, default: '' },
   bizId: { type: [Number, String], default: '' },
   templateId: { type: [Number, String], default: '' },
+  no: { type: String, default: '' },
+  name: { type: String, default: '' },
 })
+const syncing = ref(false)
 const emit = defineEmits(['update:modelValue', 'done'])
 
 const templates = ref([])
@@ -220,9 +223,18 @@ function optionValue(item) {
   return item.code || item.name || ''
 }
 
+function pickName(row, fallback = '') {
+  if (!row) {
+    return String(fallback || '').trim()
+  }
+  return String(
+    row.product_name || (row.product && row.product.name) || row.name || fallback || ''
+  ).trim()
+}
+
 function optionLabel(item) {
   if (form.biz_type === 'workorder') {
-    const name = item.product_name || (item.product && item.product.name) || ''
+    const name = pickName(item)
     return name ? (item.no + ' / ' + name) : (item.no || '')
   }
   return (item.code || '无编号') + ' / ' + (item.name || '')
@@ -328,6 +340,9 @@ function onBizTypeChange() {
 }
 
 async function onNoChange(val) {
+  if (syncing.value || lockBiz.value) {
+    return
+  }
   preview.value = null
   const key = String(val || '').trim()
   if (!key) {
@@ -350,23 +365,28 @@ async function loadBizDetail(id) {
   if (!id) {
     return
   }
-  if (form.biz_type === 'workorder') {
-    const row = await workorderInfo(id)
-    form.biz_id = row.id
-    form.no = row.no || ''
-    form.name = row.product_name || (row.product && row.product.name) || form.name || ''
-    const procs = row.processes && row.processes.length
-      ? row.processes
-      : ((row.product && row.product.processes) || [])
-    applySavedProcesses(procs)
-  } else {
-    const row = await productInfo(id)
-    form.biz_id = row.id
-    form.no = row.code || ''
-    form.name = row.name || ''
-    applySavedProcesses(row.processes || [])
-  }
-  syncPlateRange()
+  syncing.value = true
+  try {
+    if (form.biz_type === 'workorder') {
+      const row = await workorderInfo(id)
+      form.biz_id = row.id
+      form.no = row.no || form.no || ''
+      form.name = pickName(row, form.name)
+      const procs = row.processes && row.processes.length
+        ? row.processes
+        : ((row.product && row.product.processes) || [])
+      applySavedProcesses(procs)
+    } else {
+      const row = await productInfo(id)
+      form.biz_id = row.id
+      form.no = row.code || form.no || ''
+      form.name = pickName(row, form.name)
+      applySavedProcesses(row.processes || [])
+    }
+    syncPlateRange()
+  } finally {
+    syncing.value = false
+  }
 }
 
 function selectedProcesses() {
@@ -461,26 +481,38 @@ watch(
     savedProcesses.value = []
     checkedProcessKeys.value = []
     draftProcesses.value = []
+    syncing.value = true
     form.template_id = Number(props.templateId || 0) || ''
     form.biz_type = props.bizType || 'workorder'
     form.biz_id = Number(props.bizId || 0) || ''
-    form.no = ''
-    form.name = ''
+    form.no = String(props.no || '').trim()
+    form.name = String(props.name || '').trim()
     form.sheet_qty = ''
     form.qty = ''
     form.sheet_from = 1
     form.sheet_to = 1
     form.copies = 1
-    const [t, w, p] = await Promise.all([
-      templateList({ printable: 1, limit: 100 }),
-      workorderList({ limit: 100 }),
-      productList({ limit: 100 }),
-    ])
-    templates.value = t.rows || []
-    workorders.value = w.rows || []
-    products.value = p.rows || []
-    if (form.biz_id) {
-      await loadBizDetail(form.biz_id)
+    try {
+      const [t, w, p] = await Promise.all([
+        templateList({ printable: 1, limit: 100 }),
+        workorderList({ limit: 100 }),
+        productList({ limit: 100 }),
+      ])
+      templates.value = t.rows || []
+      workorders.value = w.rows || []
+      products.value = p.rows || []
+      if (form.biz_id) {
+        const listed = (form.biz_type === 'product' ? products.value : workorders.value).find(
+          (item) => Number(item.id) === Number(form.biz_id)
+        )
+        if (listed) {
+          form.no = form.no || (form.biz_type === 'product' ? listed.code : listed.no) || ''
+          form.name = form.name || pickName(listed)
+        }
+        await loadBizDetail(form.biz_id)
+      }
+    } finally {
+      syncing.value = false
     }
   }
 )

+ 2 - 0
vue/src/components/PrintHost.vue

@@ -9,5 +9,7 @@ import { printState } from "@/utils/print";
     :biz-type="printState.bizType"
     :biz-id="printState.bizId"
     :template-id="printState.templateId"
+    :no="printState.no"
+    :name="printState.name"
   />
 </template>

+ 7 - 1
vue/src/utils/print.ts

@@ -4,7 +4,9 @@ export const printState = reactive({
   visible: false,
   bizType: "workorder" as string,
   bizId: "" as number | string,
-  templateId: "" as number | string
+  templateId: "" as number | string,
+  no: "" as string,
+  name: "" as string
 });
 
 export function openPrint(
@@ -12,11 +14,15 @@ export function openPrint(
     bizType?: string;
     bizId?: number | string;
     templateId?: number | string;
+    no?: string;
+    name?: string;
   } = {}
 ) {
   printState.bizType = opts.bizType || "workorder";
   printState.bizId = opts.bizId || "";
   printState.templateId = opts.templateId || "";
+  printState.no = opts.no || "";
+  printState.name = opts.name || "";
   printState.visible = true;
 }
 

+ 1 - 1
vue/src/views/product/Edit.vue

@@ -11,7 +11,7 @@
       </el-form-item>
       <el-form-item>
         <el-button type="primary" :loading="saving" @click="onSave">保存</el-button>
-        <el-button v-if="form.id" type="success" @click="openPrint({ bizType: 'product', bizId: form.id })">套打</el-button>
+        <el-button v-if="form.id" type="success" @click="openPrint({ bizType: 'product', bizId: form.id, no: form.code, name: form.name })">套打</el-button>
         <el-button v-if="form.id" type="danger" plain @click="onDel">删除</el-button>
         <el-button @click="$router.push('/products')">返回</el-button>
       </el-form-item>

+ 1 - 1
vue/src/views/product/List.vue

@@ -14,7 +14,7 @@
       <el-table-column prop="unit" label="单位" width="80" />
       <el-table-column label="操作" width="260">
         <template #default="{ row }">
-          <el-button text type="success" @click="openPrint({ bizType: 'product', bizId: row.id })">套打</el-button>
+          <el-button text type="success" @click="openPrint({ bizType: 'product', bizId: row.id, no: row.code, name: row.name })">套打</el-button>
           <el-button text type="primary" @click="$router.push('/products/edit/' + row.id)">编辑</el-button>
           <el-button text type="danger" @click="onDel(row)">删除</el-button>
         </template>

+ 1 - 1
vue/src/views/workorder/Edit.vue

@@ -26,7 +26,7 @@
       </el-form-item>
       <el-form-item>
         <el-button type="primary" :loading="saving" @click="onSave">保存</el-button>
-        <el-button v-if="form.id" type="success" @click="openPrint({ bizType: 'workorder', bizId: form.id })">套打</el-button>
+        <el-button v-if="form.id" type="success" @click="openPrint({ bizType: 'workorder', bizId: form.id, no: form.no, name: form.product_name })">套打</el-button>
         <el-button v-if="form.id" type="danger" plain @click="onDel">删除</el-button>
         <el-button @click="$router.push('/workorders')">返回</el-button>
       </el-form-item>

+ 1 - 1
vue/src/views/workorder/List.vue

@@ -18,7 +18,7 @@
       <el-table-column prop="status" label="状态" width="100" />
       <el-table-column label="操作" width="260">
         <template #default="{ row }">
-          <el-button text type="success" @click="openPrint({ bizType: 'workorder', bizId: row.id })">套打</el-button>
+          <el-button text type="success" @click="openPrint({ bizType: 'workorder', bizId: row.id, no: row.no, name: row.product_name })">套打</el-button>
           <el-button text type="primary" @click="$router.push('/workorders/edit/' + row.id)">编辑</el-button>
           <el-button text type="danger" @click="onDel(row)">删除</el-button>
         </template>