Sfoglia il codice sorgente

feat: 添加发货状态标签组件并在主文件中注册

xieyong 1 mese fa
parent
commit
f4747e323b
2 ha cambiato i file con 66 aggiunte e 0 eliminazioni
  1. 64 0
      src/components/SendStatusTag.vue
  2. 2 0
      src/main.js

+ 64 - 0
src/components/SendStatusTag.vue

@@ -0,0 +1,64 @@
+<!--
+  发货状态标签
+  用法:
+    <send-status-tag :status="row.sendStatus" />
+    <send-status-tag :status="row.sendStatus" default-text="未收货" />
+-->
+<template>
+  <el-tag :type="tagType">{{ tagLabel }}</el-tag>
+</template>
+
+<script>
+  // 发货状态码 → 文案/tag 类型 映射
+  // value 0 同时承担「未发货/未收货」两种语义,由 defaultText 控制默认文案
+  const SEND_STATUS_LIST = [
+    { value: 0, label: '未发货' },
+    { value: 1, label: '已发货', type: 'success' },
+    { value: 2, label: '已收货', type: 'success' },
+    { value: 3, label: '受托已发', type: 'success' },
+    { value: 4, label: '请托已收', type: 'success' },
+    { value: 5, label: '受托拒收', type: 'success' },
+    { value: 6, label: '请托拒收', type: 'success' },
+    { value: 7, label: '部分发货', type: 'success' },
+    { value: 8, label: '部分收货', type: 'success' },
+    { value: 9, label: '部分驳回', type: 'success' },
+    { value: 10, label: '受托部分已发', type: 'success' },
+    { value: 11, label: '请托部分已收', type: 'success' }
+  ];
+
+  export default {
+    name: 'SendStatusTag',
+    props: {
+      // 兼容 Number / String,与后端返回类型保持宽松
+      status: {
+        type: [Number, String],
+        default: 0
+      },
+      // 受托方展示「未收货」,请托方/委外展示「未发货」
+      defaultText: {
+        type: String,
+        default: '未发货'
+      }
+    },
+    computed: {
+      // 0 / 未定义 / 空串 都视为「默认」状态
+      isDefault() {
+        const s = this.status;
+        return (
+          s === 0 || s === '0' || s === undefined || s === null || s === ''
+        );
+      },
+      currentItem() {
+        return SEND_STATUS_LIST.find((i) => i.value === Number(this.status));
+      },
+      tagLabel() {
+        return this.isDefault
+          ? this.defaultText
+          : this.currentItem?.label ?? String(this.status);
+      },
+      tagType() {
+        return this.isDefault ? undefined : this.currentItem?.type;
+      }
+    }
+  };
+</script>

+ 2 - 0
src/main.js

@@ -13,6 +13,7 @@ import './styles/index.scss';
 import DictSelection from '@/components/Dict/DictSelection';
 import HeaderTitle from '@/components/header-title';
 import authSelection from '@/components/authSelection';
+import SendStatusTag from '@/components/SendStatusTag.vue';
 import Direction from 'vue-direction-key';
 // 公共搜索文件
 
@@ -48,6 +49,7 @@ Vue.prototype.$math = create(all, config);
 import '@/icons';
 
 Vue.component('DictSelection', DictSelection);
+Vue.component('SendStatusTag', SendStatusTag);
 Vue.component('fileMain', fileMain);
 
 Vue.config.productionTip = false;