


How to use PHP and Vue to develop price management functions for warehouse management
How to use PHP and Vue to develop the price management function of warehouse management
In modern logistics warehousing management, price management is a crucial function. It can help warehouse managers and logistics personnel accurately manage the pricing information of inventory items for reasonable pricing and profit control of goods. This article will introduce how to use PHP and Vue to develop the price management function in the warehouse management system, and provide specific code examples.
1. Preparation
Before you start, make sure you have installed the development environment of PHP and Vue. You can use any code editor you like to write code.
2. Create a database table
First, we need to create a database table to store price information. Suppose our table is named prices
and contains the following fields:
-
id
: the unique identifier of the price record, auto-increment type -
product_name
: Product name, string type -
#price
: Price, floating point type -
created_at
: Record creation Time, date time type -
updated_at
: Record update time, date time type
You can use the following SQL statement to create a database table:
CREATE TABLE `prices` ( `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `product_name` VARCHAR(255) NOT NULL, `price` FLOAT NOT NULL, `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=INNODB;
3. Writing the back-end interface
Next, we need to use PHP to write the back-end interface to handle the price management function. Create a PHP file price.php
and add the following code:
<?php header('Content-Type: application/json'); // 连接数据库 $servername = "localhost"; $username = "root"; $password = "password"; $dbname = "your_database_name"; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // 获取所有价格记录 if ($_SERVER['REQUEST_METHOD'] === 'GET') { $sql = "SELECT * FROM `prices`"; $result = $conn->query($sql); if ($result->num_rows > 0) { $prices = []; while ($row = $result->fetch_assoc()) { $prices[] = $row; } echo json_encode($prices); } else { echo "[]"; } } // 添加价格记录 if ($_SERVER['REQUEST_METHOD'] === 'POST') { $product_name = $_POST['product_name']; $price = $_POST['price']; $sql = "INSERT INTO `prices` (`product_name`, `price`) VALUES ('$product_name', '$price')"; if ($conn->query($sql) === TRUE) { echo "Price record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } } // 更新价格记录 if ($_SERVER['REQUEST_METHOD'] === 'PUT') { parse_str(file_get_contents("php://input"), $put_vars); $id = $put_vars['id']; $product_name = $put_vars['product_name']; $price = $put_vars['price']; $sql = "UPDATE `prices` SET `product_name`='$product_name', `price`='$price', `updated_at`=CURRENT_TIMESTAMP WHERE `id`='$id'"; if ($conn->query($sql) === TRUE) { echo "Price record updated successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } } // 删除价格记录 if ($_SERVER['REQUEST_METHOD'] === 'DELETE') { parse_str(file_get_contents("php://input"), $delete_vars); $id = $delete_vars['id']; $sql = "DELETE FROM `prices` WHERE `id`='$id'"; if ($conn->query($sql) === TRUE) { echo "Price record deleted successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } } $conn->close(); ?>
Make sure to replace your_database_name
with your database name and modify the database connection information as needed.
4. Writing the front-end page
We will use Vue to write the front-end page. Create an HTML file index.html
and add the following code:
<!DOCTYPE html> <html> <head> <title>价格管理</title> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> </head> <body> <div id="app"> <h1 id="价格管理">价格管理</h1> <form @submit.prevent="addPrice"> <input type="text" placeholder="产品名称" v-model="newPrice.product_name" required> <input type="number" step="0.01" placeholder="价格" v-model="newPrice.price" required> <button type="submit">添加</button> </form> <table> <thead> <tr> <th>产品名称</th> <th>价格</th> <th>操作</th> </tr> </thead> <tbody> <tr v-for="price in prices" :key="price.id"> <td>{{ price.product_name }}</td> <td>{{ price.price }}</td> <td> <button @click="editPrice(price)">编辑</button> <button @click="deletePrice(price)">删除</button> </td> </tr> </tbody> </table> </div> <script> new Vue({ el: '#app', data: { prices: [], newPrice: { product_name: '', price: '' }, editPrice: { id: '', product_name: '', price: '' } }, created: function() { this.getPrices(); }, methods: { getPrices: function() { axios.get('price.php') .then(function(response) { this.prices = response.data; }.bind(this)) .catch(function(error) { console.log(error); }); }, addPrice: function() { axios.post('price.php', this.newPrice) .then(function(response) { console.log(response.data); this.getPrices(); this.newPrice.product_name = ''; this.newPrice.price = ''; }.bind(this)) .catch(function(error) { console.log(error); }); }, editPrice: function(price) { this.editPrice.id = price.id; this.editPrice.product_name = price.product_name; this.editPrice.price = price.price; }, updatePrice: function() { axios.put('price.php', this.editPrice) .then(function(response) { console.log(response.data); this.getPrices(); this.editPrice.id = ''; this.editPrice.product_name = ''; this.editPrice.price = ''; }.bind(this)) .catch(function(error) { console.log(error); }); }, deletePrice: function(price) { axios.delete('price.php', { data: price }) .then(function(response) { console.log(response.data); this.getPrices(); }.bind(this)) .catch(function(error) { console.log(error); }); } } }); </script> </body> </html>
5. Run the project
and change price.php
and index.html
Put the file into the website directory of your server and start the server. Then open the browser and visit index.html
, and you will see a simple price management page.
On the page, you can enter the product name and price, and click the Add button to add a new price record. Click the Edit button to modify the price record information. Click the Delete button to delete the price record.
6. Summary
In this article, we used PHP and Vue to develop the price management function in a simple warehouse management system. Through this function, warehouse administrators can easily manage product pricing information and achieve reasonable pricing and profit control. By writing the back-end interface and front-end page, we show how to use PHP and Vue to implement this function, and provide detailed code examples. Hope this article is helpful to you!
The above is the detailed content of How to use PHP and Vue to develop price management functions for warehouse management. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

You can add a function to the Vue button by binding the button in the HTML template to a method. Define the method and write function logic in the Vue instance.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

The future of PHP will be achieved by adapting to new technology trends and introducing innovative features: 1) Adapting to cloud computing, containerization and microservice architectures, supporting Docker and Kubernetes; 2) introducing JIT compilers and enumeration types to improve performance and data processing efficiency; 3) Continuously optimize performance and promote best practices.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.
