home.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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-richang', function (event) {
  55. event.preventDefault();
  56. goProductPage(4);
  57. }, $view);
  58. /* //洁牙
  59. $.newTouch('.btn-action-jieya', function (event) {
  60. event.preventDefault();
  61. goProductPage(4);
  62. }, $view);*/
  63. // 训犬
  64. $.newTouch('.btn-action-xunquan', function (event) {
  65. event.preventDefault();
  66. goProductPage(6);
  67. }, $view);
  68. // 断尾
  69. $.newTouch('.btn-action-duanwei', function (event) {
  70. event.preventDefault();
  71. goProductPage(7);
  72. }, $view);
  73. //除螨杀菌-碳酸浴
  74. $.newTouch('.btn-action-tansuanyun', function (event) {
  75. event.preventDefault();
  76. goProductPage(8);
  77. }, $view);
  78. // 碳酸浴
  79. /*$.newTouch('.btn-action-tansuanyun', function (event) {
  80. event.preventDefault();
  81. goProductPage(8);
  82. }, $view);*/
  83. //深度清洁=屈虫
  84. $.newTouch('.btn-action-shendu', function (event) {
  85. event.preventDefault();
  86. goProductPage(11);
  87. }, $view);
  88. // 驱虫
  89. /* $.newTouch('.btn-action-quchong', function (event) {
  90. event.preventDefault();
  91. goProductPage(11);
  92. }, $view);*/
  93. //其它-药浴
  94. $.newTouch('.btn-action-qita', function (event) {
  95. event.preventDefault();
  96. goProductPage(12);
  97. }, $view);
  98. // 药浴
  99. /* $.newTouch('.btn-action-yaoyu', function (event) {
  100. event.preventDefault();
  101. goProductPage(12);
  102. }, $view);*/
  103. // 染色
  104. $.newTouch('.btn-action-ranse', function (event) {
  105. event.preventDefault();
  106. goProductPage(13);
  107. }, $view);
  108. // 助产
  109. $.newTouch('.btn-action-zhuchan', function (event) {
  110. event.preventDefault();
  111. goComing(9);
  112. }, $view);
  113. // 我的预约
  114. $.newTouch('.btn-action-my-order', function (event) {
  115. event.preventDefault();
  116. user.checkLogin(function () {
  117. $doc.trigger('spa:navigate', {
  118. hash: 'myOrder/1',
  119. pushData: {
  120. needReload: true
  121. }
  122. });
  123. });
  124. }, $view);
  125. // 优惠券
  126. $.newTouch('.btn-action-coupon', function (event) {
  127. event.preventDefault();
  128. user.checkLogin(function () {
  129. $doc.trigger('spa:navigate', {
  130. hash: 'myCoupon'
  131. });
  132. });
  133. }, $view);
  134. // 招聘
  135. $.newTouch('.btn-action-hire', function () {
  136. event.preventDefault();
  137. $doc.trigger('spa:navigate', {
  138. hash: 'hire'
  139. });
  140. }, $view);
  141. dtd.resolve();
  142. function goProductPage(type) {
  143. user.checkLogin(function () {
  144. if (!user['productVisit'][13]) { // 预期字段不足 先清除本地数据
  145. localStorage.removeItem('user_productVisit');
  146. localStorage.removeItem('user_productVisit-time');
  147. user['productVisit'][13] = {
  148. visited: false
  149. }
  150. }
  151. if (user['productVisit'][type]['visited']) {
  152. $doc.trigger('spa:navigate', {
  153. hash: 'placeOrder',
  154. pushData: {
  155. productType: type,
  156. serviceType: type,
  157. needReset: true
  158. }
  159. });
  160. } else {
  161. $doc.trigger('spa:navigate', {
  162. hash: 'product',
  163. pushData: {
  164. type: type,
  165. needReload: true,
  166. fromHome: true
  167. }
  168. });
  169. user.productVisit[type].visited = true;
  170. user.setCache('productVisit');
  171. }
  172. });
  173. }
  174. function goComing(type) {
  175. user.checkLogin(function () {
  176. $doc.trigger('spa:navigate', {
  177. hash: 'coming',
  178. pushData: {
  179. productType: type
  180. }
  181. });
  182. });
  183. }
  184. if (!user.activities['visited_offservice0126']) {
  185. // showActivity();
  186. }
  187. function showActivity() {
  188. var imgUrl = 'http://wozhua-others.qiniudn.com/20160126-offservice.png';
  189. var d = new Image();
  190. d.src = imgUrl;
  191. d.onload = function () {
  192. $doc.trigger('spa:openpanel', ['activity', {
  193. content: imgUrl
  194. }]);
  195. }
  196. }
  197. },
  198. beforeopen: function (pageData, dtd) {
  199. localStorage.removeItem('cart_products');
  200. dtd.resolve();
  201. native.switchPopGesture(true);
  202. },
  203. afteropen: function (pageData, dtd) {
  204. var $view = this;
  205. var $doc = $(document);
  206. if (!pageData.pushData.dontNeedReload) {
  207. $doc.trigger('spa:openloader');
  208. product.getListAll(user.id, function (res) {
  209. $doc.trigger('spa:closeloader');
  210. if (res.holiday) {
  211. var offDay = res.holiday;
  212. product.offDay = offDay;
  213. }
  214. });
  215. }
  216. // 检测新用户
  217. if (!user.isCheck.couponCheck) {
  218. user.getCouponList(user.id, function (res) {
  219. if (res.success) {
  220. user.isCheck['couponCheck'] = true;
  221. user.setCache('isCheck');
  222. }
  223. });
  224. }
  225. dtd.resolve();
  226. //强制设置首页的上一页是空的,后面再调整框架
  227. pageData.prevPage = $('.spa-page-empty');
  228. },
  229. beforeclose: function (pageData, dtd) {
  230. dtd.resolve();
  231. native.switchPopGesture(false);
  232. }
  233. }
  234. })