mp_xxhjjl_inp.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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?v=20261117-select-font-v4"></script>
  9. <style>
  10. [v-cloak] {
  11. display: none !important;
  12. }
  13. html,
  14. body {
  15. margin: 0;
  16. background: #f5f5f5;
  17. font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
  18. "Microsoft YaHei", sans-serif;
  19. }
  20. #app {
  21. min-height: 100vh;
  22. box-sizing: border-box;
  23. padding-bottom: calc(76px + env(safe-area-inset-bottom));
  24. }
  25. table {
  26. margin-top: 8px;
  27. }
  28. th {
  29. width: 126px;
  30. }
  31. .nature-switch {
  32. display: flex;
  33. gap: 8px;
  34. }
  35. .nature-btn {
  36. min-width: 76px;
  37. height: 36px;
  38. color: #333;
  39. background: #f3f4f6;
  40. border: 1px solid #d7dbe2;
  41. border-radius: 5px;
  42. font-size: 15px;
  43. }
  44. .nature-btn.active {
  45. color: #fff;
  46. background: #575d6d;
  47. border-color: #575d6d;
  48. }
  49. .participant-row {
  50. display: grid;
  51. grid-template-columns: minmax(0, 1fr) 82px;
  52. gap: 8px;
  53. align-items: center;
  54. }
  55. .add-btn {
  56. height: 38px;
  57. color: #333;
  58. background: #f0f1f3;
  59. border: 1px solid #d7dbe2;
  60. border-radius: 5px;
  61. font-size: 15px;
  62. }
  63. .participants {
  64. display: flex;
  65. flex-wrap: wrap;
  66. gap: 8px;
  67. margin-top: 8px;
  68. }
  69. .participant {
  70. display: inline-flex;
  71. align-items: center;
  72. gap: 6px;
  73. padding: 6px 9px;
  74. color: #333;
  75. background: #f3f4f6;
  76. border: 1px solid #d7dbe2;
  77. border-radius: 4px;
  78. font-size: 14px;
  79. }
  80. .participant-remove {
  81. padding: 0;
  82. color: #8b95a5;
  83. background: transparent;
  84. border: 0;
  85. font-size: 18px;
  86. line-height: 1;
  87. }
  88. .ms-textarea {
  89. width: 100%;
  90. min-height: 72px;
  91. padding: 8px 0;
  92. color: #333;
  93. background: transparent;
  94. border: 0;
  95. outline: none;
  96. font: inherit;
  97. resize: none;
  98. }
  99. .bottom-bar {
  100. position: fixed;
  101. left: 0;
  102. right: 0;
  103. bottom: 0;
  104. z-index: 20;
  105. display: flex;
  106. gap: 10px;
  107. padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  108. background: #fff;
  109. box-shadow: 0 -1px 6px rgba(0, 0, 0, 0.08);
  110. box-sizing: border-box;
  111. }
  112. .bottom-bar button {
  113. flex: 1;
  114. height: 44px;
  115. border: 0;
  116. border-radius: 6px;
  117. font-size: 16px;
  118. }
  119. .bottom-bar button:disabled {
  120. opacity: 0.6;
  121. }
  122. .btn-close {
  123. flex: 0 0 34% !important;
  124. color: #333;
  125. background: #f0f1f3;
  126. }
  127. .btn-submit {
  128. color: #fff;
  129. background: #575d6d;
  130. }
  131. </style>
  132. </head>
  133. <body>
  134. <div id="app" v-cloak>
  135. <table class="table">
  136. <tr>
  137. <th>获奖性质</th>
  138. <td>
  139. <div class="nature-switch">
  140. <button type="button" class="nature-btn"
  141. :class="{active: formData.hjxz === '1'}"
  142. @click="changeNature('1')">个人</button>
  143. <button type="button" class="nature-btn"
  144. :class="{active: formData.hjxz === '2'}"
  145. @click="changeNature('2')">集体</button>
  146. </div>
  147. </td>
  148. </tr>
  149. <tr>
  150. <th>获奖类别</th>
  151. <td>
  152. <ss-select
  153. v-model="formData.hjlbm"
  154. cb="hjlb"
  155. clearable
  156. placeholder="请选择"
  157. />
  158. </td>
  159. </tr>
  160. <tr>
  161. <th>获奖日期</th>
  162. <td>
  163. <ss-datetime-picker
  164. v-model="formData.hjrq"
  165. mode="date"
  166. placeholder="请选择日期"
  167. />
  168. </td>
  169. </tr>
  170. <tr v-if="formData.hjxz === '1'">
  171. <th>获奖学生</th>
  172. <td>
  173. <ss-select
  174. v-model="formData.ryid"
  175. cb="xy"
  176. inp="true"
  177. clearable
  178. placeholder="输入姓名查询"
  179. />
  180. </td>
  181. </tr>
  182. <tr v-if="formData.hjxz === '2'">
  183. <th>参与学生</th>
  184. <td>
  185. <div class="participant-row">
  186. <ss-select
  187. v-model="participantToAdd"
  188. cb="xy"
  189. inp="true"
  190. clearable
  191. placeholder="输入姓名查询"
  192. @loaded="onStudentOptionsLoaded"
  193. />
  194. <button type="button" class="add-btn" @click="addParticipant">
  195. 添加
  196. </button>
  197. </div>
  198. <div v-if="participants.length" class="participants">
  199. <span v-for="item in participants" :key="item.ryid"
  200. class="participant">
  201. {{ item.name || item.ryid }}
  202. <button type="button" class="participant-remove"
  203. @click="removeParticipant(item.ryid)">×</button>
  204. </span>
  205. </div>
  206. </td>
  207. </tr>
  208. <tr class="ms-row">
  209. <th>描述</th>
  210. <td>
  211. <textarea
  212. v-model="formData.ms"
  213. class="ms-textarea"
  214. placeholder="请录入获奖说明"
  215. ></textarea>
  216. </td>
  217. </tr>
  218. </table>
  219. <div class="bottom-bar">
  220. <button type="button" class="btn-close" @click="goBack">关闭</button>
  221. <button type="button" class="btn-submit" :disabled="submitting"
  222. @click="submitForm">
  223. {{ submitting ? '提交中...' : '保存并提交' }}
  224. </button>
  225. </div>
  226. </div>
  227. <script>
  228. const formatLocalDate = (date) => {
  229. const year = date.getFullYear();
  230. const month = String(date.getMonth() + 1).padStart(2, "0");
  231. const day = String(date.getDate()).padStart(2, "0");
  232. return `${year}-${month}-${day}`;
  233. };
  234. (function hideShellBottomBarEarly() {
  235. try {
  236. const embedded =
  237. new URLSearchParams(window.location.search).get("embed") === "1";
  238. const parentWin = window.parent;
  239. if (embedded && parentWin &&
  240. typeof parentWin.__mpObjInpSetBottomVisible === "function") {
  241. parentWin.__mpObjInpSetBottomVisible(false);
  242. }
  243. } catch (_) {}
  244. })();
  245. window.SS.ready(function () {
  246. window.SS.dom.initializeFormApp({
  247. el: "#app",
  248. data() {
  249. return {
  250. formData: {
  251. hjxz: "1",
  252. hjlbm: "",
  253. hjrq: formatLocalDate(new Date()),
  254. ryid: "",
  255. ms: ""
  256. },
  257. participantToAdd: "",
  258. participants: [],
  259. studentOptions: [],
  260. submitting: false
  261. };
  262. },
  263. methods: {
  264. changeNature(value) {
  265. this.formData.hjxz = value;
  266. if (value === "1") {
  267. this.participants = [];
  268. this.participantToAdd = "";
  269. } else {
  270. this.formData.ryid = "";
  271. }
  272. },
  273. onStudentOptionsLoaded(options) {
  274. this.studentOptions = Array.isArray(options) ? options : [];
  275. },
  276. addParticipant() {
  277. const ryid = String(this.participantToAdd || "").trim();
  278. if (!ryid) {
  279. this.toast("请选择参与学生", "warning");
  280. return;
  281. }
  282. if (this.participants.some((item) => item.ryid === ryid)) {
  283. this.toast("该学生已添加", "warning");
  284. return;
  285. }
  286. const option = this.studentOptions.find(
  287. (item) => String(item.v) === ryid
  288. );
  289. this.participants.push({
  290. ryid: ryid,
  291. name: option ? String(option.n || ryid) : ryid
  292. });
  293. this.participantToAdd = "";
  294. },
  295. removeParticipant(ryid) {
  296. this.participants = this.participants.filter(
  297. (item) => item.ryid !== ryid
  298. );
  299. },
  300. validateForm() {
  301. if (!this.formData.hjxz) return "请选择获奖性质";
  302. if (!this.formData.hjlbm) return "请选择获奖类别";
  303. if (!this.formData.hjrq) return "请选择获奖日期";
  304. if (this.formData.hjxz === "1" && !this.formData.ryid)
  305. return "请选择获奖学生";
  306. if (this.formData.hjxz === "2" && !this.participants.length)
  307. return "请至少添加一名参与学生";
  308. return "";
  309. },
  310. buildPayload() {
  311. return {
  312. ssObjName: "xxhjjl",
  313. hjxz: this.formData.hjxz,
  314. hjxzm: this.formData.hjxz === "2" ? "5" : "1",
  315. hjlbm: this.formData.hjlbm,
  316. hjrq: this.formData.hjrq,
  317. ryid: this.formData.ryid,
  318. ryids: this.formData.hjxz === "2"
  319. ? this.participants.map((item) => item.ryid).join(",")
  320. : "",
  321. ms: String(this.formData.ms || "").trim()
  322. };
  323. },
  324. async submitForm() {
  325. if (this.submitting) return;
  326. const message = this.validateForm();
  327. if (message) {
  328. this.toast(message, "warning");
  329. return;
  330. }
  331. this.submitting = true;
  332. try {
  333. const req = window.request;
  334. if (!req || typeof req.post !== "function")
  335. throw new Error("request 未就绪");
  336. const response = await req.post(
  337. "/service?ssServ=xxhjjlMp_save",
  338. this.buildPayload(),
  339. { loading: true, formData: true }
  340. );
  341. const body = response && response.data ? response.data : {};
  342. const result = body.ssData || body;
  343. const code = body.ssCode;
  344. if (code !== undefined && Number(code) !== 0) {
  345. throw new Error(body.msg || body.message || "提交失败");
  346. }
  347. if (result && result.warnMsg) {
  348. this.toast(result.warnMsg, "warning");
  349. } else {
  350. this.toast("提交成功", "success");
  351. }
  352. setTimeout(() => this.goBack(), 800);
  353. } catch (error) {
  354. console.error("[mp_xxhjjl_inp] 提交失败", error);
  355. const raw = error && error.message ? String(error.message) : "";
  356. const readable = /[\u4e00-\u9fa5]/.test(raw) && raw.length <= 60;
  357. this.toast(readable ? raw : "提交失败,请稍后重试", "error");
  358. } finally {
  359. this.submitting = false;
  360. }
  361. },
  362. toast(message, type) {
  363. try {
  364. if (typeof showToastEffect === "function") {
  365. showToastEffect(message, 1800, type || "info");
  366. return;
  367. }
  368. } catch (_) {}
  369. try {
  370. if (typeof showToast === "function")
  371. showToast(message, type || "info");
  372. } catch (_) {}
  373. },
  374. goBack() {
  375. const hostWin =
  376. window.parent && window.parent !== window
  377. ? window.parent
  378. : window;
  379. try {
  380. if (hostWin.NavigationManager &&
  381. typeof hostWin.NavigationManager.goBack === "function") {
  382. hostWin.NavigationManager.goBack({ refreshParent: true });
  383. return;
  384. }
  385. } catch (_) {}
  386. try {
  387. hostWin.history.back();
  388. } catch (_) {}
  389. }
  390. }
  391. });
  392. });
  393. </script>
  394. </body>
  395. </html>