| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <!-- 2026-09-18 宿舍内务检查小程序专用页面。 -->
- <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?v=20261117-select-font-v4"></script>
- <style>
- [v-cloak] {
- display: none !important;
- }
- :root {
- --line: #e5e7eb;
- --text: #222222;
- --muted: #8b95a5;
- --soft: #f7f8fa;
- --green: #19a463;
- --green-soft: #eaf8f1;
- --danger: #e5484d;
- --danger-soft: #fff0f0;
- }
- * {
- box-sizing: border-box;
- }
- body {
- margin: 0;
- color: var(--text);
- background: #f3f4f6;
- font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
- "Microsoft YaHei", sans-serif;
- }
- #app {
- min-height: 100vh;
- padding-bottom: 86px;
- }
- .loading-container {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: 65vh;
- color: var(--muted);
- }
- .loading-spinner {
- width: 38px;
- height: 38px;
- margin-bottom: 12px;
- border: 4px solid #e6e8ec;
- border-top-color: var(--green);
- border-radius: 50%;
- animation: spin 0.9s linear infinite;
- }
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
- .error-box {
- margin: 18px 14px;
- padding: 18px;
- color: var(--danger);
- background: var(--danger-soft);
- border: 1px solid #ffd0d0;
- border-radius: 6px;
- line-height: 1.6;
- }
- .page-content {
- padding: 12px 14px 0;
- }
- .info-table,
- .score-table {
- overflow: hidden;
- background: #fff;
- border: 1px solid var(--line);
- border-radius: 6px;
- }
- .info-row {
- display: grid;
- grid-template-columns: 92px 1fr;
- min-height: 58px;
- border-bottom: 1px solid var(--line);
- }
- .info-row:last-child {
- border-bottom: none;
- }
- .info-label {
- display: flex;
- align-items: center;
- justify-content: flex-end;
- padding: 12px 14px;
- color: var(--muted);
- background: #fbfbfc;
- border-right: 1px solid var(--line);
- font-size: 15px;
- }
- .info-value {
- display: flex;
- align-items: center;
- min-width: 0;
- padding: 11px 12px;
- font-size: 15px;
- }
- .select-cell {
- width: 100%;
- min-width: 0;
- }
- .select-cell > .ss-select-container {
- width: 100%;
- min-width: 0;
- }
- .clickable {
- justify-content: space-between;
- gap: 10px;
- cursor: pointer;
- }
- .clickable-text {
- min-width: 0;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- .chevron {
- flex: 0 0 auto;
- color: #9aa3b2;
- font-size: 25px;
- line-height: 1;
- }
- .score-value {
- color: var(--green);
- font-weight: 700;
- font-size: 18px;
- }
- .veto-value {
- display: flex;
- align-items: center;
- justify-content: space-between;
- gap: 12px;
- width: 100%;
- }
- .native-input {
- width: 100%;
- height: 38px;
- padding: 0 10px;
- color: var(--text);
- background: #fff;
- border: 0;
- outline: none;
- font: inherit;
- }
- .native-input::placeholder {
- color: #b4bbc6;
- }
- .score-table {
- margin-top: 12px;
- }
- .score-row {
- display: grid;
- grid-template-columns: minmax(0, 1fr) 132px;
- min-height: 68px;
- overflow: visible;
- border-bottom: 1px solid var(--line);
- }
- .score-row:last-child {
- border-bottom: none;
- }
- .score-name {
- display: flex;
- align-items: center;
- padding: 10px 12px;
- line-height: 1.45;
- font-size: 15px;
- }
- .score-max {
- display: flex;
- align-items: center;
- justify-content: center;
- color: var(--muted);
- border-left: 1px solid var(--line);
- font-size: 16px;
- }
- .stepper {
- display: grid;
- grid-template-columns: 48px minmax(0, 1fr) 40px;
- align-items: center;
- width: auto;
- min-width: 0;
- margin: 10px 7px;
- background: #fff;
- border: 1px solid #cfd4dc;
- border-radius: 5px;
- overflow: hidden;
- }
- .stepper-btn {
- display: inline-flex;
- align-items: center;
- justify-content: center;
- gap: 1px;
- height: 44px;
- padding: 0;
- color: #596273;
- background: #f3f4f6;
- border: 0;
- font-size: 24px;
- line-height: 1;
- appearance: none;
- }
- .stepper-btn:disabled {
- color: #c8cdd5;
- background: #eceff2;
- }
- .stepper-deduct-num {
- font-size: 15px;
- font-weight: 400;
- line-height: 1;
- }
- .stepper-btn-symbol {
- line-height: 1;
- }
- .stepper-value {
- width: 100%;
- min-width: 0;
- height: 44px;
- padding: 0 4px;
- text-align: center;
- background: #fff;
- border: 0;
- border-left: 1px solid #e1e4e9;
- border-right: 1px solid #e1e4e9;
- outline: none;
- font: inherit;
- font-size: 15px;
- font-weight: 400;
- }
- .score-total {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 14px 4px 0;
- color: var(--muted);
- font-size: 14px;
- }
- .score-total strong {
- color: var(--green);
- font-size: 18px;
- }
- .empty-tip {
- padding: 16px 12px;
- color: var(--muted);
- text-align: center;
- font-size: 14px;
- }
- .sheet {
- max-height: 72vh;
- padding: 18px 16px 24px;
- background: #fff;
- }
- .sheet-mask {
- position: fixed;
- z-index: 9999;
- top: 0;
- right: 0;
- bottom: 0;
- left: 0;
- display: flex;
- align-items: flex-end;
- background: rgba(0, 0, 0, 0.35);
- }
- .sheet-mask .sheet {
- width: 100%;
- border-radius: 8px 8px 0 0;
- }
- .sheet-title {
- margin: 0 0 14px;
- font-size: 17px;
- font-weight: 700;
- }
- .sheet-list {
- overflow-y: auto;
- max-height: 58vh;
- }
- .sheet-item {
- padding: 13px 0;
- border-bottom: 1px solid #eef0f3;
- }
- .sheet-item:last-child {
- border-bottom: none;
- }
- .sheet-main {
- font-size: 15px;
- font-weight: 600;
- }
- .sheet-sub {
- margin-top: 4px;
- color: var(--muted);
- font-size: 13px;
- }
- .class-option {
- display: flex;
- align-items: center;
- justify-content: space-between;
- cursor: pointer;
- }
- .class-option.selected {
- color: var(--green);
- }
- .warning-bar {
- margin: 12px 14px 0;
- padding: 11px 12px;
- color: #9a6700;
- background: #fff8e6;
- border: 1px solid #ffe8a3;
- border-radius: 6px;
- line-height: 1.5;
- font-size: 14px;
- }
- .submit-hint {
- margin: 12px 14px 0;
- padding: 11px 12px;
- color: var(--danger);
- background: var(--danger-soft);
- border: 1px solid #ffd0d0;
- border-radius: 6px;
- line-height: 1.5;
- font-size: 14px;
- }
- .bottom-spacer {
- height: 16px;
- }
- </style>
- </head>
- <body>
- <div id="app" v-cloak>
- <div v-if="loading" class="loading-container">
- <div class="loading-spinner"></div>
- <div>加载中...</div>
- </div>
- <div v-else-if="errorMsg" class="error-box">
- {{ errorMsg }}
- </div>
- <template v-else>
- <div v-if="warnMsg" class="warning-bar">{{ warnMsg }}</div>
- <div v-if="submitHint" class="submit-hint">{{ submitHint }}</div>
- <div class="page-content">
- <div class="info-table">
- <div class="info-row">
- <div class="info-label">建筑物</div>
- <div class="info-value">
- <div class="select-cell">
- <ss-select
- v-model="form.jzwid"
- cb="xyssl"
- placeholder="建筑物"
- @change="onJzwChange"
- />
- </div>
- </div>
- </div>
- <div class="info-row">
- <div class="info-label">房间</div>
- <div class="info-value">
- <div class="select-cell">
- <ss-select
- :key="'room-' + form.jzwid"
- v-model="form.kfid"
- :options="roomOptions"
- :disabled="!form.jzwid || roomLoading"
- :placeholder="roomLoading ? '加载中...' : (form.jzwid ? '房间' : '请先选择建筑物')"
- @change="onKfChange"
- />
- </div>
- </div>
- </div>
- <div class="info-row">
- <div class="info-label">分数</div>
- <div class="info-value">
- <span class="score-value">{{ totalFs }}</span>
- <span class="score-max">/ {{ maxFs }}</span>
- </div>
- </div>
- <div class="info-row">
- <div class="info-label">一票否决</div>
- <div class="info-value">
- <div class="veto-value">
- <span>{{ form.veto ? '本次检查记 0 分' : '未启用' }}</span>
- <van-switch v-model="form.veto" size="22px" @change="onVetoChange"/>
- </div>
- </div>
- </div>
- <div class="info-row">
- <div class="info-label">说明</div>
- <div class="info-value">
- <input
- v-model="form.ms"
- class="native-input"
- maxlength="500"
- placeholder="请输入"
- />
- </div>
- </div>
- </div>
- <div class="score-table">
- <div v-if="!jcxmList.length" class="empty-tip">暂无评分项目</div>
- <div v-for="item in jcxmList" :key="item.ssnwjcxmm" class="score-row">
- <!-- 项目名称后固定展示满分,不随当前得分变化。 -->
- <div class="score-name">{{ item.mc }} ({{ item.mfz }})</div>
- <div class="stepper">
- <button
- class="stepper-btn"
- type="button"
- :disabled="form.veto || Number(item.value) <= 0"
- @click="changeScore(item, -1)"
- >
- <span class="stepper-btn-symbol">-</span><span
- v-if="deductedFs(item) > 0"
- class="stepper-deduct-num">{{ deductedFs(item) }}</span>
- </button>
- <input
- class="stepper-value"
- inputmode="numeric"
- :value="item.value"
- :min="0"
- :max="item.mfz"
- :disabled="form.veto"
- @input="onScoreInput(item, $event)"
- @blur="normalizeScore(item, $event)"
- />
- <button
- class="stepper-btn"
- type="button"
- :disabled="form.veto || Number(item.value) >= Number(item.mfz)"
- @click="changeScore(item, 1)"
- >
- +
- </button>
- </div>
- </div>
- </div>
- <div class="score-total">
- <span>评分合计</span>
- <strong>{{ totalFs }}</strong>
- </div>
- <div class="bottom-spacer"></div>
- </div>
- <ss-bottom
- :show-shyj="false"
- :buttons="submitting ? [{ text: '提交中...', action: 'submit' }] : bottomButtons"
- @button-click="handleBottomAction"
- :disabled="submitting"
- />
- </template>
- </div>
- <script>
- window.SS.ready(function () {
- window.SS.dom.initializeFormApp({
- el: "#app",
- data() {
- return {
- loading: true,
- submitting: false,
- errorMsg: "",
- warnMsg: "",
- submitHint: "",
- pageParams: {},
- jcxmList: [],
- beforeVetoScores: [],
- roomOptions: [],
- roomLoading: false,
- form: {
- jzwid: "",
- kfid: "",
- ms: "",
- veto: false
- },
- bottomButtons: [
- { text: "取消", action: "cancel" },
- { text: "保存并提交", action: "submit" }
- ]
- };
- },
- computed: {
- totalFs() {
- return this.jcxmList.reduce((sum, item) => sum + Number(item.value || 0), 0);
- },
- maxFs() {
- return this.jcxmList.reduce((sum, item) => sum + Number(item.mfz || 0), 0);
- }
- },
- async mounted() {
- this.pageParams = this.getUrlParams();
- window.addEventListener("pageshow", this.onPageShow);
- try {
- const sessionOk = await this.ensureSession();
- if (!sessionOk) return;
- await this.loadJcxm();
- this.restoreState();
- } catch (error) {
- console.error("[mp_ssnwjc_inp] 初始化失败", error);
- this.errorMsg = error && error.message ? error.message : "页面初始化失败";
- } finally {
- this.loading = false;
- }
- },
- methods: {
- onPageShow() {
- this.restoreState();
- },
- 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 ensureSession() {
- if (typeof window.ensureMiniProgramSessionFresh !== "function") {
- return true;
- }
- try {
- const result = await window.ensureMiniProgramSessionFresh({
- page: "mp_ssnwjc_inp",
- service: "ssnwjc_excelInitAdd",
- force: true
- });
- if (result && result.skipped && result.reason === "NO_URL_AUTH") {
- return true;
- }
- return true;
- } catch (error) {
- this.errorMsg = "登录状态刷新失败,请返回小程序重新进入";
- return false;
- }
- },
- async loadJcxm() {
- const result = await this.postService(
- "/service?ssServ=ssnwjc_excelInitAdd&ssDest=data",
- {}
- );
- this.jcxmList = (result || []).map((item) => ({
- ssnwjcxmm: Number(item.ssnwjcxmm),
- mc: item.mc,
- mfz: Number(item.mfz),
- value: Number(item.mfz)
- }));
- },
- 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;
- },
- async onJzwChange(value) {
- this.form.jzwid = String(value || "");
- this.form.kfid = "";
- this.roomOptions = [];
- if (!this.form.jzwid) return;
- try {
- this.roomLoading = true;
- const data = await this.postService(
- "/service?ssServ=ssnwjc_mpLoadRoom&ssDest=data",
- { jzwid: this.form.jzwid }
- );
- this.roomOptions = (data && data.rooms ? data.rooms : []).map((room) => ({
- n: room.mc,
- v: String(room.cdid)
- }));
- } catch (error) {
- this.roomOptions = [];
- this.showToast(error.message || "房间加载失败", "fail");
- } finally {
- this.roomLoading = false;
- }
- },
- async onKfChange(value) {
- this.form.kfid = String(value || "");
- if (!this.form.kfid) return;
- try {
- await this.postService(
- "/service?ssServ=ssnwjc_mpLoadRoom&ssDest=data",
- {
- jzwid: this.form.jzwid,
- kfid: this.form.kfid
- }
- );
- } catch (error) {
- this.showToast(error.message || "房间信息加载失败", "fail");
- }
- },
- saveState() {
- try {
- sessionStorage.setItem("mp_ssnwjc_inp_state", JSON.stringify({
- form: this.form,
- jcxmList: this.jcxmList,
- roomOptions: this.roomOptions,
- beforeVetoScores: this.beforeVetoScores
- }));
- } catch (error) {
- console.warn("[mp_ssnwjc_inp] 保存页面状态失败", error);
- }
- },
- restoreState() {
- try {
- const raw = sessionStorage.getItem("mp_ssnwjc_inp_state");
- if (!raw) return;
- const state = JSON.parse(raw);
- if (state.form) this.form = { ...this.form, ...state.form };
- if (Array.isArray(state.roomOptions)) this.roomOptions = state.roomOptions;
- if (Array.isArray(state.beforeVetoScores)) this.beforeVetoScores = state.beforeVetoScores;
- if (Array.isArray(state.jcxmList)) {
- const valueMap = new Map(
- state.jcxmList.map((item) => [String(item.ssnwjcxmm), item.value])
- );
- this.jcxmList = this.jcxmList.map((item) => ({
- ...item,
- value: valueMap.has(String(item.ssnwjcxmm))
- ? valueMap.get(String(item.ssnwjcxmm))
- : item.value
- }));
- }
- } catch (error) {
- console.warn("[mp_ssnwjc_inp] 恢复页面状态失败", error);
- }
- },
- clearState() {
- try {
- sessionStorage.removeItem("mp_ssnwjc_inp_state");
- } catch (_) {
- }
- },
- changeScore(item, delta) {
- if (this.form.veto) return;
- const next = Number(item.value || 0) + delta;
- item.value = Math.max(0, Math.min(Number(item.mfz), next));
- },
- deductedFs(item) {
- return Math.max(0, Number(item.mfz || 0) - Number(item.value || 0));
- },
- onScoreInput(item, event) {
- const raw = String(event.target.value || "").replace(/[^\d]/g, "");
- const next = raw === "" ? 0 : Number(raw);
- item.value = Math.max(0, Math.min(Number(item.mfz), next || 0));
- event.target.value = item.value;
- },
- normalizeScore(item, event) {
- const value = Number(item.value || 0);
- item.value = Math.max(0, Math.min(Number(item.mfz), value || 0));
- if (event && event.target) event.target.value = item.value;
- },
- onVetoChange(value) {
- if (value) {
- this.beforeVetoScores = this.jcxmList.map((item) => Number(item.value || 0));
- this.jcxmList.forEach((item) => {
- item.value = 0;
- });
- } else if (this.beforeVetoScores.length === this.jcxmList.length) {
- this.jcxmList.forEach((item, index) => {
- item.value = this.beforeVetoScores[index];
- });
- this.beforeVetoScores = [];
- } else {
- this.jcxmList.forEach((item) => {
- item.value = Number(item.mfz);
- });
- }
- },
- handleBottomAction(data) {
- if (data.action === "cancel") {
- this.goBack();
- } else if (data.action === "submit") {
- this.submit();
- }
- },
- validateForm() {
- if (!this.form.jzwid) return "请选择建筑物";
- if (!this.form.kfid) return "请选择房间";
- if (!this.jcxmList.length) return "评分项目未配置";
- return "";
- },
- buildSubmitData() {
- const data = {
- jzwid: this.form.jzwid,
- kfid: this.form.kfid,
- fs: this.totalFs,
- ms: (this.form.ms || "").trim(),
- veto: this.form.veto ? "1" : "0"
- };
- this.jcxmList.forEach((item) => {
- data["ssnwjcxmm" + item.ssnwjcxmm] = item.value;
- });
- return data;
- },
- async submit() {
- if (this.submitting) return;
- const message = this.validateForm();
- if (message) {
- this.submitHint = message;
- this.showToast(message, "fail");
- return;
- }
- try {
- this.submitting = true;
- this.warnMsg = "";
- this.submitHint = "";
- const result = await this.postService(
- "/service?ssServ=ssnwjc_mpSubmAdd&ssDest=data",
- this.buildSubmitData()
- );
- if (result && result.warnMsg) {
- this.warnMsg = result.warnMsg;
- this.submitHint = result.warnMsg;
- this.showToast(result.warnMsg, "fail");
- return;
- }
- this.clearState();
- try {
- sessionStorage.setItem("mp_ssnwjc_list_refresh", "1");
- sessionStorage.setItem("mp_ssnwjc_list_date", this.formatLocalDate(new Date()));
- } catch (_) {
- }
- this.showToast("提交成功", "success");
- setTimeout(() => this.goBack(), 900);
- } catch (error) {
- this.submitHint = error.message || "提交失败";
- this.showToast(this.submitHint, "fail");
- } finally {
- this.submitting = false;
- }
- },
- goBack() {
- this.clearState();
- if (this.pageParams && this.pageParams.from === "list") {
- if (window.history.length > 1) {
- window.history.back();
- } else {
- window.location.href = "/page/mp/mp_ssnwjc_list.html";
- }
- return;
- }
- if (window.wx && window.wx.miniProgram) {
- window.wx.miniProgram.navigateBack({ delta: 1 });
- } else if (window.history.length > 1) {
- window.history.back();
- }
- },
- formatLocalDate(date) {
- const year = date.getFullYear();
- const month = String(date.getMonth() + 1).padStart(2, "0");
- const day = String(date.getDate()).padStart(2, "0");
- return `${year}-${month}-${day}`;
- },
- showToast(message, type) {
- const toastType = type === "success" ? "success" : "error";
- if (typeof window.showToastEffect === "function") {
- window.showToastEffect(message, 2200, toastType);
- return;
- }
- console.log(type, message);
- }
- }
- });
- });
- </script>
- </body>
- </html>
|