gaoluyang
昨天 352fbcfaa09e261918f5a7b50bcd9ba15583b1aa
军泰伟业
1.销售退货逻辑完善与联调
已添加1个文件
已修改3个文件
438 ■■■■■ 文件已修改
src/views/salesManagement/deliveryLedger/index.vue 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/salesManagement/returnOrder/components/detailDia.vue 146 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/salesManagement/returnOrder/components/formDia.vue 125 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/salesManagement/returnOrder/index.vue 165 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/salesManagement/deliveryLedger/index.vue
@@ -639,6 +639,7 @@
    '审核中': '审核中',
    '审核拒绝': '审核拒绝',
    '审核通过': '审核通过',
    '已发货': '已发货',
    '0': '待审核',
    '1': '审核中',
    '2': '审核拒绝',
@@ -669,6 +670,7 @@
    '审核中': 'warning',
    '审核拒绝': 'danger',
    '审核通过': 'success',
    '已发货': 'success',
    '0': 'info',
    '1': 'warning',
    '2': 'danger',
src/views/salesManagement/returnOrder/components/detailDia.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,146 @@
<template>
  <el-dialog v-model="dialogVisible" title="退货单详情" width="90%" @close="closeDia">
    <div v-loading="loading">
      <span class="descriptions">基本信息</span>
      <el-descriptions :column="4" border>
        <el-descriptions-item label="退货单号">{{ detail.returnNo }}</el-descriptions-item>
        <el-descriptions-item label="单据状态">
          <el-tag :type="getStatusType(detail.status)">{{ getStatusText(detail.status) }}</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="客户名称">{{ detail.customerName }}</el-descriptions-item>
        <el-descriptions-item label="销售单号">{{ detail.salesContractNo }}</el-descriptions-item>
        <el-descriptions-item label="业务员">{{ detail.salesman }}</el-descriptions-item>
        <el-descriptions-item label="关联出库单号">{{ detail.shippingNo }}</el-descriptions-item>
        <el-descriptions-item label="项目名称">{{ detail.projectName }}</el-descriptions-item>
        <el-descriptions-item label="制单人">{{ detail.maker }}</el-descriptions-item>
        <el-descriptions-item label="制单时间">{{ detail.makeTime }}</el-descriptions-item>
        <el-descriptions-item label="退货原因">{{ detail.returnReason }}</el-descriptions-item>
        <el-descriptions-item label="退款总额">{{ detail.refundAmount }}</el-descriptions-item>
      </el-descriptions>
      <div style="padding-top: 20px">
        <span class="descriptions">产品列表</span>
        <PIMTable :isShowPagination="false" rowKey="id" :column="tableColumn" :tableData="tableData" />
      </div>
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="closeDia">关闭</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup>
import { ref } from "vue";
import { returnManagementGetById, returnManagementGetByShippingId } from "@/api/salesManagement/returnOrder.js";
const dialogVisible = ref(false);
const loading = ref(false);
const detail = ref({});
const tableData = ref([]);
const availableProducts = ref([]);
const tableColumn = [
  {align: "center", label: "产品大类", prop: "productCategory"},
  {align: "center", label: "规格型号", prop: "specificationModel"},
  {align: "center", label: "单位", prop: "unit", width: 80},
  {align: "center", label: "总数量", prop: "quantity", width: 120},
  {align: "center", label: "已退货数量", prop: "totalReturnNum", width: 120},
  {align: "center", label: "未退货数量", prop: "unQuantity", width: 120},
  {align: "center", label: "退货数量", prop: "returnQuantity", width: 120},
  {align: "center", label: "退货产品单价", prop: "price", width: 120},
  {align: "center", label: "退货产品金额", prop: "amount", width: 120},
  {align: "center", label: "是否有质量问题", prop: "isQuality", width: 140, formatData: (v) => ({ "1": "是", "2": "否" }[String(v)] ?? v)},
  {align: "center", label: "备注", prop: "remark", width: 150},
];
const getStatusType = (status) => {
  const statusMap = {
    0: "warning",
    1: "success"
  };
  return statusMap[status] || "info";
};
const getStatusText = (status) => {
  const statusMap = {
    0: "待处理",
    1: "已处理"
  };
  return statusMap[status] || "未知";
};
const openDialog = async (row) => {
  if (!row?.id) return;
  dialogVisible.value = true;
  loading.value = true;
  try {
    const res = await returnManagementGetById({ returnManagementId: row.id });
    detail.value = res?.data ?? res ?? {};
    if (detail.value.shippingId) {
      const productRes = await returnManagementGetByShippingId({ shippingId: detail.value.shippingId });
      if (productRes.code === 200) {
        availableProducts.value = productRes.data.productDtoData || [];
      }
    }
    const list =
      detail.value?.returnSaleProducts ||
        detail.value?.returnSaleProductList ||
        detail.value?.returnSaleProductDtoData ||
        [];
    tableData.value = Array.isArray(list) ? list.map(raw => {
      const productId = raw?.returnSaleLedgerProductId ?? raw?.saleLedgerProductId ?? raw?.id;
      const product = availableProducts.value.find((p) => p.id === productId);
      const normalized = {
        ...raw,
        id: productId,
        returnQuantity: Number(raw?.num ?? raw?.returnQuantity ?? 0),
        price: Number(raw?.taxInclusiveUnitPrice ?? raw?.price ?? 0),
        amount: Number(raw?.amount ?? 0).toFixed(2),
        isQuality: raw?.isQuality ?? 2,
        remark: raw?.remark ?? "",
      };
      return product ? { ...product, ...normalized } : normalized;
    }) : [];
  } catch (e) {
    console.error("Failed to load detail", e);
  } finally {
    loading.value = false;
  }
};
const closeDia = () => {
  dialogVisible.value = false;
  detail.value = {};
  tableData.value = [];
  availableProducts.value = [];
};
defineExpose({ openDialog });
</script>
<style scoped lang="scss">
.descriptions {
  margin-bottom: 20px;
  display: inline-block;
  font-size: 1rem;
  font-weight: 600;
  padding-left: 12px;
  position: relative;
}
.descriptions::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 1rem;
  background-color: #002FA7;
  border-radius: 2px;
}
</style>
src/views/salesManagement/returnOrder/components/formDia.vue
@@ -44,11 +44,6 @@
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="项目阶段:" prop="projectStage">
                <el-input v-model="form.projectStage" placeholder="项目阶段" />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="制单人:" prop="maker">
                <el-select v-model="form.maker" filterable placeholder="请选择制单人">
                  <el-option v-for="u in userOptions" :key="u.value" :label="u.label" :value="u.value" />
