From 78caa769e452f63288743b8997f7b4c21bb06ce5 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期五, 06 十一月 2026 19:00:38 +0800
Subject: [PATCH] feat(crm,mes): 扩展客户字段与重构批次号生成逻辑

---
 src/views/wls/productsales/modules/picking-bags.vue |  199 +++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 166 insertions(+), 33 deletions(-)

diff --git a/src/views/wls/productsales/modules/picking-bags.vue b/src/views/wls/productsales/modules/picking-bags.vue
index 3bc2de1..5c93b5f 100644
--- a/src/views/wls/productsales/modules/picking-bags.vue
+++ b/src/views/wls/productsales/modules/picking-bags.vue
@@ -1,50 +1,183 @@
 <script setup lang="ts">
-import { computed, ref, watch } from 'vue';
 import type { MesWmProductSalesApi } from '#/api/mes/wm/productsales';
 
-const props = defineProps<{ bags: MesWmProductSalesApi.PickingBag[]; modelValue: number[]; disabled?: boolean }>();
+import { computed, ref, watch } from 'vue';
+
+defineOptions({ name: 'PickingBags' });
+
+const props = withDefaults(
+  defineProps<{
+    bags: MesWmProductSalesApi.PickingBag[];
+    modelValue: number[];
+    disabled?: boolean;
+  }>(),
+  { disabled: false },
+);
 const emit = defineEmits<{ 'update:modelValue': [ids: number[]] }>();
-const search = ref(''), desired = ref<number>(), limit = ref(50), selectionError = ref('');
-const eligible = computed(() => props.bags.filter(b => b.selectable));
-const filtered = computed(() => props.bags.filter(b => !search.value || b.code.includes(search.value.trim()) || b.businessCode?.includes(search.value.trim())));
-watch(search, () => { limit.value = 50; });
-watch(() => props.modelValue, ids => { desired.value = ids.length || undefined; });
-function choose(bag: MesWmProductSalesApi.PickingBag, checked: boolean) {
-  selectionError.value = '';
-  emit('update:modelValue', checked ? [...props.modelValue, bag.id] : props.modelValue.filter(id => id !== bag.id));
-}
+
+const search = ref('');
+const desired = ref<number>();
+const selectionError = ref('');
+const VISIBLE_SELECTED = 8;
+
+const eligible = computed(() => props.bags.filter((bag) => bag.selectable));
+const unavailableCount = computed(() => props.bags.length - eligible.value.length);
+const filtered = computed(() => {
+  const keyword = search.value.trim();
+  if (!keyword) {
+    return props.bags;
+  }
+  return props.bags.filter(
+    (bag) =>
+      bag.code.includes(keyword) ||
+      (bag.businessCode ?? '').includes(keyword) ||
+      (bag.unavailableReason ?? '').includes(keyword),
+  );
+});
+const selectedBags = computed(() => {
+  const selected = new Set(props.modelValue);
+  return props.bags.filter((bag) => selected.has(bag.id));
+});
+const visibleSelected = computed(() => selectedBags.value.slice(0, VISIBLE_SELECTED));
+
+watch(
+  () => props.modelValue,
+  (ids) => {
+    desired.value = ids.length || undefined;
+  },
+  { immediate: true },
+);
+
+const rowSelection = computed(() => ({
+  selectedRowKeys: props.modelValue,
+  onChange: (keys: (number | string)[]) => {
+    selectionError.value = '';
+    emit('update:modelValue', keys.map(Number));
+  },
+  getCheckboxProps: (record: MesWmProductSalesApi.PickingBag) => ({
+    disabled: props.disabled || !record.selectable,
+  }),
+}));
+
+const columns = [
+  { title: '琚嬬爜', dataIndex: 'code', key: 'code', ellipsis: true },
+  { title: '涓氬姟鐮�', dataIndex: 'businessCode', key: 'businessCode', width: 160, ellipsis: true },
+  { title: '鎵樼洏', dataIndex: 'palletId', key: 'palletId', width: 90 },
+  { title: '鐘舵��', key: 'status', width: 100 },
+  { title: '璇存槑', dataIndex: 'unavailableReason', key: 'reason', width: 180, ellipsis: true },
+];
+
 function chooseQuantity() {
   const count = Number(desired.value);
   if (!Number.isInteger(count) || count < 1 || count > eligible.value.length) {
-    selectionError.value = `璇疯緭鍏� 1 鑷� ${eligible.value.length} 鐨勬暣鏁拌鏁癭; return;
+    selectionError.value = `璇疯緭鍏� 1 鑷� ${eligible.value.length} 鐨勬暣鏁拌鏁癭;
+    return;
   }
   selectionError.value = '';
-  emit('update:modelValue', eligible.value.slice(0, count).map(b => b.id));
+  emit('update:modelValue', eligible.value.slice(0, count).map((bag) => bag.id));
+}
+
+function clearAll() {
+  selectionError.value = '';
+  emit('update:modelValue', []);
+}
+
+function removeBag(id: number) {
+  emit('update:modelValue', props.modelValue.filter((bagId) => bagId !== id));
+}
+
+function rowClassName(record: MesWmProductSalesApi.PickingBag) {
+  return record.selectable ? '' : 'picking-row-disabled';
 }
 </script>
