| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8" />
- <meta
- name="viewport"
- content="width=device-width, initial-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;
- background: #f5f6f7;
- }
- #app {
- min-height: 100vh;
- padding-bottom: 88px;
- box-sizing: border-box;
- }
- .loading-card,
- .error-card,
- .form-card {
- margin: 12px;
- padding: 14px 16px;
- border-radius: 12px;
- background: #fff;
- box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
- }
- .error-card {
- color: #c62828;
- }
- .table {
- width: 100%;
- border-collapse: collapse;
- }
- .table th {
- width: 88px;
- padding: 8px 0;
- text-align: left;
- vertical-align: top;
- font-weight: 600;
- color: #374151;
- }
- .table td {
- padding: 8px 0;
- }
- </style>
- </head>
- <body>
- <div id="app" v-cloak>
- <div v-if="loading" class="loading-card">加载中...</div>
- <div v-else-if="errorMessage" class="error-card">{{ errorMessage }}</div>
- <div v-else class="form-card">
- <table class="table">
- <tr>
- <th>销假日期</th>
- <td>
- <ss-datetime-picker
- v-model="formData.jssj"
- mode="date"
- :min-date="minJssj"
- :max-date="maxJssj"
- placeholder="YYYY-MM-DD"
- >
- </ss-datetime-picker>
- </td>
- </tr>
- </table>
- </div>
- <ss-bottom
- v-if="!loading && !errorMessage"
- :buttons="bottomButtons"
- :disabled="submitting"
- @button-click="handleBottomAction"
- >
- </ss-bottom>
- </div>
- <script>
- window.SS.ready(function () {
- window.SS.dom.initializeFormApp({
- el: "#app",
- data() {
- return {
- loading: true,
- submitting: false,
- errorMessage: "",
- pageParams: {},
- rcid: "",
- saveServiceName: "rc_xj_tj",
- minJssj: "",
- maxJssj: "",
- minJssjMsg: "销假时间不能早于当前时间",
- formData: {
- jssj: "",
- },
- bottomButtons: [
- { text: "取消", action: "cancel" },
- { text: "保存", action: "submit" },
- ],
- };
- },
- mounted() {
- this.pageParams = this.getUrlParams();
- this.initPage();
- },
- methods: {
- getUrlParams() {
- const params = {};
- const urlSearchParams = new URLSearchParams(window.location.search);
- for (const [key, value] of urlSearchParams) {
- params[key] = decodeURIComponent(value);
- }
- return params;
- },
- unwrapResponseData(data) {
- if (!data || typeof data !== "object") {
- return {};
- }
- if (data.ssData && typeof data.ssData === "object") {
- return data.ssData;
- }
- return data;
- },
- async initPage() {
- const params = this.pageParams || {};
- const rcid = String(params.rcid || params.ssObjId || "").trim();
- this.rcid = rcid;
- if (!rcid) {
- this.errorMessage = "缺少请假记录ID";
- this.loading = false;
- return;
- }
- const requestUrl = params.ssToken
- ? `/service?ssToken=${encodeURIComponent(params.ssToken)}`
- : `/service?ssServ=${encodeURIComponent(
- params.service || params.ssServ || "rc_xj"
- )}`;
- try {
- const response = await request.post(
- requestUrl,
- {
- rcid: rcid,
- ssObjId: rcid,
- },
- {
- loading: false,
- formData: true,
- }
- );
- const payload = this.unwrapResponseData(response && response.data);
- if (payload.ok === false) {
- this.errorMessage = payload.msg || "销假页面初始化失败";
- return;
- }
- this.saveServiceName = String(
- payload.saveServiceName || "rc_xj_tj"
- ).trim();
- this.minJssjMsg = String(
- payload.minJssjMsg || "销假时间不能早于当前时间"
- ).trim();
- this.minJssj = String(payload.minJssj || payload.nowTime || "").trim();
- this.maxJssj = String(payload.maxJssj || payload.jssj || "").trim();
- this.formData.jssj = this.extractDateValue(
- String(payload.defaultJssj || payload.nowTime || this.minJssj || "").trim()
- );
- } catch (error) {
- console.error("[mp_rcXj] 初始化失败", error);
- this.errorMessage = "销假页面初始化失败";
- } finally {
- this.loading = false;
- }
- },
- handleBottomAction(data) {
- if (!data || !data.action) return;
- if (data.action === "cancel") {
- this.goBack(false);
- return;
- }
- if (data.action === "submit") {
- this.submitForm();
- }
- },
- goBack(refreshParent) {
- if (
- window.NavigationManager &&
- typeof window.NavigationManager.goBack === "function"
- ) {
- window.NavigationManager.goBack({ refreshParent: !!refreshParent });
- } else {
- window.history.back();
- }
- },
- showToast(message, type) {
- if (typeof window.showToast === "function") {
- window.showToast(message, type || "info");
- return;
- }
- if (typeof window.showToastEffect === "function") {
- window.showToastEffect(message, 1800, type || "info");
- return;
- }
- alert(message);
- },
- extractDateValue(value) {
- const text = String(value || "").trim();
- if (!text) return "";
- const matched = text.match(/^\d{4}-\d{2}-\d{2}/);
- return matched ? matched[0] : text;
- },
- buildSubmitJssj() {
- const dateValue = this.extractDateValue(this.formData.jssj);
- if (!dateValue) return "";
- const minDateValue = this.extractDateValue(this.minJssj);
- const maxDateValue = this.extractDateValue(this.maxJssj);
- if (minDateValue && dateValue === minDateValue && this.minJssj) {
- return String(this.minJssj).trim();
- }
- if (maxDateValue && dateValue === maxDateValue && this.maxJssj) {
- return String(this.maxJssj).trim();
- }
- return `${dateValue} 23:59`;
- },
- validateForm() {
- const value = this.extractDateValue(this.formData.jssj);
- if (!value) {
- return "请选择销假日期";
- }
- const minDateValue = this.extractDateValue(this.minJssj);
- if (minDateValue && value < minDateValue) {
- return this.minJssjMsg || "销假时间不能早于当前时间";
- }
- const maxDateValue = this.extractDateValue(this.maxJssj);
- if (maxDateValue && value > maxDateValue) {
- return "销假日期不能晚于原请假结束日期";
- }
- return "";
- },
- async submitForm() {
- if (this.submitting) return;
- const message = this.validateForm();
- if (message) {
- this.showToast(message, "warning");
- return;
- }
- this.submitting = true;
- try {
- const submitJssj = this.buildSubmitJssj();
- const response = await request.post(
- `/service?ssServ=${encodeURIComponent(
- this.saveServiceName || "rc_xj_tj"
- )}&ssDest=info`,
- {
- rcid: this.rcid,
- ssObjId: this.rcid,
- jssj: submitJssj,
- },
- {
- loading: false,
- formData: true,
- }
- );
- const payload = this.unwrapResponseData(response && response.data);
- if (payload.ok === false) {
- this.showToast(payload.msg || "销假保存失败", "error");
- return;
- }
- this.showToast(payload.msg || "销假保存成功", "success");
- setTimeout(() => this.goBack(true), 300);
- } catch (error) {
- console.error("[mp_rcXj] 保存失败", error);
- this.showToast("销假保存失败", "error");
- } finally {
- this.submitting = false;
- }
- },
- },
- });
- });
- </script>
- </body>
- </html>
|