@@ -61,19 +56,21 @@
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="结算人:" prop="settler">
                <el-select v-model="form.settler" filterable placeholder="请选择结算人">
                  <el-option v-for="u in userOptions" :key="u.value" :label="u.label" :value="u.value" />
              <el-form-item label="状态:" prop="status">
                <el-select v-model="form.status" placeholder="请选择状态">
                  <el-option label="待处理" :value="0" />
                  <el-option label="已处理" :value="1" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="状态:" prop="status">
                <el-select v-model="form.status" placeholder="请选择状态">
                  <el-option label="待审核" :value="0" />
                  <el-option label="审核中" :value="1" />
                  <el-option label="已审核" :value="2" />
                </el-select>
              <el-form-item label="退货原因:" prop="returnReason">
                <el-input v-model="form.returnReason" placeholder="请输入退货原因" />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="退款总额:" prop="refundAmount">
                <el-input v-model="form.refundAmount" disabled placeholder="自动计算" />
              </el-form-item>
            </el-col>
          </el-row>
@@ -92,6 +89,37 @@
                placeholder="请输入" 
                type="number"
                @input="(val) => handleReturnQuantityChange(val, row)"
              />
            </template>
            <template #price="{ row }">
              <el-input
                v-model="row.price"
                style="width:100px"
                placeholder="请输入"
                type="number"
                @input="(val) => handlePriceChange(val, row)"
              />
            </template>
            <template #amount="{ row }">
              <el-input
                v-model="row.amount"
                style="width:100px"
                placeholder="自动计算"
                type="number"
                disabled
              />
            </template>
            <template #isQuality="{ row }">
              <el-select v-model="row.isQuality" placeholder="请选择" style="width:120px">
                <el-option label="是" :value="1" />
                <el-option label="否" :value="2" />
              </el-select>
            </template>
            <template #remark="{ row }">
              <el-input
                v-model="row.remark"
                style="width:130px"
                placeholder="请输入"
              />
            </template>
            <template #action="{ row, index }">