+
 <template>
-  <fieldset class="pick-bags" :disabled="disabled">
-    <legend>閫夋嫨杩芥函琚嬬爜</legend>
-    <p class="pick-summary" role="status">鍙�� {{eligible.length}} 琚� 路 鏈宸查�� <strong>{{modelValue.length}}</strong> 琚�</p>
-    <div class="pick-controls">
-      <label>鏈鎷h揣鏁伴噺<input v-model="desired" type="number" min="1" :max="eligible.length" step="1" placeholder="杈撳叆琚嬫暟" /></label>
-      <button type="button" :disabled="!eligible.length" @click="chooseQuantity">鎸夋暟閲忛�夋嫨琚嬬爜</button>
-      <button type="button" :disabled="!modelValue.length" @click="emit('update:modelValue', [])">娓呯┖閫夋嫨</button>
+  <div class="rounded-lg border border-gray-200 p-3">
+    <div class="mb-3 flex flex-wrap items-center justify-between gap-2">
+      <div class="flex items-center gap-2">
+        <span class="font-semibold">鎷h揣琚嬬爜</span>
+        <a-tag color="blue">鍙�� {{ eligible.length }} 琚�</a-tag>
+        <a-tag color="green">宸查�� {{ modelValue.length }} 琚�</a-tag>
+        <a-tag v-if="unavailableCount > 0" color="default">涓嶅彲閫� {{ unavailableCount }} 琚�</a-tag>
+      </div>
+      <div class="flex flex-wrap items-center gap-2">
+        <a-input
+          v-model:value="search"
+          allow-clear
+          placeholder="鎼滅储琚嬬爜 / 涓氬姟鐮�"
+          style="width: 200px"
+        />
+        <a-input-number
+          v-model:value="desired"
+          :min="1"
+          :max="eligible.length"
+          :precision="0"
+          placeholder="琚嬫暟"
+          style="width: 90px"
+        />
+        <a-button :disabled="disabled || !eligible.length" @click="chooseQuantity">
+          鎸夋暟閲忛�夋嫨
+        </a-button>
+        <a-button :disabled="disabled || !modelValue.length" @click="clearAll">
+          娓呯┖閫夋嫨
+        </a-button>
+      </div>
     </div>
