goods.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. (function (app) {
  2. app.controller('goodsCtrl', ["$scope", "$state", 'goodsService', '$ionicSideMenuDelegate', 'msg', '$rootScope'
  3. , function ($scope, $state, goodsService, $ionicSideMenuDelegate, msg, $rootScope) {
  4. $scope.filter = {
  5. hasMore: false,
  6. pageIndex: 0,
  7. pageSize: 10,
  8. type:1,
  9. begin_address: '',
  10. end_address: '',
  11. midway_address:''
  12. }
  13. if ($rootScope.location) {
  14. var city = $rootScope.location.city;
  15. if (city) {
  16. $scope.filter.begin_address = city.slice(0, city.length - 1);
  17. }
  18. }
  19. $scope.items = [];
  20. $scope.load = function (init) {
  21. if (init) {
  22. $scope.filter.pageIndex = 1;
  23. $scope.items = [];
  24. }
  25. goodsService.listGoods($scope.filter).then(function (result) {
  26. $scope.filter.pageIndex++;
  27. var more = (result.data.data.length >= $scope.filter.pageSize);
  28. $scope.filter.hasMore = more;
  29. $scope.items = $scope.items.concat(result.data.data);
  30. if (init) {
  31. $scope.$broadcast('scroll.refreshComplete');
  32. } else {
  33. $scope.$broadcast('scroll.infiniteScrollComplete');
  34. }
  35. }, function (erro) {
  36. // msg.error(erro.data);
  37. });
  38. }
  39. $scope.toggleRight = function () {
  40. $scope.load(true);
  41. $ionicSideMenuDelegate.toggleRight();
  42. };
  43. $scope.detail = function (item) {
  44. $state.go('wl.goods_detail', {item:item})
  45. }
  46. $scope.add = function () {
  47. $state.go('wl.goods_add');
  48. }
  49. $scope.goCar = function () {
  50. $state.go('wl.car');
  51. }
  52. $scope.$on('$ionicView.beforeEnter', function (viewResult) {
  53. $scope.load(true);
  54. });
  55. }]);
  56. app.controller('goodsAddCtrl', ["$scope", "$state", "goodsService", "msg", function ($scope, $state, goodsService, msg) {
  57. $scope.vm = { type: 1 };
  58. $scope.vm.begin_addressPick = {
  59. }
  60. $scope.vm.end_addressPick = {
  61. }
  62. $scope.vm.midway_addressPick = {
  63. }
  64. $scope.save = function () {
  65. var price=new Number($scope.vm.price);
  66. if (!price) {
  67. msg.text('输入价格');
  68. return;
  69. }
  70. if (!$scope.vm.begin_addressPick.area) {
  71. msg.text('请输入出发地址');
  72. return;
  73. }
  74. if (!$scope.vm.end_addressPick.area) {
  75. msg.text('请输入到达地址');
  76. return;
  77. }
  78. if (!$scope.vm.midway_addressPick.area) {
  79. msg.text('请输入途经地址');
  80. return;
  81. }
  82. if (!$scope.vm.detail) {
  83. msg.text('请输入详情');
  84. return;
  85. }
  86. msg.loading('提交中...');
  87. $scope.vm.begin_address = getAdress($scope.vm.begin_addressPick);
  88. $scope.vm.end_address = getAdress($scope.vm.end_addressPick);
  89. $scope.vm.midway_address = getAdress($scope.vm.midway_addressPick);
  90. goodsService.addGoods($scope.vm).then(function (result) {
  91. $state.go('wl.goods');
  92. msg.hide();
  93. }, function (erro) {
  94. msg.hide();
  95. msg.error(erro.data.message);
  96. });
  97. }
  98. function getAdress(address) {
  99. return address.province + ',' + address.city + ',' + address.area;
  100. }
  101. }]);
  102. app.controller('goodsDetailCtrl', ["$scope", '$stateParams', 'msg', 'orderService', '$state', 'map'
  103. , function ($scope, $stateParams, msg, orderService, $state, map) {
  104. $scope.vm = $stateParams.item;
  105. map.getMapPic($scope.vm.begin_address).then(function (result) {
  106. $scope.vm.picUrl = result;
  107. });
  108. //下单
  109. $scope.bill = function () {
  110. msg.confirm('下单提示', '确定下单?').then(function (res) {
  111. if (res) {
  112. msg.loading('下单中...');
  113. orderService.addOrder({ message_id: $scope.vm.id }).then(function (result) {
  114. msg.hide();
  115. $state.go('wl.goods_success', {item:$scope.vm});
  116. }, function (erro) {
  117. msg.hide();
  118. msg.error(erro.data.message);
  119. })
  120. } else {
  121. }
  122. });
  123. }
  124. }]);
  125. app.controller('goodsSuccessCtrl', ['$scope', '$state', '$ionicHistory', '$stateParams', 'msg', function ($scope, $state, $ionicHistory, $stateParams, msg) {
  126. $scope.vm = $stateParams.item;
  127. //下单成功
  128. $scope.back = function () {
  129. $ionicHistory.clearHistory();
  130. $state.go('wl.goods');
  131. }
  132. $scope.pay = function () {
  133. msg.text('支付尚未开通,敬请期待');
  134. }
  135. }]);
  136. })(angular.module('app.controllers'));