@@ -159,11 +187,11 @@
    customerId: "",
    shippingId: "",
    projectId: "",
    projectStage: "",
    maker: "",
    makeTime: "",
    settler: "",
    status: 0,
    returnReason: "",
    refundAmount: "",
  },
  rules: {
    returnNo: [{
@@ -194,6 +222,10 @@
  {align: "center", label: "已退货数量", prop: "totalReturnNum", width: 120 },
  {align: "center", label: "未退货数量", prop: "unQuantity", width: 120 },
  {align: "center", label: "退货数量", prop: "returnQuantity", dataType: "slot", slot: "returnQuantity", width: 120 },
  {align: "center", label: "退货产品单价", prop: "price", dataType: "slot", slot: "price", width: 120 },
  {align: "center", label: "退货产品金额", prop: "amount", dataType: "slot", slot: "amount", width: 120 },
  {align: "center", label: "是否有质量问题", prop: "isQuality", dataType: "slot", slot: "isQuality", width: 140 },
  {align: "center", label: "备注", prop: "remark", dataType: "slot", slot: "remark", width: 150 },
  {align: "center", label: "操作" , prop: "action", dataType: "slot", slot: "action", width: 120 },
]);
const tableData = ref([]);
@@ -215,8 +247,13 @@
    id: productId,
    returnSaleProductId,
    returnSaleLedgerProductId: productId,
    productModelId: raw?.productModelId,
    num,
    returnQuantity: Number.isFinite(num) ? num : 0,
    price: Number(raw?.taxInclusiveUnitPrice ?? raw?.price ?? 0),
    amount: Number(raw?.amount ?? 0).toFixed(2),
    isQuality: raw?.isQuality ?? 2,
    remark: raw?.remark ?? "",
  };
};
@@ -248,6 +285,8 @@
        return product ? { ...product, ...normalized } : normalized;
      })
    : [];
  calculateTotalRefund();
};
const openDialog = async (type, row) => {
@@ -265,11 +304,11 @@
      customerId: "",
      shippingId: "",
      projectId: "",
      projectStage: "",
      maker: "",
      makeTime: "",
      settler: "",
      status: 0,
      returnReason: "",
      refundAmount: "",
    });
    form.value.maker = userStore.nickName || userStore.name || "";
    form.value.makeTime = new Date().toISOString().replace('T', ' ').split('.')[0]; // Default to now
@@ -282,7 +321,13 @@
    if (!valid) return;
    const returnSaleProducts = (tableData.value || []).map(el => ({
      returnSaleLedgerProductId: el.returnSaleLedgerProductId ?? el.id,
      productModelId: el.productModelId,
      unit: el.unit,
      num: Number(el.num ?? el.returnQuantity ?? 0),
      price: Number(el.price ?? 0),
      amount: Number(el.amount ?? 0),
      isQuality: el.isQuality ?? 2,
      remark: el.remark ?? "",
      id: operationType.value === "edit" ? (el.returnSaleProductId ?? "") : ""
    }));
    const payload = { ...form.value, returnSaleProducts };
