liding
9 天以前 04ecdbfb7be63ca4a3d49d3575847e728e3e9ae7
src/views/inventoryManagement/dispatchLog/Record.vue
@@ -12,14 +12,24 @@
               clearable
               @change="handleQuery"
            />
        <span class="search_title ml10">来源:</span>
        <el-select v-model="searchForm.recordType"
                   style="width: 240px"
                   placeholder="请选择"
                   clearable>
          <el-option v-for="item in stockRecordTypeOptions"
                     :key="item.value"
                     :label="item.label"
                     :value="item.value"/>
        </el-select>
            <el-button type="primary" @click="handleQuery" style="margin-left: 10px"
            >搜索</el-button
            >
         </div>
         <div>
            <el-button @click="handleOut">导出</el-button>
            <el-button type="danger" plain @click="handleDelete">删除</el-button>
            <el-button type="primary" plain @click="handlePrint">打印</el-button>
            <el-button type="danger" plain @click="handleDelete" v-if="hasDispatchCancel">删除</el-button>
            <!-- <el-button type="primary" plain @click="handlePrint">打印</el-button> -->
         </div>
      </div>
      <div class="table_list">
@@ -32,46 +42,244 @@
            :row-key="(row) => row.id"
            style="width: 100%"
            height="calc(100vh - 18.5em)"
            :fit="true"
         >
            <el-table-column align="center" type="selection" width="55" />
            <el-table-column align="center" label="序号" type="index" width="60" />
        <el-table-column
            label="出库批次"
            prop="outboundBatches"
            min-width="100"
            show-overflow-tooltip
        />
            <el-table-column align="center" type="selection" min-width="55" fixed="left" />
            <el-table-column align="center" label="序号" type="index" min-width="60" fixed="left" />
            <el-table-column
               label="出库日期"
               prop="createTime"
               label="产品类型"
               prop="parentName"
               min-width="100"
               show-overflow-tooltip
            />
            <el-table-column
               label="产品大类"
               label="车牌号"
               prop="licensePlateNo"
               min-width="120"
               show-overflow-tooltip
            />
            <el-table-column
               label="产品名称"
               prop="productName"
               min-width="120"
               show-overflow-tooltip
            />
            <el-table-column
               label="规格型号"
               prop="model"
               show-overflow-tooltip
            />
            <el-table-column
               label="单位"
               prop="unit"
               min-width="150"
               show-overflow-tooltip
            />
            <el-table-column
               label="出库数量"
               prop="stockOutNum"
               min-width="100"
               show-overflow-tooltip
            />
            <el-table-column
               label="出库人"
               prop="createBy"
               label="毛重"
               prop="grossWeight"
               min-width="100"
               show-overflow-tooltip
            />
            <el-table-column
               label="皮重"
               prop="tareWeight"
               min-width="100"
               show-overflow-tooltip
            />
            <el-table-column
               label="净重"
               prop="netWeight"
               min-width="100"
               show-overflow-tooltip
            />
            <el-table-column
               label="单位"
               prop="unit"
               min-width="80"
               show-overflow-tooltip
            />
        <el-table-column
            label="过磅日期"
            prop="weighingDate"
            min-width="120"
            show-overflow-tooltip
        />
        <el-table-column
            label="过磅员"
            prop="weighingOperator"
            min-width="100"
            show-overflow-tooltip
        />
            <el-table-column
               label="出库人"
               prop="createBy"
               min-width="100"
               show-overflow-tooltip
            />
        <el-table-column
            label="出库批次"
            prop="outboundBatches"
            min-width="150"
            show-overflow-tooltip
        />
        <el-table-column
            label="出库时间"
            prop="createTime"
            min-width="160"
            show-overflow-tooltip
        />
        <el-table-column label="来源"
                         prop="recordType"
                         min-width="100"
                         show-overflow-tooltip>
          <template #default="scope">
            {{ getRecordType(scope.row.recordType) }}
          </template>
        </el-table-column>
            <el-table-column label="操作"
                         min-width="200"
                         align="center"
                         fixed="right">
          <template #default="scope">
            <el-button
              v-if="scope.row.recordType === '0' && hasDispatchEdit"
              type="primary"
              size="mini"
              @click="handleEdit(scope.row)"
            >编辑</el-button>
            <el-button
              v-if="scope.row.recordType === '0' && scope.row.parentName === '原材料'"
              type="primary"
              size="mini"
              @click="handlePreview(scope.row)"
            >导出过磅单</el-button>
          </template>
            </el-table-column>
         </el-table>
      <el-dialog
        v-model="isShowEditModal"
        title="编辑出库"
        width="800"
        @close="closeEditModal"
      >
        <el-form label-width="140px" :model="editForm" label-position="top" ref="editFormRef">
          <!-- 非原材料显示出库数量 -->
          <template v-if="editForm.parentName !== '原材料'">
            <el-form-item
              label="出库数量"
              prop="stockOutNum"
            >
              <el-input-number
                v-model="editForm.stockOutNum"
                :min="0"
                :step="1"
                :precision="0"
                controls-position="right"
                style="width: 100%"
              />
            </el-form-item>
          </template>
          <!-- 原材料显示过磅相关字段 -->
          <template v-if="editForm.parentName === '原材料'">
            <el-form-item
              label="车牌号"
              prop="licensePlateNo"
              :rules="[{ required: true, message: '请输入车牌号', trigger: ['blur','change'] }]"
            >
              <el-input v-model="editForm.licensePlateNo" />
            </el-form-item>
            <el-form-item
              label="单位"
              prop="unit"
            >
              <el-select
                v-model="editForm.unit"
                placeholder="请选择单位"
                style="width: 100%"
                clearable
              >
                <el-option label="吨" value="吨" />
                <el-option label="公斤" value="公斤" />
              </el-select>
            </el-form-item>
            <el-form-item
              label="毛重"
              prop="grossWeight"
              :rules="[{ required: true, message: '请输入毛重', trigger: ['blur','change'] }]"
            >
              <el-input-number
                v-model="editForm.grossWeight"
                :step="0.01"
                :min="0"
                style="width: 100%"
                @change="computeNetWeightEdit"
              />
            </el-form-item>
            <el-form-item
              label="皮重"
              prop="tareWeight"
              :rules="[{ required: true, message: '请输入皮重', trigger: ['blur','change'] }]"
            >
              <el-input-number
                v-model="editForm.tareWeight"
                :step="0.01"
                :min="0"
                style="width: 100%"
                @change="computeNetWeightEdit"
              />
            </el-form-item>
            <el-form-item
              label="净重"
              prop="netWeight"
              :rules="[{ required: true, message: '净重由毛重和皮重自动计算', trigger: ['blur','change'] }]"
            >
              <el-input-number
                v-model="editForm.netWeight"
                :step="0.01"
                :min="0"
                style="width: 100%"
                disabled
              />
            </el-form-item>
            <el-form-item
              label="过磅日期"
              prop="weighingDate"
              :rules="[{ required: true, message: '请选择过磅日期', trigger: 'change' }]"
            >
              <el-date-picker
                style="width: 100%"
                v-model="editForm.weighingDate"
                value-format="YYYY-MM-DD HH:mm:ss"
                format="YYYY-MM-DD HH:mm:ss"
                type="datetime"
                placeholder="请选择过磅日期"
                clearable
              />
            </el-form-item>
            <el-form-item
              label="过磅员"
              prop="weighingOperator"
              :rules="[{ required: true, message: '请输入过磅员', trigger: ['blur','change'] }]"
            >
              <el-input v-model="editForm.weighingOperator" />
            </el-form-item>
          </template>
        </el-form>
        <template #footer>
          <div class="dialog-footer">
            <el-button type="primary" @click="handleEditSubmit">确认</el-button>
            <el-button @click="closeEditModal">取消</el-button>
          </div>
        </template>
      </el-dialog>
         <pagination
            v-show="total > 0"
            :total="total"
