home.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. define(['$', 'template', 'IScroll', 'product', 'user', 'native', 'config'], function ($, template, IScroll, product, user, native, config) {
  2. function back(event) {
  3. event.preventDefault();
  4. native.back();
  5. }
  6. return {
  7. title: '壹管家上门服务',
  8. body: '',
  9. init: function (pageData, dtd) {
  10. var $view = this;
  11. var $doc = $(document);
  12. var tpl = template('home/index', {
  13. showNavBar: !config.isWX && !config.isChubao
  14. });
  15. $('.spa-page-body', $view).html(tpl);
  16. setTimeout(function() {
  17. pageData.scroll = new IScroll('#homeScroll', {
  18. preventDefaultException: { className: /(^|\s)home-content(\s|$)/ }
  19. });
  20. }, 50);
  21. //返回
  22. $.newTouch('.back-button', function (event) {
  23. back.call(this, event);
  24. }, $view);
  25. $view.on('tapBackButton', function(event) {
  26. back.call(this, event);
  27. });
  28. //客服电话
  29. $.newTouch('.service-telephone', function (event) {
  30. event.preventDefault();
  31. native.call('4000328170');
  32. }, $view);
  33. // SPA
  34. $.newTouch('.btn-action-spa', function (event) {
  35. event.preventDefault();
  36. goProductPage(5);
  37. }, $view);
  38. // 美容
  39. $.newTouch('.btn-action-groom', function (event) {
  40. event.preventDefault();
  41. goProductPage(3);
  42. }, $view);
  43. // 剃毛
  44. $.newTouch('.btn-action-shave', function (event) {
  45. event.preventDefault();
  46. goProductPage(2);
  47. }, $view);
  48. // 洗澡
  49. $.newTouch('.btn-action-bath', function (event) {
  50. event.preventDefault();
  51. goProductPage(1);
  52. }, $view);
  53. // 洁牙
  54. $.newTouch('.btn-action-jieya', function (event) {
  55. event.preventDefault();
  56. goProductPage(4);
  57. }, $view);
  58. // 训犬
  59. $.newTouch('.btn-action-xunquan', function (event) {
  60. event.preventDefault();
  61. goProductPage(6);
  62. }, $view);
  63. // 断尾
  64. $.newTouch('.btn-action-duanwei', function (event) {
  65. event.preventDefault();
  66. goProductPage(7);
  67. }, $view);
  68. // 碳酸浴
  69. $.newTouch('.btn-action-tansuanyun', function (event) {
  70. event.preventDefault();
  71. goProductPage(8);
  72. }, $view);
  73. // 驱虫
  74. $.newTouch('.btn-action-quchong', function (event) {
  75. event.preventDefault();
  76. goProductPage(11);
  77. }, $view);
  78. // 药浴
  79. $.newTouch('.btn-action-yaoyu', function (event) {
  80. event.preventDefault();
  81. goProductPage(12);
  82. }, $view);
  83. // 染色
  84. $.newTouch('.btn-action-ranse', function (event) {
  85. event.preventDefault();
  86. goProductPage(13);
  87. }, $view);
  88. // 助产
  89. $.newTouch('.btn-action-zhuchan', function (event) {
  90. event.preventDefault();
  91. goComing(9);
  92. }, $view);
  93. // 我的预约
  94. $.newTouch('.btn-action-my-order', function (event) {
  95. event.preventDefault();
  96. user.checkLogin(function () {
  97. $doc.trigger('spa:navigate', {
  98. hash: 'myOrder/1',
  99. pushData: {
  100. needReload: true
  101. }
  102. });
  103. });
  104. }, $view);
  105. // 优惠券
  106. $.newTouch('.btn-action-coupon', function (event) {
  107. event.preventDefault();
  108. user.checkLogin(function () {
  109. $doc.trigger('spa:navigate', {
  110. hash: 'myCoupon'
  111. });
  112. });
  113. }, $view);
  114. // 招聘
  115. $.newTouch('.btn-action-hire', function() {
  116. event.preventDefault();
  117. $doc.trigger('spa:navigate', {
  118. hash: 'hire'
  119. });
  120. }, $view);
  121. dtd.resolve();
  122. function goProductPage(type) {
  123. user.checkLogin(function () {
  124. if (!user['productVisit'][13]) { // 预期字段不足 先清除本地数据
  125. localStorage.removeItem('user_productVisit');
  126. localStorage.removeItem('user_productVisit-time');
  127. user['productVisit'][13] = {
  128. visited: false
  129. }
  130. }
  131. if (user['productVisit'][type]['visited']) {
  132. $doc.trigger('spa:navigate', {
  133. hash: 'placeOrder',
  134. pushData: {
  135. productType: type,
  136. serviceType: type,
  137. needReset: true
  138. }
  139. });
  140. } else {
  141. $doc.trigger('spa:navigate', {
  142. hash: 'product',
  143. pushData: {
  144. type: type,
  145. needReload: true,
  146. fromHome: true
  147. }
  148. });
  149. user.productVisit[type].visited = true;
  150. user.setCache('productVisit');
  151. }
  152. });
  153. }
  154. function goComing(type) {
  155. user.checkLogin(function () {
  156. $doc.trigger('spa:navigate', {
  157. hash: 'coming',
  158. pushData: {
  159. productType: type
  160. }
  161. });
  162. });
  163. }
  164. if (!user.activities['visited_offservice0126']) {
  165. // showActivity();
  166. }
  167. function showActivity () {
  168. var imgUrl = 'http://wozhua-others.qiniudn.com/20160126-offservice.png';
  169. var d = new Image();
  170. d.src = imgUrl;
  171. d.onload = function() {
  172. $doc.trigger('spa:openpanel', ['activity', {
  173. content: imgUrl
  174. }]);
  175. }
  176. }
  177. },
  178. beforeopen: function(pageData, dtd) {
  179. localStorage.removeItem('cart_products');
  180. dtd.resolve();
  181. native.switchPopGesture(true);
  182. },
  183. afteropen: function(pageData, dtd) {
  184. var $view = this;
  185. var $doc = $(document);
  186. if (!pageData.pushData.dontNeedReload) {
  187. $doc.trigger('spa:openloader');
  188. product.getListAll(user.id, function(res) {
  189. $doc.trigger('spa:closeloader');
  190. if (res.holiday) {
  191. var offDay = res.holiday;
  192. product.offDay = offDay;
  193. }
  194. });
  195. }
  196. // 检测新用户
  197. if (!user.isCheck.couponCheck) {
  198. user.getCouponList(user.id, function(res) {
  199. if (res.success) {
  200. user.isCheck['couponCheck'] = true;
  201. user.setCache('isCheck');
  202. }
  203. });
  204. }
  205. dtd.resolve();
  206. //强制设置首页的上一页是空的,后面再调整框架
  207. pageData.prevPage = $('.spa-page-empty');
  208. },
  209. beforeclose: function(pageData, dtd) {
  210. dtd.resolve();
  211. native.switchPopGesture(false);
  212. }
  213. }
  214. })