|
|
@@ -1,6 +1,6 @@
|
|
|
-define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'service/Make', 'service/Fa', 'service/Account', 'service/Alert', 'service/CheckTel', 'ui.router', 'ui.bootstrap', 'file-upload', 'ngSanitize', 'service/BaseInfo'], function() {
|
|
|
+define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'service/Make', 'service/Fa', 'service/Account', 'service/Alert', 'service/CheckTel', 'ui.router', 'ui.bootstrap', 'file-upload', 'ngSanitize', 'service/BaseInfo', 'service/Cart'], function() {
|
|
|
'use strict';
|
|
|
- var app = angular.module('myApp', [ 'toaster', 'angularCharts', 'ngTable', 'ui.router', 'common.services', 'PurcServices', 'MakeServices', 'FaServices', 'AccountServices', 'AlertServices', 'ui.bootstrap', 'angularFileUpload', 'ngSanitize', 'CheckTelModule', 'ProductServices']);
|
|
|
+ var app = angular.module('myApp', [ 'toaster', 'angularCharts', 'ngTable', 'ui.router', 'common.services', 'PurcServices', 'MakeServices', 'FaServices', 'AccountServices', 'AlertServices', 'ui.bootstrap', 'angularFileUpload', 'ngSanitize', 'CheckTelModule', 'ProductServices', 'CartServices']);
|
|
|
app.init = function() {
|
|
|
angular.bootstrap(document, [ 'myApp' ]);
|
|
|
};
|
|
|
@@ -100,9 +100,17 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'ser
|
|
|
templateUrl : "static/tpl/index/purc/order_detail.html",
|
|
|
controller: 'PurcOrderDetailCtrl'
|
|
|
}).state('purc.newOrder', {
|
|
|
- url : "addOrder",
|
|
|
+ url : "/addOrder",
|
|
|
templateUrl : "static/tpl/index/purc/addOrder.html",
|
|
|
controller : 'PurcNewOrderCtrl'
|
|
|
+ }).state('purc.cart', {
|
|
|
+ url : "/cart",
|
|
|
+ templateUrl : "static/tpl/index/purc/cart.html",
|
|
|
+ controller : 'CartController'
|
|
|
+ }).state('purc.cartDetail', {
|
|
|
+ url : "/cart/:id",
|
|
|
+ templateUrl : "static/tpl/index/purc/cart_detail.html",
|
|
|
+ controller : 'CartDetailController'
|
|
|
}).state('sale.todo', {
|
|
|
url : "/todo",
|
|
|
templateUrl : "static/tpl/index/sale/todo.html"
|
|
|
@@ -3581,6 +3589,7 @@ app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams'
|
|
|
$modalInstance.close();
|
|
|
}
|
|
|
}]);
|
|
|
+
|
|
|
app.controller('SaleSampleDetailCtrl', ['$scope', '$stateParams', 'PurcSample', 'toaster', 'ReportService', function($scope, $stateParams, PurcSample, toaster, ReportService){
|
|
|
var loading = true;
|
|
|
var loadData = function() {
|
|
|
@@ -5610,6 +5619,7 @@ app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams'
|
|
|
}
|
|
|
};
|
|
|
}]);
|
|
|
+
|
|
|
app.controller('AddVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
|
|
|
$scope.checkboxes = {
|
|
|
checked : false
|
|
|
@@ -6907,7 +6917,7 @@ app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams'
|
|
|
/**
|
|
|
* 物料资料
|
|
|
*/
|
|
|
- app.controller('ProductListCtrl', ['$scope', 'GetProductInfo', 'ngTableParams', '$filter', 'BaseService', 'toaster', function($scope, GetProductInfo, ngTableParams, $filter, BaseService, toaster) {
|
|
|
+ app.controller('ProductListCtrl', ['$scope', 'GetProductInfo', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', function($scope, GetProductInfo, ngTableParams, $filter, BaseService, toaster, $timeout) {
|
|
|
$scope.active = 'all';
|
|
|
$scope.agreedText = '全部';
|
|
|
$scope.dateZoneText = '一个月内';
|
|
|
@@ -6972,11 +6982,13 @@ app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams'
|
|
|
|
|
|
//删除
|
|
|
$scope.deleteById = function(id) {
|
|
|
- console.log(id);
|
|
|
GetProductInfo.deleteById({id: id}, function(data) {
|
|
|
toaster.pop("success", "提示", "删除成功");
|
|
|
+ $timeout(function() {
|
|
|
+ window.location.reload();
|
|
|
+ }, 500);
|
|
|
}), function(response) {
|
|
|
- toaster.pop("error", "删除失败", response);
|
|
|
+ toaster.pop("error", "删除失败", response.data);
|
|
|
};
|
|
|
}
|
|
|
|
|
|
@@ -6995,7 +7007,6 @@ app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams'
|
|
|
file: file,
|
|
|
method: 'POST'
|
|
|
}).success(function(data) {
|
|
|
- console.log(data);
|
|
|
$scope.result = data;
|
|
|
$scope.success = $scope.result.success;
|
|
|
$scope.total = $scope.result.total;
|
|
|
@@ -7030,13 +7041,30 @@ app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams'
|
|
|
app.controller('ProductDetailCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster) {
|
|
|
var loadData = function() {
|
|
|
GetProductInfo.getOne({id: $stateParams.id}, function(data) {
|
|
|
+ if(data.attach) {
|
|
|
+ GetProductInfo.getAttach({id: data.attach.id}, function(data) {
|
|
|
+ console.log(data.url);
|
|
|
+ // 查看范例
|
|
|
+ $scope.showImg = function() {
|
|
|
+ var src = data.url, box = $('#image-box');
|
|
|
+ box.show();
|
|
|
+ box.find('img').attr('src', src);
|
|
|
+ box.find('a').click(function(){
|
|
|
+ box.hide();
|
|
|
+ });
|
|
|
+ box.dblclick(function(){
|
|
|
+ box.hide();
|
|
|
+ });
|
|
|
+ };
|
|
|
+ })
|
|
|
+ }
|
|
|
$scope.prodInfo = data;
|
|
|
$scope.prodInfo.$editing = false;
|
|
|
$scope.loading = false;
|
|
|
});
|
|
|
};
|
|
|
loadData();
|
|
|
-
|
|
|
+
|
|
|
// 更新
|
|
|
$scope.update = function() {
|
|
|
$scope.prodInfo.$editing = true;
|
|
|
@@ -7048,19 +7076,76 @@ app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams'
|
|
|
};
|
|
|
|
|
|
$scope.submit = function(prodInfo) {
|
|
|
- console.log(prodInfo);
|
|
|
- GetProductInfo.update({}, prodInfo, function(data) {
|
|
|
- toaster.pop("success", "提示", "提交成功");
|
|
|
- }, function(res) {
|
|
|
- toaster.pop("error", "提示" + res);
|
|
|
+ var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
|
|
|
+ console.log(file);
|
|
|
+ $upload.upload({
|
|
|
+ url: 'product/baseInfo/updateProdInfo',
|
|
|
+ file: file,
|
|
|
+ method: 'POST',
|
|
|
+ data: {
|
|
|
+ prodInfo: $scope.prodInfo
|
|
|
+ },
|
|
|
+ }).success(function(data) {
|
|
|
+ if(data.success) {
|
|
|
+ toaster.pop('success', '提示', data.success);
|
|
|
+ window.location.reload();
|
|
|
+ }
|
|
|
+ if(data.error) {
|
|
|
+ toaster.pop('error', '提示', data.error);
|
|
|
+ }
|
|
|
+ }).error(function(data) {
|
|
|
+ $scope.loadingShow = false;
|
|
|
+ toaster.pop('error', '操作失败', data.error);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ $scope.previewShow = false;
|
|
|
+ $scope.pdfShow = false;
|
|
|
+ $scope.noneFileShow = true;
|
|
|
+ $scope.$watch('myFiles', function(){
|
|
|
+ if($scope.myFiles) {
|
|
|
+ $scope.noneFileShow = false;
|
|
|
+ var file = $scope.myFiles[0];
|
|
|
+ if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
|
|
|
+ $scope.pdfShow = true;
|
|
|
+ $scope.previewShow = false;
|
|
|
+ $scope.imgPreviewName = file.name;
|
|
|
+ } else{
|
|
|
+ if (typeof(Worker) !== "undefined") {//支持HTML5
|
|
|
+ $scope.imgPreview = getObjectURL(file);
|
|
|
+ $scope.imgPreviewName = file.name;
|
|
|
+ } else{//不支持HTML5
|
|
|
+ $scope.imgPreview = 'static/img/all/preview-error.jpg';
|
|
|
+ $scope.imgPreviewName = file.name;
|
|
|
+ }
|
|
|
+ $scope.previewShow = true;
|
|
|
+ $scope.pdfShow = false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $scope.noneFileShow = true;
|
|
|
+ $scope.previewShow = false;
|
|
|
+ $scope.pdfShow = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //建立一个可存取到该file的url
|
|
|
+ var getObjectURL = function(file) {
|
|
|
+ var url = null ;
|
|
|
+ if (window.createObjectURL!=undefined) { // basic
|
|
|
+ url = window.createObjectURL(file) ;
|
|
|
+ } else if (window.URL!=undefined) { // mozilla(firefox)
|
|
|
+ url = window.URL.createObjectURL(file) ;
|
|
|
+ } else if (window.webkitURL!=undefined) { // webkit or chrome
|
|
|
+ url = window.webkitURL.createObjectURL(file) ;
|
|
|
+ }
|
|
|
+ return url ;
|
|
|
+ };
|
|
|
+
|
|
|
}]);
|
|
|
|
|
|
/**
|
|
|
* 新增物料
|
|
|
*/
|
|
|
- app.controller('NewProdInfoCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', '$modal', 'ComponentActive', 'KindAPI', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, $modal, ComponentActive, KindAPI) {
|
|
|
+ app.controller('NewProdInfoCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', '$modal', 'ComponentActive', 'KindAPI', '$timeout', function($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, $modal, ComponentActive, KindAPI, $timeout) {
|
|
|
|
|
|
$scope.prodInfo = {unit: 'PCS'};
|
|
|
// 选择类目
|
|
|
@@ -7097,15 +7182,83 @@ app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams'
|
|
|
|
|
|
//提交
|
|
|
$scope.submit = function(prodInfo){
|
|
|
- GetProductInfo.addNewProd({}, prodInfo, function(data) {
|
|
|
- toaster.pop("success", "提示", "提交成功");
|
|
|
- //提交后跳转到详情页面,防止重复提交
|
|
|
- window.location.href="#/baseInfo/prodList/"+data.id;
|
|
|
- }, function(res) {
|
|
|
- toaster.pop("error", "提示" + res);
|
|
|
+ var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
|
|
|
+ $upload.upload({
|
|
|
+ url: 'product/baseInfo/addNewProduct',
|
|
|
+ file: file,
|
|
|
+ method: 'POST',
|
|
|
+ data: {
|
|
|
+ prodInfo: $scope.prodInfo
|
|
|
+ },
|
|
|
+ }).success(function(data) {
|
|
|
+ if(data.success) {
|
|
|
+ toaster.pop('success', '提示', data.success);
|
|
|
+ $timeout(function() {
|
|
|
+ //提交后跳转到详情页面,防止重复提交
|
|
|
+ window.location.href="#/baseInfo/prodList/"+data.id;
|
|
|
+ }, 500);
|
|
|
+ }
|
|
|
+ if(data.error) {
|
|
|
+ toaster.pop('error', '提示', data.error);
|
|
|
+ $timeout(function() {
|
|
|
+ //提交后跳转到详情页面,防止重复提交
|
|
|
+ window.location.href="#/baseInfo/prodList/"+data.id;
|
|
|
+ }, 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ }).error(function(data) {
|
|
|
+ $scope.loadingShow = false;
|
|
|
+ toaster.pop('error', '操作失败', data.error);
|
|
|
});
|
|
|
+// GetProductInfo.addNewProd({}, prodInfo, function(data) {
|
|
|
+// toaster.pop("success", "提示", "提交成功");
|
|
|
+//
|
|
|
+//
|
|
|
+// }, function(res) {
|
|
|
+// toaster.pop("error", "提示" + res);
|
|
|
+// });
|
|
|
};
|
|
|
|
|
|
+ $scope.previewShow = false;
|
|
|
+ $scope.pdfShow = false;
|
|
|
+ $scope.noneFileShow = true;
|
|
|
+ $scope.$watch('myFiles', function(){
|
|
|
+ if($scope.myFiles) {
|
|
|
+ $scope.noneFileShow = false;
|
|
|
+ var file = $scope.myFiles[0];
|
|
|
+ if(file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
|
|
|
+ $scope.pdfShow = true;
|
|
|
+ $scope.previewShow = false;
|
|
|
+ $scope.imgPreviewName = file.name;
|
|
|
+ } else{
|
|
|
+ if (typeof(Worker) !== "undefined") {//支持HTML5
|
|
|
+ $scope.imgPreview = getObjectURL(file);
|
|
|
+ $scope.imgPreviewName = file.name;
|
|
|
+ } else{//不支持HTML5
|
|
|
+ $scope.imgPreview = 'static/img/all/preview-error.jpg';
|
|
|
+ $scope.imgPreviewName = file.name;
|
|
|
+ }
|
|
|
+ $scope.previewShow = true;
|
|
|
+ $scope.pdfShow = false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $scope.noneFileShow = true;
|
|
|
+ $scope.previewShow = false;
|
|
|
+ $scope.pdfShow = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //建立一个可存取到该file的url
|
|
|
+ var getObjectURL = function(file) {
|
|
|
+ var url = null ;
|
|
|
+ if (window.createObjectURL!=undefined) { // basic
|
|
|
+ url = window.createObjectURL(file) ;
|
|
|
+ } else if (window.URL!=undefined) { // mozilla(firefox)
|
|
|
+ url = window.URL.createObjectURL(file) ;
|
|
|
+ } else if (window.webkitURL!=undefined) { // webkit or chrome
|
|
|
+ url = window.webkitURL.createObjectURL(file) ;
|
|
|
+ }
|
|
|
+ return url ;
|
|
|
+ };
|
|
|
// 取消
|
|
|
$scope.cancel = function(){
|
|
|
$scope.prodInfo = angular.copy($scope.prodInfo);
|
|
|
@@ -7349,7 +7502,7 @@ app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams'
|
|
|
/**
|
|
|
* 新增采购单
|
|
|
*/
|
|
|
- app.controller('PurcNewOrderCtrl',['$scope', '$modal', 'toaster', '$filter', 'newPurcOrder', function($scope, $modal, toaster, $filter, newPurcOrder) {
|
|
|
+ app.controller('PurcNewOrderCtrl',['$scope', '$modal', 'toaster', '$filter', 'addtoCart', function($scope, $modal, toaster, $filter, addtoCart) {
|
|
|
$scope.order = {
|
|
|
date : new Date(),
|
|
|
cust : {
|
|
|
@@ -7414,7 +7567,7 @@ app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams'
|
|
|
};
|
|
|
|
|
|
// 查找客户物料
|
|
|
- $scope.dbfindCustProd = function(){
|
|
|
+ $scope.dbfindCustProd = function(index){
|
|
|
if($scope.order.cust.uu) {
|
|
|
var modalInstance = $modal.open({
|
|
|
templateUrl: 'static/tpl/index/purc/modal/purc_order_custProd.html',
|
|
|
@@ -7430,7 +7583,7 @@ app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams'
|
|
|
modalInstance.result.then(function(data) {
|
|
|
$scope.order.orderItems.push(data);
|
|
|
for(var i = 0; i < $scope.order.orderItems.length; i++) {
|
|
|
- if($scope.order.orderItems[i].code == null) {
|
|
|
+ if($scope.order.orderItems[i].code == null || i == index) {
|
|
|
$scope.order.orderItems.splice(i, 1);
|
|
|
}
|
|
|
}
|
|
|
@@ -7452,11 +7605,11 @@ app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams'
|
|
|
};
|
|
|
|
|
|
|
|
|
- // 保存
|
|
|
- $scope.save = function(order){
|
|
|
+ // 添加到购物车
|
|
|
+ $scope.addToCart = function(order) {
|
|
|
$scope.loading = true;
|
|
|
if(!$scope.order.code) //新增,设单号
|
|
|
- $scope.order.code = 'BMP' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
|
|
|
+ $scope.order.code = 'B2B' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
|
|
|
$scope.order.custUU = $scope.order.cust.uu;
|
|
|
$scope.order.custUserUU = $scope.order.custUser.userUU;
|
|
|
if($scope.order.date instanceof Date) {
|
|
|
@@ -7467,10 +7620,35 @@ app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams'
|
|
|
$scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
|
|
|
}
|
|
|
}
|
|
|
- newPurcOrder.save({}, $scope.order, function(data){
|
|
|
+ addtoCart.save({}, $scope.order, function(data){
|
|
|
$scope.loading = false;
|
|
|
toaster.pop('success', '成功', '保存成功');
|
|
|
- window.location.hash = '#/purc/order/'+data.id;
|
|
|
+ window.location.hash = '#/purc/cart/'+data.id;
|
|
|
+ }, function(response){
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('error', '保存失败', response.data);
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ // 立即购买
|
|
|
+ $scope.addToOrder = function(order) {
|
|
|
+ $scope.loading = true;
|
|
|
+ if(!$scope.order.code) //新增,设单号
|
|
|
+ $scope.order.code = 'B2B' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
|
|
|
+ $scope.order.custUU = $scope.order.cust.uu;
|
|
|
+ $scope.order.custUserUU = $scope.order.custUser.userUU;
|
|
|
+ if($scope.order.date instanceof Date) {
|
|
|
+ $scope.order.date = $scope.order.date.getTime();
|
|
|
+ }
|
|
|
+ for(var i = 0; i < $scope.order.orderItems.length; i++) {
|
|
|
+ if($scope.order.orderItems[i].delivery instanceof Date) {
|
|
|
+ $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ addtoCart.save({}, $scope.order, function(data){
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('success', '成功', '保存成功');
|
|
|
+ window.location.hash = '#/purc/cart/'+data.id;
|
|
|
}, function(response){
|
|
|
$scope.loading = false;
|
|
|
toaster.pop('error', '保存失败', response.data);
|
|
|
@@ -7967,6 +8145,187 @@ app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams'
|
|
|
});
|
|
|
}]);
|
|
|
|
|
|
+ /**
|
|
|
+ * 购物车
|
|
|
+ */
|
|
|
+ app.controller('CartController', ['$scope', 'toaster', 'getCartList', 'ngTableParams', '$filter', 'BaseService', 'cartOperation', '$timeout', function($scope, toaster, getCartList, ngTableParams, $filter, BaseService, cartOperation, $timeout) {
|
|
|
+ $scope.active = 'all';
|
|
|
+ $scope.agreedText = '全部';
|
|
|
+ $scope.dateZoneText = '一个月内';
|
|
|
+ $scope.condition = {dateZone: 1};
|
|
|
+ $scope.currency = Symbol.currency;//将币别转化为对应的符号
|
|
|
+ $scope.changeAgreed = function(agreed) {
|
|
|
+ $scope.condition.agreed = agreed;
|
|
|
+ $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
|
|
|
+ $scope.condition.$agreedOpen = false;
|
|
|
+ };
|
|
|
+ $scope.changeDateZone = function(zone) {
|
|
|
+ $scope.condition.dateZone = zone;
|
|
|
+ $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
|
|
|
+ $scope.condition.$dateZoneOpen = false;
|
|
|
+ getDateCondition(zone, $scope.condition);
|
|
|
+ $scope.tableParams.reload();
|
|
|
+ };
|
|
|
+ $scope.setActive = function(state) {
|
|
|
+ if($scope.active != state) {
|
|
|
+ $scope.active = state;
|
|
|
+ if($scope.tableParams.page() == 1)
|
|
|
+ $scope.tableParams.reload();
|
|
|
+ else
|
|
|
+ $scope.tableParams.page(1);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ var getService = function() {
|
|
|
+ return getCartList;
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.tableParams = new ngTableParams({
|
|
|
+ page : 1,
|
|
|
+ count : 5,
|
|
|
+ sorting: {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ total : 0,
|
|
|
+ counts: [5, 10, 25, 50],
|
|
|
+ getData : function($defer, params) {
|
|
|
+ $scope.loading = true;
|
|
|
+ var pageParams = params.url();
|
|
|
+ pageParams.keyword = $scope.keyword;
|
|
|
+ getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page) {
|
|
|
+ $scope.loading = false;
|
|
|
+ if(page) {
|
|
|
+ params.total(page.totalElements);
|
|
|
+ $defer.resolve(page.content);
|
|
|
+ $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
|
|
|
+ }
|
|
|
+ }, function(response) {
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('error', '数据加载失败', response.data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ $scope.getCartTotal = function(items) {
|
|
|
+ var sum = 0;
|
|
|
+ angular.forEach(items, function(item){
|
|
|
+ sum += item.qty * item.price;
|
|
|
+ });
|
|
|
+ return sum;
|
|
|
+ };
|
|
|
+
|
|
|
+ // 搜索框回车
|
|
|
+ $scope.onSearch = function() {
|
|
|
+ $scope.tableParams.page(1);
|
|
|
+ $scope.tableParams.reload();
|
|
|
+ };
|
|
|
+
|
|
|
+ // 提交
|
|
|
+ $scope.addtoOrder = function(id) {
|
|
|
+ cartOperation.addToOrder({id: id}, {}, function(data) {
|
|
|
+ if(data.success) {
|
|
|
+ toaster.pop('success', '提示', data.success);
|
|
|
+ $timeout(function() {
|
|
|
+ window.location.hash = '#/purc/cartdetail/'+data.id;
|
|
|
+ },500);
|
|
|
+ }
|
|
|
+ if(data.error) {
|
|
|
+ toaster.pop('error', '提示', data.error);
|
|
|
+ }
|
|
|
+ }, function(response) {
|
|
|
+ toaster.pop('erroer', '提示', response.data);
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ // 删除一条主记录
|
|
|
+ $scope.deleteCart = function(id) {
|
|
|
+ cartOperation.deleteCart({id: id}, {}, function(data) {
|
|
|
+ if(data.success) {
|
|
|
+ toaster.pop('success', '提示', data.success);
|
|
|
+ $timeout(function() {
|
|
|
+ window.location.reload();
|
|
|
+ },500);
|
|
|
+ }
|
|
|
+ if(data.error) {
|
|
|
+ toaster.pop('error', '提示', data.error);
|
|
|
+ }
|
|
|
+ }, function(response) {
|
|
|
+ toaster.pop('erroer', '提示', response.data);
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ // 删除一条明细
|
|
|
+ $scope.deleteDetail = function(id) {
|
|
|
+ cartOperation.deleteCartDetail({id: id}, {}, function(data) {
|
|
|
+ if(data.success) {
|
|
|
+ toaster.pop('success', '提示', data.success);
|
|
|
+ $timeout(function() {
|
|
|
+ window.location.reload();
|
|
|
+ },500);
|
|
|
+ }
|
|
|
+ if(data.error) {
|
|
|
+ toaster.pop('error', '提示', data.error);
|
|
|
+ }
|
|
|
+ }, function(response) {
|
|
|
+ toaster.pop('erroer', '提示', response.data);
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ // 清空购物车
|
|
|
+ $scope.clearCart = function() {
|
|
|
+ cartOperation.deleteCarts({}, function(data) {
|
|
|
+ if(data.success) {
|
|
|
+ toaster.pop('success', '提示', data.success);
|
|
|
+ $timeout(function() {
|
|
|
+ window.location.reload();
|
|
|
+ },500);
|
|
|
+ }
|
|
|
+ if(data.error) {
|
|
|
+ toaster.pop('error', '提示', data.error);
|
|
|
+ }
|
|
|
+ }, function(response) {
|
|
|
+ toaster.pop('erroer', '提示', response.data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }]);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 购物车详情
|
|
|
+ */
|
|
|
+ app.controller('CartDetailController', ['$scope', 'cartOperation', '$stateParams', 'toaster', '$timeout', function($scope, cartOperation, $stateParams, toaster, $timeout) {
|
|
|
+ var loadData = function() {
|
|
|
+ cartOperation.getCartDetail({id: $stateParams.id}, function(data) {
|
|
|
+ if(data.code) {
|
|
|
+ $scope.cart = data;
|
|
|
+ var sum = 0;
|
|
|
+ angular.forEach($scope.cart.cartDetails, function(item) {
|
|
|
+ sum += item.qty * item.price;
|
|
|
+ });
|
|
|
+ $scope.cart.total = sum;
|
|
|
+ $scope.loading = false;
|
|
|
+ } else {
|
|
|
+ window.location.hash = '#/purc/cart';
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+ loadData();
|
|
|
+
|
|
|
+ // 删除一条明细
|
|
|
+ $scope.deleteDetail = function(id) {
|
|
|
+ cartOperation.deleteCartDetail({id: id}, {}, function(data) {
|
|
|
+ if(data.success) {
|
|
|
+ toaster.pop('success', '提示', data.success);
|
|
|
+ $timeout(function() {
|
|
|
+ window.location.reload();
|
|
|
+ },500);
|
|
|
+ }
|
|
|
+ if(data.error) {
|
|
|
+ toaster.pop('error', '提示', data.error);
|
|
|
+ }
|
|
|
+ }, function(response) {
|
|
|
+ toaster.pop('erroer', '提示', response.data);
|
|
|
+ });
|
|
|
+ };
|
|
|
+ }]);
|
|
|
|
|
|
return app;
|
|
|
});
|