zhangwencui
2026-06-29 4c8d18cc5ed8a7b0e220c91a858d16d0310896df
src/pages/sales/salesAccount/detail.vue
@@ -25,14 +25,8 @@
                  placeholder="点击选择业务员" />
        <template #right>
          <up-icon name="arrow-right"
                   @click="showPicker = true"></up-icon>
                   @click=" showPicker = true"></up-icon>
        </template>
      </up-form-item>
      <up-form-item label="客户合同号"
                    prop="customerContractNo"
                    required>
        <up-input v-model="form.customerContractNo"
                  placeholder="请输入客户合同号" />
      </up-form-item>
      <up-form-item label="客户名称"
                    prop="customerName"
@@ -62,6 +56,18 @@
        <template #right>
          <up-icon name="arrow-right"
                   @click="showDatePicker = true"></up-icon>
        </template>
      </up-form-item>
      <up-form-item label="交货日期"
                    prop="deliveryDate"
                    required>
        <up-input v-model="form.deliveryDate"
                  readonly
                  placeholder="点击选择时间"
                  @click="showDeliveryDatePicker = true" />
        <template #right>
          <up-icon name="arrow-right"
                   @click="showDeliveryDatePicker = true"></up-icon>
        </template>
      </up-form-item>
      <up-form-item label="付款方式"
@@ -95,6 +101,15 @@
                            v-model="pickerDateValue"
                            @confirm="onDateConfirm"
                            @cancel="showDatePicker = false"
                            mode="date" />
      </up-popup>
      <up-popup :show="showDeliveryDatePicker"
                mode="bottom"
                @close="showDeliveryDatePicker = false">
        <up-datetime-picker :show="true"
                            v-model="deliveryDateValue"
                            @confirm="onDeliveryDateConfirm"
                            @cancel="showDeliveryDatePicker = false"
                            mode="date" />
      </up-popup>
      <!-- 客户选择 -->
@@ -190,7 +205,7 @@
                        @click="openCategoryPicker(idx)" />
              <template #right>
                <up-icon name="arrow-right"
                         @click="showCategoryPicker = true"></up-icon>
                         @click="openCategoryPicker(idx)"></up-icon>
              </template>
            </up-form-item>
            <!-- 规格型号 -->
@@ -203,7 +218,7 @@
                        @click="openSpecificationPicker(idx)" />
              <template #right>
                <up-icon name="arrow-right"
                         @click="showSpecificationPicker = true"></up-icon>
                         @click="openSpecificationPicker(idx)"></up-icon>
              </template>
            </up-form-item>
            <!-- 绑定机器 -->
@@ -225,6 +240,23 @@
              <up-input v-model="product.unit"
                        placeholder="请输入" />
            </up-form-item>
            <up-form-item label="是否生产"
                          prop="isProduction"
                          required>
              <u-radio-group v-model="product.isProduction"
                             :disabled="operationType === 'view'"
                             placement="row">
                <u-radio :customStyle="{ marginRight: '40rpx' }"
                         :disabled="operationType === 'view'"
                         :name="true"
                         label="是">
                </u-radio>
                <u-radio :disabled="operationType === 'view'"
                         :name="false"
                         label="否">
                </u-radio>
              </u-radio-group>
            </up-form-item>
            <!-- 税率 -->
            <up-form-item label="税率(%)"
                          prop="taxRate"
@@ -235,7 +267,7 @@
                        @click="openTaxRatePicker(idx)" />
              <template #right>
                <up-icon name="arrow-right"
                         @click="showTaxRatePicker = true"></up-icon>
                         @click="openTaxRatePicker(idx)"></up-icon>
              </template>
            </up-form-item>
            <!-- 含税单价 -->
@@ -284,7 +316,7 @@
                        @click="openInvoiceTypePicker(idx)" />
              <template #right>
                <up-icon name="arrow-right"
                         @click="showInvoiceTypePicker = true"></up-icon>
                         @click="openInvoiceTypePicker(idx)"></up-icon>
              </template>
            </up-form-item>
          </view>
