MyService.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. console.log(timeArrea);
  66. var tmpData={
  67. showNavBar: !config.isWX && !config.isChubao,
  68. list:res.data,
  69. timeArrea:timeArrea
  70. };
  71. var tpl = template('MyService/index', tmpData);
  72. $('.spa-page-body', $view).html(tpl);
  73. setTimeout(function () {
  74. pageData.scroll = new IScroll('#myServiceScroll');
  75. }, 500);
  76. } else {
  77. $doc.trigger('spa:openpanel', ['simpleAlert', {
  78. message: res.message
  79. }]);
  80. }
  81. });
  82. dtd.resolve();
  83. if (config.isWX) {
  84. wx.ready(function () {
  85. wx.onMenuShareTimeline({
  86. title: '家政服务,首选壹管家',
  87. link: 'http://www.yiguanjia.me/o2o/web/index',
  88. imgUrl: 'http://wozhua-others.qiniudn.com/icon-o2o-home.jpg'
  89. });
  90. wx.onMenuShareAppMessage({
  91. title: '家政服务,首选壹管家',
  92. desc: '全程管家,精心每一个细节!',
  93. link: 'http://www.yiguanjia.me/o2o/web/index',
  94. imgUrl: 'http://wozhua-others.qiniudn.com/icon-o2o-home.jpg'
  95. });
  96. });
  97. }
  98. }
  99. }
  100. })