wxh.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. import { CACHE_LONGITUDE, CACHE_LATITUDE } from '../config.js';
  2. //购物车减
  3. var carmin = function (that){
  4. var num = that.data.num;
  5. // 如果大于1时,才可以减
  6. if (num > 1) {
  7. num--;
  8. }
  9. // 只有大于一件的时候,才能normal状态,否则disable状态
  10. var minusStatus = num <= 1 ? 'disabled' : 'normal';
  11. // 将数值与状态写回
  12. that.setData({
  13. num: num,
  14. minusStatus: minusStatus
  15. });
  16. }
  17. //返回首页
  18. var home = function (that, e) {
  19. if (e.touches[0].clientY < 500 && e.touches[0].clientY > 0) {
  20. that.setData({
  21. top: e.touches[0].clientY
  22. })
  23. }
  24. }
  25. //购物车加
  26. var carjia = function(that){
  27. var num = that.data.num;
  28. // 不作过多考虑自增1
  29. num++;
  30. // 只有大于一件的时候,才能normal状态,否则disable状态
  31. var minusStatus = num < 1 ? 'disabled' : 'normal';
  32. // 将数值与状态写回
  33. that.setData({
  34. num: num,
  35. minusStatus: minusStatus
  36. });
  37. }
  38. //倒计时;
  39. var time = function (timeStamp, that) {
  40. var interval = null,totalSecond = timeStamp - Date.parse(new Date()) / 1000;
  41. interval = setInterval(function () {
  42. // 秒数
  43. var second = totalSecond;
  44. // 小时位
  45. var hr = Math.floor(second / 3600);
  46. var hrStr = hr.toString();
  47. if (hrStr.length == 1) hrStr = '0' + hrStr;
  48. // 分钟位
  49. var min = Math.floor((second - hr * 3600) / 60);
  50. var minStr = min.toString();
  51. if (minStr.length == 1) minStr = '0' + minStr;
  52. // 秒位
  53. var sec = second - hr * 3600 - min * 60;
  54. var secStr = sec.toString();
  55. if (secStr.length == 1) secStr = '0' + secStr;
  56. that.setData({
  57. countDownHour: hrStr,
  58. countDownMinute: minStr,
  59. countDownSecond: secStr,
  60. });
  61. totalSecond--;
  62. if (totalSecond <= 0) {
  63. clearInterval(interval);
  64. wx.showToast({
  65. title: '活动已结束',
  66. icon: 'none',
  67. duration: 1000,
  68. mask: true,
  69. })
  70. that.setData({
  71. countDownHour: '00',
  72. countDownMinute: '00',
  73. countDownSecond: '00',
  74. });
  75. }
  76. }.bind(that), 1000);
  77. that.setData({ interval: interval});
  78. }
  79. //倒计时2;
  80. var time2 = function (timeStamp, that) {
  81. var totalSecond = timeStamp - Date.parse(new Date()) / 1000;
  82. var interval = setInterval(function () {
  83. // 秒数
  84. var second = totalSecond;
  85. // // 天数位
  86. var day = Math.floor(second / 3600 / 24);
  87. var dayStr = day.toString();
  88. if (dayStr.length == 1) dayStr = '0' + dayStr;
  89. // 小时位
  90. var hr = Math.floor((second - day * 3600 * 24) / (60 * 60));
  91. var hrStr = hr.toString();
  92. if (hrStr.length == 1) hrStr = '0' + hrStr;
  93. // 分钟位
  94. // var min = Math.floor((second - hr * 3600) / 60);
  95. var min = Math.floor((second - day * 3600 * 24 - hr * 3600) / 60);
  96. var minStr = min.toString();
  97. if (minStr.length == 1) minStr = '0' + minStr;
  98. // 秒位
  99. // var sec = second - hrNew * 3600 - min * 60;
  100. var sec = Math.floor(second - day * 3600 * 24 - hr * 3600 - min * 60);
  101. var secStr = sec.toString();
  102. if (secStr.length == 1) secStr = '0' + secStr;
  103. that.setData({
  104. countDownDay: dayStr,
  105. countDownHour: hrStr,
  106. countDownMinute: minStr,
  107. countDownSecond: secStr,
  108. });
  109. totalSecond--;
  110. if (totalSecond <= 0) {
  111. clearInterval(interval);
  112. wx.showToast({
  113. title: '活动已结束',
  114. });
  115. that.setData({
  116. countDownDay: '00',
  117. countDownHour: '00',
  118. countDownMinute: '00',
  119. countDownSecond: '00',
  120. });
  121. }
  122. }.bind(that), 1000);
  123. that.setData({ interval: interval});
  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. var selfLocation = function(showMode) {
  140. const that = this;
  141. return new Promise((resolve, reject)=>{
  142. let longitude = wx.getStorageSync(CACHE_LONGITUDE); //经度
  143. let latitude = wx.getStorageSync(CACHE_LATITUDE); //纬度
  144. if (longitude && latitude) {
  145. return resolve({ longitude: longitude, latitude: latitude});
  146. }
  147. wx.getSetting({
  148. success: (res) => {
  149. if (!res.authSetting['scope.userLocation']) {
  150. wx.removeStorageSync(CACHE_LONGITUDE);
  151. wx.removeStorageSync(CACHE_LATITUDE);
  152. wx.getLocation({
  153. success: function (res) {
  154. var latitude = res.latitude;
  155. var longitude = res.longitude;
  156. wx.setStorageSync(CACHE_LONGITUDE, longitude);
  157. wx.setStorageSync(CACHE_LATITUDE, latitude);
  158. resolve(res);
  159. },
  160. fail(res) {
  161. if (res.errMsg == "getLocation:fail auth deny" && showMode == undefined) {
  162. wx.showModal({
  163. title: '您已经拒绝授权地理位置',
  164. content: '是否需要开启权限',
  165. success: function (res) {
  166. if (res.cancel) {
  167. reject(res);
  168. } else if (res.confirm) {
  169. wx.openSetting({
  170. success: function (res) {
  171. if (res.authSetting["scope.userLocation"] == true) {
  172. wx.showToast({
  173. title: '授权成功',
  174. icon: 'success',
  175. duration: 1000
  176. })
  177. wx.getLocation({
  178. success: function (res) {
  179. var latitude = res.latitude;
  180. var longitude = res.longitude;
  181. wx.setStorageSync(CACHE_LONGITUDE, longitude);
  182. wx.setStorageSync(CACHE_LATITUDE, latitude);
  183. resolve(res);
  184. }
  185. })
  186. } else {
  187. wx.showToast({
  188. title: '授权失败',
  189. icon: 'none',
  190. duration: 1000
  191. })
  192. }
  193. }
  194. })
  195. }
  196. },
  197. })
  198. }
  199. },
  200. });
  201. } else {
  202. wx.getLocation({
  203. success: function (res) {
  204. let latitude = res.latitude;
  205. let longitude = res.longitude;
  206. wx.setStorageSync(CACHE_LONGITUDE, longitude);
  207. wx.setStorageSync(CACHE_LATITUDE, latitude);
  208. resolve(res);
  209. }
  210. })
  211. }
  212. }
  213. })
  214. })
  215. }
  216. module.exports = {
  217. carmin: carmin,
  218. carjia: carjia,
  219. time: time,
  220. footan: footan,
  221. tapsize: tapsize,
  222. home: home,
  223. time2: time2,
  224. selfLocation: selfLocation
  225. }