|
|
|
<!DOCTYPE html>
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
|
|
<script type="text/javascript" src="{$smarty.const.CSS_URL}/js/jquery-1.8.1.min.js"></script>
|
|
|
|
<script type="text/javascript" src="{$smarty.const.CSS_URL}/js/jquery.form.js"></script>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
|
|
|
<title>首页</title>
|
|
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
|
|
{literal}
|
|
|
|
<style>
|
|
|
|
#prescription-form{
|
|
|
|
width: 800px;
|
|
|
|
margin-left: 100px;
|
|
|
|
}
|
|
|
|
.form-group {
|
|
|
|
margin-bottom: 15px;
|
|
|
|
}
|
|
|
|
.form-group label {
|
|
|
|
display: block;
|
|
|
|
margin-bottom: 10px;
|
|
|
|
}
|
|
|
|
.form-group input {
|
|
|
|
width: 100%;
|
|
|
|
padding: 8px;
|
|
|
|
box-sizing: border-box;
|
|
|
|
}
|
|
|
|
.form-group textarea {
|
|
|
|
width: 100%;
|
|
|
|
padding: 8px;
|
|
|
|
box-sizing: border-box;
|
|
|
|
}
|
|
|
|
.ingredient-list {
|
|
|
|
margin-top: 20px;
|
|
|
|
}
|
|
|
|
.add-button{
|
|
|
|
width: 20px;
|
|
|
|
height: 20px;
|
|
|
|
background-color: #DD4B38;
|
|
|
|
border: none;
|
|
|
|
border-radius: 50px;
|
|
|
|
color: #fff;
|
|
|
|
float: right;
|
|
|
|
}
|
|
|
|
.submit-btn{
|
|
|
|
margin-top: 50px;
|
|
|
|
width: 150px;
|
|
|
|
height: 45px;
|
|
|
|
background-color: #DD4B38;
|
|
|
|
border: none;
|
|
|
|
border-radius:5px;
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
.herb_item{
|
|
|
|
width: 800px;
|
|
|
|
position: relative;
|
|
|
|
display: flex;
|
|
|
|
line-height: 50px;
|
|
|
|
margin-top: 15px;
|
|
|
|
}
|
|
|
|
.herb_item button{
|
|
|
|
position: absolute;
|
|
|
|
left:620px;
|
|
|
|
top:15px;
|
|
|
|
width: 20px;
|
|
|
|
height: 20px;
|
|
|
|
background-color: #C28A2F;
|
|
|
|
border: none;
|
|
|
|
border-radius: 30px;
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
.herb_input{
|
|
|
|
/*width: 800px;*/
|
|
|
|
}
|
|
|
|
.herb_input input{
|
|
|
|
height: 50px;
|
|
|
|
margin-right: 30px;
|
|
|
|
text-indent: 10px;
|
|
|
|
}
|
|
|
|
#change{
|
|
|
|
position: absolute;
|
|
|
|
left: 1000px;
|
|
|
|
top:500px
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<script>
|
|
|
|
// 动态添加药材输入字段
|
|
|
|
function addIngredient() {
|
|
|
|
const ingredientList = document.getElementById('ingredient-list');
|
|
|
|
const ingredientDiv = document.createElement('div');
|
|
|
|
ingredientDiv.classList.add('herb_item');
|
|
|
|
|
|
|
|
ingredientDiv.innerHTML = `
|
|
|
|
<div class="herb_input">
|
|
|
|
<input type="text" name="herb_name[]" placeholder="药材名" required />
|
|
|
|
<input type="text" name="herb_num[]" placeholder="药量" required />
|
|
|
|
<input type="text" name="herb_desc[]" placeholder="说明"/>
|
|
|
|
</div>
|
|
|
|
<button class="" type="button" onclick="removeIngredient(this)">X</button>
|
|
|
|
`;
|
|
|
|
ingredientList.appendChild(ingredientDiv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 移除药材输入字段
|
|
|
|
function removeIngredient(button) {
|
|
|
|
button.parentElement.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
function submitForm(e) {
|
|
|
|
e.preventDefault(); // 阻止默认表单提交
|
|
|
|
|
|
|
|
const form = document.getElementById('prescription-form');
|
|
|
|
const formData = new FormData(form);
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
id: formData.get('id'),
|
|
|
|
name: formData.get('name'),
|
|
|
|
source: formData.get('source'),
|
|
|
|
method: formData.get('method'),
|
|
|
|
herbs: []
|
|
|
|
};
|
|
|
|
|
|
|
|
// 收集所有药材名称和重量
|
|
|
|
const herb_name = formData.getAll('herb_name[]');
|
|
|
|
const herb_num = formData.getAll('herb_num[]');
|
|
|
|
const herb_desc = formData.getAll('herb_desc[]');
|
|
|
|
|
|
|
|
herb_name.forEach((name, index) => {
|
|
|
|
data.herbs.push({
|
|
|
|
name: name,
|
|
|
|
num: herb_num[index],
|
|
|
|
desc: herb_desc[index]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
if(data.id.length>0){
|
|
|
|
$.ajax({
|
|
|
|
url: 'ajax_update_case', // 替换为你的服务器端处理文件
|
|
|
|
type: 'POST',
|
|
|
|
data: data,
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(response) {
|
|
|
|
alert(response.info);
|
|
|
|
if (response.status==true) {
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function(xhr, status, error) {
|
|
|
|
console.error('错误:', response);
|
|
|
|
alert('提交失败,请重试。');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
$.ajax({
|
|
|
|
url: 'ajax_save_case', // 替换为你的服务器端处理文件
|
|
|
|
type: 'POST',
|
|
|
|
data: data,
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(response) {
|
|
|
|
alert(response.info);
|
|
|
|
if (response.status==true) {
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function(xhr, status, error) {
|
|
|
|
console.error('错误:', response);
|
|
|
|
alert('提交失败,请重试。');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
{/literal}
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<h2 style="margin-left: 100px">添加药方</h2>
|
|
|
|
<form id="prescription-form" onsubmit="submitForm(event)">
|
|
|
|
<input id="id" name="id" type="hidden" value="{$data.case.id}">
|
|
|
|
<div class="form-group">
|
|
|
|
<label for="name">药方名称:</label>
|
|
|
|
<input type="text" id="name" name="name" value="{$data.case.name}" required>
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
|
|
<label for="source">药方来源:</label>
|
|
|
|
<textarea id="source" name="source" rows="4">{$data.case.source}</textarea>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="form-group">
|
|
|
|
<label for="method">用法:</label>
|
|
|
|
<textarea id="method" name="method" rows="4" required>{$data.case.method}</textarea>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{if $data.case.original}
|
|
|
|
<h3>原方 <button class="add-button" type="button" onclick="addIngredient()">+</button></h3>
|
|
|
|
{else}
|
|
|
|
<h3>药材 <button class="add-button" type="button" onclick="addIngredient()">+</button></h3>
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
<div id="ingredient-list" class="ingredient-list">
|
|
|
|
<!-- 动态添加药材输入字段 -->
|
|
|
|
{foreach from=$data.case.original key=key item=item}
|
|
|
|
<div class="herb_item">
|
|
|
|
<div class="herb_input">
|
|
|
|
<input type="text" name="herb_name[]" value="{$item.name}" placeholder="药材名" required />
|
|
|
|
<input type="text" name="herb_num[]" value="{$item.num}" placeholder="用量" required/>
|
|
|
|
<input type="text" name="herb_desc[]" value="{$item.desc}" placeholder="说明" required />
|
|
|
|
</div>
|
|
|
|
<button class="" type="button" onclick="removeIngredient(this)">X</button>
|
|
|
|
</div>
|
|
|
|
{/foreach}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div id="change" class="form-group">
|
|
|
|
<label for="method">转换后:</label>
|
|
|
|
{foreach from=$data.case_herb key=key item=item}
|
|
|
|
<div style="display: flex;line-height: 50px">
|
|
|
|
<div style="margin-right: 20px">{if $data.herb[$item.herb_id]}{$data.herb[$item.herb_id].name}{/if}</div>
|
|
|
|
<div style="margin-right: 20px">{$item.num} 克</div>
|
|
|
|
<div>{if $data.herb[$item.herb_id]}{$data.herb[$item.herb_id].desc}{/if}</div>
|
|
|
|
</div>
|
|
|
|
{/foreach}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="form-group" style="text-align: center">
|
|
|
|
<button class="submit-btn" type="submit">提交药方</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|