mp_ssnwjc_detail.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8"/>
  5. <meta name="viewport"
  6. content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
  7. <title>检查详情</title>
  8. <script src="/js/mp_base/base.js"></script>
  9. <style>
  10. [v-cloak] {
  11. display: none !important;
  12. }
  13. body {
  14. margin: 0;
  15. color: #222;
  16. background: #f3f4f6;
  17. font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
  18. "Microsoft YaHei", sans-serif;
  19. }
  20. #app {
  21. min-height: 100vh;
  22. padding-bottom: 20px;
  23. }
  24. .topbar {
  25. display: flex;
  26. align-items: center;
  27. justify-content: center;
  28. height: 52px;
  29. padding: 0 14px;
  30. background: #fff;
  31. border-bottom: 1px solid #e5e7eb;
  32. }
  33. .topbar-title {
  34. font-size: 17px;
  35. font-weight: 700;
  36. }
  37. .content {
  38. padding: 12px 14px;
  39. }
  40. .list {
  41. margin-top: 12px;
  42. overflow: hidden;
  43. background: #fff;
  44. border: 1px solid #e5e7eb;
  45. border-radius: 6px;
  46. }
  47. .student-card-list {
  48. display: grid;
  49. gap: 10px;
  50. margin-top: 12px;
  51. }
  52. .student-card-list .swipe-row {
  53. border: 1px solid #e5e7eb;
  54. border-radius: 6px;
  55. }
  56. .student-card-list .item {
  57. border-bottom: 0;
  58. }
  59. .student-card-list .card-empty {
  60. background: #fff;
  61. border: 1px solid #e5e7eb;
  62. border-radius: 6px;
  63. }
  64. .item {
  65. padding: 13px 14px;
  66. border-bottom: 1px solid #eef0f3;
  67. }
  68. .item:last-child {
  69. border-bottom: none;
  70. }
  71. .swipe-row {
  72. position: relative;
  73. overflow: hidden;
  74. background: #fff;
  75. touch-action: pan-y;
  76. }
  77. .student-delete {
  78. position: absolute;
  79. top: 0;
  80. bottom: 0;
  81. right: 0;
  82. width: 72px;
  83. padding: 0;
  84. color: #fff;
  85. background: #2f6fed;
  86. border: 0;
  87. border-radius: 0 5px 5px 0;
  88. font: inherit;
  89. font-size: 15px;
  90. transform: translateX(72px);
  91. transition: transform .18s ease;
  92. z-index: 2;
  93. }
  94. .student-content {
  95. position: relative;
  96. background: #fff;
  97. z-index: 1;
  98. }
  99. .student-content::after {
  100. content: "";
  101. position: absolute;
  102. top: 0;
  103. right: 0;
  104. bottom: 0;
  105. width: 6px;
  106. background: #007aff;
  107. }
  108. .swipe-row.dragging .student-delete {
  109. transition: none;
  110. }
  111. .item-main {
  112. font-size: 15px;
  113. font-weight: 600;
  114. }
  115. .item-sub {
  116. margin-top: 4px;
  117. color: #8b95a5;
  118. font-size: 13px;
  119. }
  120. .loading,
  121. .empty,
  122. .error {
  123. padding: 30px 14px;
  124. text-align: center;
  125. color: #8b95a5;
  126. font-size: 14px;
  127. }
  128. .error {
  129. color: #e5484d;
  130. }
  131. </style>
  132. </head>
  133. <body>
  134. <div id="app" v-cloak @touchstart="onTouchStart" @touchend="onTouchEnd">
  135. <div class="topbar">
  136. <div class="topbar-title">{{ title }}</div>
  137. </div>
  138. <div v-if="loading" class="loading">加载中...</div>
  139. <div v-else-if="errorMsg" class="error">{{ errorMsg }}</div>
  140. <div v-else class="content">
  141. <div v-if="type === 'student'" class="student-card-list">
  142. <div v-if="!roomData.students.length" class="empty card-empty">暂无有效住宿学员</div>
  143. <div
  144. v-for="student in roomData.students"
  145. :key="student.ryid"
  146. class="swipe-row"
  147. :class="{ dragging: activeRyid === String(student.ryid) }"
  148. @pointerdown.stop="onStudentPointerStart(student, $event)"
  149. @pointermove.stop="onStudentPointerMove($event)"
  150. @pointerup.stop="onStudentPointerEnd($event)"
  151. @pointercancel.stop="onStudentPointerEnd($event)"
  152. @touchstart.stop="onStudentTouchStart(student, $event)"
  153. @touchmove.stop="onStudentTouchMove($event)"
  154. @touchend.stop="onStudentTouchEnd"
  155. @touchcancel.stop="onStudentTouchEnd"
  156. @click.stop="toggleStudentActions(student)"
  157. >
  158. <button
  159. type="button"
  160. class="student-delete"
  161. :style="{ transform: 'translateX(' + actionOffset(student) + 'px)' }"
  162. @click.stop="deleteStudent(student)"
  163. >移除</button>
  164. <div
  165. class="item student-content"
  166. >
  167. <div class="item-main">{{ student.xm }}</div>
  168. <div class="item-sub">
  169. {{ student.cwmc || '未分配床位' }}
  170. <template v-if="student.bjmc"> · {{ student.bjmc }}</template>
  171. </div>
  172. </div>
  173. </div>
  174. </div>
  175. <div v-else class="list">
  176. <div v-if="!roomData.bjList.length" class="empty">暂无有效班级</div>
  177. <div v-for="bj in roomData.bjList" :key="bj.bjid" class="item">
  178. <div class="item-main">{{ bj.bjmc }}</div>
  179. </div>
  180. </div>
  181. </div>
  182. </div>
  183. <script>
  184. window.SS.ready(function () {
  185. window.SS.dom.initializeFormApp({
  186. el: "#app",
  187. data() {
  188. return {
  189. loading: true,
  190. errorMsg: "",
  191. type: "student",
  192. jzwid: "",
  193. kfid: "",
  194. touchStartX: 0,
  195. touchStartY: 0,
  196. activeRyid: "",
  197. openRyid: "",
  198. dragOffset: 0,
  199. swipeStartX: 0,
  200. swipeStartY: 0,
  201. swipeStartOffset: 0,
  202. swipeHorizontal: false,
  203. suppressClickUntil: 0,
  204. roomData: {
  205. students: [],
  206. bjList: [],
  207. xymcStr: "",
  208. bjmcStr: ""
  209. }
  210. };
  211. },
  212. computed: {
  213. title() {
  214. return this.type === "class" ? "班级详情" : "学员详情";
  215. }
  216. },
  217. async mounted() {
  218. const params = this.getUrlParams();
  219. this.type = String(params.type || "student") === "class" ? "class" : "student";
  220. this.jzwid = String(params.jzwid || "");
  221. this.kfid = String(params.kfid || "");
  222. if (!this.jzwid || !this.kfid) {
  223. this.errorMsg = "缺少房间参数";
  224. this.loading = false;
  225. return;
  226. }
  227. try {
  228. const response = await this.postService(
  229. "/service?ssServ=ssnwjc_mpLoadRoom&ssDest=data",
  230. { jzwid: this.jzwid, kfid: this.kfid }
  231. );
  232. this.roomData = {
  233. students: response.students || [],
  234. bjList: response.bjList || [],
  235. xymcStr: response.xymcStr || "",
  236. bjmcStr: response.bjmcStr || ""
  237. };
  238. } catch (error) {
  239. this.errorMsg = error.message || "详情加载失败";
  240. } finally {
  241. this.loading = false;
  242. }
  243. },
  244. methods: {
  245. eventPoint(event) {
  246. return (event.changedTouches && event.changedTouches[0])
  247. || (event.touches && event.touches[0])
  248. || event;
  249. },
  250. onStudentTouchStart(student, event) {
  251. const touch = this.eventPoint(event);
  252. if (!touch) return;
  253. const ryid = String(student.ryid);
  254. if (this.openRyid && this.openRyid !== ryid) {
  255. this.openRyid = "";
  256. }
  257. this.activeRyid = ryid;
  258. this.swipeStartX = touch.clientX;
  259. this.swipeStartY = touch.clientY;
  260. this.swipeStartOffset = this.openRyid === ryid ? -72 : 0;
  261. this.dragOffset = this.swipeStartOffset;
  262. this.swipeHorizontal = false;
  263. },
  264. onStudentTouchMove(event) {
  265. if (!this.activeRyid) return;
  266. const touch = this.eventPoint(event);
  267. if (!touch) return;
  268. const dx = touch.clientX - this.swipeStartX;
  269. const dy = touch.clientY - this.swipeStartY;
  270. if (!this.swipeHorizontal) {
  271. if (Math.abs(dx) < 5 && Math.abs(dy) < 5) return;
  272. if (Math.abs(dx) <= Math.abs(dy)) return;
  273. this.swipeHorizontal = true;
  274. }
  275. if (event.cancelable) event.preventDefault();
  276. this.dragOffset = Math.max(
  277. -72, Math.min(0, this.swipeStartOffset + dx));
  278. },
  279. onStudentTouchEnd(event) {
  280. if (!this.activeRyid) return;
  281. const touch = this.eventPoint(event);
  282. let horizontal = this.swipeHorizontal;
  283. let finalOffset = this.dragOffset;
  284. if (touch) {
  285. const dx = touch.clientX - this.swipeStartX;
  286. const dy = touch.clientY - this.swipeStartY;
  287. if (Math.abs(dx) > 30 && Math.abs(dx) > Math.abs(dy)) {
  288. horizontal = true;
  289. finalOffset = Math.max(
  290. -72, Math.min(0, this.swipeStartOffset + dx));
  291. }
  292. }
  293. if (horizontal) {
  294. this.openRyid = finalOffset <= -30 ? this.activeRyid : "";
  295. this.suppressClickUntil = Date.now() + 350;
  296. }
  297. this.activeRyid = "";
  298. this.dragOffset = 0;
  299. this.swipeHorizontal = false;
  300. },
  301. toggleStudentActions(student) {
  302. if (!student || Date.now() < this.suppressClickUntil) return;
  303. const ryid = String(student.ryid);
  304. this.openRyid = this.openRyid === ryid ? "" : ryid;
  305. },
  306. onStudentPointerStart(student, event) {
  307. if (event.pointerType === "touch") return;
  308. if (event.currentTarget
  309. && typeof event.currentTarget.setPointerCapture === "function") {
  310. event.currentTarget.setPointerCapture(event.pointerId);
  311. }
  312. this.onStudentTouchStart(student, event);
  313. },
  314. onStudentPointerMove(event) {
  315. if (event.pointerType === "touch") return;
  316. this.onStudentTouchMove(event);
  317. },
  318. onStudentPointerEnd(event) {
  319. if (event.pointerType === "touch") return;
  320. this.onStudentTouchEnd(event);
  321. },
  322. rowOffset(student) {
  323. const ryid = String(student.ryid);
  324. if (this.activeRyid === ryid) return this.dragOffset;
  325. return this.openRyid === ryid ? -72 : 0;
  326. },
  327. actionOffset(student) {
  328. return 72 + this.rowOffset(student);
  329. },
  330. deleteStudent(student) {
  331. if (!student) return;
  332. const ryid = String(student.ryid);
  333. this.roomData.students = this.roomData.students.filter(
  334. (item) => String(item.ryid) !== ryid);
  335. this.recomputeRoomSummary();
  336. this.persistInputState();
  337. this.openRyid = "";
  338. this.activeRyid = "";
  339. this.dragOffset = 0;
  340. this.showToast("已从本次检查名单移除");
  341. },
  342. recomputeRoomSummary() {
  343. const bjMap = new Map();
  344. const studentTexts = [];
  345. for (const student of this.roomData.students) {
  346. const bjid = String(student.bjid || "");
  347. if (bjid) {
  348. bjMap.set(bjid, student.bjmc || "");
  349. }
  350. studentTexts.push(student.xm + "("
  351. + (student.cwmc || "未分配床位") + ")");
  352. }
  353. this.roomData.bjList = Array.from(bjMap.entries()).map(
  354. ([bjid, bjmc]) => ({ bjid, bjmc }));
  355. this.roomData.xymcStr = studentTexts.join(",");
  356. this.roomData.bjmcStr = this.roomData.bjList
  357. .map((bj) => bj.bjmc)
  358. .join(",");
  359. },
  360. persistInputState() {
  361. try {
  362. const raw = sessionStorage.getItem("mp_ssnwjc_inp_state");
  363. if (!raw) return;
  364. const state = JSON.parse(raw);
  365. state.roomData = JSON.parse(JSON.stringify(this.roomData));
  366. if (state.form) {
  367. const bjids = this.roomData.bjList
  368. .map((bj) => String(bj.bjid))
  369. .filter(Boolean);
  370. state.form.bjidStr = bjids.join(",");
  371. if (state.form.bjid
  372. && !bjids.includes(String(state.form.bjid))) {
  373. state.form.bjid = "";
  374. }
  375. }
  376. sessionStorage.setItem(
  377. "mp_ssnwjc_inp_state", JSON.stringify(state));
  378. } catch (error) {
  379. console.warn("[mp_ssnwjc_detail] 保存检查名单失败", error);
  380. }
  381. },
  382. showToast(message) {
  383. if (typeof window.showToastEffect === "function") {
  384. window.showToastEffect(message, 1800, "success");
  385. }
  386. },
  387. getUrlParams() {
  388. const params = {};
  389. const search = new URLSearchParams(window.location.search);
  390. for (const [key, value] of search) {
  391. params[key] = decodeURIComponent(value);
  392. }
  393. return params;
  394. },
  395. getRequest() {
  396. return (window && window.request) || request;
  397. },
  398. async postService(url, data) {
  399. const req = this.getRequest();
  400. if (!req || typeof req.post !== "function") {
  401. throw new Error("请求组件未加载");
  402. }
  403. const response = await req.post(url, data, {
  404. loading: false,
  405. formData: true
  406. });
  407. const raw = response && response.data !== undefined ? response.data : response;
  408. if (raw && raw.ssCode !== undefined && Number(raw.ssCode) !== 0) {
  409. throw new Error(raw.ssMsg || "请求失败");
  410. }
  411. return raw && raw.ssData !== undefined ? raw.ssData : raw;
  412. },
  413. onTouchStart(event) {
  414. const touch = event.changedTouches && event.changedTouches[0];
  415. if (!touch) return;
  416. this.touchStartX = touch.clientX;
  417. this.touchStartY = touch.clientY;
  418. },
  419. onTouchEnd(event) {
  420. const touch = event.changedTouches && event.changedTouches[0];
  421. if (!touch) return;
  422. const dx = touch.clientX - this.touchStartX;
  423. const dy = Math.abs(touch.clientY - this.touchStartY);
  424. if (dx > 80 && dy < 60) {
  425. this.goBack();
  426. }
  427. },
  428. goBack() {
  429. if (window.history.length > 1) {
  430. window.history.back();
  431. } else if (window.wx && window.wx.miniProgram) {
  432. window.wx.miniProgram.navigateBack({ delta: 1 });
  433. }
  434. }
  435. }
  436. });
  437. });
  438. </script>
  439. </body>
  440. </html>