@@ -325,11 +357,11 @@
  const form = ref({
    id: "",
    salesContractNo: "",
    customerContractNo: "",
    customerId: "",
    customerName: "",
    projectName: "",
    executionDate: "",
    deliveryDate: "",
    paymentMethod: "",
    entryPerson: "",
    entryPersonName: "",
@@ -338,6 +370,8 @@
  const showPicker = ref(false);
  const showDatePicker = ref(false);
  const pickerDateValue = ref(Date.now());
  const showDeliveryDatePicker = ref(false);
  const deliveryDateValue = ref(Date.now());
  const showCustomerPicker = ref(false);
  const userList = ref([]);
  const customerOption = ref([]);
@@ -448,15 +482,15 @@
  // 表单校验规则
  const rules = {
    salesman: [{ required: true, message: "请选择业务员", trigger: "change" }],
    customerContractNo: [
      { required: true, message: "请输入客户合同号", trigger: "blur" },
    ],
    customerName: [
      { required: true, message: "请选择客户名称", trigger: "change" },
    ],
    projectName: [{ required: true, message: "请输入项目名称", trigger: "blur" }],
    executionDate: [
      { required: true, message: "请选择签订日期", trigger: "change" },
    ],
    deliveryDate: [
      { required: true, message: "请选择交货日期", trigger: "change" },
    ],
  };
@@ -469,6 +503,7 @@
      specificationModel: "",
      productModelId: "",
      unit: "",
      isProduction: true,
      speculativeTradingName: "",
      taxRate: "",
      taxInclusiveUnitPrice: "",
@@ -489,6 +524,11 @@
    // 保持pickerDateValue为时间戳格式,而不是格式化的字符串
    pickerDateValue.value = e.value;
    showDatePicker.value = false;
  };
  const onDeliveryDateConfirm = e => {
    form.value.deliveryDate = formatDateToYMD(e.value);
    deliveryDateValue.value = e.value;
    showDeliveryDatePicker.value = false;
  };
  // 客户选择事件
@@ -766,6 +806,23 @@
        });
        return;
      }
      const rawIsProduction = product.isProduction;
      const normalizedIsProduction =
        rawIsProduction === true || rawIsProduction === false
          ? rawIsProduction
          : rawIsProduction === 1 || rawIsProduction === 0
          ? Boolean(rawIsProduction)
          : rawIsProduction === "1" || rawIsProduction === "0"
          ? rawIsProduction === "1"
          : null;
      if (normalizedIsProduction === null) {
        uni.showToast({
          title: `产品${i + 1}:请选择是否生产`,
          icon: "none",
        });
        return;
      }
      product.isProduction = normalizedIsProduction;
      if (!product.taxRate) {
        uni.showToast({
          title: `产品${i + 1}:请选择税率`,
@@ -825,27 +882,42 @@
    form.value.entryPerson = userStore.id;
    form.value.entryPersonName = userStore.nickName;
    // 设置当天日期
    const today = new Date();
    const year = today.getFullYear();
    const month = String(today.getMonth() + 1).padStart(2, "0");
    const day = String(today.getDate()).padStart(2, "0");
    form.value.entryDate = `${year}-${month}-${day}`;
    // 设置日期选择器默认值为今天
    pickerDateValue.value = `${year}-${month}-${day}`;
    const now = new Date();
    const year = now.getFullYear();
    const month = String(now.getMonth() + 1).padStart(2, "0");
    const day = String(now.getDate()).padStart(2, "0");
    const todayStr = `${year}-${month}-${day}`;
    form.value.entryDate = todayStr;
    form.value.executionDate = todayStr;
    form.value.deliveryDate = todayStr;
    pickerDateValue.value = now.getTime();
    deliveryDateValue.value = now.getTime();
  };
  // 填充表单数据(编辑模式)
  const fillFormData = () => {
    if (!editData.value) return;
    getSalesLedgerWithProducts({ id: editData.value.id, type: 1 }).then(res => {
      productData.value = res.productData;
      const list = Array.isArray(res?.productData) ? res.productData : [];
      productData.value = list.map(item => {
        const raw = item?.isProduction;
        const normalized =
          raw === true || raw === false
            ? raw
            : raw === 1 || raw === 0
            ? Boolean(raw)
            : raw === "1" || raw === "0"
            ? raw === "1"
            : true;
        return { ...item, isProduction: normalized };
      });
    });
    console.log(editData.value);
    // 填充基本信息
    form.value.salesContractNo = editData.value.salesContractNo || "";
    form.value.customerContractNo = editData.value.customerContractNo || "";
    form.value.customerName = editData.value.customerName || "";
    form.value.projectName = editData.value.projectName || "";
    form.value.executionDate = editData.value.executionDate || "";
    form.value.deliveryDate = editData.value.deliveryDate || "";
    form.value.paymentMethod = editData.value.paymentMethod || "";
    form.value.salesman = editData.value.salesman || "";
    form.value.entryPerson = editData.value.entryPerson || "";
@@ -856,7 +928,16 @@
    // 设置日期选择器的值
    if (editData.value.executionDate) {
      pickerDateValue.value = editData.value.executionDate;
      const ts = new Date(
        String(editData.value.executionDate).replace(/-/g, "/")
      ).getTime();
      pickerDateValue.value = Number.isFinite(ts) ? ts : Date.now();
    }
    if (editData.value.deliveryDate) {
      const ts = new Date(
        String(editData.value.deliveryDate).replace(/-/g, "/")
      ).getTime();
      deliveryDateValue.value = Number.isFinite(ts) ? ts : Date.now();
    }
  };
  const getUserList = () => {