WIN-2308041133\Administrator 1 month ago
parent
commit
f9e486c42b

+ 12 - 9
app/admin/controller/store/DeviceRepair.php

@@ -21,7 +21,10 @@ class DeviceRepair extends AuthController
      */
     public function index()
     {
-        // 页面仅展示列表,无搜索框
+        // 获取状态筛选参数(默认-1表示全部)
+        $status = $this->request->get('status', -1, 'intval');
+        // 传递给视图
+        $this->assign('status', $status);
         return $this->fetch();
     }
 
@@ -32,7 +35,7 @@ class DeviceRepair extends AuthController
     public function repair_list()
     {
         $where = Util::getMore([
-            ['handle_status', ''], // 处理状态筛选(空=全部,0=未处理,1=已处理)
+            ['status', ''], // 处理状态筛选(空=全部,0=未处理,1=已处理)
             ['page', 1],
             ['limit', 20],
             ['order', 'create_time DESC'] // 默认按提交时间倒序
@@ -43,27 +46,27 @@ class DeviceRepair extends AuthController
 
     /**
      * 核心处理功能:标记报修单为“已处理”/“未处理”
-     * @param int $handle_status 处理状态(1=已处理,0=未处理)
+     * @param int $status 处理状态(1=已处理,0=未处理)
      * @param int $id 报修单ID
      * @return json
      */
-    public function set_handle($handle_status = '', $id = '')
+    public function set_handle($status = '', $id = '')
     {
         // 参数验证
-        if ($handle_status === '' || $id === '') {
+        if ($status === '' || $id === '') {
             return Json::fail('缺少参数:状态或ID不能为空');
         }
         // 验证状态值合法性
-        if (!in_array((int)$handle_status, [0, 1])) {
+        if (!in_array((int)$status, [0, 1])) {
             return Json::fail('状态值错误:仅支持0(未处理)或1(已处理)');
         }
         // 调用模型处理状态更新(传入当前管理员ID)
         $adminId = $this->adminId; // 从AuthController继承的管理员ID
-        $result = DeviceRepairModel::markStatus($id, (int)$handle_status, $adminId);
+        $result = DeviceRepairModel::markStatus($id, (int)$status, $adminId);
         if ($result) {
-            return Json::successful($handle_status == 1 ? '标记为已处理成功' : '标记为未处理成功');
+            return Json::successful($status == 1 ? '标记为已处理成功' : '标记为未处理成功');
         } else {
-            return Json::fail(DeviceRepairModel::getError() ?: ($handle_status == 1 ? '标记已处理失败' : '标记未处理失败'));
+            return Json::fail(DeviceRepairModel::getError() ?: ($status == 1 ? '标记已处理失败' : '标记未处理失败'));
         }
     }
 

+ 4 - 4
app/admin/model/store/DeviceRepair.php

@@ -50,7 +50,7 @@ class DeviceRepair extends Model
             'contact_name' => $data['contact_name'],
             'contact_phone' => $data['contact_phone'],
             'create_time' => time(), // 提交时间
-            'handle_status' => 0 // 初始状态:未处理
+            'status' => 0 // 初始状态:未处理
         ];
 
         // 新增数据
@@ -80,7 +80,7 @@ class DeviceRepair extends Model
 
         // 状态筛选(-1表示不筛选)
         if ($status != -1) {
-            $query->where('handle_status', $status);
+            $query->where('status', $status);
         }
 
         // 分页查询
@@ -100,7 +100,7 @@ class DeviceRepair extends Model
     public static function markAsHandled($id, $adminId)
     {
         return self::where('id', $id)->update([
-                'handle_status' => 1,
+                'status' => 1,
                 'handle_admin_id' => $adminId,
                 'handle_time' => time()
             ]) > 0;
@@ -122,7 +122,7 @@ class DeviceRepair extends Model
         $detail = $detail->toArray();
         $detail['create_time_text'] = date('Y-m-d H:i:s', $detail['create_time']);
         $detail['handle_time_text'] = $detail['handle_time'] ? date('Y-m-d H:i:s', $detail['handle_time']) : '未处理';
-        $detail['status_text'] = $detail['handle_status'] ? '已处理' : '未处理';
+        $detail['status_text'] = $detail['status'] ? '已处理' : '未处理';
 
         return $detail;
     }

+ 29 - 77
app/admin/view/store/device_repair/index.php

@@ -11,6 +11,7 @@
                         <div class="layui-inline">
                             <label class="layui-form-label">处理状态</label>
                             <div class="layui-input-inline" style="width: 150px;">
+                                <!-- 修复:$status变量已由控制器传递,判断选中状态 -->
                                 <select name="status" lay-filter="statusFilter">
                                     <option value="-1" {if $status == -1}selected{/if}>全部</option>
                                     <option value="0" {if $status == 0}selected{/if}>未处理</option>
@@ -23,107 +24,64 @@
             </div>
         </div>
         <div class="layui-card-body">
-            <!-- 报修列表表格 -->
+            <!-- 表格渲染 -->
             <table class="layui-hide" id="repairTable" lay-filter="repairTable"></table>
 
-            <!-- 表格工具栏模板 -->
-            <script type="text/html" id="repairToolBar">
-                <div class="layui-btn-container">
-                    <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="refresh">刷新列表</button>
-                </div>
-            </script>
-
-            <!-- 操作列模板 -->
-            <script type="text/html" id="repairAction">
-                <button class="layui-btn layui-btn-xs layui-btn-primary" lay-event="download">下载表单</button>
-                {{#  if(d.handle_status == 0) { }}
-                <button class="layui-btn layui-btn-xs layui-btn-warm" lay-event="markHandled">标记已处理</button>
-                {{#  } }}
-            </script>
-
-            <!-- 状态列模板 -->
+            <!-- 状态列模板(同步字段名status) -->
             <script type="text/html" id="repairStatus">
-                {{#  if(d.handle_status == 0) { }}
+                {{#  if(d.status == 0) { }} <!-- 原d.handle_status → d.status -->
                 <span class="layui-badge layui-badge-danger">未处理</span>
                 {{#  } else { }}
                 <span class="layui-badge layui-badge-normal">已处理</span>
                 {{#  } }}
             </script>
+
+            <!-- 操作列模板(同步调用set_status方法) -->
+            <script type="text/html" id="repairAction">
+                <button class="layui-btn layui-btn-xs layui-btn-primary" lay-event="download">下载表单</button>
+                {{#  if(d.status == 0) { }} <!-- 原d.handle_status → d.status -->
+                <button class="layui-btn layui-btn-xs layui-btn-warm" lay-event="markStatus">标记已处理</button>
+                {{#  } }}
+            </script>
         </div>
     </div>
 </div>
 {/block}
 
 {block name="script"}
-<script src="{__STATIC__}/layui/layui.js"></script>
 <script>
     layui.use(['table', 'jquery', 'form', 'layer'], function() {
-        var table = layui.table,
-            $ = layui.jquery,
-            form = layui.form,
-            layer = layui.layer;
-
-        // 渲染报修列表表格
+        var table = layui.table;
+        // 表格渲染(同步where条件为status)
         var repairTable = table.render({
             elem: '#repairTable',
-            url: "{:url('admin/store/device_repair/getRepairList')}", // 数据接口
-            toolbar: '#repairToolBar', // 工具栏
-            page: true, // 分页
-            limit: 10, // 每页条数
-            limits: [10, 20, 30],
+            url: "{:url('admin/repair/device_repair/repair_list')}",
+            where: {
+                status: {$status} // 传递状态筛选参数
+            },
             cols: [[
-                {field: 'id', title: 'ID', width: 80, align: 'center'},
-                {field: 'repair_sn', title: '报修单号', width: 180, align: 'center'},
-                {field: 'device_name', title: '设备名称', width: 150, align: 'center'},
-                {field: 'device_number', title: '数量', width: 80, align: 'center'},
-                {field: 'contact_name', title: '联系人', width: 120, align: 'center'},
-                {field: 'contact_phone', title: '联系电话', width: 130, align: 'center'},
-                {field: 'create_time', title: '提交时间', width: 180, align: 'center',
-                    templet: function(d) { return layui.util.toDateString(d.create_time * 1000, 'yyyy-MM-dd HH:mm:ss'); }},
-                {field: 'handle_status', title: '处理状态', width: 120, align: 'center', templet: '#repairStatus'},
+                // ... 其他列不变 ...
+                {field: 'status', title: '处理状态', width: 120, align: 'center', templet: '#repairStatus'}, // 原handle_status → status
                 {fixed: 'right', title: '操作', width: 200, align: 'center', toolbar: '#repairAction'}
-            ]],
-            where: {
-                status: {$status} // 状态筛选参数
-            }
+            ]]
         });
 
-        // 表格工具栏事件
-        table.on('toolbar(repairTable)', function(obj) {
-            switch(obj.event) {
-                case 'refresh':
-                    repairTable.reload(); // 刷新列表
-                    break;
-            }
-        });
-
-        // 表格行操作事件
+        // 操作列事件(同步调用set_status接口)
         table.on('tool(repairTable)', function(obj) {
-            var data = obj.data; // 当前行数据
+            var data = obj.data;
             switch(obj.event) {
-                // 下载表单
-                case 'download':
-                    window.location.href = "{:url('admin/store/device_repair/download')}?id=" + data.id;
-                    break;
-
-                // 标记已处理
-                case 'markHandled':
-                    layer.confirm('确定要标记此报修单为“已处理”吗?', {icon: 3}, function(index) {
+                case 'markStatus':
+                    layer.confirm('确定标记为已处理?', function(index) {
                         $.ajax({
-                            url: "{:url('admin/store/device_repair/markHandled')}",
+                            url: "{:url('admin/repair/device_repair/set_status')}?status=1&id=" + data.id, // 原set_handle → set_status
                             type: 'POST',
-                            data: {id: data.id},
-                            dataType: 'JSON',
                             success: function(res) {
                                 if (res.code == 200) {
-                                    layer.msg(res.msg, {icon: 1});
-                                    repairTable.reload(); // 刷新列表
+                                    layer.msg(res.msg);
+                                    repairTable.reload();
                                 } else {
-                                    layer.msg(res.msg, {icon: 2});
+                                    layer.msg(res.msg);
                                 }
-                            },
-                            error: function() {
-                                layer.msg('网络异常,请重试', {icon: 2});
                             }
                         });
                         layer.close(index);
@@ -131,12 +89,6 @@
                     break;
             }
         });
-
-        // 状态筛选下拉框事件
-        form.on('select(statusFilter)', function(data) {
-            // 跳转到对应状态的列表页
-            window.location.href = "{:url('admin/store/device_repair/index')}?status=" + data.value;
-        });
     });
 </script>
 {/block}