Browse Source

fix 有效期到期提醒

刘琳琳 1 month ago
parent
commit
6bd20156bf

+ 1 - 1
components/expirationReminderModal/index.axml

@@ -12,7 +12,7 @@
       设备 <text>已到期</text> ,请联系服务商续费激活。
     </view>
     <view class="dialog-footer" a:if="{{btnStatus}}">
-      <view class="dialog-footer-btn flex confirm magnify" onTap="confirm">已知悉</view>
+      <view class="dialog-footer-btn flex confirm magnify" onTap="cancel">已知悉</view>
     </view>
   </view>
 </view>

+ 12 - 40
components/expirationReminderModal/index.js

@@ -7,12 +7,9 @@ Component({
   /**
    * 组件的属性列表
    */
-  properties: {
-    isVisible: {
-      type: Boolean,
-      value: false,
-      observer: "handleVisibilityChange"
-    }
+  options: {
+    // 使用基础库内置的数据变化观测器
+    observers: true,
   },
   props: {
     // 是否显示modal
@@ -25,27 +22,9 @@ Component({
       type: String,
       value: ''
     },
-    // 是否显示取消按钮(默认显示)
-    // showCancelBtn: true,
     showCancelBtn: { // 定义一个属性
       type: Boolean,
       value: true, // 默认值
-      observer(newVal, oldVal) {
-        // 属性变化监听器
-        console.log('myProperty changed from', oldVal, 'to', newVal);
-        this.updateValue(newVal);
-      }
-    },
-    // 是否显示确认按钮(默认不显示)
-    showOkBtn: true,
-    //取消按钮文本
-    cancelText: '取消',
-    //确认按钮文本
-    okText: '确认',
-    //取消按钮回调
-    onCancel: {
-      type: Function,
-      value: () => {}
     },
     //确认按钮回调
     onOk: {
@@ -59,12 +38,6 @@ Component({
   data: {
     btnStatus: true,
   },
-  lifetimes: {
-    attached() {
-      // 初始化时手动调用
-      this.handleVisibilityChange(this.data.isVisible);
-    }
-  },
   didMount() {
     console.log(this.props.showCancelBtn)
   },
@@ -76,9 +49,6 @@ Component({
    * 组件的方法列表
    */
   methods: {
-    handleVisibilityChange(isVisible) {
-      console.log("Visibility on load:", isVisible);
-    },
     updateValue(newVal) {
       console.log(newVal)
       // 更新内部数据或执行其他逻辑
@@ -87,15 +57,17 @@ Component({
       });
     },
     cancel: throttle( function () {
+      const _this = this;
       setTimeout(()=>{
-        this.props.onCancel();
-      }, 100)
-    }, 1000),
-    confirm: throttle( function () {
-      setTimeout(()=>{
-        this.props.onOk();
+        _this.props.onOk();
       }, 100)
     }, 1000),
   },
-  observers: {}
+  observers: {
+    "showCancelBtn": function(val) {
+      // 属性变化监听器
+      console.log('myProperty changed from', val);
+      this.updateValue(val);
+    }
+  }
 })

+ 1 - 1
components/topTitle/index.axml

@@ -24,5 +24,5 @@
     <image a:if="{{ hasNetworkType }}" class="logo2" mode="scaleToFill" src="https://tx.hz-hanghui.com:8088/yx-fyzd/file/upload/imagesnew/static/home/wifi.png" />
     <image a:if="{{ !hasNetworkType }}" class="logo2" mode="scaleToFill" src="https://tx.hz-hanghui.com:8088/yx-fyzd/file/upload/imagesnew/static/home/no-wifi.png" />
   </view>
-  <expiration-reminder-modal :showCancelBtn="{{cusModalObj.showCloseBtn}}" content="30天" visible="{{cusModalObj.visible}}" onOk="onOk"/>
+  <expiration-reminder-modal isVisible="{{cusModalObj.showCloseBtn}}" showCancelBtn="{{cusModalObj.showCloseBtn}}" content="30天" visible="{{cusModalObj.visible}}" onOk="onOk"/>
 </view>

+ 37 - 28
components/topTitle/index.js

@@ -47,34 +47,7 @@ Component({
     this.data.timer2 && clearInterval(this.data.timer2)
     let _this = this
     this.data.timer2 = setInterval(() => {
-      // let expirationDate = app.globalData.snDisposition.expirationDate;
-      let expirationDate = '2024-12-15';
-      // let expirationDate = '2025-01-15';
-      let visible = false
-      let showCloseBtn = false
-      if (expirationDate) {
-        const now = new Date();
-        const currentStr = new Date(formatTime(now,'YYYY-MM-DD 00:00:00'));
-        const expirationDateStr = new Date(formatTime(expirationDate,'YYYY-MM-DD 00:00:00'));
-        const expirationDateStr1 = new Date(expirationDateStr.getFullYear(), expirationDateStr.getMonth(), expirationDateStr.getDate() - 30);
-        console.log(app.globalData.expirationDateOpenNum)
-        if (currentStr.getTime() == expirationDateStr1.getTime() && app.globalData.expirationDateOpenNum == 0 && !this.data.cusModalObj.visible) {
-          app.globalData.expirationDateOpenNum = app.globalData.expirationDateOpenNum + 1;
-          _this.setData({
-            'cusModalObj.visible': true,
-            'cusModalObj.showCloseBtn': true,
-          })
-          console.log(currentStr.getTime() , expirationDateStr1.getTime(),currentStr.getTime() == expirationDateStr1.getTime())
-          return
-        }
-        if(currentStr.getTime() >= expirationDateStr.getTime() && !this.data.cusModalObj.visible){
-          console.log(currentStr.getTime() , expirationDateStr.getTime(),currentStr.getTime() >= expirationDateStr.getTime())
-          _this.setData({
-            'cusModalObj.visible': true,
-            'cusModalObj.showCloseBtn': false,
-          })
-        }
-      }
+      _this.checkExpiryDate()
       this.setData({
         newDate: getDate()
       })
@@ -87,6 +60,42 @@ Component({
    * 组件的方法列表
    */
   methods: {
+    checkExpiryDate() {
+      let expiryDate = app.globalData.snDisposition.expirationDate;
+      // let expiryDate = '2025-01-25';
+      // let expiryDate = '2024-12-26';
+      if (expiryDate) {
+        console.log(`弹窗次数:${app.globalData.expirationDateOpenNum}`);
+        let { cusModalObj } = this.data
+        const now = new Date();
+        // 计算当前日期
+        const currentDate = new Date(formatTime(now,'YYYY-MM-DD 00:00:00'));
+        // 计算到期日期
+        const expiry = new Date(formatTime(expiryDate,'YYYY-MM-DD 00:00:00'));
+        // 计算到期日期30天前
+        const expiryThirtyDate = new Date(expiry.getFullYear(), expiry.getMonth(), expiry.getDate() - 30);
+
+        // 检查是否在30天之前
+        if (app.globalData.expirationDateOpenNum == 0 && !cusModalObj.visible && currentDate.getTime() == expiryThirtyDate.getTime()) {
+          console.log(`您的FKJ账户将在 30 天后到期:${expiry.toLocaleDateString()}`);
+          app.globalData.expirationDateOpenNum = app.globalData.expirationDateOpenNum + 1;
+          this.setData({
+            'cusModalObj.visible': true,
+            'cusModalObj.showCloseBtn': true,
+          })
+          return;
+        }
+
+        // 如果当前日期超过到期日期
+        if (!cusModalObj.visible && currentDate.getTime() >= expiry.getTime()) {
+          console.log(`您的FKJ账户已到期。${expiry.toLocaleDateString()}`);
+          this.setData({
+            'cusModalObj.visible': true,
+            'cusModalObj.showCloseBtn': false,
+          })
+        }
+      }
+    },
     onOk() {
       this.setData({
         'cusModalObj.visible': false