您的位置:首页 >如何使用PHP和Vue开发仓库管理的供应商管理功能
发布于2023-10-08 阅读(0)
扫一扫,手机访问
标题:使用PHP和Vue开发仓库管理的供应商管理功能
前言:
在现代企业中,仓库管理和供应商管理是非常重要的环节。仓库管理涉及到对物品的入库、出库、库存等操作,而供应商管理则是指对供应商信息的管理,包括添加、编辑、删除、查询等功能。本文将介绍如何使用PHP和Vue来开发仓库管理的供应商管理功能,并提供具体的代码示例。
一、环境准备
二、数据库设计
在MySQL数据库中创建两张表:warehouse和supplier。
warehouse表用于存储仓库的信息,包括仓库ID、仓库名称、仓库地址等字段。
supplier表用于存储供应商的信息,包括供应商ID、供应商名称、联系人、联系电话等字段。
三、后端开发
编写获取供应商列表的代码,其中使用PDO连接数据库,并执行SQL语句获取供应商列表信息。将结果以JSON格式返回给前端。
示例代码如下:
<?php
// 获取供应商列表
$db = new PDO("mysql:host=localhost;dbname=test", "username", "password");
$stmt = $db->prepare("SELECT * FROM supplier");
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($result);
?>编写添加供应商的代码,前端通过POST请求将供应商信息发送到supplier.php,后端将数据插入数据库。
示例代码如下:
<?php
// 添加供应商
$db = new PDO("mysql:host=localhost;dbname=test", "username", "password");
$stmt = $db->prepare("INSERT INTO supplier (name, contact, phone) VALUES (?, ?, ?)");
$stmt->bindParam(1, $_POST['name']);
$stmt->bindParam(2, $_POST['contact']);
$stmt->bindParam(3, $_POST['phone']);
$stmt->execute();
?>编写编辑供应商的代码,前端通过POST请求将供应商信息发送到supplier.php,后端根据供应商ID更新数据库中对应的数据。
示例代码如下:
<?php
// 编辑供应商
$db = new PDO("mysql:host=localhost;dbname=test", "username", "password");
$stmt = $db->prepare("UPDATE supplier SET name=?, contact=?, phone=? WHERE id=?");
$stmt->bindParam(1, $_POST['name']);
$stmt->bindParam(2, $_POST['contact']);
$stmt->bindParam(3, $_POST['phone']);
$stmt->bindParam(4, $_POST['id']);
$stmt->execute();
?>编写删除供应商的代码,前端通过POST请求将供应商ID发送到supplier.php,后端根据供应商ID删除数据库中对应的数据。
示例代码如下:
<?php
// 删除供应商
$db = new PDO("mysql:host=localhost;dbname=test", "username", "password");
$stmt = $db->prepare("DELETE FROM supplier WHERE id=?");
$stmt->bindParam(1, $_POST['id']);
$stmt->execute();
?>四、前端开发
在该组件中,使用axios发送请求获取供应商列表,并将数据存放在变量suppliers中。
示例代码如下:
<template>
<div>
<table>
<tr v-for="supplier in suppliers" :key="supplier.id">
<td>{{ supplier.name }}</td>
<td>{{ supplier.contact }}</td>
<td>{{ supplier.phone }}</td>
</tr>
</table>
</div>
</template>
<script>
import axios from 'axios';
export default {
data() {
return {
suppliers: []
};
},
mounted() {
axios.get('supplier.php').then(response => {
this.suppliers = response.data;
});
}
};
</script>在组件中添加添加、编辑和删除供应商的功能。通过axios发送POST请求将相应的数据发送到supplier.php。
示例代码如下:
<template>
<div>
<!-- 添加供应商 -->
<input type="text" v-model="name" placeholder="供应商名称">
<input type="text" v-model="contact" placeholder="联系人">
<input type="text" v-model="phone" placeholder="联系电话">
<button @click="addSupplier">添加供应商</button>
<!-- 编辑供应商 -->
<input type="text" v-model="editName" placeholder="供应商名称">
<input type="text" v-model="editContact" placeholder="联系人">
<input type="text" v-model="editPhone" placeholder="联系电话">
<button @click="editSupplier">编辑供应商</button>
<!-- 删除供应商 -->
<input type="text" v-model="deleteId" placeholder="供应商ID">
<button @click="deleteSupplier">删除供应商</button>
<!-- 展示供应商列表 -->
<table>
<tr v-for="supplier in suppliers" :key="supplier.id">
<td>{{ supplier.name }}</td>
<td>{{ supplier.contact }}</td>
<td>{{ supplier.phone }}</td>
</tr>
</table>
</div>
</template>
<script>
import axios from 'axios';
export default {
data() {
return {
name: '',
contact: '',
phone: '',
editName: '',
editContact: '',
editPhone: '',
deleteId: '',
suppliers: []
};
},
mounted() {
this.getSuppliers();
},
methods: {
getSuppliers() {
axios.get('supplier.php').then(response => {
this.suppliers = response.data;
});
},
addSupplier() {
axios.post('supplier.php', {
name: this.name,
contact: this.contact,
phone: this.phone
}).then(response => {
this.getSuppliers();
});
},
editSupplier() {
axios.post('supplier.php', {
id: this.editId,
name: this.editName,
contact: this.editContact,
phone: this.editPhone
}).then(response => {
this.getSuppliers();
});
},
deleteSupplier() {
axios.post('supplier.php', {
id: this.deleteId
}).then(response => {
this.getSuppliers();
});
}
}
};
</script>以上就是使用PHP和Vue开发仓库管理的供应商管理功能的具体代码示例。通过这些示例代码,我们可以实现供应商的添加、编辑、删除和查询等功能,提高仓库管理的效率和准确性。当然,这只是一个简单的示例,实际开发中可能还需要添加一些功能和做一些完善。希望本文对您有所帮助!
下一篇:win10自带输入法怎么进行设置
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
正版软件
正版软件
正版软件
正版软件
正版软件
1
2
3
7
9