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