From b3aef86a16d055f180450279ac1b8b9da29c3ec6 Mon Sep 17 00:00:00 2001
From: pengda <10266652509@qq.com>
Date: Sat, 12 Oct 2024 16:28:51 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AE=A1=E6=A0=B8=E4=B8=8D?=
 =?UTF-8?q?=E9=80=9A=E8=BF=87?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 control/admin.php                      |  6 ++---
 view/templates/admin/formula_add.html  | 44 ++++++++++++++++++++++++++++++----
 view/templates/admin/formula_list.html | 22 +++++++++++++----
 3 files changed, 60 insertions(+), 12 deletions(-)

diff --git a/control/admin.php b/control/admin.php
index 47983c5..ce38146 100644
--- a/control/admin.php
+++ b/control/admin.php
@@ -103,7 +103,7 @@ class admin extends publicBase {
             $condition['uid'] = 0;
         }
         if ($status == 0) {
-            $condition['is_delete'] = array(0, 2);
+            $condition['is_delete'] = array(0, 2, 3);
         } elseif ($status == 1) {
             $condition['is_delete'] = 2;
         } elseif ($status == 2) {
@@ -153,7 +153,7 @@ class admin extends publicBase {
         $id = $mformula->saveFormula(0, $id, $name, $source, $method, $herbs);
         if (!$id) $this->ajax_json(false, $mformula->getError());
 
-        $this->ajax_json(true, '请求成功', array('id' => $id));
+        $this->ajax_json(true, '操作成功', array('id' => $id));
     }
 
     public function ajax_delete_formula() {
@@ -164,6 +164,6 @@ class admin extends publicBase {
         $id = $mformula->deleteFormula(0, $id, $is_delete);
         if (!$id) $this->ajax_json(false, $mformula->getError());
 
-        $this->ajax_json(true, '请求成功');
+        $this->ajax_json(true, '操作成功');
     }
 }
diff --git a/view/templates/admin/formula_add.html b/view/templates/admin/formula_add.html
index 5502187..8a7e8c2 100644
--- a/view/templates/admin/formula_add.html
+++ b/view/templates/admin/formula_add.html
@@ -16,13 +16,16 @@
     <div class="container">
         <div id="main">
             <div id="main-content">
-                <div class="record-control">
+                <div>
                     <div class="header">
-                        <span style="font-size:14px;padding:5px">添加药方</span>
-                        <div class="row">&nbsp;</div>
                         <div class="flash-message"></div>
 
-                        <ul class="tabs"><li></li></ul>
+                        <ul class="tabs">
+                            <li class="active"><a href="javascript:;">添加药方</a></li>
+                            <div style="display:inline-block;float: right;">
+                                <button class="button link" onclick="to_delete({$data.id},1)">删除</button>
+                            </div>
+                        </ul>
                     </div>
                 </div>
 
@@ -111,6 +114,39 @@
 
 {literal}
 <script type="text/javascript">
+    function to_delete(id,status) {
+        if (!confirm("确定要删除吗?")) {
+            console.log("用户选择了确认");
+            return false;
+        }
+
+        const data = {
+            id: id,
+            is_delete: status,
+        };
+
+        $.ajax({
+            url: '/admin/ajax_delete_formula', // 替换为你的服务器端处理文件
+            type: 'POST',
+            data: data,
+            dataType: 'json',
+            success: function (response) {
+                alert(response.info);
+                if (response.status == true) {
+                    window.location.href = "/admin/formula_list";
+                }
+
+                if(response.data.code == 40002){
+                    window.location.href = "/admin/login";
+                }
+            },
+            error: function (xhr, status, error) {
+                console.error('错误:', response);
+                alert('提交失败,请重试。');
+            }
+        });
+    }
+
     // 动态添加药材输入字段
     function addIngredient() {
         const ingredientList = document.getElementById('ingredient-list');
diff --git a/view/templates/admin/formula_list.html b/view/templates/admin/formula_list.html
index 23d418a..e275036 100644
--- a/view/templates/admin/formula_list.html
+++ b/view/templates/admin/formula_list.html
@@ -84,6 +84,7 @@
                             <th width="200">药方名称</th>
                             <th width="200">药方来源</th>
                             <th width="200">药方详情</th>
+                            <th width="200">状态</th>
                             <th width="50">操作</th>
                         </tr>
                         </thead>
@@ -99,14 +100,25 @@
                                     <span style="margin-right: 20px">{$value.name}{if $value.desc}({$value.desc}){/if}  {$value.num_str}</span>
                                 {/foreach}
                             </td>
-
+                            <td>
+                                {if $item.is_delete == 0} 审核通过 {/if}
+                                {if $item.is_delete == 2} 待审核 {/if}
+                                {if $item.is_delete == 3} 审核不通过 {/if}
+                            </td>
                             <td>
                                 {if $item.is_delete == 2}
-                                <a href="javascript:;" onclick="to_delete({$item.id},0)">审核通过</a>
+                                <a href="javascript:;" onclick="to_status({$item.id},0)">审核通过</a>
+                                <br>
+                                <a href="javascript:;" onclick="to_status({$item.id},3)">审核不通过</a>
+                                <br>
+                                {/if}
+                                {if $item.is_delete == 3}
+                                <a href="javascript:;" onclick="to_status({$item.id},0)">审核通过</a>
+                                <br>
                                 {/if}
                                 {if $item.uid == 0}
                                 <a href="/admin/formula_add/id/{$item.id}">编辑</a>
-                                <a href="javascript:;" onclick="to_delete({$item.id},1)">删除</a>
+                                <br>
                                 {/if}
                             </td>
                         </tr>
@@ -139,8 +151,8 @@
     function to_add(){
         location.href = '/admin/formula_add';
     }
-    function to_delete(id,status) {
-        if (!confirm("确定要删除吗?")) {
+    function to_status(id,status) {
+        if (!confirm("确定要操作吗?")) {
             console.log("用户选择了确认");
             return false;
         }