index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // components/tail_tip/index.js
  2. import {
  3. getDate,
  4. getWaterDrop,
  5. formatTime
  6. } from '../../utils/index/index'
  7. const app = getApp()
  8. Component({
  9. /**
  10. * 组件的属性列表
  11. */
  12. properties: {},
  13. props: {
  14. onFinish: {
  15. type: Function,
  16. value: () => {}
  17. },
  18. showTitText: true, //是否显示“操作时间"
  19. countdown: 0, // 倒计时时间
  20. urlPath: '../../', //图片路径
  21. titleText: '', // 右侧展示页面小标题
  22. isHomePage: false, // 是否是首页
  23. },
  24. /**
  25. * 组件的初始数据
  26. */
  27. data: {
  28. newDate: '', //现在时间
  29. remainingTime: '', //倒计时剩余时间
  30. timer: null,
  31. timer2: null,
  32. count: 0,
  33. hasNetworkType: false,
  34. cusModalObj: {
  35. visible: false,
  36. showCloseBtn: true
  37. },
  38. },
  39. didMount() {
  40. let showTitText = this.props.showTitText
  41. let remainingTime = showTitText ? '操作时间 ' + this.props.countdown + ' 秒' : this.props.countdown + ' 秒'
  42. this.setData({
  43. newDate: getDate(),
  44. remainingTime,
  45. })
  46. this.data.timer2 && clearInterval(this.data.timer2)
  47. let _this = this
  48. this.data.timer2 = setInterval(() => {
  49. _this.checkExpiryDate()
  50. this.setData({
  51. newDate: getDate()
  52. })
  53. this.getNetworkType()
  54. }, 1000);
  55. this.getNetworkType()
  56. this.startCountdown()
  57. },
  58. /**
  59. * 组件的方法列表
  60. */
  61. methods: {
  62. checkExpiryDate() {
  63. let expiryDate = app.globalData.snDisposition.expirationDate;
  64. // let expiryDate = '2025-01-25';
  65. // let expiryDate = '2024-12-26';
  66. if (expiryDate && expiryDate !== '') {
  67. console.log(`弹窗次数:${app.globalData.expirationDateOpenNum}`);
  68. let { cusModalObj } = this.data
  69. const now = new Date();
  70. // 计算当前日期
  71. const currentDate = new Date(formatTime(now,'YYYY-MM-DD 00:00:00'));
  72. // 计算到期日期
  73. const expiry = new Date(formatTime(expiryDate,'YYYY-MM-DD 00:00:00'));
  74. // 计算到期日期30天前
  75. const expiryThirtyDate = new Date(expiry.getFullYear(), expiry.getMonth(), expiry.getDate() - 30);
  76. // 检查是否在30天之前
  77. if (app.globalData.expirationDateOpenNum == 0 && !cusModalObj.visible && currentDate.getTime() == expiryThirtyDate.getTime()) {
  78. console.log(`您的FKJ账户将在 30 天后到期:${expiry.toLocaleDateString()}`);
  79. app.globalData.expirationDateOpenNum = app.globalData.expirationDateOpenNum + 1;
  80. this.setData({
  81. 'cusModalObj.visible': true,
  82. 'cusModalObj.showCloseBtn': true,
  83. })
  84. return;
  85. }
  86. // 如果当前日期超过到期日期
  87. if (!cusModalObj.visible && currentDate.getTime() >= expiry.getTime()) {
  88. console.log(`您的FKJ账户已到期。${expiry.toLocaleDateString()}`);
  89. this.setData({
  90. 'cusModalObj.visible': true,
  91. 'cusModalObj.showCloseBtn': false,
  92. })
  93. }
  94. }
  95. },
  96. onOk() {
  97. this.setData({
  98. 'cusModalObj.visible': false
  99. })
  100. },
  101. // 倒计时
  102. startCountdown() {
  103. let that = this
  104. let {
  105. count
  106. } = that.data
  107. count = that.props.countdown
  108. let showTitText = that.props.showTitText
  109. if (count && count > 0) {
  110. that.data.timer && clearInterval(that.data.timer)
  111. that.data.timer = setInterval(() => {
  112. count--
  113. let remainingTime = showTitText ? '操作时间 ' + count + ' 秒' : count + ' 秒'
  114. that.setData({
  115. remainingTime
  116. })
  117. if (count <= 0) {
  118. that.data.timer && clearInterval(that.data.timer)
  119. that.props.onFinish('finish')
  120. // 倒计时结束,清除定时器
  121. }
  122. }, 1000) // 每秒更新一次倒计时数字
  123. }
  124. },
  125. // 网络状态
  126. getNetworkType() {
  127. my.getNetworkType({
  128. success: (res) => {
  129. if (res.networkType == 'NOTREACHABLE') {
  130. this.setData({
  131. hasNetworkType: false,
  132. })
  133. my.showToast({
  134. content: '网络状态异常',
  135. duration: 2000
  136. });
  137. } else {
  138. this.setData({
  139. hasNetworkType: true,
  140. })
  141. }
  142. },
  143. fail: (error) => {
  144. console.log(error)
  145. this.setData({
  146. hasNetworkType: false,
  147. })
  148. },
  149. })
  150. },
  151. // 长按logo进入设置
  152. goto() {
  153. this.data.timer && clearInterval(this.data.timer)
  154. getWaterDrop()
  155. if (this.props.isHomePage) {
  156. this.clearIntervalAll()
  157. my.reLaunch({
  158. url: '/pages/settings/login/index'
  159. });
  160. }
  161. },
  162. clearIntervalAll() {
  163. this.data.timer && clearInterval(this.data.timer)
  164. this.data.timer2 && clearInterval(this.data.timer2)
  165. },
  166. onClose() {
  167. console.log('onclose')
  168. this.clearIntervalAll();
  169. my.reLaunch({
  170. url: '/pages/home/index'
  171. });
  172. }
  173. },
  174. didUnmount() {
  175. this.clearIntervalAll();
  176. },
  177. onUnload() {
  178. this.clearIntervalAll();
  179. },
  180. observers: {}
  181. })