spring
7 天以前 add06adc5d974ac685cb637c48f2455034c8a52f
src/pages/sales/salesAccount/index.vue
@@ -79,12 +79,21 @@
              </view>
            </view>
            <up-divider></up-divider>
            <u-button class="detail-button"
            <view class="detail-buttons">
              <u-button class="detail-button"
                      size="small"
                      type="primary"
                      @click="openOut(item)">
              发货状态
            </u-button>
            <u-button class="detail-button"
                      size="small"
                      type="error"
                      plain
                      @click.stop="handleDelete(item)">
              删除
            </u-button>
            </view>
          </view>
        </view>
      </view>
@@ -106,7 +115,11 @@
<script setup>
  import { ref } from "vue";
  import { onShow } from "@dcloudio/uni-app";
  import { ledgerListPage } from "@/api/salesManagement/salesLedger";
  import {
    ledgerListPage,
    delLedger,
    productList,
  } from "@/api/salesManagement/salesLedger";
  import useUserStore from "@/store/modules/user";
  import PageHeader from "@/components/PageHeader.vue";
  const userStore = useUserStore();
@@ -125,6 +138,20 @@
  // 销售台账数据
  const ledgerList = ref([]);
  // 判断是否存在已发货/发货完成的产品
  const hasShippedProducts = products => {
    if (!products || products.length === 0) return false;
    return products.some(p => {
      const statusStr = (p.shippingStatus ?? "").toString();
      // 包含“发货”或有发货日期/车牌号视为已发货
      return (
        statusStr.includes("发货") ||
        !!p.shippingDate ||
        !!p.shippingCarNumber
      );
    });
  };
  // 返回上一页
  const goBack = () => {
@@ -151,6 +178,55 @@
    uni.setStorageSync("outData", JSON.stringify(item));
    uni.navigateTo({
      url: "/pages/sales/salesAccount/out",
    });
  };
  // 删除单条销售台账
  const handleDelete = async row => {
    if (!row || !row.id) return;
    // 获取产品列表,用于判断是否已发货
    let products = row.children && row.children.length > 0 ? row.children : null;
    if (!products) {
      try {
        const res = await productList({ salesLedgerId: row.id, type: 1 });
        products = res.data || res.records || [];
      } catch (e) {
        products = [];
      }
    }
    if (hasShippedProducts(products)) {
      uni.showToast({
        title: "已发货/发货完成的销售订单不能删除",
        icon: "none",
      });
      return;
    }
    uni.showModal({
      title: "删除确认",
      content: "选中的内容将被删除,是否确认删除?",
      success: async res => {
        if (res.confirm) {
          try {
            showLoadingToast("处理中...");
            await delLedger([row.id]);
            closeToast();
            uni.showToast({
              title: "删除成功",
              icon: "success",
            });
            getList();
          } catch (e) {
            closeToast();
            uni.showToast({
              title: "删除失败,请重试",
              icon: "none",
            });
          }
        }
      },
    });
  };
  // 处理台账信息操作(查看/编辑/新增)
@@ -209,4 +285,9 @@
<style scoped lang="scss">
  @import "@/styles/sales-common.scss";
  .detail-buttons {
    display: flex;
    gap: 10px;
    justify-content: space-between;
  }
</style>