mp_rcXj.html 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta
  6. name="viewport"
  7. content="width=device-width, initial-scale=1.0, user-scalable=no"
  8. />
  9. <title>销假</title>
  10. <script src="/js/mp_base/base.js"></script>
  11. <style>
  12. [v-cloak] {
  13. display: none !important;
  14. }
  15. body {
  16. margin: 0;
  17. background: #f5f6f7;
  18. }
  19. #app {
  20. min-height: 100vh;
  21. padding-bottom: 88px;
  22. box-sizing: border-box;
  23. }
  24. .loading-card,
  25. .error-card,
  26. .form-card {
  27. margin: 12px;
  28. padding: 14px 16px;
  29. border-radius: 12px;
  30. background: #fff;
  31. box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
  32. }
  33. .error-card {
  34. color: #c62828;
  35. }
  36. .table {
  37. width: 100%;
  38. border-collapse: collapse;
  39. }
  40. .table th {
  41. width: 88px;
  42. padding: 8px 0;
  43. text-align: left;
  44. vertical-align: top;
  45. font-weight: 600;
  46. color: #374151;
  47. }
  48. .table td {
  49. padding: 8px 0;
  50. }
  51. </style>
  52. </head>
  53. <body>
  54. <div id="app" v-cloak>
  55. <div v-if="loading" class="loading-card">加载中...</div>
  56. <div v-else-if="errorMessage" class="error-card">{{ errorMessage }}</div>
  57. <div v-else class="form-card">
  58. <table class="table">
  59. <tr>
  60. <th>销假日期</th>
  61. <td>
  62. <ss-datetime-picker
  63. v-model="formData.jssj"
  64. mode="date"
  65. :min-date="minJssj"
  66. :max-date="maxJssj"
  67. placeholder="YYYY-MM-DD"
  68. >
  69. </ss-datetime-picker>
  70. </td>
  71. </tr>
  72. </table>
  73. </div>
  74. <ss-bottom
  75. v-if="!loading && !errorMessage"
  76. :buttons="bottomButtons"
  77. :disabled="submitting"
  78. @button-click="handleBottomAction"
  79. >
  80. </ss-bottom>
  81. </div>
  82. <script>
  83. window.SS.ready(function () {
  84. window.SS.dom.initializeFormApp({
  85. el: "#app",
  86. data() {
  87. return {
  88. loading: true,
  89. submitting: false,
  90. errorMessage: "",
  91. pageParams: {},
  92. rcid: "",
  93. saveServiceName: "rc_xj_tj",
  94. minJssj: "",
  95. maxJssj: "",
  96. minJssjMsg: "销假时间不能早于当前时间",
  97. formData: {
  98. jssj: "",
  99. },
  100. bottomButtons: [
  101. { text: "取消", action: "cancel" },
  102. { text: "保存", action: "submit" },
  103. ],
  104. };
  105. },
  106. mounted() {
  107. this.pageParams = this.getUrlParams();
  108. this.initPage();
  109. },
  110. methods: {
  111. getUrlParams() {
  112. const params = {};
  113. const urlSearchParams = new URLSearchParams(window.location.search);
  114. for (const [key, value] of urlSearchParams) {
  115. params[key] = decodeURIComponent(value);
  116. }
  117. return params;
  118. },
  119. unwrapResponseData(data) {
  120. if (!data || typeof data !== "object") {
  121. return {};
  122. }
  123. if (data.ssData && typeof data.ssData === "object") {
  124. return data.ssData;
  125. }
  126. return data;
  127. },
  128. async initPage() {
  129. const params = this.pageParams || {};
  130. const rcid = String(params.rcid || params.ssObjId || "").trim();
  131. this.rcid = rcid;
  132. if (!rcid) {
  133. this.errorMessage = "缺少请假记录ID";
  134. this.loading = false;
  135. return;
  136. }
  137. const requestUrl = params.ssToken
  138. ? `/service?ssToken=${encodeURIComponent(params.ssToken)}`
  139. : `/service?ssServ=${encodeURIComponent(
  140. params.service || params.ssServ || "rc_xj"
  141. )}`;
  142. try {
  143. const response = await request.post(
  144. requestUrl,
  145. {
  146. rcid: rcid,
  147. ssObjId: rcid,
  148. },
  149. {
  150. loading: false,
  151. formData: true,
  152. }
  153. );
  154. const payload = this.unwrapResponseData(response && response.data);
  155. if (payload.ok === false) {
  156. this.errorMessage = payload.msg || "销假页面初始化失败";
  157. return;
  158. }
  159. this.saveServiceName = String(
  160. payload.saveServiceName || "rc_xj_tj"
  161. ).trim();
  162. this.minJssjMsg = String(
  163. payload.minJssjMsg || "销假时间不能早于当前时间"
  164. ).trim();
  165. this.minJssj = String(payload.minJssj || payload.nowTime || "").trim();
  166. this.maxJssj = String(payload.maxJssj || payload.jssj || "").trim();
  167. this.formData.jssj = this.extractDateValue(
  168. String(payload.defaultJssj || payload.nowTime || this.minJssj || "").trim()
  169. );
  170. } catch (error) {
  171. console.error("[mp_rcXj] 初始化失败", error);
  172. this.errorMessage = "销假页面初始化失败";
  173. } finally {
  174. this.loading = false;
  175. }
  176. },
  177. handleBottomAction(data) {
  178. if (!data || !data.action) return;
  179. if (data.action === "cancel") {
  180. this.goBack(false);
  181. return;
  182. }
  183. if (data.action === "submit") {
  184. this.submitForm();
  185. }
  186. },
  187. goBack(refreshParent) {
  188. if (
  189. window.NavigationManager &&
  190. typeof window.NavigationManager.goBack === "function"
  191. ) {
  192. window.NavigationManager.goBack({ refreshParent: !!refreshParent });
  193. } else {
  194. window.history.back();
  195. }
  196. },
  197. showToast(message, type) {
  198. if (typeof window.showToast === "function") {
  199. window.showToast(message, type || "info");
  200. return;
  201. }
  202. if (typeof window.showToastEffect === "function") {
  203. window.showToastEffect(message, 1800, type || "info");
  204. return;
  205. }
  206. alert(message);
  207. },
  208. extractDateValue(value) {
  209. const text = String(value || "").trim();
  210. if (!text) return "";
  211. const matched = text.match(/^\d{4}-\d{2}-\d{2}/);
  212. return matched ? matched[0] : text;
  213. },
  214. buildSubmitJssj() {
  215. const dateValue = this.extractDateValue(this.formData.jssj);
  216. if (!dateValue) return "";
  217. const minDateValue = this.extractDateValue(this.minJssj);
  218. const maxDateValue = this.extractDateValue(this.maxJssj);
  219. if (minDateValue && dateValue === minDateValue && this.minJssj) {
  220. return String(this.minJssj).trim();
  221. }
  222. if (maxDateValue && dateValue === maxDateValue && this.maxJssj) {
  223. return String(this.maxJssj).trim();
  224. }
  225. return `${dateValue} 23:59`;
  226. },
  227. validateForm() {
  228. const value = this.extractDateValue(this.formData.jssj);
  229. if (!value) {
  230. return "请选择销假日期";
  231. }
  232. const minDateValue = this.extractDateValue(this.minJssj);
  233. if (minDateValue && value < minDateValue) {
  234. return this.minJssjMsg || "销假时间不能早于当前时间";
  235. }
  236. const maxDateValue = this.extractDateValue(this.maxJssj);
  237. if (maxDateValue && value > maxDateValue) {
  238. return "销假日期不能晚于原请假结束日期";
  239. }
  240. return "";
  241. },
  242. async submitForm() {
  243. if (this.submitting) return;
  244. const message = this.validateForm();
  245. if (message) {
  246. this.showToast(message, "warning");
  247. return;
  248. }
  249. this.submitting = true;
  250. try {
  251. const submitJssj = this.buildSubmitJssj();
  252. const response = await request.post(
  253. `/service?ssServ=${encodeURIComponent(
  254. this.saveServiceName || "rc_xj_tj"
  255. )}&ssDest=info`,
  256. {
  257. rcid: this.rcid,
  258. ssObjId: this.rcid,
  259. jssj: submitJssj,
  260. },
  261. {
  262. loading: false,
  263. formData: true,
  264. }
  265. );
  266. const payload = this.unwrapResponseData(response && response.data);
  267. if (payload.ok === false) {
  268. this.showToast(payload.msg || "销假保存失败", "error");
  269. return;
  270. }
  271. this.showToast(payload.msg || "销假保存成功", "success");
  272. setTimeout(() => this.goBack(true), 300);
  273. } catch (error) {
  274. console.error("[mp_rcXj] 保存失败", error);
  275. this.showToast("销假保存失败", "error");
  276. } finally {
  277. this.submitting = false;
  278. }
  279. },
  280. },
  281. });
  282. });
  283. </script>
  284. </body>
  285. </html>