123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- (function (app) {
- app.controller('goodsCtrl', ["$scope", "$state", 'goodsService', '$ionicSideMenuDelegate', 'msg', '$rootScope'
- , function ($scope, $state, goodsService, $ionicSideMenuDelegate, msg, $rootScope) {
- $scope.filter = {
- hasMore: false,
- pageIndex: 0,
- pageSize: 10,
- type:1,
- begin_address: '',
- end_address: '',
- midway_address:''
- }
- if ($rootScope.location) {
- var city = $rootScope.location.city;
- if (city) {
- $scope.filter.begin_address = city.slice(0, city.length - 1);
- }
- }
- $scope.items = [];
- $scope.load = function (init) {
- if (init) {
- $scope.filter.pageIndex = 1;
- $scope.items = [];
- }
- goodsService.listGoods($scope.filter).then(function (result) {
- $scope.filter.pageIndex++;
- var more = (result.data.data.length >= $scope.filter.pageSize);
- $scope.filter.hasMore = more;
- $scope.items = $scope.items.concat(result.data.data);
-
- if (init) {
- $scope.$broadcast('scroll.refreshComplete');
- } else {
- $scope.$broadcast('scroll.infiniteScrollComplete');
- }
- }, function (erro) {
- // msg.error(erro.data);
- });
- }
- $scope.toggleRight = function () {
- $scope.load(true);
- $ionicSideMenuDelegate.toggleRight();
- };
- $scope.detail = function (item) {
- $state.go('wl.goods_detail', {item:item})
- }
- $scope.add = function () {
- $state.go('wl.goods_add');
- }
- $scope.goCar = function () {
- $state.go('wl.car');
- }
- $scope.$on('$ionicView.beforeEnter', function (viewResult) {
- $scope.load(true);
- });
- }]);
- app.controller('goodsAddCtrl', ["$scope", "$state", "goodsService", "msg", function ($scope, $state, goodsService, msg) {
- $scope.vm = { type: 1 };
- $scope.vm.begin_addressPick = {
- }
- $scope.vm.end_addressPick = {
- }
- $scope.vm.midway_addressPick = {
- }
- $scope.save = function () {
- var price=new Number($scope.vm.price);
- if (!price) {
- msg.text('输入价格');
- return;
- }
- if (!$scope.vm.begin_addressPick.area) {
- msg.text('请输入出发地址');
- return;
- }
- if (!$scope.vm.end_addressPick.area) {
- msg.text('请输入到达地址');
- return;
- }
- if (!$scope.vm.midway_addressPick.area) {
- msg.text('请输入途经地址');
- return;
- }
- if (!$scope.vm.detail) {
- msg.text('请输入详情');
- return;
- }
- msg.loading('提交中...');
- $scope.vm.begin_address = getAdress($scope.vm.begin_addressPick);
- $scope.vm.end_address = getAdress($scope.vm.end_addressPick);
- $scope.vm.midway_address = getAdress($scope.vm.midway_addressPick);
- goodsService.addGoods($scope.vm).then(function (result) {
- $state.go('wl.goods');
- msg.hide();
- }, function (erro) {
- msg.hide();
- msg.error(erro.data.message);
- });
- }
- function getAdress(address) {
- return address.province + ',' + address.city + ',' + address.area;
- }
- }]);
- app.controller('goodsDetailCtrl', ["$scope", '$stateParams', 'msg', 'orderService', '$state', 'map'
- , function ($scope, $stateParams, msg, orderService, $state, map) {
- $scope.vm = $stateParams.item;
- map.getMapPic($scope.vm.begin_address).then(function (result) {
- $scope.vm.picUrl = result;
- });
- //下单
- $scope.bill = function () {
- msg.confirm('下单提示', '确定下单?').then(function (res) {
- if (res) {
- msg.loading('下单中...');
- orderService.addOrder({ message_id: $scope.vm.id }).then(function (result) {
- msg.hide();
- $state.go('wl.goods_success', {item:$scope.vm});
- }, function (erro) {
- msg.hide();
- msg.error(erro.data.message);
- })
- } else {
- }
- });
- }
- }]);
- app.controller('goodsSuccessCtrl', ['$scope', '$state', '$ionicHistory', '$stateParams', 'msg', function ($scope, $state, $ionicHistory, $stateParams, msg) {
- $scope.vm = $stateParams.item;
- //下单成功
- $scope.back = function () {
- $ionicHistory.clearHistory();
- $state.go('wl.goods');
- }
- $scope.pay = function () {
- msg.text('支付尚未开通,敬请期待');
- }
- }]);
- })(angular.module('app.controllers'));
|