order.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. var app = new Vue({
  2. 'el': '#app',
  3. 'data': {
  4. // 列表数据
  5. dataList: [],
  6. // 参数
  7. params: {
  8. page: 1,
  9. status: 0,
  10. pageSize: 10,
  11. },
  12. loading: false,
  13. loaded: false,
  14. },
  15. created: function(){
  16. this.getDataList(0);
  17. },
  18. mounted: function(){
  19. var _this = this;
  20. $(".weui-navbar__item").click(function(){
  21. _this.params.page = 1;
  22. _this.loaded = false;
  23. _this.params.status = $(this).index();
  24. $(this).addClass('on').siblings().removeClass('on');
  25. _this.dataList = [];
  26. _this.getDataList(0);
  27. });
  28. $(window).scroll(function(){
  29. var scrollHeight = $(this).scrollTop();
  30. var height = $('body')[0].scrollHeight;
  31. var docHeight = $(this).outerHeight();
  32. if(docHeight+scrollHeight >= height){
  33. if(_this.loading || _this.loaded){
  34. return false;
  35. }
  36. _this.params.page++;
  37. _this.getDataList(1);
  38. }
  39. })
  40. },
  41. methods: {
  42. // 获取列表数据
  43. getDataList: function(more){
  44. var _this = this;
  45. _this.loading = true;
  46. if(_this.params.page == 1){
  47. _this.dataList = [];
  48. }
  49. $.showLoading("数据加载中...");
  50. $.post('/weixin/order/getList', _this.params, function (res) {
  51. _this.loading = false;
  52. $.hideLoading();
  53. if (res.code == 'success') {
  54. if(res.data.length<=0 && _this.params.page > 1){
  55. _this.loaded = true;
  56. $.toast("已加载完全部...",'text');
  57. return false;
  58. }
  59. if(more){
  60. $.each(res.data, function(k,item){
  61. console.log(item);
  62. _this.dataList.push(item);
  63. });
  64. }else{
  65. _this.dataList = res.data
  66. }
  67. }else if(res.code == 'login'){
  68. login(res.data.url);
  69. }
  70. }, "json");
  71. },
  72. // 商品详情
  73. showGoods:function(id){
  74. if(id>0){
  75. location.href = '/weixin/goods/detail?id='+id;
  76. }
  77. },
  78. // 确认收货
  79. delivery: function(data){
  80. var _this = this;
  81. $.modal({
  82. title: "确认收货",
  83. text: "发货信息:"+(data.confirm_remark? data.confirm_remark : '无'),
  84. buttons: [
  85. { text: "取消", onClick: function(){ return false; }},
  86. { text: "确认", className: "default", onClick: function(){
  87. $.showLoading("提交处理中...");
  88. $.post('/weixin/order/delivery', {id: data.id}, function (res) {
  89. $.hideLoading();
  90. if (res.code == 'success') {
  91. $.toast(res.message, 'text');
  92. setTimeout(function(){
  93. _this.getDataList(0);
  94. }, 500)
  95. }else if(res.code == 'login'){
  96. login(res.data.url);
  97. }else {
  98. $.toast(res.message, 'text');
  99. }
  100. },"json");
  101. return false;
  102. } },
  103. ]
  104. });
  105. },
  106. }
  107. })