標題:使用PHP和Vue開發(fā)倉庫管理的供應商管理功能
前言:
在現(xiàn)代企業(yè)中,倉庫管理和供應商管理是非常重要的環(huán)節(jié)。倉庫管理涉及到對物品的入庫、出庫、庫存等操作,而供應商管理則是指對供應商信息的管理,包括添加、編輯、刪除、查詢等功能。本文將介紹如何使用PHP和Vue來開發(fā)倉庫管理的供應商管理功能,并提供具體的代碼示例。
一、環(huán)境準備
- 所需工具:PHP、Vue.js、MySQL等需要安裝相關(guān)的PHP擴展(如PDO擴展)和Vue.js插件(如axios)
二、數(shù)據(jù)庫設(shè)計
在MySQL數(shù)據(jù)庫中創(chuàng)建兩張表:warehouse和supplier。
warehouse表用于存儲倉庫的信息,包括倉庫ID、倉庫名稱、倉庫地址等字段。
supplier表用于存儲供應商的信息,包括供應商ID、供應商名稱、聯(lián)系人、聯(lián)系電話等字段。
三、后端開發(fā)
- 創(chuàng)建PHP文件,命名為supplier.php,用于處理供應商相關(guān)的請求。
編寫獲取供應商列表的代碼,其中使用PDO連接數(shù)據(jù)庫,并執(zhí)行SQL語句獲取供應商列表信息。將結(jié)果以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請求將供應商信息發(fā)送到supplier.php,后端將數(shù)據(jù)插入數(shù)據(jù)庫。
示例代碼如下:
<?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請求將供應商信息發(fā)送到supplier.php,后端根據(jù)供應商ID更新數(shù)據(jù)庫中對應的數(shù)據(jù)。
示例代碼如下:
<?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發(fā)送到supplier.php,后端根據(jù)供應商ID刪除數(shù)據(jù)庫中對應的數(shù)據(jù)。
示例代碼如下:
<?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(); ?>
登錄后復制
四、前端開發(fā)
- 在Vue.js項目中創(chuàng)建一個供應商管理的組件,命名為SupplierManagement.vue。
在該組件中,使用axios發(fā)送請求獲取供應商列表,并將數(shù)據(jù)存放在變量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發(fā)送POST請求將相應的數(shù)據(jù)發(fā)送到supplier.php。
示例代碼如下:
<template> <div> <!-- 添加供應商 --> <input type="text" v-model="name" placeholder="供應商名稱"> <input type="text" v-model="contact" placeholder="聯(lián)系人"> <input type="text" v-model="phone" placeholder="聯(lián)系電話"> <button @click="addSupplier">添加供應商</button> <!-- 編輯供應商 --> <input type="text" v-model="editName" placeholder="供應商名稱"> <input type="text" v-model="editContact" placeholder="聯(lián)系人"> <input type="text" v-model="editPhone" placeholder="聯(lián)系電話"> <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開發(fā)倉庫管理的供應商管理功能的具體代碼示例。通過這些示例代碼,我們可以實現(xiàn)供應商的添加、編輯、刪除和查詢等功能,提高倉庫管理的效率和準確性。當然,這只是一個簡單的示例,實際開發(fā)中可能還需要添加一些功能和做一些完善。希望本文對您有所幫助!
以上就是如何使用PHP和Vue開發(fā)倉庫管理的供應商管理功能的詳細內(nèi)容,更多請關(guān)注www.92cms.cn其它相關(guān)文章!