@@ -374,7 +419,6 @@
  if(res.code === 200){
    // If backend returns project info, set it
    if (res.data.projectId) form.value.projectId = res.data.projectId;
    if (res.data.projectStage) form.value.projectStage = res.data.projectStage;
    
    // Store available products for selection
    availableProducts.value = res.data.productDtoData || [];
@@ -388,7 +432,6 @@
  const current = Number(val);
  
  if (current > max) {
    // Need nextTick to ensure update if user typed too fast or pasted
    proxy.$nextTick(() => {
      row.returnQuantity = max;
      row.num = max;
@@ -402,6 +445,29 @@
  } else {
    row.num = current;
  }
  calculateRowAmount(row);
  calculateTotalRefund();
};
const handlePriceChange = (val, row) => {
  if (val === "" || val === null) {
    row.price = 0;
  }
  calculateRowAmount(row);
  calculateTotalRefund();
};
const calculateRowAmount = (row) => {
  const quantity = Number(row.returnQuantity || 0);
  const price = Number(row.price || 0);
  row.amount = (quantity * price).toFixed(2);
};
const calculateTotalRefund = () => {
  const total = tableData.value.reduce((sum, row) => {
    return sum + Number(row.amount || 0);
  }, 0);
  form.value.refundAmount = total.toFixed(2);
};
const availableProducts = ref([]);
@@ -429,26 +495,23 @@
// Removed checkSelectable to allow toggling existing items
const confirmProductSelection = () => {
  // Rebuild tableData based on selection, preserving existing data (returnQuantity)
  const newTableData = [];
  
  selectedProducts.value.forEach(product => {
    // Check if product was already in tableData to preserve user input
    const existing = tableData.value.find(item => item.id === product.id);
    if (existing) {
      newTableData.push(existing);
    } else {
      // Create new entry
      newTableData.push({
        ...product, // Keep all product display fields (productName, model, unit, etc.)
        // Map to backend entity structure for submission
        ...product,
        returnSaleLedgerProductId: product.id, 
        returnQuantity: 0, // Default input
        num: 0, // Backend quantity field
        // Ensure display fields are available if they come from 'product'
        // If product has different field names than tableColumn expects, map them here
        productModelId: product.productModelId,
        returnQuantity: 0,
        num: 0,
        price: Number(product.taxInclusiveUnitPrice ?? 0),
        amount: "0.00",
        isQuality: 2,
        remark: "",
        productName: product.productName,
        specificationModel: product.specificationModel,
        unit: product.unit,
src/views/salesManagement/returnOrder/index.vue
@@ -4,22 +4,22 @@
      <el-form :model="searchForm" class="demo-form-inline">
        <el-row :gutter="20">
          <el-col :span="4">
            <el-form-item>
            <el-form-item label="退货单号">
              <el-input v-model="searchForm.returnNo" placeholder="请输入退货单号" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item>
            <el-form-item label="客户名称">
              <el-input v-model="searchForm.customerName" placeholder="客户名称" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item>
            <el-form-item label="销售单号">
              <el-input v-model="searchForm.salesContractNo" placeholder="销售单号" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item>
            <el-form-item label="关联出库单号">
              <el-input v-model="searchForm.shippingNo" placeholder="关联出库单号" clearable />
            </el-form-item>
          </el-col>
@@ -33,46 +33,27 @@
      </el-form>
    </div>
    <div class="table_list">
      <div class="table_header" style="display:flex;justify-content:space-between;align-items:center;">
        <div>
          <el-button type="primary" @click="openForm('add')">新建销售退货</el-button>
        </div>
        <div>
          <el-button type="danger" plain @click="handleDelete">删除</el-button>
          <el-button @click="columnsDialogVisible = true">列表字段</el-button>
        </div>
      <div class="table_header" style="display: flex;justify-content: flex-end;margin-bottom: 10px;">
        <el-button type="primary" @click="openForm('add')">新建销售退货</el-button>
        <el-button type="danger" plain @click="handleDelete">删除</el-button>
      </div>
      <PIMTable
        rowKey="id"
        :column="visibleColumns"
        :column="tableColumn"
        :tableData="tableData"
        :page="page"
        :isSelection="true"
        @selection-change="handleSelectionChange"
        :tableLoading="tableLoading"
        @pagination="pagination"
      />
      >
        <template #status="{ row }">
          <el-tag :type="getStatusType(row.status)">{{ getStatusText(row.status) }}</el-tag>
        </template>
      </PIMTable>
    </div>
    <form-dia ref="formDia" @close="handleQuery" />
    <el-dialog v-model="columnsDialogVisible" title="自定义显示列项" width="600px">
      <div class="columns-tip">注:列表项显示不得少于5项;拖动右侧把手可调整显示顺序</div>
      <ul class="columns-list">
        <li v-for="(col, idx) in allColumns" :key="col.prop"
            class="columns-item"
            draggable="true"
            @dragstart="onDragStart(idx)"
            @dragover.prevent
            @drop="onDrop(idx)">
          <el-checkbox v-model="col.selected">{{ col.label }}</el-checkbox>
          <span class="drag-handle">≡</span>
        </li>
      </ul>
      <template #footer>
        <el-button @click="resetColumns">恢复默认</el-button>
        <el-button type="primary" @click="saveColumns">保存</el-button>
      </template>
    </el-dialog>
    <detail-dia ref="detailDia" />
  </div>
</template>
@@ -80,12 +61,18 @@
import { reactive, ref, toRefs, computed, getCurrentInstance, nextTick, onMounted } from "vue";
import { ElMessageBox } from "element-plus";
import FormDia from "./components/formDia.vue";
import DetailDia from "./components/detailDia.vue";
import { returnManagementList, returnManagementDel, returnManagementHandle } from "@/api/salesManagement/returnOrder.js";
const { proxy } = getCurrentInstance();
const formDia = ref();
const detailDia = ref();
const openForm = (type, row) => {
  nextTick(() => formDia.value?.openDialog(type, row));
};
const openDetail = (row) => {
  nextTick(() => detailDia.value?.openDialog(row));
};
const handleRowDelete = (row) => {
@@ -132,86 +119,36 @@
const { searchForm } = toRefs(data);
const documentStatusOptions = ref([
  { label: "待审核", value: 0 },
  { label: "审核中", value: 1 },
  { label: "已审核", value: 2 }
  { label: "待处理", value: 0 },
  { label: "已处理", value: 1 }
]);
const defaultColumns = [
  { label: "退货单号", prop: "returnNo", minWidth: 160 },
  { label: "单据状态", prop: "status", minWidth: 120, formatData: (v) => ({ "0": "待审核", "1": "审核中", "2": "已审核" }[String(v)] ?? v) },
  { label: "制单时间", prop: "makeTime", minWidth: 170 },
  { label: "客户名称", prop: "customerName", minWidth: 220 },
  { label: "销售单号", prop: "salesContractNo", minWidth: 160 },
  { label: "业务员", prop: "salesman", minWidth: 120 },
  { label: "关联出库单号", prop: "shippingNo", minWidth: 170 },
  { label: "项目名称", prop: "projectName", minWidth: 180 },
  { label: "项目阶段", prop: "projectStage", minWidth: 120 },
  { label: "制单人", prop: "maker", minWidth: 120 },
  { label: "结算人", prop: "settler", minWidth: 120 },
  { label: "退货单号", prop: "returnNo", width: 160 },
  { label: "单据状态", prop: "status", width: 90, dataType: "slot", slot: "status" },
  { label: "制单时间", prop: "makeTime", width: 170 },
  { label: "客户名称", prop: "customerName", width: 220 },
  { label: "销售单号", prop: "salesContractNo", width: 160 },
  { label: "业务员", prop: "salesman", width: 120 },
  { label: "关联出库单号", prop: "shippingNo", width: 170 },
  { label: "项目名称", prop: "projectName", width: 180 },
  { label: "制单人", prop: "maker", width: 120 },
  {
    label: "操作",
    prop: "operation",
    dataType: "action",
    align: "center",
    fixed: "right",
    width: 160,
    width: 240,
    operation: [
      { name: "编辑", disabled: (row) => row.status !== 0, type: "text", clickFun: (row) => openForm("edit", row) },
      { name: "处理", disabled: (row) => row.status !== 0, type: "text", clickFun: (row) => handleRowHandle(row) },
      { name: "退款处理", disabled: (row) => row.status !== 0, type: "text", clickFun: (row) => handleRowHandle(row) },
      { name: "详情", type: "text", clickFun: (row) => openDetail(row) },
      { name: "删除", disabled: (row) => row.status !== 0, type: "text", clickFun: (row) => handleRowDelete(row) },
    ],
  },
];
const COLUMNS_KEY = "return_order_columns_v2";
const columnsDialogVisible = ref(false);
const allColumns = ref([]);
const initColumns = () => {
  const saved = localStorage.getItem(COLUMNS_KEY);
  if (saved) {
    try {
      const parsed = JSON.parse(saved);
      // åˆå¹¶é»˜è®¤åˆ—与已保存配置,避免后续新增列丢失
      const map = new Map(parsed.map(c => [c.prop, c]));
      allColumns.value = defaultColumns.map(d => {
        const found = map.get(d.prop);
        return { ...d, selected: found ? !!found.selected : true };
      });
      // ä»¥ä¿å­˜çš„顺序为准
      const order = parsed.map(p => p.prop);
      allColumns.value.sort((a, b) => order.indexOf(a.prop) - order.indexOf(b.prop));
      return;
    } catch {}
  }
  allColumns.value = defaultColumns.map(c => ({ ...c, selected: true }));
};
initColumns();
const visibleColumns = computed(() => allColumns.value.filter(c => c.selected));
let dragFrom = -1;
const onDragStart = (idx) => {
  dragFrom = idx;
};
const onDrop = (to) => {
  if (dragFrom < 0 || dragFrom === to) return;
  const arr = [...allColumns.value];
  const [moved] = arr.splice(dragFrom, 1);
  arr.splice(to, 0, moved);
  allColumns.value = arr;
  dragFrom = -1;
};
const resetColumns = () => {
  allColumns.value = defaultColumns.map(c => ({ ...c, selected: true }));
  localStorage.removeItem(COLUMNS_KEY);
};
const saveColumns = () => {
  const toSave = allColumns.value.map(({ label, prop, width, selected }) => ({ label, prop, width, selected }));
  localStorage.setItem(COLUMNS_KEY, JSON.stringify(toSave));
  columnsDialogVisible.value = false;
};
const tableColumn = defaultColumns;
const tableData = ref([]);
const tableLoading = ref(false);
@@ -221,6 +158,7 @@
const handleReset = () => {
  Object.keys(searchForm.value).forEach(k => searchForm.value[k] = "");
  handleQuery();
};
const handleSelectionChange = (selection) => {
  selectedRows.value = selection;
@@ -265,6 +203,22 @@
  });
};
const getStatusType = (status) => {
  const statusMap = {
    0: "warning",
    1: "success"
  };
  return statusMap[status] || "info";
};
const getStatusText = (status) => {
  const statusMap = {
    0: "待处理",
    1: "已处理"
  };
  return statusMap[status] || "未知";
};
onMounted(() => {
  getList();
});
@@ -276,20 +230,5 @@
  padding: 1rem 1rem 0 1rem;
  border: 8px;
  border-radius: 16px;
}
.table_list {
  height: calc(100vh - 230px);
  min-height: 360px;
  background: #fff;
  margin-top: 20px;
  display: flex;
  flex-direction: column;
}
.columns-tip{color:#909399;margin-bottom:10px;font-size:12px;}
.columns-list{list-style:none;padding:0;margin:0;max-height:360px;overflow:auto;}
.columns-item{display:flex;justify-content:space-between;align-items:center;padding:8px 10px;border:1px solid #f0f0f0;border-radius:6px;margin-bottom:8px;cursor:move;background:#fff;}
.columns-item .drag-handle{color:#909399;padding-left:12px;user-select:none;}
.table_header {
  margin-bottom: 15px;
}
</style>