| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8"/>
- <meta name="viewport"
- content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
- <title>检查详情</title>
- <script src="/js/mp_base/base.js"></script>
- <style>
- [v-cloak] {
- display: none !important;
- }
- body {
- margin: 0;
- color: #222;
- background: #f3f4f6;
- font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
- "Microsoft YaHei", sans-serif;
- }
- #app {
- min-height: 100vh;
- padding-bottom: 20px;
- }
- .topbar {
- display: flex;
- align-items: center;
- justify-content: center;
- height: 52px;
- padding: 0 14px;
- background: #fff;
- border-bottom: 1px solid #e5e7eb;
- }
- .topbar-title {
- font-size: 17px;
- font-weight: 700;
- }
- .content {
- padding: 12px 14px;
- }
- .list {
- margin-top: 12px;
- overflow: hidden;
- background: #fff;
- border: 1px solid #e5e7eb;
- border-radius: 6px;
- }
- .student-card-list {
- display: grid;
- gap: 10px;
- margin-top: 12px;
- }
- .student-card-list .swipe-row {
- border: 1px solid #e5e7eb;
- border-radius: 6px;
- }
- .student-card-list .item {
- border-bottom: 0;
- }
- .student-card-list .card-empty {
- background: #fff;
- border: 1px solid #e5e7eb;
- border-radius: 6px;
- }
- .item {
- padding: 13px 14px;
- border-bottom: 1px solid #eef0f3;
- }
- .item:last-child {
- border-bottom: none;
- }
- .swipe-row {
- position: relative;
- overflow: hidden;
- background: #fff;
- touch-action: pan-y;
- }
- .student-delete {
- position: absolute;
- top: 0;
- bottom: 0;
- right: 0;
- width: 72px;
- padding: 0;
- color: #fff;
- background: #2f6fed;
- border: 0;
- border-radius: 0 5px 5px 0;
- font: inherit;
- font-size: 15px;
- transform: translateX(72px);
- transition: transform .18s ease;
- z-index: 2;
- }
- .student-content {
- position: relative;
- background: #fff;
- z-index: 1;
- }
- .student-content::after {
- content: "";
- position: absolute;
- top: 0;
- right: 0;
- bottom: 0;
- width: 6px;
- background: #007aff;
- }
- .swipe-row.dragging .student-delete {
- transition: none;
- }
- .item-main {
- font-size: 15px;
- font-weight: 600;
- }
- .item-sub {
- margin-top: 4px;
- color: #8b95a5;
- font-size: 13px;
- }
- .loading,
- .empty,
- .error {
- padding: 30px 14px;
- text-align: center;
- color: #8b95a5;
- font-size: 14px;
- }
- .error {
- color: #e5484d;
- }
- </style>
- </head>
- <body>
- <div id="app" v-cloak @touchstart="onTouchStart" @touchend="onTouchEnd">
- <div class="topbar">
- <div class="topbar-title">{{ title }}</div>
- </div>
- <div v-if="loading" class="loading">加载中...</div>
- <div v-else-if="errorMsg" class="error">{{ errorMsg }}</div>
- <div v-else class="content">
- <div v-if="type === 'student'" class="student-card-list">
- <div v-if="!roomData.students.length" class="empty card-empty">暂无有效住宿学员</div>
- <div
- v-for="student in roomData.students"
- :key="student.ryid"
- class="swipe-row"
- :class="{ dragging: activeRyid === String(student.ryid) }"
- @pointerdown.stop="onStudentPointerStart(student, $event)"
- @pointermove.stop="onStudentPointerMove($event)"
- @pointerup.stop="onStudentPointerEnd($event)"
- @pointercancel.stop="onStudentPointerEnd($event)"
- @touchstart.stop="onStudentTouchStart(student, $event)"
- @touchmove.stop="onStudentTouchMove($event)"
- @touchend.stop="onStudentTouchEnd"
- @touchcancel.stop="onStudentTouchEnd"
- @click.stop="toggleStudentActions(student)"
- >
- <button
- type="button"
- class="student-delete"
- :style="{ transform: 'translateX(' + actionOffset(student) + 'px)' }"
- @click.stop="deleteStudent(student)"
- >移除</button>
- <div
- class="item student-content"
- >
- <div class="item-main">{{ student.xm }}</div>
- <div class="item-sub">
- {{ student.cwmc || '未分配床位' }}
- <template v-if="student.bjmc"> · {{ student.bjmc }}</template>
- </div>
- </div>
- </div>
- </div>
- <div v-else class="list">
- <div v-if="!roomData.bjList.length" class="empty">暂无有效班级</div>
- <div v-for="bj in roomData.bjList" :key="bj.bjid" class="item">
- <div class="item-main">{{ bj.bjmc }}</div>
- </div>
- </div>
- </div>
- </div>
- <script>
- window.SS.ready(function () {
- window.SS.dom.initializeFormApp({
- el: "#app",
- data() {
- return {
- loading: true,
- errorMsg: "",
- type: "student",
- jzwid: "",
- kfid: "",
- touchStartX: 0,
- touchStartY: 0,
- activeRyid: "",
- openRyid: "",
- dragOffset: 0,
- swipeStartX: 0,
- swipeStartY: 0,
- swipeStartOffset: 0,
- swipeHorizontal: false,
- suppressClickUntil: 0,
- roomData: {
- students: [],
- bjList: [],
- xymcStr: "",
- bjmcStr: ""
- }
- };
- },
- computed: {
- title() {
- return this.type === "class" ? "班级详情" : "学员详情";
- }
- },
- async mounted() {
- const params = this.getUrlParams();
- this.type = String(params.type || "student") === "class" ? "class" : "student";
- this.jzwid = String(params.jzwid || "");
- this.kfid = String(params.kfid || "");
- if (!this.jzwid || !this.kfid) {
- this.errorMsg = "缺少房间参数";
- this.loading = false;
- return;
- }
- try {
- const response = await this.postService(
- "/service?ssServ=ssnwjc_mpLoadRoom&ssDest=data",
- { jzwid: this.jzwid, kfid: this.kfid }
- );
- this.roomData = {
- students: response.students || [],
- bjList: response.bjList || [],
- xymcStr: response.xymcStr || "",
- bjmcStr: response.bjmcStr || ""
- };
- } catch (error) {
- this.errorMsg = error.message || "详情加载失败";
- } finally {
- this.loading = false;
- }
- },
- methods: {
- eventPoint(event) {
- return (event.changedTouches && event.changedTouches[0])
- || (event.touches && event.touches[0])
- || event;
- },
- onStudentTouchStart(student, event) {
- const touch = this.eventPoint(event);
- if (!touch) return;
- const ryid = String(student.ryid);
- if (this.openRyid && this.openRyid !== ryid) {
- this.openRyid = "";
- }
- this.activeRyid = ryid;
- this.swipeStartX = touch.clientX;
- this.swipeStartY = touch.clientY;
- this.swipeStartOffset = this.openRyid === ryid ? -72 : 0;
- this.dragOffset = this.swipeStartOffset;
- this.swipeHorizontal = false;
- },
- onStudentTouchMove(event) {
- if (!this.activeRyid) return;
- const touch = this.eventPoint(event);
- if (!touch) return;
- const dx = touch.clientX - this.swipeStartX;
- const dy = touch.clientY - this.swipeStartY;
- if (!this.swipeHorizontal) {
- if (Math.abs(dx) < 5 && Math.abs(dy) < 5) return;
- if (Math.abs(dx) <= Math.abs(dy)) return;
- this.swipeHorizontal = true;
- }
- if (event.cancelable) event.preventDefault();
- this.dragOffset = Math.max(
- -72, Math.min(0, this.swipeStartOffset + dx));
- },
- onStudentTouchEnd(event) {
- if (!this.activeRyid) return;
- const touch = this.eventPoint(event);
- let horizontal = this.swipeHorizontal;
- let finalOffset = this.dragOffset;
- if (touch) {
- const dx = touch.clientX - this.swipeStartX;
- const dy = touch.clientY - this.swipeStartY;
- if (Math.abs(dx) > 30 && Math.abs(dx) > Math.abs(dy)) {
- horizontal = true;
- finalOffset = Math.max(
- -72, Math.min(0, this.swipeStartOffset + dx));
- }
- }
- if (horizontal) {
- this.openRyid = finalOffset <= -30 ? this.activeRyid : "";
- this.suppressClickUntil = Date.now() + 350;
- }
- this.activeRyid = "";
- this.dragOffset = 0;
- this.swipeHorizontal = false;
- },
- toggleStudentActions(student) {
- if (!student || Date.now() < this.suppressClickUntil) return;
- const ryid = String(student.ryid);
- this.openRyid = this.openRyid === ryid ? "" : ryid;
- },
- onStudentPointerStart(student, event) {
- if (event.pointerType === "touch") return;
- if (event.currentTarget
- && typeof event.currentTarget.setPointerCapture === "function") {
- event.currentTarget.setPointerCapture(event.pointerId);
- }
- this.onStudentTouchStart(student, event);
- },
- onStudentPointerMove(event) {
- if (event.pointerType === "touch") return;
- this.onStudentTouchMove(event);
- },
- onStudentPointerEnd(event) {
- if (event.pointerType === "touch") return;
- this.onStudentTouchEnd(event);
- },
- rowOffset(student) {
- const ryid = String(student.ryid);
- if (this.activeRyid === ryid) return this.dragOffset;
- return this.openRyid === ryid ? -72 : 0;
- },
- actionOffset(student) {
- return 72 + this.rowOffset(student);
- },
- deleteStudent(student) {
- if (!student) return;
- const ryid = String(student.ryid);
- this.roomData.students = this.roomData.students.filter(
- (item) => String(item.ryid) !== ryid);
- this.recomputeRoomSummary();
- this.persistInputState();
- this.openRyid = "";
- this.activeRyid = "";
- this.dragOffset = 0;
- this.showToast("已从本次检查名单移除");
- },
- recomputeRoomSummary() {
- const bjMap = new Map();
- const studentTexts = [];
- for (const student of this.roomData.students) {
- const bjid = String(student.bjid || "");
- if (bjid) {
- bjMap.set(bjid, student.bjmc || "");
- }
- studentTexts.push(student.xm + "("
- + (student.cwmc || "未分配床位") + ")");
- }
- this.roomData.bjList = Array.from(bjMap.entries()).map(
- ([bjid, bjmc]) => ({ bjid, bjmc }));
- this.roomData.xymcStr = studentTexts.join(",");
- this.roomData.bjmcStr = this.roomData.bjList
- .map((bj) => bj.bjmc)
- .join(",");
- },
- persistInputState() {
- try {
- const raw = sessionStorage.getItem("mp_ssnwjc_inp_state");
- if (!raw) return;
- const state = JSON.parse(raw);
- state.roomData = JSON.parse(JSON.stringify(this.roomData));
- if (state.form) {
- const bjids = this.roomData.bjList
- .map((bj) => String(bj.bjid))
- .filter(Boolean);
- state.form.bjidStr = bjids.join(",");
- if (state.form.bjid
- && !bjids.includes(String(state.form.bjid))) {
- state.form.bjid = "";
- }
- }
- sessionStorage.setItem(
- "mp_ssnwjc_inp_state", JSON.stringify(state));
- } catch (error) {
- console.warn("[mp_ssnwjc_detail] 保存检查名单失败", error);
- }
- },
- showToast(message) {
- if (typeof window.showToastEffect === "function") {
- window.showToastEffect(message, 1800, "success");
- }
- },
- getUrlParams() {
- const params = {};
- const search = new URLSearchParams(window.location.search);
- for (const [key, value] of search) {
- params[key] = decodeURIComponent(value);
- }
- return params;
- },
- getRequest() {
- return (window && window.request) || request;
- },
- async postService(url, data) {
- const req = this.getRequest();
- if (!req || typeof req.post !== "function") {
- throw new Error("请求组件未加载");
- }
- const response = await req.post(url, data, {
- loading: false,
- formData: true
- });
- const raw = response && response.data !== undefined ? response.data : response;
- if (raw && raw.ssCode !== undefined && Number(raw.ssCode) !== 0) {
- throw new Error(raw.ssMsg || "请求失败");
- }
- return raw && raw.ssData !== undefined ? raw.ssData : raw;
- },
- onTouchStart(event) {
- const touch = event.changedTouches && event.changedTouches[0];
- if (!touch) return;
- this.touchStartX = touch.clientX;
- this.touchStartY = touch.clientY;
- },
- onTouchEnd(event) {
- const touch = event.changedTouches && event.changedTouches[0];
- if (!touch) return;
- const dx = touch.clientX - this.touchStartX;
- const dy = Math.abs(touch.clientY - this.touchStartY);
- if (dx > 80 && dy < 60) {
- this.goBack();
- }
- },
- goBack() {
- if (window.history.length > 1) {
- window.history.back();
- } else if (window.wx && window.wx.miniProgram) {
- window.wx.miniProgram.navigateBack({ delta: 1 });
- }
- }
- }
- });
- });
- </script>
- </body>
- </html>
|