|
|
@@ -0,0 +1,339 @@
|
|
|
+define(['app/app'], function (app) {
|
|
|
+ "use strict";
|
|
|
+ // Controller 主动报价 - 新增
|
|
|
+ app.register.controller('SaleQuotationNewCtrl', ['$scope', '$stateParams', '$filter', 'ngTableParams', 'toaster', 'BaseService', '$modal', 'B2bQuotation', 'B2bVendorInfo', '$rootScope', 'B2bCurrentRole', function ($scope, $stateParams, $filter, ngTableParams, toaster, BaseService, $modal, Quotation, VendorInfo, $rootScope, CurrentRole) {
|
|
|
+ BaseService.scrollBackToTop();
|
|
|
+
|
|
|
+ // 获取当前用户是否为普通用户
|
|
|
+ CurrentRole.isUser({}, {}, function (data) {
|
|
|
+ $scope.isUser = data.isUser;
|
|
|
+ });
|
|
|
+
|
|
|
+ var staticItem = null;
|
|
|
+
|
|
|
+ if (!angular.isUndefined($stateParams.id)) {// 查看模式
|
|
|
+ $scope.loading = true;
|
|
|
+ $rootScope.enteryStatus = true;
|
|
|
+ Quotation.getItem({id: $stateParams.id}, function (data) {
|
|
|
+ // data.$editing = false;
|
|
|
+ $scope.item = data;
|
|
|
+ $scope.item.$editing = true; // 取消要点击修改才可以编辑的交互
|
|
|
+ staticItem = angular.copy(data);
|
|
|
+ $scope.loading = false;
|
|
|
+ }, function (response) {
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('error', '数据加载失败', response.data);
|
|
|
+ });
|
|
|
+ } else {// 新增模式
|
|
|
+ $rootScope.enteryStatus = false;
|
|
|
+ $scope.item = {
|
|
|
+ quotation: {
|
|
|
+ currency: 'RMB',
|
|
|
+ taxrate: 17,
|
|
|
+ },
|
|
|
+ product: {},
|
|
|
+ prices: [{lapQty: 0}],
|
|
|
+ minOrderQty: 1,
|
|
|
+ minPackQty: 1,
|
|
|
+ $endDateOpen: false,
|
|
|
+ $editing: true
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ $scope.getMinDate = function (item) {
|
|
|
+ return $filter('date')(new Date, 'yyyy-MM-dd');
|
|
|
+ };
|
|
|
+
|
|
|
+ //是否不能被点击
|
|
|
+ $scope.isDisabled = function () {
|
|
|
+ return $scope.item.quotation.status == 101 && $scope.item.agreed == null;
|
|
|
+ }
|
|
|
+
|
|
|
+ $scope.openDatePicker = function ($event, openParam) {
|
|
|
+ $event.preventDefault();
|
|
|
+ $event.stopPropagation();
|
|
|
+ $scope.item.$endDateOpen = !openParam;
|
|
|
+ };
|
|
|
+
|
|
|
+ // 增加一个分段
|
|
|
+ $scope.addPrice = function () {
|
|
|
+ if ($scope.item.prices.length >= 10) {
|
|
|
+ toaster.pop('warning', '提示', '最多支持10个分段!');
|
|
|
+ } else
|
|
|
+ $scope.item.prices.push({});
|
|
|
+ };
|
|
|
+
|
|
|
+ // 删除一个分段
|
|
|
+ $scope.removePrice = function (index) {
|
|
|
+ $scope.item.prices.splice(index, 1);
|
|
|
+ };
|
|
|
+
|
|
|
+ // 查找客户
|
|
|
+ $scope.dbfindCust = function () {
|
|
|
+ if ($scope.item.$editing) {
|
|
|
+ var modalInstance = $modal.open({
|
|
|
+ templateUrl: 'static/view/vendor/b2b/modal/quotation_new_cust.html',
|
|
|
+ controller: 'DbfindCustCtrl',
|
|
|
+ size: 'lg',
|
|
|
+ resolve: {}
|
|
|
+ });
|
|
|
+
|
|
|
+ modalInstance.result.then(function (data) {
|
|
|
+ $scope.item.quotation.cust = data.myEnterprise;
|
|
|
+ $scope.item.quotation.custUser = data.myUser;
|
|
|
+ $scope.item.product = null;
|
|
|
+ }, function () {
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 赋值客户信息
|
|
|
+ if ($rootScope.custuu) {
|
|
|
+ VendorInfo.customerInfo({custuu: $rootScope.custuu}, {}, function (data) {
|
|
|
+ $scope.item.quotation.cust = data.myEnterprise;
|
|
|
+ $scope.item.quotation.custUser = data.myUser;
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 赋值物料信息
|
|
|
+ if ($rootScope.prodId) {
|
|
|
+ VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function (data) {
|
|
|
+ $scope.item.product.code = data.code;
|
|
|
+ $scope.item.product.title = data.title;
|
|
|
+ $scope.item.product.spec = data.spec;
|
|
|
+ $scope.item.product.unit = data.unit;
|
|
|
+ $scope.item.product.id = data.id;
|
|
|
+ }, function (response) {
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 查找客户物料
|
|
|
+ $scope.dbfindCustProd = function () {
|
|
|
+ if ($scope.item.$editing) {
|
|
|
+ if ($scope.item.quotation.cust) {
|
|
|
+ var modalInstance = $modal.open({
|
|
|
+ templateUrl: 'static/view/vendor/b2b/modal/quotation_new_custProd.html',
|
|
|
+ controller: 'DbfindCustProdCtrl',
|
|
|
+ size: 'lg',
|
|
|
+ resolve: {
|
|
|
+ custUU: function () {
|
|
|
+ return $scope.item.quotation.cust.uu
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ modalInstance.result.then(function (data) {
|
|
|
+ $scope.item.product = data;
|
|
|
+ }, function () {
|
|
|
+
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ toaster.pop('error', '错误', '请先选择客户');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 根据传入的询价相关的信息封装成报价需要的信息
|
|
|
+ if ($stateParams.inquiryItem != null) {
|
|
|
+ var item = $stateParams.inquiryItem;
|
|
|
+ $scope.item.quotation.cust = item.inquiry.enterprise;
|
|
|
+ $scope.item.quotation.custUser = item.inquiry.recorderUser;
|
|
|
+ $scope.item.quotation.custUserUU = item.inquiry.recorderUU;
|
|
|
+ if (item.product == null || item.product.id == null) {
|
|
|
+ toaster.pop('info', '暂未匹配到物料信息,请手动选择');
|
|
|
+ } else {
|
|
|
+ $scope.item.product = item.product;
|
|
|
+ if (item.replies.length > 0) {
|
|
|
+ $scope.item.prices = item.replies;
|
|
|
+ angular.forEach($scope.item.prices, function(price) {
|
|
|
+ price.id = null;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ $scope.item.quotation.taxrate = item.taxrate;
|
|
|
+ $scope.item.minPackQty = item.minPackQty;
|
|
|
+ $scope.item.minOrderQty = item.minOrderQty;
|
|
|
+ $scope.item.leadtime = item.leadtime;
|
|
|
+ $scope.item.quotation.currency = item.currency;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存
|
|
|
+ $scope.save = function () {
|
|
|
+ var valid = true;
|
|
|
+ angular.forEach($scope.item.prices, function(price, $index) {
|
|
|
+ if ($index > 0 && price.lapQty <= $scope.item.prices[$index - 1].lapQty) {
|
|
|
+ valid = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (!valid) {
|
|
|
+ toaster.pop('info', '提示', '分段数量请保持递增!');
|
|
|
+ } else {
|
|
|
+ $scope.loading = true;
|
|
|
+ if (!$scope.item.quotation.code) //新增,设单号
|
|
|
+ $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
|
|
|
+ $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
|
|
|
+ if ($scope.item.quotation.custUserUU == null) {
|
|
|
+ $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
|
|
|
+ }
|
|
|
+ $scope.item.productId = $scope.item.product.id;
|
|
|
+ Quotation.save({}, $scope.item, function (data) {
|
|
|
+ $scope.loading = false;
|
|
|
+ $scope.item = data;
|
|
|
+ toaster.pop('success', '成功', '保存成功');
|
|
|
+ if ($stateParams.id)
|
|
|
+ window.location.reload();
|
|
|
+ else
|
|
|
+ window.location.hash = '#/sale/quotation/list';
|
|
|
+ }, function (response) {
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('error', '保存失败', response.data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+ // 更新
|
|
|
+ $scope.update = function () {
|
|
|
+ $scope.item.$editing = true;
|
|
|
+ };
|
|
|
+
|
|
|
+ // 取消
|
|
|
+ $scope.cancel = function () {
|
|
|
+ $scope.item.$editing = false;
|
|
|
+ $scope.item = angular.copy(staticItem);
|
|
|
+ };
|
|
|
+
|
|
|
+ // 提交
|
|
|
+ $scope.submit = function () {
|
|
|
+ var valid = true;
|
|
|
+ angular.forEach($scope.item.prices, function(price, $index) {
|
|
|
+ if ($index > 0 && price.lapQty <= $scope.item.prices[$index - 1].lapQty) {
|
|
|
+ valid = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (!valid) {
|
|
|
+ toaster.pop('info', '提示', '分段数量请保持递增!');
|
|
|
+ } else {
|
|
|
+ $scope.loading = true;
|
|
|
+ if (!$scope.item.quotation.code) //新增,设单号
|
|
|
+ $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
|
|
|
+ $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
|
|
|
+ if ($scope.item.quotation.custUserUU == null) {
|
|
|
+ $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
|
|
|
+ }
|
|
|
+ $scope.item.productId = $scope.item.product.id;
|
|
|
+ // $scope.item.quotation.status = 101;//已提交
|
|
|
+ if ($scope.item.quotation.date instanceof Date) {
|
|
|
+ $scope.item.quotation.date = $scope.item.quotation.date.getTime();
|
|
|
+ }
|
|
|
+ if ($scope.item.quotation.endDate instanceof Date) {
|
|
|
+ $scope.item.quotation.endDate = $scope.item.quotation.endDate.getTime();
|
|
|
+ }
|
|
|
+ Quotation.submit({}, $scope.item, function (data) {
|
|
|
+ $scope.loading = false;
|
|
|
+ $scope.item = data;
|
|
|
+ toaster.pop('success', '成功', '提交成功');
|
|
|
+ // window.location.hash = '#/sale/quotation/' + data.id;
|
|
|
+ window.location.hash = '#/sale/quotation/list';
|
|
|
+ }, function (response) {
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('error', '保存失败', response.data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.deleteById = function (id) {
|
|
|
+ Quotation.deleteById({id: id}, {}, function (data) {
|
|
|
+ window.location.href = "#/sale/quotation/list";
|
|
|
+ }, function (response) {
|
|
|
+ toaster.pop('error', '提示', response.data);
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }]);
|
|
|
+
|
|
|
+ // 查找客户
|
|
|
+ app.register.controller('DbfindCustCtrl', ['$scope', 'B2bCustomer', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function ($scope, Customer, BaseService, ngTableParams, toaster, $modalInstance) {
|
|
|
+ BaseService.scrollBackToTop();
|
|
|
+ $scope.tableParams = new ngTableParams({
|
|
|
+ page: 1,
|
|
|
+ count: 20
|
|
|
+ }, {
|
|
|
+ total: 0,
|
|
|
+ counts: [5, 10, 25, 50],
|
|
|
+ getData: function ($defer, params) {
|
|
|
+ $scope.loading = true;
|
|
|
+ var pageParams = params.url();
|
|
|
+ pageParams.keyword = $scope.keyword;
|
|
|
+ Customer.get(BaseService.parseParams(pageParams), function (page) {
|
|
|
+ $scope.loading = false;
|
|
|
+ if (page) {
|
|
|
+ params.total(page.totalElement);
|
|
|
+ $defer.resolve(page.content);
|
|
|
+ }
|
|
|
+ $scope.totalCount = page.totalElement;
|
|
|
+ }, function (response) {
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('error', '数据加载失败', response.data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ $scope.onSearch = function () {
|
|
|
+ $scope.tableParams.page(1);
|
|
|
+ $scope.tableParams.reload();
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.cancel = function () {
|
|
|
+ $modalInstance.dismiss();
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.check = function (cust) {
|
|
|
+ $modalInstance.close(cust);
|
|
|
+ };
|
|
|
+ }]);
|
|
|
+
|
|
|
+ // 查找客户物料
|
|
|
+ app.register.controller('DbfindCustProdCtrl', ['$scope', 'B2bProduct', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'custUU', function ($scope, Product, BaseService, ngTableParams, toaster, $modalInstance, custUU) {
|
|
|
+ BaseService.scrollBackToTop();
|
|
|
+ $scope.tableParams = new ngTableParams({
|
|
|
+ page: 1,
|
|
|
+ count: 20
|
|
|
+ }, {
|
|
|
+ total: 0,
|
|
|
+ counts: [5, 10, 25, 50],
|
|
|
+ getData: function ($defer, params) {
|
|
|
+ $scope.loading = true;
|
|
|
+ var pageParams = params.url();
|
|
|
+ pageParams.keyword = $scope.keyword;
|
|
|
+ pageParams.custUU = custUU;
|
|
|
+ Product.get.call(null, BaseService.parseParams(pageParams), function (page) {
|
|
|
+ $scope.loading = false;
|
|
|
+ if (page) {
|
|
|
+ params.total(page.totalElement);
|
|
|
+ $defer.resolve(page.content);
|
|
|
+ $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
|
|
|
+ }
|
|
|
+ }, function (response) {
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('error', '数据加载失败', response.data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 取消
|
|
|
+ $scope.cancel = function () {
|
|
|
+ $modalInstance.dismiss();
|
|
|
+ };
|
|
|
+
|
|
|
+ // 选择
|
|
|
+ $scope.check = function (cust) {
|
|
|
+ $modalInstance.close(cust);
|
|
|
+ };
|
|
|
+
|
|
|
+ // 搜索框回车
|
|
|
+ $scope.onSearch = function () {
|
|
|
+ $scope.tableParams.page(1);
|
|
|
+ $scope.tableParams.reload();
|
|
|
+ };
|
|
|
+ }]);
|
|
|
+
|
|
|
+});
|