|
|
@@ -0,0 +1,397 @@
|
|
|
+define(['app/app'], function(app) {
|
|
|
+ /**
|
|
|
+ * 新增采购单
|
|
|
+ */
|
|
|
+ app.register.controller('PurcNewOrderCtrl', ['$scope', '$modal', 'toaster', '$filter', 'B2bAddtoCart', '$rootScope', 'B2bVendorInfo', 'ngTableParams', 'BaseService', 'B2bProduct', 'B2bNewPurcOrder', 'B2bCartOperation', 'B2bShipAddress', 'B2bVendor', '$http', '$window', 'B2bToken', 'B2bRecentPrice',
|
|
|
+ function ($scope, $modal, toaster, $filter, addtoCart, $rootScope, VendorInfo, ngTableParams, BaseService, Product, newPurcOrder, cartOperation, ShipAddress, Vendor, $http, $window, token, recentPrice) {
|
|
|
+ BaseService.scrollBackToTop();
|
|
|
+ // 每次进入时先清除掉rootScope下的venduu
|
|
|
+ $rootScope.venduu = null;
|
|
|
+ // 获取收货地址列表
|
|
|
+ ShipAddress.shipAddList({}, function (data) {
|
|
|
+ $scope.ships = data;
|
|
|
+ $scope.order.shipadd = $scope.ships[0];
|
|
|
+ });
|
|
|
+
|
|
|
+ // 获取地址信息
|
|
|
+ $http.get('resources/citydata/city.json', {
|
|
|
+ "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
|
|
|
+ }).then(function (response) {
|
|
|
+ $scope.provinces = response.data;
|
|
|
+ });
|
|
|
+ var getToken = function() {
|
|
|
+ if($scope.token == null) {
|
|
|
+ token.info({userType: 'purcorder'}, {}, function(data) {
|
|
|
+ $scope.token = data.token;
|
|
|
+ }, function(response) {
|
|
|
+ toaster.pop('error', '提示', response.data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ getToken();
|
|
|
+
|
|
|
+ $scope.order = {
|
|
|
+ date: new Date(),
|
|
|
+ vend: {
|
|
|
+ uu: '',
|
|
|
+ },
|
|
|
+ vendUser: {},
|
|
|
+ code: $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
|
|
|
+ orderItems: {
|
|
|
+ product: {},
|
|
|
+ },
|
|
|
+ rate: 17
|
|
|
+ };
|
|
|
+
|
|
|
+ //商品信息
|
|
|
+ $scope.order.orderItems = [];
|
|
|
+ var item = {
|
|
|
+ code: null,
|
|
|
+ title: null,
|
|
|
+ spec: null,
|
|
|
+ unit: null,
|
|
|
+ qty: null,
|
|
|
+ price: null,
|
|
|
+ remark: null,
|
|
|
+ delivery: null,
|
|
|
+ prid: null,
|
|
|
+ taxrate: null
|
|
|
+ };
|
|
|
+
|
|
|
+ if ($rootScope.businessCode) {
|
|
|
+ VendorInfo.getVendorInfo({businessCode: $rootScope.businessCode}, {}, function (data) {
|
|
|
+ $scope.id = data.id;
|
|
|
+ $scope.order.vend.enName = data.vendorEnterprise.enName;
|
|
|
+ $scope.order.vend.enAddress = data.vendorEnterprise.enAddress;
|
|
|
+ $scope.order.vend.uu = data.vendorEnterprise.uu;
|
|
|
+ $scope.order.paymethods = data.paymethod;
|
|
|
+ $rootScope.venduu = data.vendorEnterprise.uu;
|
|
|
+ Vendor.contacts({venduu: $scope.order.vend.uu}, {}, function (data) {
|
|
|
+ $scope.contacts = data;
|
|
|
+ $scope.order.vendor = $scope.contacts[0];
|
|
|
+ });
|
|
|
+ }, function (response) {
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ ;
|
|
|
+
|
|
|
+ // 查找供应商
|
|
|
+ $scope.dbfindVend = function () {
|
|
|
+ var modalInstance = $modal.open({
|
|
|
+ templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
|
|
|
+ controller: 'DbfindVendorInfoCtrl',
|
|
|
+ size: 'lg',
|
|
|
+ resolve: {
|
|
|
+ orderItems: function () {
|
|
|
+ return $scope.order.orderItems;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ modalInstance.result.then(function (data) {
|
|
|
+ $rootScope.venduu = data.vendorEnterprise.uu;
|
|
|
+ $scope.id = data.id;
|
|
|
+ $scope.order.vend = data.vendorEnterprise;
|
|
|
+ $scope.order.vend.enName = data.vendorEnterprise.enName;
|
|
|
+ $scope.order.vendUser = data.vendorUser;
|
|
|
+ $scope.order.payments = data.paymethod;
|
|
|
+ $scope.order.orderItems = [];
|
|
|
+ var item = {
|
|
|
+ code: null,
|
|
|
+ title: null,
|
|
|
+ spec: null,
|
|
|
+ unit: null,
|
|
|
+ qty: null,
|
|
|
+ price: null,
|
|
|
+ remark: null,
|
|
|
+ delivery: null,
|
|
|
+ taxrate: null
|
|
|
+ };
|
|
|
+ Vendor.contacts({venduu: $scope.order.vend.uu}, {}, function (data) {
|
|
|
+ $scope.contacts = data;
|
|
|
+ $scope.order.vendor = $scope.contacts[0];
|
|
|
+ });
|
|
|
+
|
|
|
+ }, function () {
|
|
|
+
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ // 联想词 start
|
|
|
+ // 获取供应商
|
|
|
+ $scope.getSimilarVendors = function (value) {
|
|
|
+ if (value) {
|
|
|
+ return Vendor.getSimilarVendors({keyword: value}).$promise.then(function (data) {
|
|
|
+ return data.map(function (item) {
|
|
|
+ return item;
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.onAssociateCmpClick = function (vendor, order) {
|
|
|
+ $scope.order.vend.uu = vendor.venduu;
|
|
|
+ $scope.id = vendor.id;
|
|
|
+ $scope.order.payments = vendor.paymethod;
|
|
|
+ $rootScope.venduu = $scope.order.vend.uu;
|
|
|
+ Vendor.contacts({venduu: $scope.order.vend.uu}, {}, function (data) {
|
|
|
+ $scope.contacts = data;
|
|
|
+ $scope.order.vendor = $scope.contacts[0];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 联想词 end
|
|
|
+
|
|
|
+// $scope.order.orderItems.push(item);
|
|
|
+ if ($rootScope.prodId) {
|
|
|
+ VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function (data) {
|
|
|
+ item.code = data.code;
|
|
|
+ item.title = data.title;
|
|
|
+ item.spec = data.spec;
|
|
|
+ item.unit = data.unit;
|
|
|
+ item.id = data.id;
|
|
|
+ $scope.order.orderItems.push(item);
|
|
|
+ $rootScope.prodId = null;// 清除掉prodId
|
|
|
+ }, function (response) {
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //增加商品
|
|
|
+ $scope.addProduct = function (index) {
|
|
|
+ if ($scope.order.orderItems[index].code == null) {
|
|
|
+ toaster.pop('info', '提示', '请先选择商品');
|
|
|
+ } else {
|
|
|
+ $scope.order.orderItems.push({
|
|
|
+ code: null,
|
|
|
+ title: null,
|
|
|
+ spec: null,
|
|
|
+ unit: null,
|
|
|
+ qty: null,
|
|
|
+ price: null,
|
|
|
+ remark: null,
|
|
|
+ delivery: null,
|
|
|
+ $endDateOpen: false,
|
|
|
+ taxrate: $scope.order.rate,
|
|
|
+ prodsource: 'seller'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+ //删除商品
|
|
|
+ $scope.deleteProduct = function (index) {
|
|
|
+ $scope.order.orderItems.splice(index, 1);
|
|
|
+ };
|
|
|
+
|
|
|
+ // 搜索框回车
|
|
|
+ $scope.onSearch = function (keyword) {
|
|
|
+ $scope.keyword = keyword;
|
|
|
+ $scope.tableParams.page(1);
|
|
|
+ $scope.tableParams.reload();
|
|
|
+ };
|
|
|
+
|
|
|
+ $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;
|
|
|
+ $scope.tip = $scope.keyword;
|
|
|
+ pageParams.vendUU = $scope.order.vend.uu;
|
|
|
+ Product.vendPord.call(null, BaseService.parseParams(pageParams), function (page) {
|
|
|
+ $scope.loading = false;
|
|
|
+ if (page) {
|
|
|
+ params.total(page.totalElement);
|
|
|
+ $scope.total = page.totalElement;
|
|
|
+ $defer.resolve(page.content);
|
|
|
+ }
|
|
|
+ }, function (response) {
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('error', '数据加载失败', response.data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ // 选择
|
|
|
+ $scope.check = function (data) {
|
|
|
+ var price = null;
|
|
|
+ var qty = null;
|
|
|
+ var taxRate = null;
|
|
|
+ if (data.id) {
|
|
|
+ recentPrice.agreed({prId: data.id}, {}, function(response) {
|
|
|
+ price = response.price;
|
|
|
+ qty = response.qty;
|
|
|
+ taxRate = response.taxRate;
|
|
|
+ $scope.order.orderItems.push({
|
|
|
+ code: data.code,
|
|
|
+ title: data.title,
|
|
|
+ spec: data.spec,
|
|
|
+ unit: data.unit,
|
|
|
+ qty: qty,
|
|
|
+ price: price,
|
|
|
+ remark: null,
|
|
|
+ delivery: null,
|
|
|
+ prid: data.id,
|
|
|
+ taxrate: taxRate,
|
|
|
+ prodsource: 'seller',
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 导入商品信息
|
|
|
+ $scope.uplodaByBatch = function () {
|
|
|
+ var modalInstance = $modal.open({
|
|
|
+ templateUrl: 'static/tpl/index/purc/modal/purc_uplodaByBatch.html',
|
|
|
+ controller: 'PurcUploadByBatchCtrl',
|
|
|
+ size: 'lg',
|
|
|
+ resolve: {}
|
|
|
+ });
|
|
|
+
|
|
|
+ modalInstance.result.then(function (data) {
|
|
|
+ angular.forEach(data, function (prod) {
|
|
|
+ $scope.order.orderItems.push({
|
|
|
+ code: prod.code,
|
|
|
+ title: prod.title,
|
|
|
+ unit: 'PCS',
|
|
|
+ spec: prod.spec,
|
|
|
+ qty: prod.amount,
|
|
|
+ price: prod.rateprice,
|
|
|
+ remark: prod.remark,
|
|
|
+ delivery: prod.date,
|
|
|
+ prid: prod.id,
|
|
|
+ taxrate: prod.rate,
|
|
|
+ prodsource: 'purchaser'
|
|
|
+ });
|
|
|
+ })
|
|
|
+ }, function () {
|
|
|
+
|
|
|
+ });
|
|
|
+ };
|
|
|
+ // 监听venduu发生变化,重新加载物料信息
|
|
|
+ $scope.$watch('order.vend.uu', function (n, o) {
|
|
|
+ if (n == o) {
|
|
|
+ return;
|
|
|
+ } else {
|
|
|
+ $scope.tableParams.page(1);
|
|
|
+ $scope.tableParams.reload();
|
|
|
+ }
|
|
|
+ }, true);
|
|
|
+
|
|
|
+ $scope.getMinDate = function (item) {
|
|
|
+ return $filter('date')(new Date, 'yyyy-MM-dd');
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.openDatePicker = function ($event, openParam, index) {
|
|
|
+ $event.preventDefault();
|
|
|
+ $event.stopPropagation();
|
|
|
+ $scope.order.orderItems[index].$endDateOpen = !openParam;
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ // 添加到购物车
|
|
|
+ $scope.addToCart = function (order) {
|
|
|
+ $scope.loading = true;
|
|
|
+ $scope.order.status = 311;
|
|
|
+ $scope.order.vendusertel = order.vendor.tel;
|
|
|
+ $scope.order.venduser = order.vendor.venduser;
|
|
|
+ $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
|
|
|
+ $scope.order.vendUU = $scope.order.vend.uu;
|
|
|
+ $scope.order.vendUserUU = $scope.order.vendUser.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();
|
|
|
+ }
|
|
|
+ if ($scope.order.currency != 'RMB') {
|
|
|
+ $scope.order.orderItems[i].rate = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ addtoCart.save({token: $scope.token}, $scope.order, function (data) {
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('success', '成功', '保存成功');
|
|
|
+ window.location.hash = '#/purc/cart/' + data.id;
|
|
|
+ $window.location.reload();
|
|
|
+ }, function (response) {
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('error', '保存失败', response.data);
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ // 立即购买
|
|
|
+ $scope.addToOrder = function (order) {
|
|
|
+ $scope.loading = true;
|
|
|
+ $scope.order.status = 200;
|
|
|
+ $scope.order.vendusertel = order.vendor.tel;
|
|
|
+ $scope.order.venduser = order.vendor.venduser + '' + order.vendor.tel;
|
|
|
+ $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
|
|
|
+ $scope.order.vendUU = $scope.order.vend.uu;
|
|
|
+ $scope.order.vendUserUU = $scope.order.vendUser.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();
|
|
|
+ }
|
|
|
+ if ($scope.order.currency != 'RMB') {
|
|
|
+ $scope.order.orderItems[i].rate = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ addtoCart.save({token: $scope.token}, $scope.order, function (data) {
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('success', '成功', '保存成功');
|
|
|
+ window.location.hash = '#/purc/order/' + data.id;
|
|
|
+ }, function (response) {
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('error', '保存失败', response.data);
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ // 新增收货地址保存
|
|
|
+ $scope.saveShipAddress = function (ship) {
|
|
|
+ ship.address = ship.province + ship.city + ship.district;
|
|
|
+ ShipAddress.saveAddress({}, ship, function (data) {
|
|
|
+ if (data.success) {
|
|
|
+ ShipAddress.shipAddList({}, function (data) {
|
|
|
+ $scope.ships = data;
|
|
|
+ $scope.order.shipadd = $scope.ships[0];
|
|
|
+ });
|
|
|
+ toaster.pop('success', '提示', data.success);
|
|
|
+ }
|
|
|
+ if (data.error) {
|
|
|
+ toaster.pop('error', '提示', data.error);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 新增供应商联系人
|
|
|
+ $scope.addContact = function (uu) {
|
|
|
+ var modalInstance = $modal.open({
|
|
|
+ animation: true,
|
|
|
+ templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
|
|
|
+ controller: 'AddContacCtrl',
|
|
|
+ resolve: {}
|
|
|
+ });
|
|
|
+ modalInstance.result.then(function (data) {
|
|
|
+ $scope.contact = data;
|
|
|
+ $scope.contact.venduu = uu;
|
|
|
+ Vendor.saveContact({}, $scope.contact, function (data) {
|
|
|
+ Vendor.contacts({venduu: $scope.order.vend.uu}, {}, function (data) {
|
|
|
+ $scope.contacts = data;
|
|
|
+ $scope.order.vendor = $scope.contacts[0];
|
|
|
+ });
|
|
|
+ toaster.pop('success', '提示', '联系人保存成功');
|
|
|
+ }, function (response) {
|
|
|
+ toaster.pop('error', '失败', response.data);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ }]);
|
|
|
+});
|