index.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. // let expirationDate = app.globalData.snDisposition.expirationDate;
  50. let expirationDate = '2024-12-15';
  51. // let expirationDate = '2025-01-15';
  52. let visible = false
  53. let showCloseBtn = false
  54. if (expirationDate) {
  55. const now = new Date();
  56. const currentStr = new Date(formatTime(now,'YYYY-MM-DD 00:00:00'));
  57. const expirationDateStr = new Date(formatTime(expirationDate,'YYYY-MM-DD 00:00:00'));
  58. const expirationDateStr1 = new Date(expirationDateStr.getFullYear(), expirationDateStr.getMonth(), expirationDateStr.getDate() - 30);
  59. console.log(app.globalData.expirationDateOpenNum)
  60. if (currentStr.getTime() == expirationDateStr1.getTime() && app.globalData.expirationDateOpenNum == 0 && !this.data.cusModalObj.visible) {
  61. app.globalData.expirationDateOpenNum = app.globalData.expirationDateOpenNum + 1;
  62. _this.setData({
  63. 'cusModalObj.visible': true,
  64. 'cusModalObj.showCloseBtn': true,
  65. })
  66. console.log(currentStr.getTime() , expirationDateStr1.getTime(),currentStr.getTime() == expirationDateStr1.getTime())
  67. return
  68. }
  69. if(currentStr.getTime() >= expirationDateStr.getTime() && !this.data.cusModalObj.visible){
  70. console.log(currentStr.getTime() , expirationDateStr.getTime(),currentStr.getTime() >= expirationDateStr.getTime())
  71. _this.setData({
  72. 'cusModalObj.visible': true,
  73. 'cusModalObj.showCloseBtn': false,
  74. })
  75. }
  76. }
  77. this.setData({
  78. newDate: getDate()
  79. })
  80. this.getNetworkType()
  81. }, 1000);
  82. this.getNetworkType()
  83. this.startCountdown()
  84. },
  85. /**
  86. * 组件的方法列表
  87. */
  88. methods: {
  89. onOk() {
  90. this.setData({
  91. 'cusModalObj.visible': false
  92. })
  93. },
  94. // 倒计时
  95. startCountdown() {
  96. let that = this
  97. let {
  98. count
  99. } = that.data
  100. count = that.props.countdown
  101. let showTitText = that.props.showTitText
  102. if (count && count > 0) {
  103. that.data.timer && clearInterval(that.data.timer)
  104. that.data.timer = setInterval(() => {
  105. count--
  106. let remainingTime = showTitText ? '操作时间 ' + count + ' 秒' : count + ' 秒'
  107. that.setData({
  108. remainingTime
  109. })
  110. if (count <= 0) {
  111. that.data.timer && clearInterval(that.data.timer)
  112. that.props.onFinish('finish')
  113. // 倒计时结束,清除定时器
  114. }
  115. }, 1000) // 每秒更新一次倒计时数字
  116. }
  117. },
  118. // 网络状态
  119. getNetworkType() {
  120. my.getNetworkType({
  121. success: (res) => {
  122. if (res.networkType == 'NOTREACHABLE') {
  123. this.setData({
  124. hasNetworkType: false,
  125. })
  126. my.showToast({
  127. content: '网络状态异常',
  128. duration: 2000
  129. });
  130. } else {
  131. this.setData({
  132. hasNetworkType: true,
  133. })
  134. }
  135. },
  136. fail: (error) => {
  137. console.log(error)
  138. this.setData({
  139. hasNetworkType: false,
  140. })
  141. },
  142. })
  143. },
  144. // 长按logo进入设置
  145. goto() {
  146. this.data.timer && clearInterval(this.data.timer)
  147. getWaterDrop()
  148. if (this.props.isHomePage) {
  149. this.clearIntervalAll()
  150. my.reLaunch({
  151. url: '/pages/settings/login/index'
  152. });
  153. }
  154. },
  155. clearIntervalAll() {
  156. this.data.timer && clearInterval(this.data.timer)
  157. this.data.timer2 && clearInterval(this.data.timer2)
  158. },
  159. onClose() {
  160. console.log('onclose')
  161. this.clearIntervalAll();
  162. my.reLaunch({
  163. url: '/pages/home/index'
  164. });
  165. }
  166. },
  167. didUnmount() {
  168. this.clearIntervalAll();
  169. },
  170. onUnload() {
  171. this.clearIntervalAll();
  172. },
  173. observers: {}
  174. })