car.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. (function (app) {
  2. app.controller('carCtrl', ["$scope", "$ionicSideMenuDelegate", "$state", 'carService', 'msg', '$rootScope','config', function ($scope, $ionicSideMenuDelegate, $state, carService, msg, $rootScope,config) {
  3. $scope.filter = {
  4. hasMore: false,
  5. pageIndex: 0,
  6. pageSize: 10,
  7. type: 2,
  8. begin_address: '',
  9. end_address: '',
  10. midway_address: ''
  11. }
  12. $scope.host = config.server +'/upload/photo/';
  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. carService.listCars($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.message);
  37. });
  38. }
  39. $scope.toggleRight = function () {
  40. $scope.load(true);
  41. $ionicSideMenuDelegate.toggleRight();
  42. };
  43. $scope.detail = function (item) {
  44. $state.go('wl.car_detail', { item: item })
  45. }
  46. $scope.add = function () {
  47. $state.go('wl.car_add');
  48. }
  49. $scope.goGoods = function () {
  50. $state.go('wl.goods');
  51. }
  52. $scope.$on('$ionicView.beforeEnter', function (viewResult) {
  53. $scope.load(true);
  54. });
  55. }]);
  56. app.controller('carAddCtrl', ["$scope", "$state", "carService", "msg", function ($scope, $state, carService, msg) {
  57. $scope.$on('$ionicView.beforeEnter', function (viewResult) {
  58. $scope.vm = { type: 1 };
  59. $scope.vm.begin_addressPick = {
  60. }
  61. $scope.vm.end_addressPick = {
  62. }
  63. $scope.vm.midway_addressPick = {
  64. }
  65. $scope.truckOpt = [];
  66. carService.listTrucks().then(function (result) {
  67. angular.forEach(result.data.data, function (item) {
  68. $scope.truckOpt.push({ id: item.id, name: item.name })
  69. });
  70. }, function (erro) {
  71. msg.error(erro.data.message);
  72. });
  73. });
  74. $scope.save = function () {
  75. $scope.vm.type = 2;
  76. var price = new Number($scope.vm.price);
  77. if (!price) {
  78. msg.text('输入价格');
  79. return;
  80. }
  81. if (!$scope.vm.begin_addressPick.area) {
  82. msg.text('请输入出发地址');
  83. return;
  84. }
  85. if (!$scope.vm.end_addressPick.area) {
  86. msg.text('请输入到达地址');
  87. return;
  88. }
  89. if (!$scope.vm.midway_addressPick.area) {
  90. msg.text('请输入途经地址');
  91. return;
  92. }
  93. if (!$scope.vm.detail) {
  94. msg.text('请输入详情');
  95. return;
  96. }
  97. msg.loading('提交中...');
  98. if (!$scope.vm.contact_name) {
  99. msg.text('请输入随车联系人');
  100. return;
  101. }
  102. if (!$scope.vm.contact_phone) {
  103. msg.text('请输入随车联系电话');
  104. return;
  105. }
  106. $scope.vm.begin_address = getAdress($scope.vm.begin_addressPick);
  107. $scope.vm.end_address = getAdress($scope.vm.end_addressPick);
  108. $scope.vm.midway_address = getAdress($scope.vm.midway_addressPick);
  109. carService.addCar($scope.vm).then(function (result) {
  110. $state.go('wl.car');
  111. msg.hide();
  112. }, function (erro) {
  113. msg.hide();
  114. msg.error(erro.data.message);
  115. });
  116. }
  117. function getAdress(address) {
  118. return address.province + ',' + address.city + ',' + address.area;
  119. }
  120. }]);
  121. app.controller('carDetailCtrl', ["$scope", '$stateParams', 'msg', 'orderService', '$state', 'map',
  122. function ($scope, $stateParams, msg, orderService, $state, map) {
  123. $scope.vm = $stateParams.item;
  124. map.getMapPic($scope.vm.begin_address).then(function (result) {
  125. $scope.vm.picUrl = result;
  126. });
  127. //下单
  128. $scope.bill = function () {
  129. msg.confirm('下单提示', '确定下单?').then(function (res) {
  130. if (res) {
  131. msg.loading('下单中...');
  132. orderService.addOrder({ message_id: $scope.vm.id }).then(function (result) {
  133. msg.hide();
  134. $state.go('wl.car_success', { item: $scope.vm });
  135. }, function (erro) {
  136. msg.hide();
  137. msg.error(erro.data.message);
  138. })
  139. } else {
  140. }
  141. });
  142. }
  143. }]);
  144. app.controller('carSuccessCtrl', ['$scope', '$state', '$ionicHistory', '$stateParams', 'msg', function ($scope, $state, $ionicHistory, $stateParams, msg) {
  145. $scope.vm = $stateParams.item;
  146. //下单成功
  147. $scope.back = function () {
  148. $ionicHistory.clearHistory();
  149. $state.go('wl.car');
  150. }
  151. $scope.pay = function () {
  152. msg.text('支付尚未开通,敬请期待');
  153. }
  154. }]);
  155. })(angular.module('app.controllers'));