StoreController.js 4.8 KB
"use strict";
var storeController = angular.module('storeController',[]);

storeController.controller('storeController', [
    '$state',
    '$rootScope',
    '$scope',
    'StoreService',
    function($state,$rootScope, $scope, StoreService) {
        $scope.stores=[];
        StoreService.storePager();
        $scope.$on('store.list',function(){
            $scope.stores=StoreService.stores.datas;
        });
    }]
);

storeController.controller('editStoreController', [
    '$rootScope',
    '$scope',
    'StoreService',
    function($rootScope, $scope, StoreService) {
        $scope.imageUrl = '';
        $scope.editStoreInfo={
            contact:'',
            contactPhone:'',
            name:'',
            freightRemark:'',
            headImg:'',
            address:''
        };
        StoreService.getStoreDetail(function (data) {
            $scope.editStoreInfo = data.data;
            $scope.imageUrl = $scope.editStoreInfo.headImg;
        });
        $scope.onSubmitStore=function(){
            $scope.editStoreInfo.headImg=$scope.imageUrl;
            StoreService.editStore($scope.editStoreInfo);
        }

    }]
);

storeController.controller('storeRefundAddressController', [
    '$rootScope',
    '$scope',
    'StoreService',
    function($rootScope, $scope, StoreService) {
        $scope.storeId =  $rootScope.$stateParams.storeId;
        $scope.currentPage = 1;
        $scope.numPages = 1;
        $scope.pageSize = 20;
        $scope.totalRecord = 0;
        $scope.pages = [];
        $scope.storeRefundAddressList=[];
        $scope.storeRefundAddressQuery={
            storeId: $scope.storeId,
            storeName:'',
            contact:'',
            contactPhone:'',
            address:'',
            pageNow:1,
            pageSize:20
        };
        StoreService.storeRefundAddressPager($scope.storeRefundAddressQuery);
        $scope.$on('storeRefundAddress.list',function(){
            $scope.storeRefundAddressList=StoreService.storeRefundAddressList.datas;
            $scope.numPages=StoreService.storeRefundAddressList.totalPage;
            $scope.totalRecord=StoreService.storeRefundAddressList.totalRecord;
        });
        //选当前页
        $scope.onSelectPage = function(page) {
            $scope.storeRefundAddressQuery.pageNow=page;
            $scope.currentPage=page;
            StoreService.storeRefundAddressPager($scope.storeRefundAddressQuery);
        };
        $scope.searchStoreRefundAddress=function(){
            $scope.storeRefundAddressQuery.pageNow=1;
            StoreService.storeRefundAddressPager($scope.storeRefundAddressQuery);
        };
        $scope.deleteStoreRefundAddress=function(id){
            if(confirm("小主,确定要删除该条数据吗?")){
                StoreService.deleteStoreRefundAddress(id,function() {
                    StoreService.storeRefundAddressPager($scope.storeRefundAddressQuery);
                    $scope.$on('storeRefundAddress.list',function(){
                        $scope.storeRefundAddressList=StoreService.storeRefundAddressList.datas;
                        $scope.numPages=StoreService.storeRefundAddressList.totalPage;
                        $scope.totalRecord=StoreService.storeRefundAddressList.totalRecord;
                    });
                })
            }
        }

    }]
);

storeController.controller('editStoreRefundAddressController', [
    '$rootScope',
    '$scope',
    'StoreService',
    function($rootScope, $scope, StoreService) {
        $scope.stores=[];
        var addressId = $rootScope.$stateParams.addressId;
        $scope.editStoreRefundAddressInfo={
            id:'',
            supplierId:'',
            contact:'',
            contactPhone:'',
            address:'',
            refundStandardRemark:'',
            addressId:addressId
        };
        if(addressId!==''){
            StoreService.getStoreRefundAddressDetail(addressId,function (data) {
                $scope.editStoreRefundAddressInfo = data.data;
            });
        }
        function getStoreName(){
            if($scope.stores&&$scope.stores.length){
                var type = $scope.editStoreRefundAddressInfo.storeId;
                var list = $scope.stores;
                for(var i=0;i<list.length;i++){
                    if(list[i]['id'] == type){
                        $scope.storeObj = $scope.stores[i];
                        break;
                    }
                    if(type == '') {
                        $scope.storeObj = null;
                        break;
                    }
                }
            }
        }

        StoreService.listStore();
        $scope.$on('store.list',function(){
            $scope.stores=StoreService.stores;
            getStoreName();
        });
        $scope.onSubmitStoreRefundAddress=function(){
            StoreService.editStoreRefundAddress($scope.editStoreRefundAddressInfo);
        }

    }]
);