rebate_history.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. <?php
  2. require_once 'conn.php';
  3. checkLogin();
  4. // 辅助函数
  5. $urlStr = '';
  6. // 处理筛选条件
  7. $fliterFromDate = $_GET['fliterFromDate'] ?? '';
  8. $fliterToDate = $_GET['fliterToDate'] ?? '';
  9. $fliterStr = "";
  10. if (!empty($fliterFromDate)) {
  11. $fliterStr .= " AND rr.redemption_date >= '" . mysqli_real_escape_string($conn, $fliterFromDate) . "'";
  12. $urlStr .= "&fliterFromDate=" . urlencode($fliterFromDate);
  13. }
  14. if (!empty($fliterToDate)) {
  15. $fliterStr .= " AND rr.redemption_date <= '" . mysqli_real_escape_string($conn, $fliterToDate) . " 23:59:59'";
  16. $urlStr .= "&fliterToDate=" . urlencode($fliterToDate);
  17. }
  18. // 搜索参数
  19. $keys = $_GET['Keys'] ?? '';
  20. $keyscode = mysqli_real_escape_string($conn, $keys);
  21. $page = isset($_GET['Page']) ? intval($_GET['Page']) : 1;
  22. // 构建基本条件SQL
  23. $employee_id = $_SESSION['employee_id'];
  24. $isAdmin = checkIfAdmin();
  25. // 检查是否为财务角色或管理员
  26. $isFinance = false;
  27. $checkRoleSql = "SELECT em_permission_role_id FROM employee WHERE id = $employee_id";
  28. $roleResult = mysqli_query($conn, $checkRoleSql);
  29. if ($roleResult && $row = mysqli_fetch_assoc($roleResult)) {
  30. $isFinance = ($row['em_permission_role_id'] == 6 || $row['em_permission_role_id'] == 1);
  31. }
  32. // 基础查询,计算总记录数
  33. $countSql = "SELECT COUNT(*) AS total
  34. FROM rebate_redemptions rr
  35. JOIN customer c ON rr.customer_id = c.id
  36. WHERE 1=1";
  37. // 非管理员和非财务只能查看自己客户的返点历史
  38. if (!$isAdmin && !$isFinance) {
  39. $countSql .= " AND c.cs_belong = $employee_id";
  40. }
  41. // 添加搜索条件
  42. if (!empty($keyscode)) {
  43. $countSql .= " AND (c.cs_company LIKE '%$keyscode%' OR c.cs_code LIKE '%$keyscode%')";
  44. }
  45. // 添加日期筛选
  46. $countSql .= $fliterStr;
  47. // 执行查询获取总记录数
  48. $countResult = mysqli_query($conn, $countSql);
  49. if (!$countResult) {
  50. die("查询记录数量错误: " . mysqli_error($conn));
  51. }
  52. $countRow = mysqli_fetch_assoc($countResult);
  53. $totalRecords = $countRow['total'];
  54. // 设置每页显示记录数和分页
  55. $pageSize = 20;
  56. // 计算总页数
  57. $totalPages = ceil($totalRecords / $pageSize);
  58. if ($totalPages < 1) $totalPages = 1;
  59. // 验证当前页码
  60. if ($page < 1) $page = 1;
  61. if ($page > $totalPages) $page = $totalPages;
  62. // 计算起始记录
  63. $offset = ($page - 1) * $pageSize;
  64. // 查询返点兑换历史记录
  65. $sql = "SELECT
  66. rr.id AS redemption_id,
  67. rr.customer_id,
  68. c.cs_code,
  69. c.cs_company AS customer_name,
  70. rr.redemption_date,
  71. rr.total_rebate_amount,
  72. rr.notes,
  73. rr.status,
  74. rr.examine_status,
  75. rr.examine_date,
  76. e.em_user AS employee_name,
  77. e2.em_user AS examine_by_name,
  78. (SELECT COUNT(DISTINCT product_id) FROM rebate_redemption_items WHERE redemption_id = rr.id) AS product_count
  79. FROM
  80. rebate_redemptions rr
  81. JOIN
  82. customer c ON rr.customer_id = c.id
  83. LEFT JOIN
  84. employee e ON rr.created_by = e.id
  85. LEFT JOIN
  86. employee e2 ON rr.examine_by = e2.id
  87. WHERE
  88. 1=1";
  89. // 非管理员和非财务只能查看自己客户的返点历史
  90. if (!$isAdmin && !$isFinance) {
  91. $sql .= " AND c.cs_belong = $employee_id";
  92. }
  93. // 添加搜索条件
  94. if (!empty($keyscode)) {
  95. $sql .= " AND (c.cs_company LIKE '%$keyscode%' OR c.cs_code LIKE '%$keyscode%')";
  96. }
  97. // 添加日期筛选
  98. $sql .= $fliterStr;
  99. // 添加排序和分页
  100. $sql .= " ORDER BY rr.redemption_date DESC, rr.id DESC LIMIT $offset, $pageSize";
  101. $result = mysqli_query($conn, $sql);
  102. if (!$result) {
  103. die("查询返点历史错误: " . mysqli_error($conn));
  104. }
  105. // 获取返点历史记录
  106. $redemptions = [];
  107. while ($row = mysqli_fetch_assoc($result)) {
  108. $redemptions[] = $row;
  109. }
  110. // 处理审核操作
  111. if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'examine' && $isFinance) {
  112. $redemptionId = isset($_POST['redemption_id']) ? intval($_POST['redemption_id']) : 0;
  113. $examineStatus = isset($_POST['examine_status']) ? intval($_POST['examine_status']) : 0;
  114. if ($redemptionId > 0 && in_array($examineStatus, [1, 2])) {
  115. $updateSql = "UPDATE rebate_redemptions
  116. SET examine_status = $examineStatus,
  117. examine_date = NOW(),
  118. examine_by = $employee_id
  119. WHERE id = $redemptionId";
  120. if (mysqli_query($conn, $updateSql)) {
  121. // 刷新页面以显示更新后的状态
  122. echo "<script>window.location.href = window.location.href;</script>";
  123. exit;
  124. } else {
  125. echo "<script>alert('审核操作失败: " . mysqli_error($conn) . "');</script>";
  126. }
  127. }
  128. }
  129. ?>
  130. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  131. <html xmlns="http://www.w3.org/1999/xhtml">
  132. <head>
  133. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  134. <title>客户返点历史</title>
  135. <link rel="stylesheet" href="css/common.css" type="text/css" />
  136. <link rel="stylesheet" href="css/alert.css" type="text/css" />
  137. <script src="js/jquery-1.7.2.min.js"></script>
  138. <script src="js/js.js"></script>
  139. <style>
  140. body {
  141. margin: 0;
  142. padding: 20px;
  143. background: #fff;
  144. }
  145. #man_zone {
  146. margin-left: 0;
  147. }
  148. /* 表格布局 */
  149. .table2 {
  150. width: 100%;
  151. }
  152. .theader, .tline {
  153. display: flex;
  154. flex-direction: row;
  155. align-items: center;
  156. width: 100%;
  157. border-bottom: 1px solid #ddd;
  158. }
  159. .theader {
  160. background-color: #f2f2f2;
  161. font-weight: bold;
  162. height: 40px;
  163. }
  164. .tline {
  165. height: 45px;
  166. }
  167. .tline:hover {
  168. background-color: #f5f5f5;
  169. }
  170. .col2 { width: 5%; text-align: center; }
  171. .col3 { width: 15%; }
  172. .col4 { width: 12%; text-align: center; }
  173. .col5 { width: 8%; text-align: center; }
  174. .col6 { width: 15%; text-align: right; }
  175. .col7 { width: 10%; text-align: center; }
  176. .col8 { width: 15%; text-align: center; }
  177. .col9 { width: 15%; text-align: center; }
  178. /* 表格布局修复 */
  179. .table2 .col2 { width: 5%; text-align: center; }
  180. .table2 .col3 { width: 15%; }
  181. .table2 .col4 { width: 12%; text-align: center; }
  182. .table2 .col5 { width: 8%; text-align: center; }
  183. .table2 .col6 { width: 15%; text-align: right; }
  184. .table2 .col7 { width: 10%; text-align: center; }
  185. .table2 .col8 { width: 15%; text-align: center; }
  186. .table2 .col9 { width: 15%; text-align: center; }
  187. .theader > div, .tline > div {
  188. padding: 0 5px;
  189. overflow: hidden;
  190. text-overflow: ellipsis;
  191. white-space: nowrap;
  192. display: flex;
  193. align-items: center;
  194. justify-content: center;
  195. }
  196. .col3 {
  197. justify-content: flex-start !important;
  198. }
  199. .col7 {
  200. justify-content: flex-end !important;
  201. }
  202. /* 日期选择器样式 */
  203. .date-input {
  204. padding: 5px;
  205. border: 1px solid #ccc;
  206. border-radius: 3px;
  207. }
  208. /* 滑动面板样式 */
  209. .rb-slidepanel {
  210. cursor: pointer;
  211. }
  212. .rb-slidepanel.open {
  213. font-weight: bold;
  214. color: #3366cc;
  215. }
  216. .notepanel {
  217. display: none;
  218. background: #f9f9f9;
  219. padding: 10px;
  220. border: 1px solid #eee;
  221. margin-bottom: 10px;
  222. }
  223. .notepanel .noteItem {
  224. font-weight: bold;
  225. margin-bottom: 5px;
  226. }
  227. .rebate-details {
  228. margin-top: 10px;
  229. border-top: 1px dashed #ddd;
  230. padding-top: 10px;
  231. }
  232. /* 状态样式 */
  233. .status-active {
  234. color: #27ae60;
  235. font-weight: bold;
  236. }
  237. .status-cancelled {
  238. color: #e74c3c;
  239. text-decoration: line-through;
  240. }
  241. /* 审核状态样式 */
  242. .examine-pending {
  243. color: #f39c12;
  244. font-weight: bold;
  245. }
  246. .examine-approved {
  247. color: #27ae60;
  248. font-weight: bold;
  249. }
  250. .examine-rejected {
  251. color: #e74c3c;
  252. font-weight: bold;
  253. }
  254. /* 备注文本溢出控制 */
  255. .notes-text {
  256. max-width: 200px;
  257. white-space: nowrap;
  258. overflow: hidden;
  259. text-overflow: ellipsis;
  260. display: inline-block;
  261. }
  262. /* 审核操作按钮 */
  263. .examine-btn {
  264. display: inline-block;
  265. padding: 3px 8px;
  266. margin: 0 2px;
  267. border-radius: 3px;
  268. cursor: pointer;
  269. text-decoration: none;
  270. font-size: 12px;
  271. color: white;
  272. box-sizing: border-box;
  273. height: 24px;
  274. line-height: 18px;
  275. vertical-align: middle;
  276. }
  277. .approve-btn {
  278. background-color: #0f9d58; /* 绿色 */
  279. }
  280. .reject-btn {
  281. background-color: #db4437; /* 红色 */
  282. }
  283. .examine-btn:hover {
  284. opacity: 0.9;
  285. }
  286. /* 模态窗口样式 */
  287. .modal {
  288. display: none;
  289. position: fixed;
  290. z-index: 1000;
  291. left: 0;
  292. top: 0;
  293. width: 100%;
  294. height: 100%;
  295. background-color: rgba(0,0,0,0.5);
  296. }
  297. .modal-content {
  298. background-color: #fefefe;
  299. margin: 15% auto;
  300. padding: 20px;
  301. border: 1px solid #888;
  302. width: 300px;
  303. border-radius: 5px;
  304. text-align: center;
  305. }
  306. .modal-buttons {
  307. margin-top: 20px;
  308. display: flex;
  309. justify-content: center;
  310. }
  311. .modal-btn {
  312. padding: 5px 15px;
  313. margin: 0 5px;
  314. border-radius: 3px;
  315. cursor: pointer;
  316. display: inline-block;
  317. min-width: 60px;
  318. height: 30px;
  319. line-height: 20px;
  320. text-align: center;
  321. font-size: 14px;
  322. border: none;
  323. }
  324. .confirm-btn {
  325. background-color: #3498db;
  326. color: white;
  327. }
  328. .cancel-btn {
  329. background-color: #95a5a6;
  330. color: white;
  331. }
  332. </style>
  333. </head>
  334. <body>
  335. <div id="man_zone">
  336. <div class="fastSelect clear">
  337. <H1>客户返点历史查询</H1>
  338. <div class="selectItem">
  339. <label>兑换日期</label>
  340. <input type="date" name="fliterFromDate" class="date-input filterSearch" value="<?= $fliterFromDate ?>">
  341. <label>到</label>
  342. <input type="date" name="fliterToDate" class="date-input filterSearch" value="<?= $fliterToDate ?>">
  343. </div>
  344. <div class="inputSearch">
  345. <input type="text" id="keys" class="inputTxt" placeholder="请输入客户名称或编码"
  346. value="<?= empty($keyscode) ? '' : $keyscode ?>" />
  347. <input type="button" id="searchgo" class="searchgo" value="搜索"
  348. onClick="location.href='?Keys='+encodeURIComponent(document.getElementById('keys').value)" />
  349. </div>
  350. <div style="text-align: right; margin-top: 10px; clear: both;">
  351. <a href="rebate_expiring.php" class="btn1" style="display: inline-flex; align-items: center; justify-content: center; padding: 5px 15px; margin-top: 0; height: 22px; background-color: #e74c3c; margin-right: 5px;">查看过期预警</a>
  352. <a href="rebate_summary.php" class="btn1" style="display: inline-flex; align-items: center; justify-content: center; padding: 5px 15px; margin-top: 0; height: 22px;">返回返点统计</a>
  353. </div>
  354. </div>
  355. <div class="table2 em<?= $_SESSION['employee_id'] ?>">
  356. <div class="theader">
  357. <div class="col2">序号</div>
  358. <div class="col3">客户编码</div>
  359. <div class="col4">兑换日期</div>
  360. <div class="col5">产品数</div>
  361. <div class="col6">返点金额</div>
  362. <div class="col7">处理人</div>
  363. <div class="col8">审核状态</div>
  364. <div class="col9">操作</div>
  365. </div>
  366. <?php
  367. if (!empty($redemptions)) {
  368. $tempNum = ($page - 1) * $pageSize;
  369. foreach ($redemptions as $redemption) {
  370. $tempNum++;
  371. $statusClass = $redemption['status'] == 1 ? 'status-active' : 'status-cancelled';
  372. // 审核状态
  373. $examineStatusText = '未审核';
  374. $examineStatusClass = 'examine-pending';
  375. if ($redemption['examine_status'] == 1) {
  376. $examineStatusText = '已通过';
  377. $examineStatusClass = 'examine-approved';
  378. } elseif ($redemption['examine_status'] == 2) {
  379. $examineStatusText = '已拒绝';
  380. $examineStatusClass = 'examine-rejected';
  381. }
  382. ?>
  383. <div class="tline">
  384. <div class="col2"><?= $tempNum ?></div>
  385. <div class="col3 rb-slidepanel" data-id="<?= $redemption['redemption_id'] ?>"><?= htmlspecialcharsFix($redemption['cs_code']) ?></div>
  386. <div class="col4"><?= date('Y-m-d', strtotime($redemption['redemption_date'])) ?></div>
  387. <div class="col5"><?= $redemption['product_count'] ?></div>
  388. <div class="col6 <?= $statusClass ?>"><?= number_format($redemption['total_rebate_amount'], 2) ?> 元</div>
  389. <div class="col7"><?= htmlspecialcharsFix($redemption['employee_name']) ?></div>
  390. <div class="col8 <?= $examineStatusClass ?>">
  391. <?= $examineStatusText ?>
  392. <?php if ($redemption['examine_status'] > 0 && !empty($redemption['examine_by_name'])): ?>
  393. <!-- <div style="font-size: 12px; color: #666; margin-top: 2px;">
  394. <?= htmlspecialcharsFix($redemption['examine_by_name']) ?>
  395. <br><?= date('m-d H:i', strtotime($redemption['examine_date'])) ?>
  396. </div> -->
  397. <?php endif; ?>
  398. </div>
  399. <div class="col9">
  400. <a href="javascript:void(0)" class="rb-toggleDetail" data-id="<?= $redemption['redemption_id'] ?>">查看详情</a>
  401. <?php if ($isFinance && $redemption['examine_status'] == 0 && $redemption['status'] == 1): ?>
  402. <span style="margin-left: 5px; display: inline-block;">
  403. <a href="javascript:void(0)" class="examine-btn approve-btn"
  404. data-id="<?= $redemption['redemption_id'] ?>" data-status="1">通过</a>
  405. <a href="javascript:void(0)" class="examine-btn reject-btn"
  406. data-id="<?= $redemption['redemption_id'] ?>" data-status="2">拒绝</a>
  407. </span>
  408. <?php endif; ?>
  409. </div>
  410. </div>
  411. <div class="notepanel clear" id="detail-<?= $redemption['redemption_id'] ?>">
  412. <div class="noteItem">返点详情</div>
  413. <?php if (!empty($redemption['notes'])): ?>
  414. <div style="margin-bottom: 10px; color: #666;">
  415. <strong>备注:</strong> <?= htmlspecialcharsFix($redemption['notes']) ?>
  416. </div>
  417. <?php endif; ?>
  418. <div class="rebate-details" id="rebate-details-<?= $redemption['redemption_id'] ?>">
  419. <div style="text-align: center; padding: 10px;">
  420. <img src="images/loading.gif" alt="加载中" style="width: 20px; height: 20px;">
  421. 加载返点详情...
  422. </div>
  423. </div>
  424. </div>
  425. <?php
  426. }
  427. } else {
  428. if (empty($keys) && empty($fliterStr)) {
  429. echo '<div class="tline"><div style="width: 100%; text-align: center;">当前没有返点历史记录</div></div>';
  430. } else {
  431. echo '<div class="tline"><div style="width: 100%; text-align: center;"><a href="?">没有找到匹配的返点历史记录,点击返回</a></div></div>';
  432. }
  433. }
  434. ?>
  435. <div class="showpagebox">
  436. <?php
  437. if ($totalPages > 1) {
  438. $pageName = "?Keys=$keys$urlStr&";
  439. $pageLen = 3;
  440. if ($page > 1) {
  441. echo "<a href=\"{$pageName}Page=1\">首页</a>";
  442. echo "<a href=\"{$pageName}Page=" . ($page - 1) . "\">上一页</a>";
  443. }
  444. if ($pageLen * 2 + 1 >= $totalPages) {
  445. $startPage = 1;
  446. $endPage = $totalPages;
  447. } else {
  448. if ($page <= $pageLen + 1) {
  449. $startPage = 1;
  450. $endPage = $pageLen * 2 + 1;
  451. } else {
  452. $startPage = $page - $pageLen;
  453. $endPage = $page + $pageLen;
  454. }
  455. if ($page + $pageLen > $totalPages) {
  456. $startPage = $totalPages - $pageLen * 2;
  457. $endPage = $totalPages;
  458. }
  459. }
  460. for ($i = $startPage; $i <= $endPage; $i++) {
  461. if ($i == $page) {
  462. echo "<a class=\"current\">$i</a>";
  463. } else {
  464. echo "<a href=\"{$pageName}Page=$i\">$i</a>";
  465. }
  466. }
  467. if ($page < $totalPages) {
  468. if ($totalPages - $page > $pageLen) {
  469. echo "<a href=\"{$pageName}Page=$totalPages\">...$totalPages</a>";
  470. }
  471. echo "<a href=\"{$pageName}Page=" . ($page + 1) . "\">下一页</a>";
  472. echo "<a href=\"{$pageName}Page=$totalPages\">尾页</a>";
  473. }
  474. }
  475. ?>
  476. </div>
  477. </div>
  478. <!-- 审核确认模态窗口 -->
  479. <div id="examineModal" class="modal">
  480. <div class="modal-content">
  481. <p id="examineMessage">确认要执行此操作吗?</p>
  482. <div class="modal-buttons">
  483. <form id="examineForm" method="post">
  484. <input type="hidden" name="action" value="examine">
  485. <input type="hidden" name="redemption_id" id="modalRedemptionId" value="">
  486. <input type="hidden" name="examine_status" id="modalExamineStatus" value="">
  487. <button type="submit" class="modal-btn confirm-btn">确认</button>
  488. <button type="button" class="modal-btn cancel-btn" id="cancelExamine">取消</button>
  489. </form>
  490. </div>
  491. </div>
  492. </div>
  493. <script>
  494. $(document).ready(function() {
  495. // 添加日期验证逻辑
  496. $('input[name="fliterToDate"]').on('change', function() {
  497. var fromDate = $('input[name="fliterFromDate"]').val();
  498. var toDate = $(this).val();
  499. if (fromDate && toDate && new Date(toDate) < new Date(fromDate)) {
  500. alert('结束日期不能早于开始日期');
  501. $(this).val(''); // 清空结束日期
  502. return false;
  503. }
  504. });
  505. // 开始日期变更时也进行验证
  506. $('input[name="fliterFromDate"]').on('change', function() {
  507. var fromDate = $(this).val();
  508. var toDate = $('input[name="fliterToDate"]').val();
  509. if (fromDate && toDate && new Date(toDate) < new Date(fromDate)) {
  510. alert('开始日期不能晚于结束日期');
  511. $('input[name="fliterToDate"]').val(''); // 清空结束日期
  512. return false;
  513. }
  514. });
  515. // 处理筛选条件改变
  516. $('.filterSearch').change(function() {
  517. var url = '?';
  518. var keys = $('#keys').val();
  519. if (keys && keys != '请输入客户名称或编码') {
  520. url += 'Keys=' + encodeURIComponent(keys) + '&';
  521. }
  522. $('.filterSearch').each(function() {
  523. var name = $(this).attr('name');
  524. var value = $(this).val();
  525. if (value) {
  526. url += name + '=' + encodeURIComponent(value) + '&';
  527. }
  528. });
  529. // 移除末尾的&
  530. if (url.endsWith('&')) {
  531. url = url.substring(0, url.length - 1);
  532. }
  533. location.href = url;
  534. });
  535. // 切换显示返点详情
  536. $('.rb-toggleDetail').on('click', function(e) {
  537. e.preventDefault();
  538. e.stopPropagation(); // 阻止事件冒泡
  539. var redemptionId = $(this).data('id');
  540. var $detailPanel = $('#detail-' + redemptionId);
  541. var $panel = $(this);
  542. if ($detailPanel.is(':visible')) {
  543. $detailPanel.slideUp();
  544. $panel.text('查看详情');
  545. // 移除打开状态
  546. $panel.closest('.tline').find('.rb-slidepanel').removeClass('open');
  547. } else {
  548. $detailPanel.slideDown();
  549. $panel.text('收起详情');
  550. // 添加打开状态
  551. $panel.closest('.tline').find('.rb-slidepanel').addClass('open');
  552. // 加载详情数据
  553. loadRedemptionDetails(redemptionId);
  554. }
  555. });
  556. // 客户名称点击也可以切换显示
  557. $('.rb-slidepanel').on('click', function(e) {
  558. e.preventDefault();
  559. e.stopPropagation(); // 阻止事件冒泡
  560. var redemptionId = $(this).data('id');
  561. var $detailPanel = $('#detail-' + redemptionId);
  562. var $toggleButton = $('.rb-toggleDetail[data-id="' + redemptionId + '"]');
  563. if ($detailPanel.is(':visible')) {
  564. $detailPanel.slideUp();
  565. $toggleButton.text('查看详情');
  566. $(this).removeClass('open');
  567. } else {
  568. $detailPanel.slideDown();
  569. $toggleButton.text('收起详情');
  570. $(this).addClass('open');
  571. // 加载详情数据
  572. loadRedemptionDetails(redemptionId);
  573. }
  574. });
  575. // 审核按钮点击事件
  576. $('.examine-btn').on('click', function() {
  577. var redemptionId = $(this).data('id');
  578. var examineStatus = $(this).data('status');
  579. var actionText = examineStatus == 1 ? '通过' : '拒绝';
  580. $('#modalRedemptionId').val(redemptionId);
  581. $('#modalExamineStatus').val(examineStatus);
  582. $('#examineMessage').text('确认要' + actionText + '这条返点记录吗?');
  583. $('#examineModal').show();
  584. });
  585. // 取消审核按钮
  586. $('#cancelExamine').on('click', function() {
  587. $('#examineModal').hide();
  588. });
  589. // 点击模态窗口外部关闭模态窗口
  590. $(window).on('click', function(e) {
  591. if ($(e.target).is('#examineModal')) {
  592. $('#examineModal').hide();
  593. }
  594. });
  595. // 加载返点详情
  596. function loadRedemptionDetails(redemptionId) {
  597. var $detailsContainer = $('#rebate-details-' + redemptionId);
  598. // 检查是否已经加载过
  599. if ($detailsContainer.data('loaded')) {
  600. return;
  601. }
  602. // 异步加载详情
  603. $.ajax({
  604. url: 'get_rebate_details.php',
  605. type: 'GET',
  606. data: { redemption_id: redemptionId },
  607. dataType: 'json',
  608. success: function(data) {
  609. if (data && data.success) {
  610. var html = '<table class="detail-table" style="width:100%; border-collapse: collapse;">';
  611. html += '<tr style="background-color: #eee; font-weight: bold;">' +
  612. '<th style="padding: 8px; text-align: left; border: 1px solid #ddd;">订单编号</th>' +
  613. '<th style="padding: 8px; text-align: left; border: 1px solid #ddd;">产品名称</th>' +
  614. '<th style="padding: 8px; text-align: center; border: 1px solid #ddd;">数量</th>' +
  615. '<th style="padding: 8px; text-align: right; border: 1px solid #ddd;">返点单价</th>' +
  616. '<th style="padding: 8px; text-align: right; border: 1px solid #ddd;">返点金额</th>' +
  617. '</tr>';
  618. $.each(data.items, function(i, item) {
  619. html += '<tr style="border-bottom: 1px solid #ddd;">' +
  620. '<td style="padding: 8px; border: 1px solid #ddd;">' + item.order_code + '</td>' +
  621. '<td style="padding: 8px; border: 1px solid #ddd;">' + item.product_name + '</td>' +
  622. '<td style="padding: 8px; text-align: center; border: 1px solid #ddd;">' + item.quantity + ' ' + item.unit + '</td>' +
  623. '<td style="padding: 8px; text-align: right; border: 1px solid #ddd;">' + item.rebate_amount + ' 元/件</td>' +
  624. '<td style="padding: 8px; text-align: right; border: 1px solid #ddd;">' + item.total_rebate + ' 元</td>' +
  625. '</tr>';
  626. });
  627. html += '</table>';
  628. $detailsContainer.html(html);
  629. $detailsContainer.data('loaded', true);
  630. } else {
  631. $detailsContainer.html('<div style="padding: 10px; color: #e74c3c;">加载详情失败: ' + (data.message || '未知错误') + '</div>');
  632. }
  633. },
  634. error: function(jqXHR, textStatus, errorThrown) {
  635. $detailsContainer.html('<div style="padding: 10px; color: #e74c3c;">加载详情失败: ' + textStatus + '</div>');
  636. }
  637. });
  638. }
  639. });
  640. </script>
  641. </div>
  642. </body>
  643. </html>