当前位置: 首页 > news >正文

仓库物品带下拉提示搜索与开单自定义数量和备注带提交反馈单页功能

搜索:带下拉提示 可关闭 超数量可下滑;输入停顿后查询以减少请求

表单,自定义数量和备注,自动计价...

 

<?php
/*
以下为csv文件:Yao.table.jijia.csv 示范数据:
code,中文名,英文名,单价,计价单位,备注
X001,阿司匹林,Aspirin,0.5,片,用于缓解轻中度疼痛
X002,布洛芬,Ibuprofen,0.7,片,缓解炎症和疼痛
X003,氯雷他定,Loratadine,1.0,片,缓解过敏症状
X004,阿司匹林4,Aspirin,0.5,片,用于缓解轻中度疼痛
X005,布洛芬5,Ibuprofen,0.7,片,缓解炎症和疼痛
X006,氯雷他定6,Loratadine,1.0,片,缓解过敏症状
X007,阿司匹林7,Aspirin,0.5,片,用于缓解轻中度疼痛
*/if($_GET["act"]=="cha"){
setlocale(LC_ALL, 'C'); //window:删除行首双斜杠
header('Content-Type: application/json; charset=UTF-8');
$query = $_GET['query'] ?? '';
// 读取 CSV 文件并进行药名查询
$data = [];
if (($handle = fopen('Yao.table.jijia.csv', 'r')) !== FALSE) {while (($row = fgetcsv($handle, 1000, ',')) !== FALSE) {if (strpos($row[1], $query) !== FALSE) {$data[] = ['code' => $row[0],'中文名' => $row[1],'英文名' => $row[2],'单价' => $row[3],'单位' => $row[4],'备注' => $row[5]];}}fclose($handle);
}
echo json_encode(array_slice($data, 0, 10)); // 最多返回10条exit();
}
if($_GET["act"]=="ti"){
header('Content-Type: application/json; charset=UTF-8');
$data = json_decode(file_get_contents('php://input'), true);
echo json_encode($data); exit();
}?>
<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><title>药单开具页面</title><style>body {font-family: Arial, sans-serif;padding: 10px;background-color: #f4f4f9;}#top-bar {display: flex;gap: 5px;margin-bottom: 10px;position: relative;}input {width: 99%;line-height: 28px;}#medicine-list {position: absolute;top: 28px;width: 280px;background-color: white;border: 1px solid #ddd;max-height: 280px;overflow-y: auto;display: none;z-index: 1;}#medicine-list div {padding: 5px;cursor: pointer;position: relative;}#medicine-list div:hover {background-color: #f0f0f0;}#medicine-list .close-btn {position: absolute;right: 5px;color: red;cursor: pointer;font-weight: bold;z-index: 3;}table {width: 100%;border-collapse: collapse;margin: 20px 0;}table, th, td {border: 1px solid #ddd;padding: 2px;}th {background-color: #f4f4f4;text-align: left;}.text-right {text-align: right;}.text-center {text-align: center;}.text-gray {color: #888;}.bta {margin-top: 0px;padding: 8px 12px;background-color: #198754;color: white;border: none;cursor: pointer;min-width: 80px;border-radius: 5px;}.btn {margin: 0;padding: 8px 12px;background-color: red;color: white;border: none;cursor: pointer;border-radius: 5px;}.hidden {display: none;}</style>
</head>
<body>
<div id="top-bar"><input type="text" id="medicine-input" placeholder="输入药名"><button onclick="addMedicine()" class='bta'>添加</button><button onclick="window.location.reload()" class='bta'>新开</button><div id="medicine-list"></div>
</div><table id="medicine-table"><thead><tr><th>药品代码</th><th>药名</th><th>数量</th><th>单价</th><th>金额</th><th>用药备注</th><th>操作</th></tr></thead><tbody id="medicine-body"><!-- 动态生成的药品行 --></tbody><tfoot><tr><td colspan="4" class="text-right">总价:</td><td id="total-price" class="text-center">0.00</td><td colspan="2"></td></tr></tfoot>
</table><button id="submit-btn" class="bta" onclick="submitMedicineForm()">提交</button><script>let medicines = []; // 存储获取到的药品列表let selectedMedicines = {}; // 选择的药品信息let searchTimeout;// 延迟查询药名列表document.getElementById('medicine-input').addEventListener('input', function () {clearTimeout(searchTimeout);searchTimeout = setTimeout(fetchMedicineList, 500);});// 获取药名列表function fetchMedicineList() {const query = document.getElementById('medicine-input').value;if (query.length < 1) {document.getElementById('medicine-list').style.display = 'none';return;}fetch('?act=cha&query=' + encodeURIComponent(query)).then(response => response.json()).then(data => {medicines = data;showMedicineList();});}// 显示药名提示列表function showMedicineList() {const listContainer = document.getElementById('medicine-list');listContainer.innerHTML = `<div class="close-btn" onclick="closeMedicineList()">×</div>`;medicines.forEach(med => {const item = document.createElement('div');item.innerText = med.中文名;item.onclick = () => {document.getElementById('medicine-input').value = med.中文名;listContainer.style.display = 'none';};listContainer.appendChild(item);});listContainer.style.display = 'block';}// 关闭药名提示列表function closeMedicineList() {document.getElementById('medicine-list').style.display = 'none';}// 添加药品到计价表function addMedicine() {const name = document.getElementById('medicine-input').value;const medicine = medicines.find(m => m.中文名 === name);if (!medicine || selectedMedicines[medicine.code]) return; // 防止重复添加selectedMedicines[medicine.code] = medicine;const row = document.createElement('tr');row.id = `row-${medicine.code}`;row.innerHTML = `<td>${medicine.code}</td><td>${medicine.中文名}</td><td><input type="number" value="1" min="1" onchange="updateAmount('${medicine.code}', this.value)"></td><td class="text-right">${medicine.单价}</td><td id="amount-${medicine.code}" class="text-right">${medicine.单价}</td><td><input type="text" value="${medicine.备注}" onchange="updateRemark('${medicine.code}', this.value)"></td><td class="text-center"><button onclick="removeMedicine('${medicine.code}')" class='btn'>删</button></td>`;document.getElementById('medicine-body').appendChild(row);updateTotalPrice();}// 更新单个药品的金额function updateAmount(code, quantity) {const medicine = selectedMedicines[code];const amount = parseFloat(medicine.单价) * parseInt(quantity);document.getElementById(`amount-${code}`).innerText = amount.toFixed(2);updateTotalPrice();}// 更新单个药品备注function updateRemark(code, remark) {selectedMedicines[code].备注 = remark;}// 删除药品并更新总价function removeMedicine(code) {delete selectedMedicines[code];document.getElementById(`row-${code}`).remove();updateTotalPrice();}// 更新总价function updateTotalPrice() {let total = 0;for (const code in selectedMedicines) {const rowAmount = document.getElementById(`amount-${code}`);total += parseFloat(rowAmount.innerText);}document.getElementById('total-price').innerText = total.toFixed(2);}// 提交药单function submitMedicineForm() {const formData = [];for (const code in selectedMedicines) {const quantity = document.querySelector(`input[type="number"][onchange="updateAmount('${code}', this.value)"]`).value;formData.push({code,name: selectedMedicines[code].中文名,quantity,price: selectedMedicines[code].单价,amount: (quantity * selectedMedicines[code].单价).toFixed(2),remark: selectedMedicines[code].备注});}fetch('?act=ti&tt=tt', {method: 'POST',headers: {'Content-Type': 'application/json'},body: JSON.stringify(formData)}).then(response => response.json()).then(data => {//alert('提交成功!');document.getElementById('medicine-table').innerHTML = generateFinalTable(data);document.getElementById('submit-btn').style.display = 'none';});}// 显示提交后无输入表单及总价function generateFinalTable(data) {let total = 0;let table = `<thead><tr><th>药品代码</th><th>药名</th><th>数量</th><th>单价</th><th>金额</th><th>用药备注</th></tr></thead><tbody>`;data.forEach(item => {total += parseFloat(item.amount);table += `<tr><td>${item.code}</td><td>${item.name}</td><td>${item.quantity}</td><td class="text-right">${item.price}</td><td class="text-right">${item.amount}</td><td>${item.remark}</td></tr>`;});table += `<tfoot><tr><td colspan="4" class="text-right">总价:</td><td class="text-center">${total.toFixed(2)}</td><td></td></tr></tfoot>`;table += `</tbody>`;return table;}
</script></body>
</html>

 


http://www.mrgr.cn/news/63341.html

相关文章:

  • COMSOL细观混凝土砂浆及界面过渡区受压损伤破坏
  • Java集合使用注意事项总结
  • vite乾坤 vite-plugin-qiankun 报错 ReferenceError: ReadableStream is not defined
  • Android 音量调节流程分析
  • nmcli、ip、ifcfg配置网络区分方法
  • 淘宝API接口( item_fee- 淘宝商品快递费用查询)
  • 充电宝哪一款最实用?2024年推荐五款性价比最高选择,附选购攻略
  • R语言贝叶斯
  • LeetCode 热题 100之二叉树
  • 语音IC方案,在交通信号灯语音提示器的应用解析,NV040D
  • T10打卡—数据增强
  • 一文了解运维监控体系的方方面面
  • 低压电容补偿不用时会有电流损耗吗?
  • 力扣11.1
  • 创建线程池时为什么不建议使用Executors进行创建
  • VMware Workstation 17.0虚拟机安装Ubuntu Server 22.04.5 LTS并配置SSH与XFTP详细过程
  • 基于Matlab GUI的说话人识别测试平台
  • 基于SpringBoot的健身房系统的设计与实现(源码+定制+开发)
  • 国标GB28181摄像机接入EasyGBS国标GB28181软件与国标协议对接解决方案
  • 聚“芯”而行,华普微亮相第五届Silicon Labs Works With大会
  • HashSet 和 TreeSet 分别是如何实现去重的
  • Java 批量导出Word模板生成ZIP文件到浏览器默认下载位置
  • 【经验分享】从网页下载内嵌PDF的小妙招,亲测好用
  • OpenEuler 使用ffmpeg x11grab捕获屏幕流,rtsp推流,并用vlc播放
  • React04 State变量 组件渲染
  • fasdsdsadsa