MyService.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**
  2. * Created by PhpStorm.
  3. * User: Jinguo
  4. * Date: 2017/1/5
  5. * Time: 14:24
  6. */
  7. define(['$', 'template', 'user', 'config', 'IScroll', 'api'], function ($, template, user, config, IScroll, api) {
  8. function back(event) {
  9. event.preventDefault();
  10. $(document).trigger('spa:navigate', {
  11. hash: '',
  12. pushData: {
  13. dontNeedReload: true
  14. }
  15. });
  16. }
  17. function fixScroll(pageData) {
  18. if (pageData.scroll) {
  19. pageData.scroll.destroy();
  20. pageData.scroll = null;
  21. }
  22. setTimeout(function () {
  23. pageData.scroll = new IScroll('#myCouponScroll');
  24. }, 50);
  25. }
  26. return {
  27. title: '壹管家上门服务',
  28. body: '',
  29. init: function (pageData, dtd) {
  30. var $view = this;
  31. var $doc = $(document);
  32. // 返回
  33. $view.on('swipeRight', function (event) {
  34. back.call(this, event);
  35. });
  36. $.newTouch('.back-button', function (event) {
  37. back.call(this, event);
  38. }, $view);
  39. $view.on('tapBackButton', function (event) {
  40. back.call(this, event);
  41. });
  42. dtd.resolve();
  43. },
  44. beforeopen: function (pageData, dtd) {
  45. var $view = this;
  46. var $doc = $(document);
  47. $doc.trigger('spa:openloader');
  48. api.geteservation({user_id: user.id}, function (res) {
  49. console.log(res);
  50. });
  51. api.geteservation({user_id: user.id}, function (res) {
  52. $doc.trigger('spa:closeloader');
  53. if (res.success) {
  54. /*function getLocalTime(nS) {
  55. return new Date(parseInt(nS) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
  56. }*/
  57. // console.log(getLocalTime(res.data[0].time));
  58. var timeArrea = [];
  59. /*for(var i=0;i<res.data.length;i++){
  60. res.data[i].time=getLocalTime(res.data[i].time);
  61. if(res.data[i].num==""){
  62. res.data[i].num="暂无预产期"
  63. }
  64. }*/
  65. if (res.data.length==0) {
  66. console.log("if");
  67. showListBar=false;
  68. } else {
  69. showListBar=true;
  70. }
  71. console.log(showListBar);
  72. /*if(res.data){
  73. console.log("if");
  74. }else {
  75. console.log("else");
  76. }*/
  77. var tmpData = {
  78. showNavBar: !config.isWX && !config.isChubao,
  79. list: res.data,
  80. timeArrea: timeArrea,
  81. showListBar:showListBar
  82. };
  83. var tpl = template('MyService/index', tmpData);
  84. $('.spa-page-body', $view).html(tpl);
  85. setTimeout(function () {
  86. pageData.scroll = new IScroll('#myServiceScroll');
  87. }, 500);
  88. } else {
  89. $doc.trigger('spa:openpanel', ['simpleAlert', {
  90. message: res.message
  91. }]);
  92. }
  93. });
  94. dtd.resolve();
  95. if (config.isWX) {
  96. wx.ready(function () {
  97. wx.onMenuShareTimeline({
  98. title: '家政服务,首选壹管家',
  99. link: 'http://www.yiguanjia.me/o2o/web/index',
  100. imgUrl: 'http://wozhua-others.qiniudn.com/icon-o2o-home.jpg'
  101. });
  102. wx.onMenuShareAppMessage({
  103. title: '家政服务,首选壹管家',
  104. desc: '全程管家,精心每一个细节!',
  105. link: 'http://www.yiguanjia.me/o2o/web/index',
  106. imgUrl: 'http://wozhua-others.qiniudn.com/icon-o2o-home.jpg'
  107. });
  108. });
  109. }
  110. }
  111. }
  112. })