<template>
|
<div class="app-container">
|
<div class="search_form">
|
<el-form :model="searchForm" :inline="true">
|
<el-form-item label="销售订单号:">
|
<el-input v-model="searchForm.salesContractNo" placeholder="请输入" clearable prefix-icon="Search"
|
@change="handleQuery" />
|
</el-form-item>
|
<el-form-item label="车牌号:">
|
<el-input v-model="searchForm.shippingCarNumber" placeholder="请输入" clearable prefix-icon="Search"
|
@change="handleQuery" />
|
</el-form-item>
|
<el-form-item>
|
<el-button type="primary" @click="handleQuery"> 搜索 </el-button>
|
</el-form-item>
|
</el-form>
|
</div>
|
<div class="table_list">
|
<div class="actions">
|
<div></div>
|
<div>
|
<el-button @click="handleOut">导出</el-button>
|
<el-button type="danger" plain @click="handleDelete">删除</el-button>
|
</div>
|
</div>
|
<el-table :data="tableData" border v-loading="tableLoading" @selection-change="handleSelectionChange"
|
:row-key="(row) => row.id" style="width: 100%" height="calc(100vh - 18.5em)">
|
<el-table-column align="center" type="selection" width="55" />
|
<el-table-column align="center" label="序号" type="index" width="60" />
|
<el-table-column label="销售订单" prop="salesContractNo" show-overflow-tooltip />
|
<el-table-column label="客户名称" prop="customerName" show-overflow-tooltip />
|
<el-table-column label="发货时间" prop="shippingDate" show-overflow-tooltip />
|
<el-table-column label="发货车牌号" prop="shippingCarNumber" show-overflow-tooltip />
|
<el-table-column fixed="right" label="操作" width="150" align="center">
|
<template #default="scope">
|
<el-button link type="primary" size="small" @click="openForm('edit', scope.row)">编辑</el-button>
|
<el-button link type="danger" size="small" @click="handleDeleteSingle(scope.row)">删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
<pagination v-show="total > 0" :total="total" layout="total, sizes, prev, pager, next, jumper"
|
:page="page.current" :limit="page.size" @pagination="paginationChange" />
|
</div>
|
<el-dialog v-model="dialogFormVisible" :title="operationType === 'add' ? '新增发货台账' : '编辑发货台账'" width="50%"
|
@close="closeDia">
|
<el-form :model="form" label-width="120px" label-position="top" :rules="rules" ref="formRef">
|
<el-row :gutter="30">
|
<el-col :span="24">
|
<el-form-item label="销售订单:" prop="salesContractNo">
|
<el-select v-model="form.salesContractNo" placeholder="请选择" clearable filterable
|
@change="handleSalesOrderChange" style="width: 100%" :disabled="operationType === 'edit'">
|
<el-option v-for="item in salesOrderOptions" :key="item.salesContractNo"
|
:label="item.salesContractNo" :value="item.salesContractNo">
|
{{ item.salesContractNo + ' - ' + item.customerName }}
|
</el-option>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="30">
|
<el-col :span="24">
|
<el-form-item label="客户名称:" prop="customerName">
|
<el-input v-model="form.customerName" placeholder="请输入" clearable :disabled="operationType === 'edit'" />
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="30">
|
<el-col :span="24">
|
<el-form-item label="发货时间:" prop="shippingDate">
|
<el-date-picker style="width: 100%" v-model="form.shippingDate" value-format="YYYY-MM-DD"
|
format="YYYY-MM-DD" type="date" placeholder="请选择" clearable />
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="30">
|
<el-col :span="24">
|
<el-form-item label="发货车牌号:" prop="shippingCarNumber">
|
<el-input v-model="form.shippingCarNumber" placeholder="请输入" clearable />
|
</el-form-item>
|
</el-col>
|
</el-row>
|
|
</el-form>
|
<template #footer>
|
<div class="dialog-footer">
|
<el-button type="primary" @click="submitForm">确认</el-button>
|
<el-button @click="closeDia">取消</el-button>
|
</div>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script setup>
|
import pagination from "@/components/PIMTable/Pagination.vue";
|
import { onMounted, ref, reactive, toRefs, getCurrentInstance } from "vue";
|
import { ElMessageBox } from "element-plus";
|
import {
|
deliveryLedgerListPage,
|
addOrUpdateDeliveryLedger,
|
delDeliveryLedger,
|
} from "@/api/salesManagement/deliveryLedger.js";
|
|
|
const { proxy } = getCurrentInstance();
|
const tableData = ref([]);
|
const selectedRows = ref([]);
|
const tableLoading = ref(false);
|
const salesOrderOptions = ref([]);
|
const page = reactive({
|
current: 1,
|
size: 100,
|
});
|
const total = ref(0);
|
|
// 用户信息表单弹框数据
|
const operationType = ref("");
|
const dialogFormVisible = ref(false);
|
const data = reactive({
|
searchForm: {
|
salesContractNo: "", // 销售订单号
|
shippingCarNumber: "", // 车牌号
|
},
|
form: {
|
id: null,
|
salesContractNo: "",
|
customerName: "",
|
shippingDate: "",
|
shippingCarNumber: "",
|
},
|
rules: {
|
salesContractNo: [{ required: true, message: "请选择销售订单", trigger: "change" }],
|
customerName: [{ required: true, message: "请输入客户名称", trigger: "blur" }],
|
shippingDate: [{ required: true, message: "请选择发货时间", trigger: "change" }],
|
shippingCarNumber: [{ required: true, message: "请输入发货车牌号", trigger: "blur" }],
|
},
|
});
|
const { form, rules } = toRefs(data);
|
const { searchForm } = toRefs(data);
|
|
|
|
// 查询列表
|
const handleQuery = () => {
|
page.current = 1;
|
getList();
|
};
|
|
const paginationChange = (obj) => {
|
page.current = obj.page;
|
page.size = obj.limit;
|
getList();
|
};
|
|
const getList = () => {
|
tableLoading.value = true;
|
deliveryLedgerListPage({ ...searchForm.value, ...page })
|
.then((res) => {
|
tableLoading.value = false;
|
tableData.value = res.data.records || [];
|
total.value = res.data.total || 0;
|
})
|
.catch(() => {
|
tableLoading.value = false;
|
});
|
};
|
|
// 销售订单变化时自动填充客户名称
|
const handleSalesOrderChange = (value) => {
|
const selectedOrder = salesOrderOptions.value.find(item => item.salesContractNo === value);
|
if (selectedOrder) {
|
form.value.customerName = selectedOrder.customerName;
|
}
|
};
|
|
// 表格选择数据
|
const handleSelectionChange = (selection) => {
|
selectedRows.value = selection;
|
};
|
|
// 打开弹框
|
const openForm = async (type, row) => {
|
operationType.value = type;
|
if (type === 'edit' && row) {
|
form.value = {
|
id: row.id ?? null,
|
salesContractNo: row.salesContractNo ?? "",
|
customerName: row.customerName ?? "",
|
shippingDate: row.shippingDate || getCurrentDate(),
|
shippingCarNumber: row.shippingCarNumber ?? "",
|
};
|
} else {
|
form.value = {
|
id: null,
|
salesContractNo: "",
|
customerName: "",
|
shippingDate: getCurrentDate(),
|
shippingCarNumber: "",
|
};
|
}
|
|
dialogFormVisible.value = true;
|
};
|
|
// 提交表单
|
const submitForm = () => {
|
proxy.$refs["formRef"].validate((valid) => {
|
if (valid) {
|
const payload = {
|
id: form.value.id,
|
shippingDate: form.value.shippingDate,
|
shippingCarNumber: form.value.shippingCarNumber,
|
};
|
addOrUpdateDeliveryLedger(payload).then((res) => {
|
proxy.$modal.msgSuccess("操作成功");
|
closeDia();
|
getList();
|
});
|
}
|
});
|
};
|
|
// 关闭弹框
|
const closeDia = () => {
|
proxy.resetForm("formRef");
|
dialogFormVisible.value = false;
|
};
|
|
// 导出
|
const handleOut = () => {
|
ElMessageBox.confirm("选中的内容将被导出,是否确认导出?", "导出", {
|
confirmButtonText: "确认",
|
cancelButtonText: "取消",
|
type: "warning",
|
})
|
.then(() => {
|
proxy.download("/shippingInfo/export", {}, "发货台账.xlsx");
|
})
|
.catch(() => {
|
proxy.$modal.msg("已取消");
|
});
|
};
|
|
// 批量删除
|
const handleDelete = () => {
|
let ids = [];
|
if (selectedRows.value.length > 0) {
|
ids = selectedRows.value.map((item) => item.id);
|
} else {
|
proxy.$modal.msgWarning("请选择数据");
|
return;
|
}
|
ElMessageBox.confirm("选中的内容将被删除,是否确认删除?", "删除", {
|
confirmButtonText: "确认",
|
cancelButtonText: "取消",
|
type: "warning",
|
})
|
.then(() => {
|
delDeliveryLedger(ids).then((res) => {
|
proxy.$modal.msgSuccess("删除成功");
|
getList();
|
});
|
})
|
.catch(() => {
|
proxy.$modal.msg("已取消");
|
});
|
};
|
|
// 单个删除
|
const handleDeleteSingle = (row) => {
|
ElMessageBox.confirm("此操作将删除该记录,是否确认?", "删除", {
|
confirmButtonText: "确认",
|
cancelButtonText: "取消",
|
type: "warning",
|
})
|
.then(() => {
|
delDeliveryLedger([row.id]).then((res) => {
|
proxy.$modal.msgSuccess("删除成功");
|
getList();
|
});
|
})
|
.catch(() => {
|
proxy.$modal.msg("已取消");
|
});
|
};
|
|
// 获取当前日期并格式化为 YYYY-MM-DD
|
function getCurrentDate() {
|
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");
|
return `${year}-${month}-${day}`;
|
}
|
|
onMounted(() => {
|
getList();
|
});
|
</script>
|
|
<style scoped lang="scss">
|
.table_list {
|
margin-top: unset;
|
}
|
|
.actions {
|
display: flex;
|
justify-content: space-between;
|
margin-bottom: 10px;
|
}
|
</style>
|