|
|
@@ -0,0 +1,189 @@
|
|
|
+define(['app/app'], function (app) {
|
|
|
+ "use strict";
|
|
|
+ // 客户详情
|
|
|
+ app.register.controller('CustomerDetailCtrl', ['$scope', 'toaster', '$stateParams', 'B2bVendor', '$modal', 'B2bProduct', 'ngTableParams', 'BaseService', '$rootScope', 'B2bVendorService', 'AuthenticationService', function ($scope, toaster, $stateParams, Vendor, $modal, Product, ngTableParams, BaseService, $rootScope, VendorService, AuthenticationService) {
|
|
|
+ BaseService.scrollBackToTop();
|
|
|
+ $scope.userInfoResult = true;
|
|
|
+ AuthenticationService.getAuthentication().success(function (data) {
|
|
|
+ $scope.loading = false;
|
|
|
+ $scope.thisUser = data;
|
|
|
+ });
|
|
|
+ $scope.vendorContacts = [];
|
|
|
+ var loadData = function () {
|
|
|
+ Vendor.getCustomerDetail({id: $stateParams.id}, {}, function (data) {
|
|
|
+ $scope.customer = data.myEnterprise;
|
|
|
+ $scope.customerInfo = data;
|
|
|
+ Vendor.custContacts({enuu: $scope.customer.uu}, {}, function (data) {
|
|
|
+ $scope.Contacts = data;
|
|
|
+ });
|
|
|
+
|
|
|
+ // 查看已分配人员
|
|
|
+ VendorService.userInfo.query({uu: $scope.customer.uu}, null, function (data) {
|
|
|
+ $scope.custInfos = data;
|
|
|
+ var getPage = function (page, size) {
|
|
|
+ if ($scope.custInfos) {
|
|
|
+ var result = {};
|
|
|
+ result.totalCount = $scope.custInfos.length;
|
|
|
+ result.content = $scope.custInfos.slice((page - 1) * size, page * size);
|
|
|
+ if ($scope.custInfos.length % size == 0) {
|
|
|
+ result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
|
|
|
+ } else {
|
|
|
+ result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
|
|
|
+ }
|
|
|
+ result.first = page == 1;
|
|
|
+ result.last = page == result.totalPage;
|
|
|
+ result.page = page;
|
|
|
+ result.next = page - 0 + 1;
|
|
|
+ result.pre = page - 1;
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $scope.userdata = getPage(1, 4);
|
|
|
+ $scope.first = function () {
|
|
|
+ $scope.userdata = getPage($scope.userdata.pre, 4);
|
|
|
+ }
|
|
|
+ $scope.last = function () {
|
|
|
+ $scope.userdata = getPage($scope.userdata.next, 4);
|
|
|
+ }
|
|
|
+ }, function (response) {
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('error', '数据加载失败', response.data);
|
|
|
+ });
|
|
|
+ }, function (response) {
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('error', '数据加载失败', response.data);
|
|
|
+ });
|
|
|
+ };
|
|
|
+ loadData();
|
|
|
+
|
|
|
+ // 新增客户联系人
|
|
|
+ $scope.addContact = function (uu) {
|
|
|
+ var modalInstance = $modal.open({
|
|
|
+ animation: true,
|
|
|
+ templateUrl: 'static/tpl/index/sale/contact_person_modal.html',
|
|
|
+ controller: 'AddContacCtrl',
|
|
|
+ resolve: {}
|
|
|
+ });
|
|
|
+ modalInstance.result.then(function (data) {
|
|
|
+ $scope.contact = data;
|
|
|
+ $scope.contact.myenuu = uu;
|
|
|
+ Vendor.saveCustContact({}, $scope.contact, function (data) {
|
|
|
+ toaster.pop('success', '提示', '联系人保存成功');
|
|
|
+ $scope.Contacts.push(data);
|
|
|
+ }, function (response) {
|
|
|
+ toaster.pop('error', '失败', response.data);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 编辑客户联系人
|
|
|
+ $scope.edit = function (contact) {
|
|
|
+ var modalInstance = $modal.open({
|
|
|
+ animation: true,
|
|
|
+ templateUrl: 'static/tpl/index/sale/contact_person_modal.html',
|
|
|
+ controller: 'EditContacCtrl',
|
|
|
+ resolve: {
|
|
|
+ contact: function () {
|
|
|
+ return contact;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ modalInstance.result.then(function (data) {
|
|
|
+ Vendor.saveContact({}, data, function (data) {
|
|
|
+ loadData();
|
|
|
+ toaster.pop('success', '提示', '联系人修改成功');
|
|
|
+ }, function (response) {
|
|
|
+ toaster.pop('error', '失败', response.data);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除客户联系人
|
|
|
+ $scope.deleteById = function (id, index) {
|
|
|
+ $scope.Contacts.splice(index, 1);
|
|
|
+ Vendor.deleteContact({id: id}, {}, function (data) {
|
|
|
+ toaster.pop('success', '提示', '客户联系人删除成功');
|
|
|
+ loadData();
|
|
|
+ }, function (response) {
|
|
|
+ toaster.pop('error', '提示', response.data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 供应商物料信息
|
|
|
+ $scope.viewProdList = function (uu) {
|
|
|
+ $scope.uu = uu;
|
|
|
+ $scope.tableParams.page(1);
|
|
|
+ $scope.tableParams.reload();
|
|
|
+ };
|
|
|
+
|
|
|
+ // 搜索框回车
|
|
|
+ $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.custUU = $scope.uu;
|
|
|
+ pageParams.keyword = $scope.keyword;
|
|
|
+ $scope.tip = $scope.keyword;
|
|
|
+ Product.get.call(null, BaseService.parseParams(pageParams), function (page) {
|
|
|
+ $scope.loading = false;
|
|
|
+ if (page) {
|
|
|
+ params.total(page.totalElement);
|
|
|
+ $scope.total = page.totalElement;
|
|
|
+ $defer.resolve(page.content);
|
|
|
+ $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
|
|
|
+ }
|
|
|
+ }, function (response) {
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('error', '数据加载失败', response.data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ $scope.addUserInfo = function () {
|
|
|
+ //TODO
|
|
|
+ if ($scope.thisUser.sys) {
|
|
|
+ var modalInstance = $modal.open({
|
|
|
+ animation: true,
|
|
|
+ templateUrl: 'static/tpl/index/account/add_userInfo.html',
|
|
|
+ controller: 'AddUserInfoCtrl',
|
|
|
+ resolve: {
|
|
|
+ customer: function () {
|
|
|
+ return $scope.customerInfo;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ modalInstance.result.then(function (changed, checked) {
|
|
|
+ loadData();
|
|
|
+ if (changed) {
|
|
|
+ if (checked) {
|
|
|
+ $scope.newUser.roles = checked;
|
|
|
+ } else {
|
|
|
+ loadUsers();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ } else {
|
|
|
+ toaster.pop('error', '您不是管理员,无权限分配用户!');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $scope.Quotation = function (uu, id) {
|
|
|
+ $rootScope.custuu = uu;
|
|
|
+ $rootScope.prodId = id;
|
|
|
+ window.location.hash = "#/sale/quotation/new";
|
|
|
+ }
|
|
|
+ }]);
|
|
|
+});
|