@@ -86,20 +294,27 @@
<script setup>
import pagination from "@/components/PIMTable/Pagination.vue";
import { ref } from "vue";
import { ref, computed } from "vue";
import { ElMessageBox } from "element-plus";
import useUserStore from "@/store/modules/user";
import { getCurrentDate } from "@/utils/index.js";
import { checkPermi } from "@/utils/permission.js";
import {
   getStockOutPage,
   delStockOut,
  editStockOut,
} from "@/api/inventoryManagement/stockOut.js";
import {
  findAllQualifiedStockOutRecordTypeOptions, findAllUnQualifiedStockOutRecordTypeOptions,
} from "@/api/basicData/enum.js";
const userStore = useUserStore();
const { proxy } = getCurrentInstance();
const tableData = ref([]);
const selectedRows = ref([]);
const tableLoading = ref(false);
// 来源类型选项
const stockRecordTypeOptions = ref([]);
const page = reactive({
   current: 1,
   size: 100,
@@ -114,6 +329,9 @@
  }
})
const hasDispatchEdit = computed(() => checkPermi(['dispatch_edit']));
const hasDispatchCancel = computed(() => checkPermi(['dispatch_cancel']));
// 打印相关
const printPreviewVisible = ref(false);
const printData = ref([]);
@@ -123,26 +341,8 @@
   searchForm: {
      supplierName: "",
      timeStr: "",
   },
   form: {
      supplierId: null,
      supplierName: '',
      productId: null,
      productName: '',
      userId: userStore.userId,
      nickName: '',
      model: '',
      productModelId: null,
      unit: '',
      productrecordId: null,
      taxInclusiveUnitPrice: '',
      taxInclusiveTotalPrice: '',
      taxRate: '',
      taxExclusiveTotalPrice: '',
      inboundTime: '',
      inboundBatch: '',
      inboundQuantity: ''
   },
    recordType: "",
   }
});
const { searchForm } = toRefs(data);
@@ -173,6 +373,25 @@
      });
};
const getRecordType = (recordType) => {
  return stockRecordTypeOptions.value.find(item => item.value === recordType)?.label || ''
}
// 获取来源类型选项
const fetchStockRecordTypeOptions = () => {
  if (props.type === '0') {
    findAllQualifiedStockOutRecordTypeOptions()
        .then(res => {
          stockRecordTypeOptions.value = res.data;
        })
    return
  }
  findAllUnQualifiedStockOutRecordTypeOptions()
      .then(res => {
        stockRecordTypeOptions.value = res.data;
      })
}
// 表格选择数据
const handleSelectionChange = (selection) => {
   // 过滤掉子数据
@@ -180,6 +399,57 @@
   console.log("selection", selectedRows.value);
};
const expandedRowKeys = ref([]);
// 导出过磅单
const handlePreview = (row) => {
  proxy.$download.name(row.weighbridgeDocPath);
}
// 编辑出库
const isShowEditModal = ref(false);
const editFormRef = ref(null);
const editForm = ref({});
// 毛重 - 皮重 计算净重(保留两位小数,且不为负)
const computeNetWeightEdit = () => {
  const gross = Number(editForm.value?.grossWeight ?? NaN);
  const tare = Number(editForm.value?.tareWeight ?? NaN);
  if (Number.isFinite(gross) && Number.isFinite(tare)) {
    const net = gross - tare;
    const safeNet = Number(net.toFixed(2));
    editForm.value.netWeight = safeNet > 0 ? safeNet : 0;
  } else {
    editForm.value.netWeight = undefined;
  }
};
const handleEdit = (row) => {
  editForm.value = { ...row };
  computeNetWeightEdit();
  isShowEditModal.value = true;
};
const closeEditModal = () => {
  isShowEditModal.value = false;
  editForm.value = {};
  editFormRef.value?.clearValidate?.();
};
const handleEditSubmit = () => {
  editFormRef.value?.validate?.((valid) => {
    if (!valid) return;
    const submitData = {
      ...editForm.value,
      productType: editForm.value.parentName === '原材料' ? 0 : 1,
      netWeight: editForm.value.parentName === '原材料' ? editForm.value.netWeight : editForm.value.stockOutNum
    };
    editStockOut(submitData).then(() => {
      closeEditModal();
      proxy.$modal.msgSuccess("编辑成功");
      getList();
    });
  });
};
// 导出
const handleOut = () => {
@@ -189,7 +459,7 @@
      type: "warning",
   })
      .then(() => {
         proxy.download("/stockmanagement/export", {}, "出库台账.xlsx");
         proxy.download("/stockOutRecord/exportStockOutRecord", {type: props.type}, props.type === '0' ? "合格出库台账.xlsx" : "不合格出库台账.xlsx");
      })
      .catch(() => {
         proxy.$modal.msg("已取消");
@@ -512,6 +782,7 @@
};
onMounted(() => {
   getList();
  fetchStockRecordTypeOptions();
});
</script>