huminmin
4 天以前 5952d34811ee82e797ef0070f84ff041381072a5
src/views/procurementManagement/purchaseReturnOrder/New.vue
@@ -3,10 +3,14 @@
    <el-dialog
        v-model="isShow"
        title="新增采购退货"
        width="1200"
        width="1600"
        @close="closeModal"
    >
      <el-form label-width="140px" :model="formState" label-position="top" ref="formRef" :inline="true">
        <div class="section-title">
          <span class="title-dot"></span>
          <span class="title-text">基本信息</span>
        </div>
        <el-form-item
            label="退料单号"
            prop="no"
@@ -231,78 +235,138 @@
        >
          <el-input v-model="formState.remark" type="textarea" placeholder="请输入备注"/>
        </el-form-item>
      </el-form>
      <el-button type="primary" size="small" style="margin-bottom: 10px;" @click="isShowProductsModal = true" :disabled="!formState.purchaseLedgerId">添加产品</el-button>
      <el-table :data="products" border>
        <el-table-column align="center"
                         type="selection"
                         width="55" />
        <el-table-column align="center"
                         label="序号"
                         type="index"
                         width="60" />
        <el-table-column label="产品大类"
                         prop="productCategory" />
        <el-table-column label="规格型号"
                         prop="specificationModel" />
        <el-table-column label="单位"
                         prop="unit"
                         width="70" />
        <el-table-column label="数量"
                         prop="quantity"
                         width="70" />
        <el-table-column label="库存预警数量"
                         prop="warnNum"
                         width="120"
                         show-overflow-tooltip />
        <el-table-column label="税率(%)"
                         prop="taxRate"
                         width="80" />
        <el-table-column label="含税单价(元)"
                         prop="taxInclusiveUnitPrice"
                         :formatter="formattedNumber"
                         width="150" />
        <el-table-column label="含税总价(元)"
                         prop="taxInclusiveTotalPrice"
                         :formatter="formattedNumber"
                         width="150" />
        <el-table-column label="不含税总价(元)"
                         prop="taxExclusiveTotalPrice"
                         :formatter="formattedNumber"
                         width="150" />
        <el-table-column label="是否质检"
                         prop="isChecked"
                         width="150">
          <template #default="scope">
            <el-tag :type="scope.row.isChecked ? 'success' : 'info'">
              {{ scope.row.isChecked ? '是' : '否' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column fixed="right"
                         label="操作"
                         width="120"
                         align="center">
          <template #default="scope">
            <el-button
              link
              type="primary"
              size="small"
            >
              编辑
            </el-button>
            <el-button
                link
                type="danger"
                size="small"
                @click="delProduct(scope.$index)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
        <div style="margin: 20px 0;">
            <div class="section-title">
              <span class="title-dot"></span>
              <span class="title-text">产品列表</span>
            </div>
            <el-button type="primary" size="small" style="margin-bottom: 20px" @click="isShowProductsModal = true" :disabled="!formState.purchaseLedgerId">添加产品</el-button>
            <el-table :data="formState.purchaseReturnOrderProductsDtos"
                      border
                      max-height="400"
                      :scroll-y="true"
                      show-summary
                      :summary-method="summarizeChildrenTable">
              <el-table-column align="center"
                               type="selection"
                               width="55" />
              <el-table-column align="center"
                               label="序号"
                               type="index"
                               width="60" />
              <el-table-column label="产品大类"
                               prop="productCategory" />
              <el-table-column label="规格型号"
                               prop="specificationModel" />
              <el-table-column label="单位"
                               prop="unit"
                               width="70" />
              <el-table-column label="数量"
                               prop="quantity"
                               width="70" />
              <el-table-column label="退货数量"
                               prop="returnQuantity"
                               width="180">
                <template #default="scope">
                  <el-input-number v-model="scope.row.returnQuantity"
                            controls-position="right"
                            :step="1"
                            :min="1"
                            :max="scope.row.quantity"
                            required
                            placeholder="请输入退货数量" />
                </template>
              </el-table-column>
              <el-table-column label="库存预警数量"
                               prop="warnNum"
                               width="120"
                               show-overflow-tooltip />
              <el-table-column label="税率(%)"
                               prop="taxRate"
                               width="80" />
              <el-table-column label="含税单价(元)"
                               prop="taxInclusiveUnitPrice"
                               :formatter="formattedNumber"
                               width="150" />
              <el-table-column label="含税总价(元)"
                               prop="taxInclusiveTotalPrice"
                               :formatter="formattedNumber"
                               width="150" />
              <el-table-column label="不含税总价(元)"
                               prop="taxExclusiveTotalPrice"
                               :formatter="formattedNumber"
                               width="150" />
              <el-table-column label="是否质检"
                               prop="isChecked"
                               width="150">
                <template #default="scope">
                  <el-tag :type="scope.row.isChecked ? 'success' : 'info'">
                    {{ scope.row.isChecked ? '是' : '否' }}
                  </el-tag>
                </template>
              </el-table-column>
              <el-table-column fixed="right"
                               label="操作"
                               width="100"
                               align="center">
                <template #default="scope">
                  <el-button
                      link
                      type="danger"
                      size="small"
                      @click="delProduct(scope.$index)"
                  >
                    删除
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        <div class="section-title">
          <span class="title-dot"></span>
          <span class="title-text">费用信息</span>
        </div>
        <el-form-item
            label="整单折扣额:"
            prop="totalDiscountAmount"
        >
          <el-input-number v-model="formState.totalDiscountAmount"
                           controls-position="right"
                           :step="0.01"
                           :precision="2"
                           style="width: 100%;"
                           @change="handleChangeTotalDiscountAmount"
                           placeholder="请输入整单折扣额"/>
        </el-form-item>
        <el-form-item
            label="整单折扣率:"
            prop="totalDiscountAmount"
        >
          <el-input-number v-model="formState.totalDiscountRate"
                           controls-position="right"
                           :step="0.01"
                           :precision="2"
                           style="width: 100%;"
                           placeholder="请输入整单折扣率"/>
        </el-form-item>
        <el-form-item
            label="成交金额:"
            prop="totalAmount"
        >
          <el-input-number v-model="formState.totalAmount"
                           controls-position="right"
                           :step="0.01"
                           :precision="2"
                           style="width: 100%;"
                           @change="handleChangeTotalAmount"
                           placeholder="请输入成交金额"/>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="handleSubmit">确认</el-button>
@@ -349,6 +413,10 @@
  preparedUserId: undefined,
  returnUserId: undefined,
  purchaseLedgerId: undefined,
  purchaseReturnOrderProductsDtos: [],
  totalDiscountAmount: 0,
  totalDiscountRate: undefined,
  totalAmount: 0,
});
// 供应商选项
const supplierOptions = ref([])
@@ -381,8 +449,6 @@
const userOptions = ref([])
// 采购台账选项
const purchaseLedgerOptions = ref([])
// 产品列表数据
const products = ref([])
// 是否展示产品列表数据
const isShowProductsModal = ref(false)
@@ -402,6 +468,31 @@
const closeModal = () => {
  isShow.value = false;
};
const summarizeChildrenTable = (param) => {
  return proxy.summarizeTable(
      param,
      [
        "quantity",
        "returnQuantity",
        "taxInclusiveUnitPrice",
        "taxInclusiveTotalPrice",
        "taxExclusiveTotalPrice",
      ],
      {
        quantity: { noDecimal: true }, // 不保留小数
        returnQuantity: { noDecimal: true }, // 不保留小数
      }
  );
};
const handleChangeTotalDiscountAmount= () => {
  formState.value.totalAmount = formState.value.totalDiscountAmount * -1
}
const handleChangeTotalAmount= () => {
  formState.value.totalDiscountAmount = formState.value.totalAmount * -1
}
// 获取供应商选项
const fetchSupplierOptions = () => {
@@ -449,7 +540,7 @@
// 处理改变采购台账数据
const handleChangePurchaseLedgerId = () => {
  products.value = []
  formState.value.purchaseReturnOrderProductsDtos = []
}
// 处理改变是否默认编号
@@ -461,16 +552,29 @@
// 增加产品
const handleAddProduct = (selectedRows) => {
  products.value.push(...selectedRows)
  const existingIds = new Set(formState.value.purchaseReturnOrderProductsDtos.map(item => item.id));
  const newProducts = selectedRows.filter(item => !existingIds.has(item.id)).map(item => ({
    ...item,
    returnQuantity: undefined,
    salesLedgerProductId: item.id,
  }));
  formState.value.purchaseReturnOrderProductsDtos.push(...newProducts);
}
// 删除单项产品
const delProduct = (index) => {
  products.value.splice(index, 1)
  formState.value.purchaseReturnOrderProductsDtos.splice(index, 1)
}
// 提交表单
const handleSubmit = () => {
  // 验证退货数量
  const hasEmptyReturnQuantity = formState.value.purchaseReturnOrderProductsDtos.some(item => !item.returnQuantity || item.returnQuantity <= 0);
  if (hasEmptyReturnQuantity) {
    proxy.$modal.msgError("请为所有产品填写退货数量");
    return;
  }
  proxy.$refs["formRef"].validate(valid => {
    if (valid) {
      createPurchaseReturnOrder(formState.value).then(res => {
@@ -490,3 +594,25 @@
  isShow,
});
</script>
<style scoped lang="scss">
.section-title {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  font-size: 16px;
  font-weight: 600;
  color: #303133;
  width: 100%;
  clear: both;
}
.title-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background-color: #409EFF;
  border-radius: 50%;
  margin-right: 8px;
}
</style>