|
|
@@ -10,419 +10,455 @@ define(['app/app'], function (app) {
|
|
|
/**
|
|
|
* 客户采购订单
|
|
|
*/
|
|
|
- app.register.controller('saleOrderCtrl', ['$scope', '$filter', 'ngTableParams', 'toaster', 'BaseService', '$timeout', '$modal', 'B2bSearchFilter', '$http', '$rootScope', 'B2bCommerce',
|
|
|
- function ($scope, $filter, ngTableParams, toaster, BaseService, $timeout, $modal, SearchFilter, $http, $rootScope, B2bCommerce) {
|
|
|
- BaseService.scrollBackToTop();
|
|
|
- $rootScope.active = 'vendor_order';
|
|
|
- $rootScope.autoMonth = false;
|
|
|
- $scope.storeType = 'order';
|
|
|
- $scope.active = 'todo';
|
|
|
- $scope.dateZoneText = '不限';
|
|
|
- $scope.deliveryZoneText = '不限';
|
|
|
- $scope.condition = {dateZone: 1, deliveryZone: -1};
|
|
|
- /* 时间筛选初始化*/
|
|
|
- var fromDate = new Date();
|
|
|
- var toDate = new Date();
|
|
|
- fromDate.setMonth(fromDate.getMonth() - 1);
|
|
|
- fromDate.setHours(0, 0, 0, 0);
|
|
|
- toDate.setHours(23, 59, 59, 999);
|
|
|
- $scope.condition.dateFrom = fromDate;
|
|
|
- $scope.condition.dateTo = toDate;
|
|
|
-
|
|
|
- $scope.changeDateZone = function (zone) {
|
|
|
- $scope.condition.dateZone = zone;
|
|
|
- $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
|
|
|
- $scope.condition.$dateZoneOpen = false;
|
|
|
- SearchFilter.getDateCondition(zone, $scope.condition);
|
|
|
- $scope.tableParams.page(1);
|
|
|
- $scope.tableParams.reload();
|
|
|
- };
|
|
|
- $scope.changeDeliveryZone = function (zone) {
|
|
|
- $scope.condition.deliveryZoneText = zone;
|
|
|
- $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
|
|
|
- $scope.condition.$delievryZoneOpen = false;
|
|
|
- SearchFilter.getDeliveryCondition(zone, $scope.condition);
|
|
|
- $scope.tableParams.reload();
|
|
|
- };
|
|
|
- $scope.nowdate = new Date();
|
|
|
- // 切换单据类型
|
|
|
- $scope.setActive = function (state) {
|
|
|
- if ($scope.active != state) {
|
|
|
- $scope.active = state;
|
|
|
- if ($scope.tableParams.page() == 1)
|
|
|
- $scope.tableParams.reload();
|
|
|
- else
|
|
|
- $scope.tableParams.page(1);
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- // 打开日期选择框
|
|
|
- $scope.openChooseDatePicker = function ($event, item, openParam, status) {
|
|
|
- if (status != null) {
|
|
|
- if (status == 1) {
|
|
|
- if ($scope.startDate != null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- if (status == 2) {
|
|
|
- if ($scope.endDate != null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- $event.preventDefault();
|
|
|
- $event.stopPropagation();
|
|
|
- item[openParam] = !item[openParam];
|
|
|
- if (openParam == 'startDateOpen'){
|
|
|
- if (item['endDateOpen']){
|
|
|
- item['endDateOpen'] = !item['endDateOpen'];
|
|
|
- }
|
|
|
- } else if(openParam == 'endDateOpen'){
|
|
|
- if (item['startDateOpen']){
|
|
|
- item['startDateOpen'] = !item['startDateOpen'];
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- // 选择查找日期
|
|
|
- $scope.onDateCondition = function () {
|
|
|
- $scope.param.page = 1;
|
|
|
- $scope.tableParams.page(1);
|
|
|
- $scope.tableParams.reload();
|
|
|
- };
|
|
|
-
|
|
|
- /**
|
|
|
- * 先获取B2B访问路径再进行下一步操作
|
|
|
- */
|
|
|
- B2bCommerce.accessUrl({}, function (data) {
|
|
|
- var b2bUrl = data.url;
|
|
|
-
|
|
|
- // 分页获取列表数据
|
|
|
- $scope.tableParams = new ngTableParams({ // ng-Table参数
|
|
|
- page: 1,
|
|
|
- count: 20,
|
|
|
- sorting: {
|
|
|
- date: 'desc',
|
|
|
- id: 'desc'
|
|
|
- }
|
|
|
- }, {
|
|
|
- total: 0,
|
|
|
- counts: [5, 10, 15, 25, 50],
|
|
|
- getData: function ($defer, params) { // 获取数据的方法
|
|
|
- $scope.loading = true;
|
|
|
- var param = BaseService.parseParams(params.url());
|
|
|
- param.searchFilter = { // 筛选条件
|
|
|
- keyword: $scope.keyword,
|
|
|
- fromDate: SearchFilter.getDateTime($scope.condition.dateFrom),
|
|
|
- endDate: SearchFilter.getDateTime($scope.condition.dateTo)
|
|
|
- };
|
|
|
- param._state = $scope.active;
|
|
|
- $http({
|
|
|
- method: 'get',
|
|
|
- dataType: 'json',
|
|
|
- url: b2bUrl + "/sale/orders/info/nosearch",
|
|
|
- params: param
|
|
|
- }).success(function (data) {
|
|
|
- params.total(data.totalElement);
|
|
|
- $defer.resolve(data.content);
|
|
|
- $scope.searchFilterXls = angular.copy(param.searchFilter);//保存当前取值的条件
|
|
|
- }).error(function (response) {
|
|
|
- toaster.pop('error', response);
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- //获得各分类未阅读数量
|
|
|
- /* var getUnreadCount = function () {
|
|
|
- PurcOrderItem.getUnreadCount(null, function (data) {
|
|
|
- $scope.unread = data;
|
|
|
- });
|
|
|
- };
|
|
|
- getUnreadCount();*/
|
|
|
-
|
|
|
- //设置单据已读
|
|
|
- /* $scope.setOrdersRead = function (id) {
|
|
|
- // 如果单据本身已读,则不发送请求修改数据
|
|
|
- if (!$scope.isUnread(id)){
|
|
|
- return;
|
|
|
- }
|
|
|
- var sourceId = [];
|
|
|
- sourceId.push(id);
|
|
|
- PurcOrderItem.setRead({}, sourceId, function (message) {
|
|
|
- getUnreadCount();
|
|
|
- });
|
|
|
- };*/
|
|
|
-
|
|
|
- //批量设置单据已读
|
|
|
- /* $scope.setOrdersReadByBatch = function () {
|
|
|
- var sourceId = [];
|
|
|
- angular.forEach($scope.tableParams.data, function (order) {
|
|
|
- if (order.$selected == true) {
|
|
|
- sourceId.push(order.id);
|
|
|
- }
|
|
|
- });
|
|
|
- PurcOrderItem.setRead({}, sourceId, function (message) {
|
|
|
- getUnreadCount();
|
|
|
- });
|
|
|
- };*/
|
|
|
-
|
|
|
- /* $scope.setOrdersReadByState = function () {
|
|
|
- if (!$scope.unread.replied || $scope.unread.replied == 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
- PurcOrderItem.setReadByState({}, function () {
|
|
|
- getUnreadIds();
|
|
|
- getUnreadCount();
|
|
|
- });
|
|
|
- };*/
|
|
|
-
|
|
|
- /* var getUnreadIds = function () {
|
|
|
- PurcOrderItem.getUnreadIds({}, "", function (message) {
|
|
|
- $scope.unreadCode = message.content;
|
|
|
- });
|
|
|
- };*/
|
|
|
- // getUnreadIds();
|
|
|
- /*$scope.isUnread = function (id) {
|
|
|
- for (var i in $scope.unreadCode) {
|
|
|
- if (id == $scope.unreadCode[i]) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- };*/
|
|
|
-
|
|
|
- $scope.getOrderTotal = function (items) {
|
|
|
- var sum = 0;
|
|
|
- angular.forEach(items, function (item) {
|
|
|
- sum += item.qty * item.price;
|
|
|
- });
|
|
|
- return sum;
|
|
|
- };
|
|
|
-
|
|
|
- $scope.openDatePicker = function ($event, item, openParam) {
|
|
|
- $event.preventDefault();
|
|
|
- $event.stopPropagation();
|
|
|
- item[openParam] = !item[openParam];
|
|
|
- };
|
|
|
-
|
|
|
- $scope.openFilterDatePicker = function ($event, item, openParam) {
|
|
|
- $event.preventDefault();
|
|
|
- $event.stopPropagation();
|
|
|
- item[openParam] = !item[openParam];
|
|
|
- if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
|
|
|
- $scope.tableParams.reload();
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- $scope.parseDate = function (dateStr) {
|
|
|
- if (dateStr) {
|
|
|
- return Date.parse(dateStr, 'yyyy-MM-dd');
|
|
|
- }
|
|
|
- return new Date();
|
|
|
- };
|
|
|
-
|
|
|
- // 获取token信息
|
|
|
- $scope.getToken = function() {
|
|
|
- $http({
|
|
|
- method: 'get',
|
|
|
- dataType: 'json',
|
|
|
- url: b2bUrl + "/token?userType=sale"
|
|
|
- }).success(function (data) {
|
|
|
- $scope.token = data.token;
|
|
|
- }).error(function (response) {
|
|
|
- toaster.pop('error', response.data);
|
|
|
- });
|
|
|
- }
|
|
|
+ app.register.controller('saleOrderCtrl', ['$scope', '$filter', 'B2bPurcOrderItem', 'B2bPurcOrder', 'ngTableParams', 'toaster', 'B2bReportService', 'BaseService', 'B2bPagingRelease', 'B2bSnapshotService', 'B2bPurcOrderItemInfo', 'token', 'B2bCurrentRole', '$timeout', '$modal', function ($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService, PagingRelease, SnapshotService, PurcOrderItemInfo, token, CurrentRole, $timeout, $modal) {
|
|
|
+ BaseService.scrollBackToTop();
|
|
|
+
|
|
|
+ // 判断是否为普通用户
|
|
|
+ CurrentRole.isUser({}, {}, function (data) {
|
|
|
+ $scope.isUser = data.isUser;
|
|
|
+ });
|
|
|
+
|
|
|
+ $scope.active = 'todo';
|
|
|
+ $scope.dateZoneText = '不限';
|
|
|
+ $scope.deliveryZoneText = '不限';
|
|
|
+ $scope.condition = {dateZone: 1, deliveryZone: -1};
|
|
|
+ /* 时间筛选初始化*/
|
|
|
+ var fromDate = new Date();
|
|
|
+ var toDate = new Date();
|
|
|
+ fromDate.setMonth(fromDate.getMonth() - 1);
|
|
|
+ fromDate.setHours(0, 0, 0, 0);
|
|
|
+ toDate.setHours(23, 59, 59, 999);
|
|
|
+ $scope.condition.dateFrom = fromDate;
|
|
|
+ $scope.condition.dateTo = toDate;
|
|
|
+
|
|
|
+ $scope.changeDateZone = function (zone) {
|
|
|
+ $scope.condition.dateZone = zone;
|
|
|
+ $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
|
|
|
+ $scope.condition.$dateZoneOpen = false;
|
|
|
+ getDateCondition(zone, $scope.condition);
|
|
|
+ $scope.tableParams.page(1);
|
|
|
+ $scope.tableParams.reload();
|
|
|
+ };
|
|
|
+ $scope.changeDeliveryZone = function (zone) {
|
|
|
+ $scope.condition.deliveryZoneText = zone;
|
|
|
+ $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
|
|
|
+ $scope.condition.$delievryZoneOpen = false;
|
|
|
+ getDelveryCondition(zone, $scope.condition);
|
|
|
+ $scope.tableParams.reload();
|
|
|
+ };
|
|
|
+ $scope.nowdate = new Date();
|
|
|
+ // 切换单据类型
|
|
|
+ $scope.setActive = function (state) {
|
|
|
+ if ($scope.active != state) {
|
|
|
+ $scope.active = state;
|
|
|
+ if ($scope.tableParams.page() == 1)
|
|
|
+ $scope.tableParams.reload();
|
|
|
+ else
|
|
|
+ $scope.tableParams.page(1);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.searchMethod = false;
|
|
|
+ // 切换数据来源(正常数据 or 历史数据)
|
|
|
+ var getService = function () {
|
|
|
+ return $scope.searchMethod ? PurcOrderItem : PurcOrderItemInfo;
|
|
|
+ };
|
|
|
+ $scope.tableParams = new ngTableParams({ // ng-Table参数
|
|
|
+ page: 1,
|
|
|
+ count: 10,
|
|
|
+ sorting: {
|
|
|
+ date: 'desc',
|
|
|
+ id: 'desc'
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ total: 0,
|
|
|
+ counts: [5, 10, 15, 25, 50],
|
|
|
+ getData: function ($defer, params) { // 获取数据的方法
|
|
|
+ $scope.loading = true;
|
|
|
+ var pageParams = params.url();
|
|
|
+ pageParams.searchFilter = { // 筛选条件
|
|
|
+ keyword: $scope.keyword,
|
|
|
+ fromDate: getDateTime($scope.condition.dateFrom),
|
|
|
+ endDate: getDateTime($scope.condition.dateTo)
|
|
|
+ };
|
|
|
+ getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
|
|
|
+ $scope.loading = false;
|
|
|
+ if (page) {
|
|
|
+ $defer.resolve(page.content);
|
|
|
+ params.total(page.totalElement);
|
|
|
+ $scope.infoCommon = page
|
|
|
+ $scope.infoCommon.all = page.content.length
|
|
|
+ $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
|
|
|
+ }
|
|
|
+ }, function (response) {
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('error', '数据加载失败', response.data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- $scope.onReplyClick = function (item, inverse) {
|
|
|
- if (item.reply) {
|
|
|
- if (!item.reply.qty || item.reply.qty < 0 /*|| item.reply.qty > item.qty*/) {
|
|
|
- toaster.pop('warning', '提示', '请填写有效的回复数量!');
|
|
|
- return;
|
|
|
- }
|
|
|
- var reply = angular.copy(item.reply);
|
|
|
- if (reply.delivery) {
|
|
|
- if (typeof reply.delivery == 'object') {
|
|
|
- reply.delivery = reply.delivery.getTime();
|
|
|
- }
|
|
|
- } else {
|
|
|
- reply.delivery = item.delivery;
|
|
|
- }
|
|
|
- // 取相反
|
|
|
- if (inverse && inverse == -1) {
|
|
|
- reply.qty = -1 * reply.qty;
|
|
|
- }
|
|
|
- $scope.loading = true;
|
|
|
- if($scope.token != null) {
|
|
|
- $http({
|
|
|
- method: 'post',
|
|
|
- dataType: 'json',
|
|
|
- url: b2bUrl + "/sale/orders/items/" + item.id + "/reply?token=" + $scope.token,
|
|
|
- data: reply
|
|
|
- }).success(function () {
|
|
|
- $scope.loading = false;
|
|
|
- toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
|
|
|
- $scope.tableParams.reload();
|
|
|
- }).error(function (response) {
|
|
|
- $scope.loading = false;
|
|
|
- toaster.pop('error', '回复失败', response.data);
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- //打印 采购单
|
|
|
- /* $scope.print = function (order) {
|
|
|
- var newPage = window.open("about:blank");
|
|
|
- PurcOrder.printPermission({}, function () {
|
|
|
- PurcOrder.printCount({id: order.id}, {});//增加打印此次 // 在此方法内添加记录日志
|
|
|
- if (order.display == 1) $scope.setDisplay('setRead', order.id);//设置为已查看状态
|
|
|
- ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id , newPage);
|
|
|
- $scope.tableParams.reload();
|
|
|
- },function (response) {
|
|
|
- newPage.close();
|
|
|
- toaster.pop('error', '打印失败', response.data);
|
|
|
- });
|
|
|
- };*/
|
|
|
-
|
|
|
- $scope.getReply = function (item) {
|
|
|
- if (!item.replies) {
|
|
|
- $http({
|
|
|
- method: 'get',
|
|
|
- dataType: 'json',
|
|
|
- url: b2bUrl + "/sale/orders/items/" + item.id + "/reply/all"
|
|
|
- }).success(function (replies) {
|
|
|
- item.replies = replies;
|
|
|
- });
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- $scope.checkboxes = {
|
|
|
- checked: false
|
|
|
- };
|
|
|
-
|
|
|
- // 点击勾选全部的复选框
|
|
|
- $scope.checkAll = function () {
|
|
|
- angular.forEach($scope.tableParams.data, function (item) {
|
|
|
- item.$selected = $scope.checkboxes.checked;
|
|
|
- });
|
|
|
- };
|
|
|
-
|
|
|
- // 点击其中一个明细的复选框
|
|
|
- $scope.checkOne = function (order) {
|
|
|
- var result = true;
|
|
|
- angular.forEach($scope.tableParams.data, function (item) {
|
|
|
- if (item.$selected != true) {
|
|
|
- result = false;
|
|
|
- return;
|
|
|
- }
|
|
|
- });
|
|
|
- $scope.checkboxes.checked = result;
|
|
|
- };
|
|
|
-
|
|
|
- //批量回复采购订单
|
|
|
- $scope.replyByBatch = function () {
|
|
|
- $scope.loading = true;
|
|
|
- var str = '';
|
|
|
- angular.forEach($scope.tableParams.data, function (order) {
|
|
|
- if (order.$selected == true) {
|
|
|
- str += order.id;
|
|
|
- str += ',';
|
|
|
- }
|
|
|
- });
|
|
|
- if (!(str == '')) {
|
|
|
- $scope.loading = false;
|
|
|
- str = str.substr(0, str.length - 1);
|
|
|
- var modalInstance = $modal.open({
|
|
|
- animation: true,
|
|
|
- templateUrl: 'static/view/vendor/b2b/modal/reply_bybatch.html',
|
|
|
- controller: 'ReplyByBatchCtrl',
|
|
|
- resolve: {}
|
|
|
- });
|
|
|
- modalInstance.result.then(function(data) {
|
|
|
- $scope.loading = true;
|
|
|
- var reply = data;
|
|
|
- var date = null;
|
|
|
- if (reply.date && reply.method == 1) {
|
|
|
- date = reply.date.getTime();
|
|
|
- }
|
|
|
- $http({
|
|
|
- method: 'post',
|
|
|
- dataType: 'json',
|
|
|
- url: b2bUrl + "/sale/orders/items/reply?date=" + date,
|
|
|
- data: str
|
|
|
- }).success(function () {
|
|
|
- $scope.loading = false;
|
|
|
- $scope.tableParams.reload();
|
|
|
- toaster.pop('success', '提示', '批量回复成功');
|
|
|
- }), error(function () {
|
|
|
- $scope.loading = false;
|
|
|
- toaster.pop('error', '提示', '批量回复失败');
|
|
|
- });
|
|
|
- });
|
|
|
- } else {//没有勾选其中的明细
|
|
|
- toaster.pop('error', '提示', '请先选择需要回复的单据');
|
|
|
- $scope.loading = false;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- // 搜索框回车
|
|
|
- $scope.onSearch = function () {
|
|
|
- // 每次搜索重置获取数据方法
|
|
|
- $scope.tableParams.page(1);
|
|
|
- $scope.tableParams.reload();
|
|
|
- };
|
|
|
-
|
|
|
- // 选择查找日期
|
|
|
- $scope.onDateCondition = function () {
|
|
|
- $scope.tableParams.page(1);
|
|
|
- $scope.tableParams.reload();
|
|
|
- };
|
|
|
-
|
|
|
- //设置为已查看
|
|
|
- /*$scope.setDisplay = function (state, orderId) {
|
|
|
- if (orderId) {//设置单个
|
|
|
- PurcOrder[state].call({}, {ids: '' + orderId}, function () {
|
|
|
- $scope.tableParams.reload();
|
|
|
- }, function () {
|
|
|
- toaster.pop('error', '错误', "设置失败");
|
|
|
- });
|
|
|
- } else {//设置已勾选的
|
|
|
- var str = null;
|
|
|
- angular.forEach($scope.tableParams.data, function (order) {
|
|
|
- if (order.$selected == true) {
|
|
|
- if (str != null && str != '') str += ',';
|
|
|
- str += order.id;
|
|
|
- }
|
|
|
- });
|
|
|
- if (str != null && str != '') {
|
|
|
- PurcOrder[state].call({}, {ids: '' + str}, function () {
|
|
|
- $scope.tableParams.reload();
|
|
|
- }, function () {
|
|
|
- toaster.pop('error', '错误', "设置失败");
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- };*/
|
|
|
-
|
|
|
- // 导出
|
|
|
- $scope.exportXls = function () {
|
|
|
- $http({
|
|
|
- method: 'get',
|
|
|
- dataType: 'json',
|
|
|
- url: b2bUrl + "/sale/orders/xls/permission"
|
|
|
- }).success(function (data) {
|
|
|
- if (data.success){
|
|
|
- window.location.href = b2bUrl + 'sale/orders/xls?_state=' + $scope.active + '&searchFilter='
|
|
|
- + encodeURIComponent(angular.toJson($scope.searchFilterXls));
|
|
|
- }
|
|
|
- }), error(function (response) {
|
|
|
- toaster.pop('error', '数据加载失败', response.data);
|
|
|
- });
|
|
|
- }
|
|
|
+ //获得各分类未阅读数量
|
|
|
+ var getUnreadCount = function () {
|
|
|
+ PurcOrderItem.getUnreadCount(null, function (data) {
|
|
|
+ $scope.unread = data;
|
|
|
+ });
|
|
|
+ };
|
|
|
+ getUnreadCount();
|
|
|
+
|
|
|
+ //设置单据已读
|
|
|
+ $scope.setOrdersRead = function (id) {
|
|
|
+ // 如果单据本身已读,则不发送请求修改数据
|
|
|
+ if (!$scope.isUnread(id)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var sourceId = [];
|
|
|
+ sourceId.push(id);
|
|
|
+ PurcOrderItem.setRead({}, sourceId, function (message) {
|
|
|
+ getUnreadCount();
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ //批量设置单据已读
|
|
|
+ $scope.setOrdersReadByBatch = function () {
|
|
|
+ var sourceId = [];
|
|
|
+ angular.forEach($scope.tableParams.data, function (order) {
|
|
|
+ if (order.$selected == true) {
|
|
|
+ sourceId.push(order.id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ PurcOrderItem.setRead({}, sourceId, function (message) {
|
|
|
+ getUnreadCount();
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.setOrdersReadByState = function () {
|
|
|
+ if (!$scope.unread.replied || $scope.unread.replied == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ PurcOrderItem.setReadByState({}, function () {
|
|
|
+ getUnreadIds();
|
|
|
+ getUnreadCount();
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ var getUnreadIds = function () {
|
|
|
+ PurcOrderItem.getUnreadIds({}, "", function (message) {
|
|
|
+ $scope.unreadCode = message.content;
|
|
|
+ });
|
|
|
+ };
|
|
|
+ getUnreadIds();
|
|
|
+ $scope.isUnread = function (id) {
|
|
|
+ for (var i in $scope.unreadCode) {
|
|
|
+ if (id == $scope.unreadCode[i]) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.getOrderTotal = function (items) {
|
|
|
+ var sum = 0;
|
|
|
+ angular.forEach(items, function (item) {
|
|
|
+ sum += item.qty * item.price;
|
|
|
+ });
|
|
|
+ return sum;
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.openDatePicker = function ($event, item, openParam) {
|
|
|
+ $event.preventDefault();
|
|
|
+ $event.stopPropagation();
|
|
|
+ item[openParam] = !item[openParam];
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.openFilterDatePicker = function ($event, item, openParam) {
|
|
|
+ $event.preventDefault();
|
|
|
+ $event.stopPropagation();
|
|
|
+ item[openParam] = !item[openParam];
|
|
|
+ if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
|
|
|
+ $scope.tableParams.reload();
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.parseDate = function (dateStr) {
|
|
|
+ if (dateStr)
|
|
|
+ return Date.parse(dateStr, 'yyyy-MM-dd');
|
|
|
+ return new Date();
|
|
|
+ };
|
|
|
+
|
|
|
+ // 获取token信息
|
|
|
+ $scope.getToken = function() {
|
|
|
+ token.info({userType: 'sale'}, {}, function(data) {
|
|
|
+ $scope.token = data.token;
|
|
|
+ }, function(response) {
|
|
|
+ toaster.pop('error', '提示', response.data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ $scope.onReplyClick = function (item, inverse) {
|
|
|
+ if (item.reply) {
|
|
|
+ if (!item.reply.qty || item.reply.qty < 0 /*|| item.reply.qty > item.qty*/) {
|
|
|
+ toaster.pop('warning', '提示', '请填写有效的回复数量!');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var reply = angular.copy(item.reply);
|
|
|
+ if (reply.delivery) {
|
|
|
+ if (typeof reply.delivery == 'object')
|
|
|
+ reply.delivery = reply.delivery.getTime();
|
|
|
+ } else {
|
|
|
+ reply.delivery = item.delivery;
|
|
|
+ }
|
|
|
+ if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
|
|
|
+ $scope.loading = true;
|
|
|
+ if($scope.token != null) {
|
|
|
+ PurcOrderItem.reply({orderItemId: item.id, token: $scope.token}, reply, function () {
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
|
|
|
+ $scope.tableParams.reload();
|
|
|
+ }, function (response) {
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('error', '回复失败', response.data);
|
|
|
});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ //打印 采购单
|
|
|
+ $scope.print = function (order) {
|
|
|
+ var newPage = window.open("about:blank");
|
|
|
+ PurcOrder.printPermission({}, function () {
|
|
|
+ PurcOrder.printCount({id: order.id}, {});//增加打印此次 // 在此方法内添加记录日志
|
|
|
+ if (order.display == 1) $scope.setDisplay('setRead', order.id);//设置为已查看状态
|
|
|
+ ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id , newPage);
|
|
|
+ $scope.tableParams.reload();
|
|
|
+ },function (response) {
|
|
|
+ newPage.close();
|
|
|
+ toaster.pop('error', '打印失败', response.data);
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.getReply = function (item) {
|
|
|
+ if (!item.replies) {
|
|
|
+ PurcOrderItem.getReply({orderItemId: item.id}, function (replies) {
|
|
|
+ item.replies = replies;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.checkboxes = {
|
|
|
+ checked: false
|
|
|
+ };
|
|
|
+
|
|
|
+ // 点击勾选全部的复选框
|
|
|
+ $scope.checkAll = function () {
|
|
|
+ angular.forEach($scope.tableParams.data, function (item) {
|
|
|
+ item.$selected = $scope.checkboxes.checked;
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ // 点击其中一个明细的复选框
|
|
|
+ $scope.checkOne = function (order) {
|
|
|
+ var result = true;
|
|
|
+ angular.forEach($scope.tableParams.data, function (item) {
|
|
|
+ if (item.$selected != true) {
|
|
|
+ result = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $scope.checkboxes.checked = result;
|
|
|
+ };
|
|
|
+
|
|
|
+ //批量回复采购订单
|
|
|
+ $scope.replyByBatch = function () {
|
|
|
+ $scope.loading = true;
|
|
|
+ var str = '';
|
|
|
+ angular.forEach($scope.tableParams.data, function (order) {
|
|
|
+ if (order.$selected == true) {
|
|
|
+ str += order.id;
|
|
|
+ str += ',';
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (!(str == '')) {
|
|
|
+ $scope.loading = false;
|
|
|
+ str = str.substr(0, str.length - 1);
|
|
|
+ var modalInstance = $modal.open({
|
|
|
+ animation: true,
|
|
|
+ templateUrl: 'static/view/vendor/b2b/modal/reply_bybatch.html',
|
|
|
+ controller: 'ReplyByBatchCtrl',
|
|
|
+ resolve: {}
|
|
|
+ });
|
|
|
+ modalInstance.result.then(function(data) {
|
|
|
+ $scope.loading = true;
|
|
|
+ var reply = data;
|
|
|
+ var date = null;
|
|
|
+ if (reply.date && reply.method == 1) {
|
|
|
+ date = reply.date.getTime();
|
|
|
+ }
|
|
|
+ PurcOrderItem.replyByBatch({date: date}, str, function () {
|
|
|
+ $scope.loading = false;
|
|
|
+ $scope.tableParams.reload();
|
|
|
+ toaster.pop('success', '提示', '批量回复成功');
|
|
|
+ }, function (response) {
|
|
|
+ $scope.loading = false;
|
|
|
+ toaster.pop('error', '提示', '批量回复失败');
|
|
|
+ });
|
|
|
+ });
|
|
|
+ } else {//没有勾选其中的明细
|
|
|
+ toaster.pop('error', '提示', '请先选择需要回复的单据');
|
|
|
+ $scope.loading = false;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ // 搜索框回车
|
|
|
+ $scope.onSearch = function (keyword) {
|
|
|
+ // 每次搜索重置获取数据方法
|
|
|
+ $scope.searchMethod = false;
|
|
|
+ if(keyword != null && keyword != '') {
|
|
|
+ $scope.searchMethod = true;
|
|
|
+ }
|
|
|
+ $scope.tableParams.page(1);
|
|
|
+ $scope.tableParams.reload();
|
|
|
+ };
|
|
|
+ // 选择查找日期
|
|
|
+ $scope.onDateCondition = function () {
|
|
|
+ $scope.tableParams.page(1);
|
|
|
+ $scope.tableParams.reload();
|
|
|
+ };
|
|
|
+ //设置为已查看
|
|
|
+ $scope.setDisplay = function (state, orderId) {
|
|
|
+ if (orderId) {//设置单个
|
|
|
+ PurcOrder[state].call({}, {ids: '' + orderId}, function () {
|
|
|
+ $scope.tableParams.reload();
|
|
|
+ }, function () {
|
|
|
+ toaster.pop('error', '错误', "设置失败");
|
|
|
+ });
|
|
|
+ } else {//设置已勾选的
|
|
|
+ var str = null;
|
|
|
+ angular.forEach($scope.tableParams.data, function (order) {
|
|
|
+ if (order.$selected == true) {
|
|
|
+ if (str != null && str != '') str += ',';
|
|
|
+ str += order.id;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (str != null && str != '') {
|
|
|
+ PurcOrder[state].call({}, {ids: '' + str}, function () {
|
|
|
+ $scope.tableParams.reload();
|
|
|
+ }, function () {
|
|
|
+ toaster.pop('error', '错误', "设置失败");
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 导出
|
|
|
+ $scope.exportXls = function () {
|
|
|
+ PurcOrderItem.exportXls({}, {}, function (data) {
|
|
|
+ if (data.success){
|
|
|
+ window.location.href = 'sale/orders/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
|
|
|
+ }
|
|
|
+ }, function (response) {
|
|
|
+ toaster.pop('error', '数据加载失败', response.data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将日期转化为整数日期
|
|
|
+ */
|
|
|
+ var getDateTime = function (date) {
|
|
|
+ if (angular.isDate(date)) {
|
|
|
+ return date.getTime();
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面状态按钮过滤
|
|
|
+ */
|
|
|
+ var getState = function (active) {
|
|
|
+ var fn = 'get';
|
|
|
+ switch (active) {
|
|
|
+ case 'done':
|
|
|
+ fn = 'getDone';
|
|
|
+ break;
|
|
|
+ case 'todo':
|
|
|
+ fn = 'getTodo';
|
|
|
+ break;
|
|
|
+ case 'end':
|
|
|
+ fn = 'getEnd';
|
|
|
+ break;
|
|
|
+ case 'waiting':
|
|
|
+ fn = 'getWaiting';
|
|
|
+ break;
|
|
|
+ case 'received':
|
|
|
+ fn = 'getReceived';
|
|
|
+ break;
|
|
|
+ case 'invalid':
|
|
|
+ fn = 'getInvalid';
|
|
|
+ break;
|
|
|
+ // 已采纳
|
|
|
+ case 'agreed':
|
|
|
+ fn = 'getAgreed';
|
|
|
+ break;
|
|
|
+ // 未采纳
|
|
|
+ case 'refused':
|
|
|
+ fn = 'getRefused';
|
|
|
+ break;
|
|
|
+ // 个人
|
|
|
+ case 'personal':
|
|
|
+ fn = 'getPersonal';
|
|
|
+ break;
|
|
|
+ // 集体
|
|
|
+ case 'teams':
|
|
|
+ fn = 'getTeams';
|
|
|
+ break;
|
|
|
+ // 非标准
|
|
|
+ case 'nonstandard':
|
|
|
+ fn = 'getNonstandard';
|
|
|
+ break;
|
|
|
+ // 标准
|
|
|
+ case 'standard':
|
|
|
+ fn = 'getStandard';
|
|
|
+ break;
|
|
|
+ // 变更单无需确认
|
|
|
+ case 'unread':
|
|
|
+ fn = 'getUnread';
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return fn;
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 改变单据日期范围
|
|
|
+ */
|
|
|
+ var getDateCondition = function (zone, condition) {
|
|
|
+ var fromDate = new Date();
|
|
|
+ var toDate = new Date();
|
|
|
+ //去除时分秒限制,dateFrom设置成0时0分0秒,dateTo设置成23时59分59秒
|
|
|
+ fromDate.setHours(0, 0, 0, 0);
|
|
|
+ toDate.setHours(23, 59, 59, 999);
|
|
|
+ if (zone == -1) { // 自定义时间,什么都不做
|
|
|
+
|
|
|
+ } else if (zone == 1) {
|
|
|
+ fromDate.setMonth(fromDate.getMonth() - 1);
|
|
|
+ condition.dateFrom = fromDate;
|
|
|
+ condition.dateTo = toDate;
|
|
|
+ } else if (zone == 3) {
|
|
|
+ fromDate.setMonth(fromDate.getMonth() - 3);
|
|
|
+ condition.dateFrom = fromDate;
|
|
|
+ condition.dateTo = toDate;
|
|
|
+ } else if (zone == 6) {
|
|
|
+ fromDate.setMonth(fromDate.getMonth() - 6);
|
|
|
+ condition.dateFrom = fromDate;
|
|
|
+ condition.dateTo = toDate;
|
|
|
+ } else {
|
|
|
+ condition.dateFrom = null;
|
|
|
+ condition.dateTo = null;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
}]);
|
|
|
|
|
|
- /**
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
* 批量回复模态框
|
|
|
*/
|
|
|
app.register.controller('ReplyByBatchCtrl', ['$scope', '$modalInstance', '$filter', 'toaster', function($scope, $modalInstance, $filter, toaster) {
|