-    <p class="pick-help">鎸夋暟閲忛�夋嫨灏嗘浛鎹㈠綋鍓嶉�夋嫨锛屾寜琚嬬爜椤哄簭閫夊彇鍙�夎銆傝鏍稿瀹炵墿锛屾垨閫愯鍕鹃�夈��</p>
-    <p v-if="selectionError" class="pick-error" role="alert">{{selectionError}}</p>
-    <label class="pick-search">鏌ユ壘琚嬬爜<input v-model="search" type="search" placeholder="杈撳叆涓氬姟鐮佹垨杩芥函鐮�" /></label>
-    <div class="pick-list">
-      <label v-for="bag in filtered.slice(0, limit)" :key="bag.id" class="pick-option" :class="{ 'pick-unavailable': !bag.selectable, 'pick-selected': modelValue.includes(bag.id) }">
-        <input type="checkbox" :checked="modelValue.includes(bag.id)" :disabled="!bag.selectable" :aria-label="'閫夋嫨琚嬬爜 ' + bag.code" @change="choose(bag, ($event.target as HTMLInputElement).checked)" />
-        <span><strong>{{bag.code}}</strong><small v-if="bag.businessCode">涓氬姟鐮� {{bag.businessCode}}</small><small v-if="bag.unavailableReason">{{bag.unavailableReason}}</small></span>
-      </label>
-      <p v-if="!filtered.length" class="pick-help">娌℃湁鍖归厤鐨勮鐮�</p>
+
+    <a-alert
+      v-if="selectionError"
+      type="error"
+      show-icon
+      :message="selectionError"
+      class="mb-2"
+    />
+
+    <a-table
+      row-key="id"
+      :row-selection="rowSelection"
+      :columns="columns"
+      :data-source="filtered"
+      :pagination="{ pageSize: 10, showSizeChanger: false, size: 'small' }"
+      :scroll="{ y: 280 }"
+      :row-class-name="rowClassName"
+      bordered
+      size="small"
+    >
+      <template #bodyCell="{ column, record }">
+        <template v-if="column.key === 'palletId'">
+          {{ record.palletId ? `#${record.palletId}` : '-' }}
+        </template>
+        <template v-else-if="column.key === 'status'">
+          <a-tag :color="record.selectable ? 'green' : 'default'">
+            {{ record.selectable ? '鍙��' : '涓嶅彲閫�' }}
+          </a-tag>
+        </template>
+        <template v-else-if="column.key === 'reason'">
+          {{ record.unavailableReason || '-' }}
+        </template>
+      </template>
+    </a-table>
+
+    <div v-if="selectedBags.length" class="mt-3 flex flex-wrap items-center gap-1">
+      <span class="text-sm text-gray-500">宸查�夎鐮侊細</span>
+      <a-tag
+        v-for="bag in visibleSelected"
+        :key="bag.id"
+        :closable="!disabled"
+        @close="removeBag(bag.id)"
+      >
+        {{ bag.code }}
+      </a-tag>
+      <a-tag v-if="selectedBags.length > VISIBLE_SELECTED">
+        +{{ selectedBags.length - VISIBLE_SELECTED }}
+      </a-tag>
     </div>
-    <button v-if="filtered.length > limit" type="button" @click="limit += 50">鏄剧ず鏇村琚嬬爜锛坽{limit}} / {{filtered.length}}锛�</button>
-    <details v-if="modelValue.length"><summary>鏍稿鍏ㄩ儴宸查�夎鐮侊紙{{modelValue.length}} 琚嬶級</summary><p v-for="bag in bags.filter(b => modelValue.includes(b.id))" :key="bag.id" class="pick-code">{{bag.code}}<small v-if="bag.businessCode"> 路 {{bag.businessCode}}</small></p></details>
-  </fieldset>
+  </div>
 </template>
+
 <style scoped>
-.pick-bags{border:0;padding:0;margin:16px 0;min-width:0;color:inherit}.pick-bags legend{font-weight:600}.pick-summary{margin:8px 0}.pick-controls{display:flex;align-items:flex-end;gap:8px;flex-wrap:wrap}.pick-controls label{flex:1;min-width:130px}.pick-bags label{font-weight:500}.pick-bags input[type=number],.pick-bags input[type=search]{display:block;width:100%;min-width:0;min-height:44px;border:1px solid #64748b;border-radius:6px;background:var(--background, white);color:inherit;padding:8px 10px;font:inherit}.pick-bags button{min-height:44px;padding:8px 12px;border:1px solid #64748b;border-radius:6px;color:#0369a1;background:var(--background, white);cursor:pointer}.pick-bags button:disabled{opacity:.5;cursor:default}.pick-help{font-size:14px;color:#475569;line-height:1.5;margin:10px 0}.pick-search{display:block;margin:12px 0}.pick-list{max-height:360px;overflow:auto;border-top:1px solid #e2e8f0}.pick-option{display:flex;align-items:center;gap:12px;min-height:64px;padding:10px 4px;border-bottom:1px solid #e2e8f0;cursor:pointer}.pick-option input{width:20px;height:20px;flex-shrink:0;accent-color:#0369a1}.pick-option span{min-width:0;overflow-wrap:anywhere}.pick-option strong{display:block;font-weight:500}.pick-option small{display:block;color:#475569;font-size:14px}.pick-selected{background:#f0f9ff;color:#0f172a}.pick-unavailable{cursor:default;background:#f8fafc;color:#475569}.pick-error{color:#b91c1c}.pick-code{overflow-wrap:anywhere;font-size:14px;padding:6px 0}.pick-bags summary{cursor:pointer;min-height:44px;padding:10px 0;color:#0369a1}.pick-bags :focus-visible{outline:2px solid #0369a1;outline-offset:2px}
+:deep(.picking-row-disabled) {
+  color: #94a3b8;
+  background: #f8fafc;
+}
 </style>

--
Gitblit v1.9.3