wxh.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. var URl = 'https://qipei.9gt.net';
  2. // var apikey = '?appid=21&appkey=zb34e7d15453e97507ef794cf7b051zbefvgfdedfgt'
  3. //购物车减
  4. var carmin = function (that){
  5. var num = that.data.num;
  6. // 如果大于1时,才可以减
  7. if (num > 1) {
  8. num--;
  9. }
  10. // 只有大于一件的时候,才能normal状态,否则disable状态
  11. var minusStatus = num <= 1 ? 'disabled' : 'normal';
  12. // 将数值与状态写回
  13. that.setData({
  14. num: num,
  15. minusStatus: minusStatus
  16. });
  17. }
  18. //返回首页
  19. var home = function (that, e) {
  20. if (e.touches[0].clientY < 500 && e.touches[0].clientY > 0) {
  21. that.setData({
  22. top: e.touches[0].clientY
  23. })
  24. }
  25. }
  26. //购物车加
  27. var carjia = function(that){
  28. var num = that.data.num;
  29. // 不作过多考虑自增1
  30. num++;
  31. // 只有大于一件的时候,才能normal状态,否则disable状态
  32. var minusStatus = num < 1 ? 'disabled' : 'normal';
  33. // 将数值与状态写回
  34. that.setData({
  35. num: num,
  36. minusStatus: minusStatus
  37. });
  38. }
  39. //倒计时;
  40. var time = function (timeStamp, that) {
  41. var totalSecond = timeStamp - Date.parse(new Date()) / 1000;
  42. var interval = setInterval(function () {
  43. // 秒数
  44. var second = totalSecond;
  45. // // 天数位
  46. // var day = Math.floor(second / 3600 / 24);
  47. // var dayStr = day.toString();
  48. // if (dayStr.length == 1) dayStr = '0' + dayStr;
  49. // 小时位
  50. var hr = Math.floor(second / 3600);
  51. var hrStr = hr.toString();
  52. if (hrStr.length == 1) hrStr = '0' + hrStr;
  53. // 分钟位
  54. var min = Math.floor((second - hr * 3600) / 60);
  55. var minStr = min.toString();
  56. if (minStr.length == 1) minStr = '0' + minStr;
  57. // 秒位
  58. var sec = second - hr * 3600 - min * 60;
  59. var secStr = sec.toString();
  60. if (secStr.length == 1) secStr = '0' + secStr;
  61. that.setData({
  62. // countDownDay: dayStr,
  63. countDownHour: hrStr,
  64. countDownMinute: minStr,
  65. countDownSecond: secStr,
  66. });
  67. totalSecond--;
  68. if (totalSecond <= 0) {
  69. clearInterval(interval);
  70. wx.showToast({
  71. title: '活动已结束',
  72. });
  73. that.setData({
  74. // countDownDay: '00',
  75. countDownHour: '00',
  76. countDownMinute: '00',
  77. countDownSecond: '00',
  78. });
  79. }
  80. }.bind(that), 1000);
  81. }
  82. //倒计时2;
  83. var time2 = function (timeStamp, that) {
  84. var totalSecond = timeStamp - Date.parse(new Date()) / 1000;
  85. var interval = setInterval(function () {
  86. // 秒数
  87. var second = totalSecond;
  88. // // 天数位
  89. var day = Math.floor(second / 3600 / 24);
  90. var dayStr = day.toString();
  91. if (dayStr.length == 1) dayStr = '0' + dayStr;
  92. // 小时位
  93. var hr = Math.floor(second / 3600);
  94. var hrStr = hr.toString();
  95. if (hrStr.length == 1) hrStr = '0' + hrStr;
  96. // 分钟位
  97. var min = Math.floor((second - hr * 3600) / 60);
  98. var minStr = min.toString();
  99. if (minStr.length == 1) minStr = '0' + minStr;
  100. // 秒位
  101. var sec = second - hr * 3600 - min * 60;
  102. var secStr = sec.toString();
  103. if (secStr.length == 1) secStr = '0' + secStr;
  104. that.setData({
  105. countDownDay: dayStr,
  106. countDownHour: hrStr,
  107. countDownMinute: minStr,
  108. countDownSecond: secStr,
  109. });
  110. totalSecond--;
  111. if (totalSecond <= 0) {
  112. clearInterval(interval);
  113. wx.showToast({
  114. title: '活动已结束',
  115. });
  116. that.setData({
  117. countDownDay: '00',
  118. countDownHour: '00',
  119. countDownMinute: '00',
  120. countDownSecond: '00',
  121. });
  122. }
  123. }.bind(that), 1000);
  124. }
  125. var footan = function(that){
  126. that.setData({
  127. prostatus: true,
  128. show: false
  129. })
  130. }
  131. var tapsize = function(that,e){
  132. var $indexs = e.target.dataset.indexs;//内
  133. var $index = e.target.dataset.index;//外
  134. that.setData({
  135. taberindexs: $indexs,
  136. taberindex: $index
  137. })
  138. }
  139. module.exports = {
  140. URl: URl,//要引用的函数 xx:xx
  141. // apikey: apikey,
  142. carmin: carmin,
  143. carjia: carjia,
  144. time: time,
  145. footan: footan,
  146. tapsize: tapsize,
  147. home: home,
  148. time2: time2
  149. }