DIV CSS 佈局教程網

EasyUI 打造通用訂單管理頁:JS 實作全解析
編輯:JavaScript綜合知識     

訂單管理是後台系統中不可或缺的功能。本文以 jQuery EasyUI 為基礎,示範如何打造一個功能完整的訂單管理頁面,包含列表展示、成交操作、刪除與自動重新整理等實用功能。

頁面骨架

整個頁面以 EasyUI 的 datagrid 作為核心,透過 url 屬性指定資料來源,並啟用分頁與序號顯示:

<table id="dg" title="預訂裝修管理" class="easyui-datagrid"
  style="width: 1200px; height: 590px"
  url="<%=basePath%>findSubsByPage.action"
  toolbar="#toolbar" pagination="true" rownumbers="true"
  fitColumns="true" singleSelect="true">
  <thead>
    <tr>
      <th field="tel" width="40">聯繫方式</th>
      <th field="name" width="20">聯繫人</th>
      <th field="nametype" width="30">裝修名稱</th>
      <th field="orderTime" width="50">預訂時間</th>
      <th field="content" width="50">備註內容</th>
      <th field="sex" width="20">性別</th>
      <th field="nowTime" width="50">提交時間</th>
    </tr>
  </thead>
</table>

成交與篩選操作

頁面上方提供了「刪除訂單」、「未成交訂單」、「已成交訂單」與「成交」等工具按鈕。其中「成交」操作會先跳出確認對話框,確認後才送出請求:

$("#ok").click(function() {
  var url = "../updateSub.action";
  var row = $('#dg').datagrid('getSelected');
  if (row != null) {
    $.confirm({
      'title' : '操作確認提示',
      'message' : '您確認要進行此成交操作?',
      'buttons' : {
        'Yes' : { 'class' : 'blue', 'action' : function() {
          $.post(url, { id : row.id }, function() { $('#dg').datagrid('reload'); });
        } },
        'No' : { 'class' : 'gray', 'action' : function() { } }
      }
    });
  } else { alert("您未選中任何信息!"); }
});

刪除訂單

刪除功能同樣先透過 $.messager.confirm 向使用者確認,避免誤刪,成功後重新載入表格:

function destroyUser() {
  var row = $('#dg').datagrid('getSelected');
  if (row) {
    $.messager.confirm('操作提示', '您確定要刪除此條訂單?', function(r) {
      if (r) {
        $.post('../deleteSub.action', { id : row.id }, function(result) {
          if (result.success) { $('#dg').datagrid('reload'); }
        }, 'json');
      }
    });
  }
}

自動重新整理

為了讓後台數據保持即時,程式用了兩種重新整理機制:一是每 60 秒透過 setInterval 重載表格資料;二是透過 setTimeout 定期呼叫 myrefresh() 重整整個頁面,確保管理者看到的永遠是最新的訂單狀態。

小結

這套訂單管理頁把 EasyUI 的 datagrid、confirm 對話框與 Ajax 請求巧妙結合,示範了一個兼具「查詢、篩選、成交、刪除、自動更新」的完整後台解決方案,很適合作為後台系統開發的參考範本。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved